1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PINAUTH_SECRET_H
17 #define PINAUTH_SECRET_H
18 
19 #include <cstdint>
20 #include <openssl/evp.h>
21 #include <vector>
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace PinAuth {
27 enum AuthType : uint32_t {
28     ALGO_VERSION_V0 = 0,
29     ALGO_VERSION_V1 = 1,
30     ALGO_VERSION_V2 = 2,
31     ALGO_VERSION_V3 = 3
32 };
33 
34 class Scrypt : public NoCopyable {
35 public:
Scrypt(std::vector<uint8_t> algoParameter)36     explicit Scrypt(std::vector<uint8_t> algoParameter) : algoParameter_(std::move(algoParameter)) {}
37     ~Scrypt() override = default;
38     std::vector<uint8_t> GetScrypt(const std::vector<uint8_t> &data, uint32_t algoVersion);
39 
40 private:
41     bool DoScrypt(const std::vector<uint8_t> &data, uint32_t algoVersion, EVP_PKEY_CTX *pctx);
42     std::vector<uint8_t> algoParameter_ = {};
43 };
44 } // namespace PinAuth
45 } // namespace UserIam
46 } // namespace OHOS
47 
48 #endif // PINAUTH_SECRET_H