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 NAPI_CRYPTO_FRAMEWORK_DEFINES_H
17 #define NAPI_CRYPTO_FRAMEWORK_DEFINES_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 namespace OHOS {
23 namespace CryptoFramework {
24 constexpr size_t CALLBACK_SIZE = 1;
25 constexpr size_t ARGS_SIZE_ONE = 1;
26 constexpr size_t ARGS_SIZE_TWO = 2;
27 constexpr size_t ARGS_SIZE_THREE = 3;
28 constexpr size_t ARGS_SIZE_FOUR = 4;
29 constexpr size_t GCM_AUTH_TAG_LEN = 16;
30 constexpr size_t CCM_AUTH_TAG_LEN = 12;
31 constexpr int32_t PARAM0 = 0;
32 constexpr int32_t PARAM1 = 1;
33 constexpr int32_t PARAM2 = 2;
34 constexpr uint32_t JS_ERR_DEFAULT_ERR = 0;
35 constexpr uint32_t JS_ERR_INVALID_PARAMS = 401;
36 constexpr uint32_t JS_ERR_NOT_SUPPORT = 801;
37 constexpr uint32_t JS_ERR_OUT_OF_MEMORY = 17620001;
38 constexpr uint32_t JS_ERR_RUNTIME_ERROR = 17620002;
39 constexpr uint32_t JS_ERR_CRYPTO_OPERATION = 17630001;
40 
41 constexpr int32_t SPEC_ITEM_TYPE_BIG_INT = 1;
42 constexpr int32_t SPEC_ITEM_TYPE_NUM = 2;
43 constexpr int32_t SPEC_ITEM_TYPE_STR = 3;
44 constexpr int32_t SPEC_ITEM_TYPE_UINT8ARR = 4;
45 
46 const std::string CRYPTO_TAG_DATA = "data";
47 const std::string CRYPTO_TAG_ERR_CODE = "code";
48 const std::string CRYPTO_TAG_ERR_MSG = "message";
49 const std::string CRYPTO_TAG_ALG_NAME = "algName";
50 const std::string CRYPTO_TAG_FORMAT = "format";
51 const std::string CRYPTO_TAG_PUB_KEY = "pubKey";
52 const std::string CRYPTO_TAG_PRI_KEY = "priKey";
53 const std::string CRYPTO_TAG_COMM_PARAMS = "params";
54 const std::string IV_PARAMS = "iv";
55 const std::string AAD_PARAMS = "aad";
56 const std::string AUTHTAG_PARAMS = "authTag";
57 const std::string ALGO_PARAMS = "algName";
58 const std::string ALGO_PARAMS_OLD = "algoName";
59 const std::string IV_PARAMS_SPEC = "IvParamsSpec";
60 const std::string GCM_PARAMS_SPEC = "GcmParamsSpec";
61 const std::string CCM_PARAMS_SPEC = "CcmParamsSpec";
62 
63 const std::string DSA_ASY_KEY_SPEC = "DSA";
64 const std::string ECC_ASY_KEY_SPEC = "ECC";
65 const std::string RSA_ASY_KEY_SPEC = "RSA";
66 const std::string X25519_ASY_KEY_SPEC = "X25519";
67 const std::string ED25519_ASY_KEY_SPEC = "Ed25519";
68 const std::string DH_ASY_KEY_SPEC = "DH";
69 const std::string SM2_ASY_KEY_SPEC = "SM2";
70 const std::string TAG_SPEC_TYPE = "specType";
71 const std::string DSA_COMM_ASY_KEY_SPEC = "DsaCommParamsSpec";
72 const std::string DSA_PUB_ASY_KEY_SPEC = "DsaPubKeyParamsSpec";
73 const std::string DSA_KEYPAIR_ASY_KEY_SPEC = "DsaKeyPairParamsSpec";
74 
75 const std::string ECC_COMM_ASY_KEY_SPEC = "EccCommParamsSpec";
76 const std::string ECC_PRI_ASY_KEY_SPEC = "EccPriKeyParamsSpec";
77 const std::string ECC_PUB_ASY_KEY_SPEC = "EccPubKeyParamsSpec";
78 const std::string ECC_KEYPAIR_ASY_KEY_SPEC = "EccKeyPairParamsSpec";
79 const std::string ECC_FIELD_TYPE_FP = "Fp";
80 
81 const std::string RSA_COMM_ASY_KEY_SPEC = "RsaCommParamsSpec";
82 const std::string RSA_PUB_ASY_KEY_SPEC = "RsaPubKeyParamsSpec";
83 const std::string RSA_KEYPAIR_ASY_KEY_SPEC = "RsaKeyPairParamsSpec";
84 
85 const std::string PBKDF2_ALG_NAME = "PBKDF2";
86 const std::string PBKDF2_PARAMS_ITER = "iterations";
87 const std::string PBKDF2_PARAMS_PASSWORD = "password";
88 
89 const std::string SM2_UTIL_PARAM_X_COORDINATE = "xCoordinate";
90 const std::string SM2_UTIL_PARAM_Y_COORDINATE = "yCoordinate";
91 const std::string SM2_UTIL_PARAM_CIPHER_TEXT_DATA = "cipherTextData";
92 const std::string SM2_UTIL_PARAM_HASH_DATA = "hashData";
93 
94 const std::string KDF_PARAMS_SALT = "salt";
95 const std::string KDF_PARAMS_KEY_SIZE = "keySize";
96 
97 const std::string HKDF_ALG_NAME = "HKDF";
98 const std::string HKDF_PARAMS_KEY = "key";
99 const std::string HKDF_PARAMS_INFO = "info";
100 
101 } // namespace CryptoFramework
102 } // namespace OHOS
103 
104 #endif // NAPI_CRYPTO_FRAMEWORK_DEFINES_H
105