1526fd984Sopenharmony_ci/* 2526fd984Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3526fd984Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4526fd984Sopenharmony_ci * you may not use this file except in compliance with the License. 5526fd984Sopenharmony_ci * You may obtain a copy of the License at 6526fd984Sopenharmony_ci * 7526fd984Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8526fd984Sopenharmony_ci * 9526fd984Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10526fd984Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11526fd984Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12526fd984Sopenharmony_ci * See the License for the specific language governing permissions and 13526fd984Sopenharmony_ci * limitations under the License. 14526fd984Sopenharmony_ci */ 15526fd984Sopenharmony_ci 16526fd984Sopenharmony_ci#include "hks_lite_api.h" 17526fd984Sopenharmony_ci#include "hks_lite_api_common.h" 18526fd984Sopenharmony_ci#include "hks_type.h" 19526fd984Sopenharmony_ci 20526fd984Sopenharmony_ci#include "jsi.h" 21526fd984Sopenharmony_ci 22526fd984Sopenharmony_cinamespace OHOS { 23526fd984Sopenharmony_cinamespace ACELite { 24526fd984Sopenharmony_ci 25526fd984Sopenharmony_civoid AddInt32PropertyInLite(JSIValue object, const char *name, int32_t value) 26526fd984Sopenharmony_ci{ 27526fd984Sopenharmony_ci JSIValue numberProperty = JSI::CreateNumber(value); 28526fd984Sopenharmony_ci JSI::SetNamedProperty(object, name, numberProperty); 29526fd984Sopenharmony_ci} 30526fd984Sopenharmony_ci 31526fd984Sopenharmony_cistatic JSIValue CreateHuksErrCode(void) 32526fd984Sopenharmony_ci{ 33526fd984Sopenharmony_ci JSIValue errorCode = JSI::CreateObject(); 34526fd984Sopenharmony_ci 35526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_PERMISSION_FAIL", HUKS_ERR_CODE_PERMISSION_FAIL); 36526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_NOT_SYSTEM_APP", HUKS_ERR_CODE_NOT_SYSTEM_APP); 37526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_ILLEGAL_ARGUMENT", HUKS_ERR_CODE_ILLEGAL_ARGUMENT); 38526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_NOT_SUPPORTED_API", HUKS_ERR_CODE_NOT_SUPPORTED_API); 39526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED", HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED); 40526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT", 41526fd984Sopenharmony_ci HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT); 42526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT", 43526fd984Sopenharmony_ci HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT); 44526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_FILE_OPERATION_FAIL", HUKS_ERR_CODE_FILE_OPERATION_FAIL); 45526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_COMMUNICATION_FAIL", HUKS_ERR_CODE_COMMUNICATION_FAIL); 46526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_CRYPTO_FAIL", HUKS_ERR_CODE_CRYPTO_FAIL); 47526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_KEY_AUTH_PERMANENTLY_INVALIDATED", 48526fd984Sopenharmony_ci HUKS_ERR_CODE_KEY_AUTH_PERMANENTLY_INVALIDATED); 49526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_KEY_AUTH_VERIFY_FAILED", HUKS_ERR_CODE_KEY_AUTH_VERIFY_FAILED); 50526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_KEY_AUTH_TIME_OUT", HUKS_ERR_CODE_KEY_AUTH_TIME_OUT); 51526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_SESSION_LIMIT", HUKS_ERR_CODE_SESSION_LIMIT); 52526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_ITEM_NOT_EXIST", HUKS_ERR_CODE_ITEM_NOT_EXIST); 53526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_EXTERNAL_ERROR", HUKS_ERR_CODE_EXTERNAL_ERROR); 54526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_CREDENTIAL_NOT_EXIST", HUKS_ERR_CODE_CREDENTIAL_NOT_EXIST); 55526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_INSUFFICIENT_MEMORY", HUKS_ERR_CODE_INSUFFICIENT_MEMORY); 56526fd984Sopenharmony_ci AddInt32PropertyInLite(errorCode, "HUKS_ERR_CODE_CALL_SERVICE_FAILED", HUKS_ERR_CODE_CALL_SERVICE_FAILED); 57526fd984Sopenharmony_ci 58526fd984Sopenharmony_ci return errorCode; 59526fd984Sopenharmony_ci} 60526fd984Sopenharmony_ci 61526fd984Sopenharmony_cistatic JSIValue CreateHuksKeyPurpose(void) 62526fd984Sopenharmony_ci{ 63526fd984Sopenharmony_ci JSIValue keyPurpose = JSI::CreateObject(); 64526fd984Sopenharmony_ci 65526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPurpose, "HUKS_KEY_PURPOSE_ENCRYPT", HKS_KEY_PURPOSE_ENCRYPT); 66526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPurpose, "HUKS_KEY_PURPOSE_DECRYPT", HKS_KEY_PURPOSE_DECRYPT); 67526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPurpose, "HUKS_KEY_PURPOSE_SIGN", HKS_KEY_PURPOSE_SIGN); 68526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPurpose, "HUKS_KEY_PURPOSE_VERIFY", HKS_KEY_PURPOSE_VERIFY); 69526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPurpose, "HUKS_KEY_PURPOSE_MAC", HKS_KEY_PURPOSE_MAC); 70526fd984Sopenharmony_ci 71526fd984Sopenharmony_ci return keyPurpose; 72526fd984Sopenharmony_ci} 73526fd984Sopenharmony_ci 74526fd984Sopenharmony_cistatic JSIValue CreateHuksKeyPadding(void) 75526fd984Sopenharmony_ci{ 76526fd984Sopenharmony_ci JSIValue keyPadding = JSI::CreateObject(); 77526fd984Sopenharmony_ci 78526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_NONE", HKS_PADDING_NONE); 79526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_PKCS7", HKS_PADDING_PKCS7); 80526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_PKCS1_V1_5", HKS_PADDING_PKCS1_V1_5); 81526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_OAEP", HKS_PADDING_OAEP); 82526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_PSS", HKS_PADDING_PSS); 83526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_ISO_IEC_9796_2", HKS_PADDING_ISO_IEC_9796_2); 84526fd984Sopenharmony_ci AddInt32PropertyInLite(keyPadding, "HUKS_PADDING_ISO_IEC_9797_1", HKS_PADDING_ISO_IEC_9797_1); 85526fd984Sopenharmony_ci 86526fd984Sopenharmony_ci return keyPadding; 87526fd984Sopenharmony_ci} 88526fd984Sopenharmony_ci 89526fd984Sopenharmony_cistatic JSIValue CreateHuksCipherMode(void) 90526fd984Sopenharmony_ci{ 91526fd984Sopenharmony_ci JSIValue keyCipherMode = JSI::CreateObject(); 92526fd984Sopenharmony_ci 93526fd984Sopenharmony_ci AddInt32PropertyInLite(keyCipherMode, "HUKS_MODE_ECB", HKS_MODE_ECB); 94526fd984Sopenharmony_ci AddInt32PropertyInLite(keyCipherMode, "HUKS_MODE_CBC", HKS_MODE_CBC); 95526fd984Sopenharmony_ci AddInt32PropertyInLite(keyCipherMode, "HUKS_MODE_CTR", HKS_MODE_CTR); 96526fd984Sopenharmony_ci AddInt32PropertyInLite(keyCipherMode, "HUKS_MODE_GCM", HKS_MODE_GCM); 97526fd984Sopenharmony_ci 98526fd984Sopenharmony_ci return keyCipherMode; 99526fd984Sopenharmony_ci} 100526fd984Sopenharmony_ci 101526fd984Sopenharmony_cistatic JSIValue CreateHuksKeySize(void) 102526fd984Sopenharmony_ci{ 103526fd984Sopenharmony_ci JSIValue keySize = JSI::CreateObject(); 104526fd984Sopenharmony_ci 105526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_AES_KEY_SIZE_128", HKS_AES_KEY_SIZE_128); 106526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_AES_KEY_SIZE_192", HKS_AES_KEY_SIZE_192); 107526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_AES_KEY_SIZE_256", HKS_AES_KEY_SIZE_256); 108526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_AES_KEY_SIZE_512", HKS_AES_KEY_SIZE_512); 109526fd984Sopenharmony_ci 110526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_DES_KEY_SIZE_64", HKS_DES_KEY_SIZE_64); 111526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_3DES_KEY_SIZE_128", HKS_3DES_KEY_SIZE_128); 112526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_3DES_KEY_SIZE_192", HKS_3DES_KEY_SIZE_192); 113526fd984Sopenharmony_ci 114526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_RSA_KEY_SIZE_1024", HKS_RSA_KEY_SIZE_1024); 115526fd984Sopenharmony_ci AddInt32PropertyInLite(keySize, "HUKS_RSA_KEY_SIZE_2048", HKS_RSA_KEY_SIZE_2048); 116526fd984Sopenharmony_ci 117526fd984Sopenharmony_ci return keySize; 118526fd984Sopenharmony_ci} 119526fd984Sopenharmony_ci 120526fd984Sopenharmony_cistatic JSIValue CreateHuksKeyAlg(void) 121526fd984Sopenharmony_ci{ 122526fd984Sopenharmony_ci JSIValue keyAlg = JSI::CreateObject(); 123526fd984Sopenharmony_ci 124526fd984Sopenharmony_ci AddInt32PropertyInLite(keyAlg, "HUKS_ALG_AES", HKS_ALG_AES); 125526fd984Sopenharmony_ci AddInt32PropertyInLite(keyAlg, "HUKS_ALG_DES", HKS_ALG_DES); 126526fd984Sopenharmony_ci AddInt32PropertyInLite(keyAlg, "HUKS_ALG_3DES", HKS_ALG_3DES); 127526fd984Sopenharmony_ci 128526fd984Sopenharmony_ci AddInt32PropertyInLite(keyAlg, "HUKS_ALG_HMAC", HKS_ALG_HMAC); 129526fd984Sopenharmony_ci AddInt32PropertyInLite(keyAlg, "HUKS_ALG_CMAC", HKS_ALG_CMAC); 130526fd984Sopenharmony_ci 131526fd984Sopenharmony_ci AddInt32PropertyInLite(keyAlg, "HUKS_ALG_RSA", HKS_ALG_RSA); 132526fd984Sopenharmony_ci 133526fd984Sopenharmony_ci return keyAlg; 134526fd984Sopenharmony_ci} 135526fd984Sopenharmony_ci 136526fd984Sopenharmony_cistatic JSIValue CreateHuksKeyFlag(void) 137526fd984Sopenharmony_ci{ 138526fd984Sopenharmony_ci JSIValue keyFlag = JSI::CreateObject(); 139526fd984Sopenharmony_ci 140526fd984Sopenharmony_ci AddInt32PropertyInLite(keyFlag, "HUKS_KEY_FLAG_IMPORT_KEY", HKS_KEY_FLAG_IMPORT_KEY); 141526fd984Sopenharmony_ci AddInt32PropertyInLite(keyFlag, "HUKS_KEY_FLAG_GENERATE_KEY", HKS_KEY_FLAG_GENERATE_KEY); 142526fd984Sopenharmony_ci AddInt32PropertyInLite(keyFlag, "HUKS_KEY_FLAG_AGREE_KEY", HKS_KEY_FLAG_AGREE_KEY); 143526fd984Sopenharmony_ci AddInt32PropertyInLite(keyFlag, "HUKS_KEY_FLAG_DERIVE_KEY", HKS_KEY_FLAG_DERIVE_KEY); 144526fd984Sopenharmony_ci 145526fd984Sopenharmony_ci return keyFlag; 146526fd984Sopenharmony_ci} 147526fd984Sopenharmony_ci 148526fd984Sopenharmony_cistatic JSIValue CreateHuksKeyStorageType(void) 149526fd984Sopenharmony_ci{ 150526fd984Sopenharmony_ci JSIValue keyStorageType = JSI::CreateObject(); 151526fd984Sopenharmony_ci 152526fd984Sopenharmony_ci AddInt32PropertyInLite(keyStorageType, "HUKS_STORAGE_TEMP", HKS_STORAGE_TEMP); 153526fd984Sopenharmony_ci AddInt32PropertyInLite(keyStorageType, "HUKS_STORAGE_PERSISTENT", HKS_STORAGE_PERSISTENT); 154526fd984Sopenharmony_ci 155526fd984Sopenharmony_ci return keyStorageType; 156526fd984Sopenharmony_ci} 157526fd984Sopenharmony_ci 158526fd984Sopenharmony_cistatic JSIValue CreateHuksTagType(void) 159526fd984Sopenharmony_ci{ 160526fd984Sopenharmony_ci JSIValue tagType = JSI::CreateObject(); 161526fd984Sopenharmony_ci 162526fd984Sopenharmony_ci AddInt32PropertyInLite(tagType, "HUKS_TAG_TYPE_INVALID", HKS_TAG_TYPE_INVALID); 163526fd984Sopenharmony_ci AddInt32PropertyInLite(tagType, "HUKS_TAG_TYPE_INT", HKS_TAG_TYPE_INT); 164526fd984Sopenharmony_ci AddInt32PropertyInLite(tagType, "HUKS_TAG_TYPE_UINT", HKS_TAG_TYPE_UINT); 165526fd984Sopenharmony_ci AddInt32PropertyInLite(tagType, "HUKS_TAG_TYPE_ULONG", HKS_TAG_TYPE_ULONG); 166526fd984Sopenharmony_ci AddInt32PropertyInLite(tagType, "HUKS_TAG_TYPE_BOOL", HKS_TAG_TYPE_BOOL); 167526fd984Sopenharmony_ci AddInt32PropertyInLite(tagType, "HUKS_TAG_TYPE_BYTES", HKS_TAG_TYPE_BYTES); 168526fd984Sopenharmony_ci 169526fd984Sopenharmony_ci return tagType; 170526fd984Sopenharmony_ci} 171526fd984Sopenharmony_ci 172526fd984Sopenharmony_cistatic void AddHuksTagPart1(JSIValue tag) 173526fd984Sopenharmony_ci{ 174526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_INVALID", HKS_TAG_INVALID); 175526fd984Sopenharmony_ci 176526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_ALGORITHM", HKS_TAG_ALGORITHM); 177526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_PURPOSE", HKS_TAG_PURPOSE); 178526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_SIZE", HKS_TAG_KEY_SIZE); 179526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_PADDING", HKS_TAG_PADDING); 180526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_BLOCK_MODE", HKS_TAG_BLOCK_MODE); 181526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_TYPE", HKS_TAG_KEY_TYPE); 182526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_ASSOCIATED_DATA", HKS_TAG_ASSOCIATED_DATA); 183526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_NONCE", HKS_TAG_NONCE); 184526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_IV", HKS_TAG_IV); 185526fd984Sopenharmony_ci 186526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_INFO", HKS_TAG_INFO); 187526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_PWD", HKS_TAG_PWD); 188526fd984Sopenharmony_ci 189526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_GENERATE_TYPE", HKS_TAG_KEY_GENERATE_TYPE); 190526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_ALIAS", HKS_TAG_KEY_ALIAS); 191526fd984Sopenharmony_ci 192526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_ORIGINATION_EXPIRE_DATETIME", HKS_TAG_ORIGINATION_EXPIRE_DATETIME); 193526fd984Sopenharmony_ci 194526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_USAGE_EXPIRE_DATETIME", HKS_TAG_USAGE_EXPIRE_DATETIME); 195526fd984Sopenharmony_ci 196526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_CREATION_DATETIME", HKS_TAG_CREATION_DATETIME); 197526fd984Sopenharmony_ci} 198526fd984Sopenharmony_ci 199526fd984Sopenharmony_cistatic void AddHuksTagPart2(JSIValue tag) 200526fd984Sopenharmony_ci{ 201526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_IS_KEY_ALIAS", HKS_TAG_IS_KEY_ALIAS); 202526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_STORAGE_FLAG", HKS_TAG_KEY_STORAGE_FLAG); 203526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_FLAG", HKS_TAG_KEY_FLAG); 204526fd984Sopenharmony_ci 205526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_SECURE_KEY_ALIAS", HKS_TAG_SECURE_KEY_ALIAS); 206526fd984Sopenharmony_ci 207526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY_DOMAIN", HKS_TAG_KEY_DOMAIN); 208526fd984Sopenharmony_ci 209526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_PROCESS_NAME", HKS_TAG_PROCESS_NAME); 210526fd984Sopenharmony_ci 211526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_KEY", HKS_TAG_KEY); 212526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_AE_TAG", HKS_TAG_AE_TAG); 213526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_IS_KEY_HANDLE", HKS_TAG_IS_KEY_HANDLE); 214526fd984Sopenharmony_ci 215526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_OS_VERSION", HKS_TAG_OS_VERSION); 216526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_OS_PATCHLEVEL", HKS_TAG_OS_PATCHLEVEL); 217526fd984Sopenharmony_ci 218526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_SYMMETRIC_KEY_DATA", HKS_TAG_SYMMETRIC_KEY_DATA); 219526fd984Sopenharmony_ci} 220526fd984Sopenharmony_ci 221526fd984Sopenharmony_cistatic void AddHuksTagPart3(JSIValue tag) 222526fd984Sopenharmony_ci{ 223526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_DIGEST", HKS_TAG_DIGEST); 224526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_RSA_PSS_SALT_LEN_TYPE", HKS_TAG_RSA_PSS_SALT_LEN_TYPE); 225526fd984Sopenharmony_ci AddInt32PropertyInLite(tag, "HUKS_TAG_IMPORT_KEY_TYPE", HKS_TAG_IMPORT_KEY_TYPE); 226526fd984Sopenharmony_ci} 227526fd984Sopenharmony_ci 228526fd984Sopenharmony_cistatic JSIValue CreateHuksTag(void) 229526fd984Sopenharmony_ci{ 230526fd984Sopenharmony_ci JSIValue tag = JSI::CreateObject(); 231526fd984Sopenharmony_ci 232526fd984Sopenharmony_ci AddHuksTagPart1(tag); 233526fd984Sopenharmony_ci AddHuksTagPart2(tag); 234526fd984Sopenharmony_ci AddHuksTagPart3(tag); 235526fd984Sopenharmony_ci 236526fd984Sopenharmony_ci return tag; 237526fd984Sopenharmony_ci} 238526fd984Sopenharmony_ci 239526fd984Sopenharmony_cistatic JSIValue CreateHuksKeyDigest() 240526fd984Sopenharmony_ci{ 241526fd984Sopenharmony_ci JSIValue keyDigest = JSI::CreateObject(); 242526fd984Sopenharmony_ci 243526fd984Sopenharmony_ci AddInt32PropertyInLite(keyDigest, "HUKS_DIGEST_SHA1", HKS_DIGEST_SHA1); 244526fd984Sopenharmony_ci AddInt32PropertyInLite(keyDigest, "HUKS_DIGEST_SHA256", HKS_DIGEST_SHA256); 245526fd984Sopenharmony_ci 246526fd984Sopenharmony_ci return keyDigest; 247526fd984Sopenharmony_ci} 248526fd984Sopenharmony_ci 249526fd984Sopenharmony_cistatic JSIValue CreateHuksImportKeyType() 250526fd984Sopenharmony_ci{ 251526fd984Sopenharmony_ci JSIValue importKeyType = JSI::CreateObject(); 252526fd984Sopenharmony_ci 253526fd984Sopenharmony_ci AddInt32PropertyInLite(importKeyType, "HUKS_KEY_TYPE_PUBLIC_KEY", HKS_KEY_TYPE_PUBLIC_KEY); 254526fd984Sopenharmony_ci AddInt32PropertyInLite(importKeyType, "HUKS_KEY_TYPE_PRIVATE_KEY", HKS_KEY_TYPE_PRIVATE_KEY); 255526fd984Sopenharmony_ci AddInt32PropertyInLite(importKeyType, "HUKS_KEY_TYPE_KEY_PAIR", HKS_KEY_TYPE_KEY_PAIR); 256526fd984Sopenharmony_ci 257526fd984Sopenharmony_ci return importKeyType; 258526fd984Sopenharmony_ci} 259526fd984Sopenharmony_ci 260526fd984Sopenharmony_cistatic JSIValue CreateHuksRsaPssSaltLenType() 261526fd984Sopenharmony_ci{ 262526fd984Sopenharmony_ci JSIValue rsaPssSaltLenType = JSI::CreateObject(); 263526fd984Sopenharmony_ci 264526fd984Sopenharmony_ci AddInt32PropertyInLite(rsaPssSaltLenType, "HUKS_RSA_PSS_SALT_LEN_DIGEST", HKS_RSA_PSS_SALTLEN_DIGEST); 265526fd984Sopenharmony_ci AddInt32PropertyInLite(rsaPssSaltLenType, "HUKS_RSA_PSS_SALT_LEN_MAX", HKS_RSA_PSS_SALTLEN_MAX); 266526fd984Sopenharmony_ci 267526fd984Sopenharmony_ci return rsaPssSaltLenType; 268526fd984Sopenharmony_ci} 269526fd984Sopenharmony_ci 270526fd984Sopenharmony_cistatic void InitHuksModuleEnum(JSIValue exports) 271526fd984Sopenharmony_ci{ 272526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksExceptionErrCode", CreateHuksErrCode()); 273526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeyPurpose", CreateHuksKeyPurpose()); 274526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeyPadding", CreateHuksKeyPadding()); 275526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksCipherMode", CreateHuksCipherMode()); 276526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeySize", CreateHuksKeySize()); 277526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeyAlg", CreateHuksKeyAlg()); 278526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeyFlag", CreateHuksKeyFlag()); 279526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeyStorageType", CreateHuksKeyStorageType()); 280526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksTagType", CreateHuksTagType()); 281526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksTag", CreateHuksTag()); 282526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksKeyDigest", CreateHuksKeyDigest()); 283526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksImportKeyType", CreateHuksImportKeyType()); 284526fd984Sopenharmony_ci JSI::SetNamedProperty(exports, "HuksRsaPssSaltLenType", CreateHuksRsaPssSaltLenType()); 285526fd984Sopenharmony_ci} 286526fd984Sopenharmony_ci 287526fd984Sopenharmony_civoid InitHuksModule(JSIValue exports) 288526fd984Sopenharmony_ci{ 289526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "generateKeyItem", HksLiteModule::generateKeyItem); 290526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "deleteKeyItem", HksLiteModule::deleteKeyItem); 291526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "isKeyItemExist", HksLiteModule::isKeyItemExist); 292526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "hasKeyItem", HksLiteModule::hasKeyItem); 293526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "importKeyItem", HksLiteModule::importKeyItem); 294526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "exportKeyItem", HksLiteModule::exportKeyItem); 295526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "getKeyProperties", HksLiteModule::getKeyProperties); 296526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "importWrappedKeyItem", HksLiteModule::importWrappedKeyItem); 297526fd984Sopenharmony_ci 298526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "initSession", HksLiteModule::initSession); 299526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "updateSession", HksLiteModule::updateSession); 300526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "finishSession", HksLiteModule::finishSession); 301526fd984Sopenharmony_ci JSI::SetModuleAPI(exports, "abortSession", HksLiteModule::abortSession); 302526fd984Sopenharmony_ci 303526fd984Sopenharmony_ci InitHuksModuleEnum(exports); 304526fd984Sopenharmony_ci} 305526fd984Sopenharmony_ci} // namespace ACELite 306526fd984Sopenharmony_ci} // namespace OHOS 307