11bd4fe43Sopenharmony_ci/** 21bd4fe43Sopenharmony_ci * @file hks_client.h 31bd4fe43Sopenharmony_ci * 41bd4fe43Sopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd. 51bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 61bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License. 71bd4fe43Sopenharmony_ci * You may obtain a copy of the License at 81bd4fe43Sopenharmony_ci * 91bd4fe43Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 101bd4fe43Sopenharmony_ci * 111bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 121bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 131bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 141bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and 151bd4fe43Sopenharmony_ci * limitations under the License. 161bd4fe43Sopenharmony_ci */ 171bd4fe43Sopenharmony_ci 181bd4fe43Sopenharmony_ci/** 191bd4fe43Sopenharmony_ci * Description: Contains key generation, signature verify, 201bd4fe43Sopenharmony_ci * encryption and decryption, key derivation, key agreement, etc. \n 211bd4fe43Sopenharmony_ci * Author: Huawei \n 221bd4fe43Sopenharmony_ci * Create: 2019-06-19 231bd4fe43Sopenharmony_ci */ 241bd4fe43Sopenharmony_ci/** 251bd4fe43Sopenharmony_ci * @defgroup iot_hks 261bd4fe43Sopenharmony_ci * @ingroup hks 271bd4fe43Sopenharmony_ci */ 281bd4fe43Sopenharmony_ci 291bd4fe43Sopenharmony_ci#ifndef HKS_CLIENT_H 301bd4fe43Sopenharmony_ci#define HKS_CLIENT_H 311bd4fe43Sopenharmony_ci 321bd4fe43Sopenharmony_ci#include "hks_types.h" 331bd4fe43Sopenharmony_ci 341bd4fe43Sopenharmony_ci#ifdef __cplusplus 351bd4fe43Sopenharmony_ciextern "C" { 361bd4fe43Sopenharmony_ci#endif 371bd4fe43Sopenharmony_ci 381bd4fe43Sopenharmony_ci/** 391bd4fe43Sopenharmony_ci* @ingroup iot_hks 401bd4fe43Sopenharmony_ci* @brief Hks get sdk version.CNcomment:获取HKS sdk版本号。CNend 411bd4fe43Sopenharmony_ci* 421bd4fe43Sopenharmony_ci* @par 描述: 431bd4fe43Sopenharmony_ci* Hks get sdk version.CNcomment:获取HKS sdk版本号。CNend 441bd4fe43Sopenharmony_ci* 451bd4fe43Sopenharmony_ci* @attention None 461bd4fe43Sopenharmony_ci* @param sdk_version [OUT] type #struct hks_blob *,get sdk version.CNcomment:HKS sdk版本号。CNend 471bd4fe43Sopenharmony_ci* 481bd4fe43Sopenharmony_ci* @retval None 491bd4fe43Sopenharmony_ci* @par 依赖: 501bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 511bd4fe43Sopenharmony_ci* @see hks_get_sdk_version 521bd4fe43Sopenharmony_ci*/ 531bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC void hks_get_sdk_version(struct hks_blob *sdk_version); 541bd4fe43Sopenharmony_ci 551bd4fe43Sopenharmony_ci/** 561bd4fe43Sopenharmony_ci* @ingroup iot_hks 571bd4fe43Sopenharmony_ci* @brief Hks init.CNcomment:hks 初始化。CNend 581bd4fe43Sopenharmony_ci* 591bd4fe43Sopenharmony_ci* @par 描述: 601bd4fe43Sopenharmony_ci* Hks init.CNcomment:hks 初始化。CNend 611bd4fe43Sopenharmony_ci* 621bd4fe43Sopenharmony_ci* @attention None 631bd4fe43Sopenharmony_ci* @param None 641bd4fe43Sopenharmony_ci* 651bd4fe43Sopenharmony_ci* @retval #0 Success. 661bd4fe43Sopenharmony_ci* @retval #Other Failure. 671bd4fe43Sopenharmony_ci* @par 依赖: 681bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 691bd4fe43Sopenharmony_ci* @see hks_init 701bd4fe43Sopenharmony_ci*/ 711bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_init(void); 721bd4fe43Sopenharmony_ci 731bd4fe43Sopenharmony_ci/** 741bd4fe43Sopenharmony_ci* @ingroup iot_hks 751bd4fe43Sopenharmony_ci* @brief Hks destroy.CNcomment:销毁 hks。CNend 761bd4fe43Sopenharmony_ci* 771bd4fe43Sopenharmony_ci* @par 描述: 781bd4fe43Sopenharmony_ci* Hks destroy.CNcomment:销毁 hks。CNend 791bd4fe43Sopenharmony_ci* 801bd4fe43Sopenharmony_ci* @attention None 811bd4fe43Sopenharmony_ci* @param None 821bd4fe43Sopenharmony_ci* 831bd4fe43Sopenharmony_ci* @retval None 841bd4fe43Sopenharmony_ci* @par 依赖: 851bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 861bd4fe43Sopenharmony_ci* @see hks_destroy 871bd4fe43Sopenharmony_ci*/ 881bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC void hks_destroy(void); 891bd4fe43Sopenharmony_ci 901bd4fe43Sopenharmony_ci/** 911bd4fe43Sopenharmony_ci* @ingroup iot_hks 921bd4fe43Sopenharmony_ci* @brief Refresh key info and root key info.CNcomment:刷新密钥信息和根密钥信息。CNend 931bd4fe43Sopenharmony_ci* 941bd4fe43Sopenharmony_ci* @par 描述: 951bd4fe43Sopenharmony_ci* Refresh key info and root key info.CNcomment:刷新密钥信息和根密钥信息。CNend 961bd4fe43Sopenharmony_ci* 971bd4fe43Sopenharmony_ci* @attention None 981bd4fe43Sopenharmony_ci* @param None 991bd4fe43Sopenharmony_ci* 1001bd4fe43Sopenharmony_ci* @retval #0 Success. 1011bd4fe43Sopenharmony_ci* @retval #Other Failure. 1021bd4fe43Sopenharmony_ci* @par 依赖: 1031bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 1041bd4fe43Sopenharmony_ci* @see hks_refresh_key_info 1051bd4fe43Sopenharmony_ci*/ 1061bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_refresh_key_info(void); 1071bd4fe43Sopenharmony_ci 1081bd4fe43Sopenharmony_ci/** 1091bd4fe43Sopenharmony_ci* @ingroup iot_hks 1101bd4fe43Sopenharmony_ci* @brief Generate key Only ED25519 algorithm key pair generation is supported The number of local storage keys. 1111bd4fe43Sopenharmony_ci CNcomment:生成密钥仅支持ED25519算法密钥对生成本地存储密钥。CNend 1121bd4fe43Sopenharmony_ci* 1131bd4fe43Sopenharmony_ci* @par 描述: 1141bd4fe43Sopenharmony_ci* Generate key Only ED25519 algorithm key pair generation is supported The number of local storage keys 1151bd4fe43Sopenharmony_ci (including generated ED25519 public-private key pairs imported ED25519 public keys) is limited to 16. 1161bd4fe43Sopenharmony_ci CNcomment:生成密钥仅支持ED25519算法密钥对生成本地存储密钥 1171bd4fe43Sopenharmony_ci (包括导入的ED25519公共密钥和私有ED25519生成的ED25519公共密钥对)的数量限制为16个。CNend 1181bd4fe43Sopenharmony_ci* 1191bd4fe43Sopenharmony_ci* @attention None 1201bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob *,key alias, constraint condition:key_alias->size <= 64. 1211bd4fe43Sopenharmony_ci CNcomment:密钥别名,约束条件:key_alias-> size <= 64。CNend 1221bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,The parameter of the key which need to generate 1231bd4fe43Sopenharmony_ci constraint condition: key_param cannot be NULL & key_param->key_type must be HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519. 1241bd4fe43Sopenharmony_ci CNcomment:需要生成的密钥参数 约束条件: 1251bd4fe43Sopenharmony_ci key_param不能为NULL & key_param-> key_type必须为HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519。CNend 1261bd4fe43Sopenharmony_ci* @retval #0 Success. 1271bd4fe43Sopenharmony_ci* @retval #Other Failure. 1281bd4fe43Sopenharmony_ci* @par 依赖: 1291bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 1301bd4fe43Sopenharmony_ci* @see hks_generate_key 1311bd4fe43Sopenharmony_ci*/ 1321bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_generate_key(const struct hks_blob *key_alias, 1331bd4fe43Sopenharmony_ci const struct hks_key_param *key_param); 1341bd4fe43Sopenharmony_ci 1351bd4fe43Sopenharmony_ci/** 1361bd4fe43Sopenharmony_ci* @ingroup iot_hks 1371bd4fe43Sopenharmony_ci* @brief Generate the X25519 algorithm key pair and return it to the caller. The generated key pair is not saved in HKS. 1381bd4fe43Sopenharmony_ci CNcomment:生成X25519算法秘钥对并返回给调用者,生成的秘钥对不在hks保存。CNend 1391bd4fe43Sopenharmony_ci* 1401bd4fe43Sopenharmony_ci* @par 描述: 1411bd4fe43Sopenharmony_ci* Generate the X25519 algorithm key pair and return it to the caller. 1421bd4fe43Sopenharmony_ci The generated key pair is not saved in HKS. 1431bd4fe43Sopenharmony_ci CNcomment:生成X25519算法秘钥对并返回给调用者,生成的秘钥对不在hks保存。CNend 1441bd4fe43Sopenharmony_ci* 1451bd4fe43Sopenharmony_ci* @attention None 1461bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,Used to specify related parameters that affect 1471bd4fe43Sopenharmony_ci key generation, constraint condition: key_param.key_type must be HKS_KEY_TYPE_ECC_KEYPAIR_CURVE25519 1481bd4fe43Sopenharmony_ci key_param.usage must be hks_alg_ecdh(HKS_ALG_SELECT_RAW). 1491bd4fe43Sopenharmony_ci CNcomment:用于指定影响秘钥生成的相关参数, 约束条件:key_param.key_type必须为HKS_KEY_TYPE_ECC_KEYPAIR_CURVE25519 1501bd4fe43Sopenharmony_ci key_param.usage必须为hks_alg_ecdh(HKS_ALG_SELECT_RAW)。CNend 1511bd4fe43Sopenharmony_ci* @param pri_key [OUT] type #struct hks_blob *,Used to save the generated private key 1521bd4fe43Sopenharmony_ci CNcomment:用于保存生成的私钥。CNend 1531bd4fe43Sopenharmony_ci* @param pub_key [OUT] type #struct hks_blob *,Used to save the generated public key. 1541bd4fe43Sopenharmony_ci CNcomment:用于保存生成的公钥。CNend 1551bd4fe43Sopenharmony_ci* @param 1561bd4fe43Sopenharmony_ci* @retval #0 Success. 1571bd4fe43Sopenharmony_ci* @retval #Other Failure. 1581bd4fe43Sopenharmony_ci* @par 依赖: 1591bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 1601bd4fe43Sopenharmony_ci* @see hks_generate_asymmetric_key 1611bd4fe43Sopenharmony_ci*/ 1621bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_generate_asymmetric_key( 1631bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, struct hks_blob *pri_key, 1641bd4fe43Sopenharmony_ci struct hks_blob *pub_key); 1651bd4fe43Sopenharmony_ci 1661bd4fe43Sopenharmony_ci/** 1671bd4fe43Sopenharmony_ci* @ingroup iot_hks 1681bd4fe43Sopenharmony_ci* @brief Associate the ED25519 algorithm public key and the parameters of the public key with the alias and 1691bd4fe43Sopenharmony_ci import it into HKS to save. CNcomment:将ED25519算法公钥以及公钥的参数与别名关联并导入到hks中保存。CNend 1701bd4fe43Sopenharmony_ci* 1711bd4fe43Sopenharmony_ci* @par 描述: 1721bd4fe43Sopenharmony_ci* Associate the ED25519 algorithm public key and the parameters of the public key with the alias and 1731bd4fe43Sopenharmony_ci import it into HKS to save. CNcomment:将ED25519算法公钥以及公钥的参数与别名关联并导入到hks中保存。CNend 1741bd4fe43Sopenharmony_ci* 1751bd4fe43Sopenharmony_ci* @attention None 1761bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob *,Alias to specify to save the ED25519 public key. 1771bd4fe43Sopenharmony_ci CNcomment:用于指定保存ED25519公钥的别名。CNend 1781bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,The key parameters associated with 1791bd4fe43Sopenharmony_ci the public key are saved to the HKS together with the public key, constraint condition: key_param.key_type must be 1801bd4fe43Sopenharmony_ci HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519 1811bd4fe43Sopenharmony_ci CNcomment:和公钥关联的秘钥参数,与公钥一起保存到hks中, 约束条件:key_param.key_type必须为 1821bd4fe43Sopenharmony_ci HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519。CNend 1831bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob *,Public key to be imported into hks. 1841bd4fe43Sopenharmony_ci CNcomment:需要导入到hks中的公钥。CNend 1851bd4fe43Sopenharmony_ci* @retval #0 Success. 1861bd4fe43Sopenharmony_ci* @retval #Other Failure. 1871bd4fe43Sopenharmony_ci* @par 依赖: 1881bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 1891bd4fe43Sopenharmony_ci* @see hks_import_public_key 1901bd4fe43Sopenharmony_ci*/ 1911bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_import_public_key( 1921bd4fe43Sopenharmony_ci const struct hks_blob *key_alias, 1931bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, const struct hks_blob *key); 1941bd4fe43Sopenharmony_ci 1951bd4fe43Sopenharmony_ci/** 1961bd4fe43Sopenharmony_ci* @ingroup iot_hks 1971bd4fe43Sopenharmony_ci* @brief Export the public key associated with the file name saved in the HKS system. 1981bd4fe43Sopenharmony_ci CNcomment:导出保存在hks系统中与文件名关联的公钥。CNend 1991bd4fe43Sopenharmony_ci* 2001bd4fe43Sopenharmony_ci* @par 描述: 2011bd4fe43Sopenharmony_ci* Export the public key associated with the file name saved in the HKS system. 2021bd4fe43Sopenharmony_ci CNcomment:导出保存在hks系统中与文件名关联的公钥。CNend 2031bd4fe43Sopenharmony_ci* 2041bd4fe43Sopenharmony_ci* @attention None 2051bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob * Alias used to associate with the exported public key, 2061bd4fe43Sopenharmony_ci constraint condition: key_alias->size <= 64. 2071bd4fe43Sopenharmony_ci CNcomment:用于与导出公钥关联的别名, 约束条件:key_alias-> size <= 64。CNend 2081bd4fe43Sopenharmony_ci* @param key [OUT] type #struct hks_blob * Cache of hks public key.CNcomment:存放 hks公钥的缓存。CNend 2091bd4fe43Sopenharmony_ci* @retval #0 Success. 2101bd4fe43Sopenharmony_ci* @retval #Other Failure. 2111bd4fe43Sopenharmony_ci* @par 依赖: 2121bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 2131bd4fe43Sopenharmony_ci* @see hks_export_public_key 2141bd4fe43Sopenharmony_ci*/ 2151bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_export_public_key( 2161bd4fe43Sopenharmony_ci const struct hks_blob *key_alias, struct hks_blob *key); 2171bd4fe43Sopenharmony_ci 2181bd4fe43Sopenharmony_ci/** 2191bd4fe43Sopenharmony_ci* @ingroup iot_hks 2201bd4fe43Sopenharmony_ci* @brief Delete the public key associated with the alias saved in the HKS system. 2211bd4fe43Sopenharmony_ci CNcomment:删除保存在hks系统中与别名关联的公钥。CNend 2221bd4fe43Sopenharmony_ci* 2231bd4fe43Sopenharmony_ci* @par 描述: 2241bd4fe43Sopenharmony_ci* Delete the public key associated with the alias saved in the HKS system. 2251bd4fe43Sopenharmony_ci CNcomment:删除保存在hks系统中与别名关联的公钥。CNend 2261bd4fe43Sopenharmony_ci* 2271bd4fe43Sopenharmony_ci* @attention None 2281bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob * The alias associated with the delete key, 2291bd4fe43Sopenharmony_ci constraint condition: key_alias->size <= 64. 2301bd4fe43Sopenharmony_ci CNcomment:与删除秘钥关联的别名, 约束条件:key_alias-> size <= 64。CNend 2311bd4fe43Sopenharmony_ci* @retval #0 Success. 2321bd4fe43Sopenharmony_ci* @retval #Other Failure. 2331bd4fe43Sopenharmony_ci* @par 依赖: 2341bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 2351bd4fe43Sopenharmony_ci* @see hks_delete_key 2361bd4fe43Sopenharmony_ci*/ 2371bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_delete_key(const struct hks_blob *key_alias); 2381bd4fe43Sopenharmony_ci 2391bd4fe43Sopenharmony_ci/** 2401bd4fe43Sopenharmony_ci* @ingroup iot_hks 2411bd4fe43Sopenharmony_ci* @brief Export key attributes associated with aliases stored in the HKS system. 2421bd4fe43Sopenharmony_ci CNcomment:导出保存在hks系统中与别名关联的秘钥属性。CNend 2431bd4fe43Sopenharmony_ci* 2441bd4fe43Sopenharmony_ci* @par 描述: 2451bd4fe43Sopenharmony_ci* Export key attributes associated with aliases stored in the HKS system. 2461bd4fe43Sopenharmony_ci CNcomment:导出保存在hks系统中与别名关联的秘钥属性。CNend 2471bd4fe43Sopenharmony_ci* 2481bd4fe43Sopenharmony_ci* @attention None 2491bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob * Alias used to associate with the exported public key, 2501bd4fe43Sopenharmony_ci constraint condition: key_alias->size <= 64. 2511bd4fe43Sopenharmony_ci CNcomment:用于与导出公钥关联的别名, 约束条件:key_alias-> size <= 64。CNend 2521bd4fe43Sopenharmony_ci* @param key_param [OUT] type #struct hks_key_param * Pointer to key attribute. CNcomment:存放秘钥属性的指针。CNend 2531bd4fe43Sopenharmony_ci* @retval #0 Success. 2541bd4fe43Sopenharmony_ci* @retval #Other Failure. 2551bd4fe43Sopenharmony_ci* @par 依赖: 2561bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 2571bd4fe43Sopenharmony_ci* @see hks_get_key_param 2581bd4fe43Sopenharmony_ci*/ 2591bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_get_key_param(const struct hks_blob *key_alias, 2601bd4fe43Sopenharmony_ci struct hks_key_param *key_param); 2611bd4fe43Sopenharmony_ci 2621bd4fe43Sopenharmony_ci/** 2631bd4fe43Sopenharmony_ci* @ingroup iot_hks 2641bd4fe43Sopenharmony_ci* @brief Determine if there is a public or secret key pair associated with the alias in hks. 2651bd4fe43Sopenharmony_ci CNcomment:判断hks中是否存在与别名关联的公钥或秘钥对。CNend 2661bd4fe43Sopenharmony_ci* 2671bd4fe43Sopenharmony_ci* @par 描述: 2681bd4fe43Sopenharmony_ci* Determine if there is a public or secret key pair associated with the alias in hks. 2691bd4fe43Sopenharmony_ci CNcomment:判断hks中是否存在与别名关联的公钥或秘钥对。CNend 2701bd4fe43Sopenharmony_ci* 2711bd4fe43Sopenharmony_ci* @attention None 2721bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob * The alias associated with the delete key, 2731bd4fe43Sopenharmony_ci constraint condition: key_alias->size <= 64. 2741bd4fe43Sopenharmony_ci CNcomment:与删除秘钥关联的别名, 约束条件:key_alias-> size <= 64。CNend 2751bd4fe43Sopenharmony_ci* @retval #0 Success. 2761bd4fe43Sopenharmony_ci* @retval #Other Failure. 2771bd4fe43Sopenharmony_ci* @par 依赖: 2781bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 2791bd4fe43Sopenharmony_ci* @see hks_is_key_exist 2801bd4fe43Sopenharmony_ci*/ 2811bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_is_key_exist(const struct hks_blob *key_alias); 2821bd4fe43Sopenharmony_ci 2831bd4fe43Sopenharmony_ci/** 2841bd4fe43Sopenharmony_ci* @ingroup iot_hks 2851bd4fe43Sopenharmony_ci* @brief Generate a secure random number, no longer than 1024 bytes. CNcomment:生成安全随机数,长度不超过1024字节。CNend 2861bd4fe43Sopenharmony_ci* 2871bd4fe43Sopenharmony_ci* @par 描述: 2881bd4fe43Sopenharmony_ci* Generate a secure random number, no longer than 1024 bytes. 2891bd4fe43Sopenharmony_ci CNcomment:生成安全随机数,长度不超过1024字节。CNend 2901bd4fe43Sopenharmony_ci* 2911bd4fe43Sopenharmony_ci* @attention None 2921bd4fe43Sopenharmony_ci* @param random [OUT] type #struct hks_blob * Used to save generated random numbers, 2931bd4fe43Sopenharmony_ci random->size must be specified by the caller ,constraint condition: random->size <= 1024. 2941bd4fe43Sopenharmony_ci CNcomment:用于保存生成的随机数, random-> size必须由调用方指定,约束条件:random-> size <= 1024。CNend 2951bd4fe43Sopenharmony_ci* @retval #0 Success. 2961bd4fe43Sopenharmony_ci* @retval #Other Failure. 2971bd4fe43Sopenharmony_ci* @par 依赖: 2981bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 2991bd4fe43Sopenharmony_ci* @see hks_generate_random 3001bd4fe43Sopenharmony_ci*/ 3011bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_generate_random(struct hks_blob *random); 3021bd4fe43Sopenharmony_ci 3031bd4fe43Sopenharmony_ci/** 3041bd4fe43Sopenharmony_ci* @ingroup iot_hks 3051bd4fe43Sopenharmony_ci* @brief Generate a data signature using the ED25519 private key associated with the alias in hks. 3061bd4fe43Sopenharmony_ci CNcomment:使用hks中与别名关联的ED25519私钥生成数据签名。CNend 3071bd4fe43Sopenharmony_ci* 3081bd4fe43Sopenharmony_ci* @par 描述: 3091bd4fe43Sopenharmony_ci* Generate a data signature using the ED25519 private key associated with the alias in hks. 3101bd4fe43Sopenharmony_ci CNcomment:使用hks中与别名关联的ED25519私钥生成数据签名。CNend 3111bd4fe43Sopenharmony_ci* 3121bd4fe43Sopenharmony_ci* @attention None 3131bd4fe43Sopenharmony_ci* @param key_alias [IN] type #const struct hks_blob * Sign using alias of secret key, 3141bd4fe43Sopenharmony_ci constraint condition: key_alias->size <= 64. 3151bd4fe43Sopenharmony_ci CNcomment:签名使用秘钥的别名, 约束条件:key_alias-> size <= 64。CNend 3161bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,Attributes of the key associated with key_alias. 3171bd4fe43Sopenharmony_ci CNcomment:与key_alias关联的秘钥的属性。CNend 3181bd4fe43Sopenharmony_ci* @param hash [IN] type #const struct hks_blob *,Data to be signed. CNcomment:待签名的数据。CNend 3191bd4fe43Sopenharmony_ci* @param signature [OUT] type #struct hks_blob *,Output data signature, constraint condition: 3201bd4fe43Sopenharmony_ci signature->size bigger & equal 64。 3211bd4fe43Sopenharmony_ci CNcomment:输出的数据签名,约束条件:签名大小> = 64。CNend 3221bd4fe43Sopenharmony_ci* @retval #0 Success. 3231bd4fe43Sopenharmony_ci* @retval #Other Failure. 3241bd4fe43Sopenharmony_ci* @par 依赖: 3251bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 3261bd4fe43Sopenharmony_ci* @see hks_asymmetric_sign 3271bd4fe43Sopenharmony_ci*/ 3281bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_asymmetric_sign( 3291bd4fe43Sopenharmony_ci const struct hks_blob *key_alias, 3301bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, const struct hks_blob *hash, 3311bd4fe43Sopenharmony_ci struct hks_blob *signature); 3321bd4fe43Sopenharmony_ci 3331bd4fe43Sopenharmony_ci/** 3341bd4fe43Sopenharmony_ci* @ingroup iot_hks 3351bd4fe43Sopenharmony_ci* @brief Verify data signature using ED25519 public key. CNcomment:使用ED25519公钥验证数据签名。CNend 3361bd4fe43Sopenharmony_ci* 3371bd4fe43Sopenharmony_ci* @par 描述: 3381bd4fe43Sopenharmony_ci* Verify data signature using ED25519 public key. CNcomment:使用ED25519公钥验证数据签名。CNend 3391bd4fe43Sopenharmony_ci* 3401bd4fe43Sopenharmony_ci* @attention None 3411bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob * The alias or ED25519 public key associated with the ED25519 key. 3421bd4fe43Sopenharmony_ci CNcomment:与ED25519秘钥关联的别名或ED25519公钥。CNend 3431bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,The attributes of the key associated with the key. 3441bd4fe43Sopenharmony_ci CNcomment:与key关联的秘钥的属性。CNend 3451bd4fe43Sopenharmony_ci* @param hash [IN] type #const struct hks_blob *,Signed data. CNcomment:签名的数据。CNend 3461bd4fe43Sopenharmony_ci* @param signature [IN] type #const struct hks_blob *,Data signature,constraint condition: 3471bd4fe43Sopenharmony_ci signature->size bigger & equal 64。 3481bd4fe43Sopenharmony_ci CNcomment:数据签名, 约束条件:签名大小> = 64。CNend 3491bd4fe43Sopenharmony_ci* @retval #0 Success. 3501bd4fe43Sopenharmony_ci* @retval #Other Failure. 3511bd4fe43Sopenharmony_ci* @par 依赖: 3521bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 3531bd4fe43Sopenharmony_ci* @see hks_asymmetric_verify 3541bd4fe43Sopenharmony_ci*/ 3551bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_asymmetric_verify(const struct hks_blob *key, 3561bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, const struct hks_blob *hash, 3571bd4fe43Sopenharmony_ci const struct hks_blob *signature); 3581bd4fe43Sopenharmony_ci 3591bd4fe43Sopenharmony_ci/** 3601bd4fe43Sopenharmony_ci* @ingroup iot_hks 3611bd4fe43Sopenharmony_ci* @brief Data encryption using AES-128-GCM algorithm. CNcomment:使用AES-128-GCM算法对数据加密。CNend 3621bd4fe43Sopenharmony_ci* 3631bd4fe43Sopenharmony_ci* @par 描述: 3641bd4fe43Sopenharmony_ci* Data encryption using AES-128-GCM algorithm. CNcomment:使用AES-128-GCM算法对数据加密。CNend 3651bd4fe43Sopenharmony_ci* 3661bd4fe43Sopenharmony_ci* @attention None 3671bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob *,The key used to encrypt the plaintext. 3681bd4fe43Sopenharmony_ci CNcomment:用于加密明文的秘钥。CNend 3691bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,The attributes of the key associated with the key. 3701bd4fe43Sopenharmony_ci constraint condition: key_param.key_type is HKS_KEY_TYPE_AES, key_param.key_len is 128 or 192 or 256; 3711bd4fe43Sopenharmony_ci key_param.key_usage is HKS_KEY_USAGE_ENCRYPT, key_param.key_mode is HKS_ALG_GCM; 3721bd4fe43Sopenharmony_ci key_param.key_pad is HKS_PADDING_NONE 3731bd4fe43Sopenharmony_ci CNcomment:与key关联的秘钥的属性,约束条件:key_param.key_type为HKS_KEY_TYPE_AES,key_param.key_len为128或192或256; 3741bd4fe43Sopenharmony_ci key_param.key_usage是HKS_KEY_USAGE_ENCRYPT,key_param.key_mode是HKS_ALG_GCM; 3751bd4fe43Sopenharmony_ci key_param.key_pad为HKS_PADDING_NONE。CNend 3761bd4fe43Sopenharmony_ci* @param crypt_param [IN] type #const struct hks_crypt_param *,Vectors and additional data used for encryption. 3771bd4fe43Sopenharmony_ci CNcomment:加密使用的向量和附加数据。CNend 3781bd4fe43Sopenharmony_ci* @param plain_text [IN] type #const struct hks_blob *,Data plaintext。CNcomment:数据明文。CNend 3791bd4fe43Sopenharmony_ci* @param cipher_text_with_tag [OUT] type #struct hks_blob *,Data ciphertext CNcomment:数据密文。CNend 3801bd4fe43Sopenharmony_ci* @retval #0 Success. 3811bd4fe43Sopenharmony_ci* @retval #Other Failure. 3821bd4fe43Sopenharmony_ci* @par 依赖: 3831bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 3841bd4fe43Sopenharmony_ci* @see hks_aead_encrypt 3851bd4fe43Sopenharmony_ci*/ 3861bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_aead_encrypt(const struct hks_blob *key, 3871bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, 3881bd4fe43Sopenharmony_ci const struct hks_crypt_param *crypt_param, 3891bd4fe43Sopenharmony_ci const struct hks_blob *plain_text, 3901bd4fe43Sopenharmony_ci struct hks_blob *cipher_text_with_tag); 3911bd4fe43Sopenharmony_ci 3921bd4fe43Sopenharmony_ci/** 3931bd4fe43Sopenharmony_ci* @ingroup iot_hks 3941bd4fe43Sopenharmony_ci* @brief Decrypt ciphertext using AES-128-GCM algorithm. CNcomment:使用AES-128-GCM算法对密文解密。CNend 3951bd4fe43Sopenharmony_ci* 3961bd4fe43Sopenharmony_ci* @par 描述: 3971bd4fe43Sopenharmony_ci* Decrypt ciphertext using AES-128-GCM algorithm. CNcomment:使用AES-128-GCM算法对密文解密。CNend 3981bd4fe43Sopenharmony_ci* 3991bd4fe43Sopenharmony_ci* @attention None 4001bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob *,Secret key for decryption. CNcomment:用于解密的秘钥。CNend 4011bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,The attributes of the key associated with the key. 4021bd4fe43Sopenharmony_ci constraint condition: key_param.key_type is HKS_KEY_TYPE_AES, key_param.key_len is 128 or 192 or 256; 4031bd4fe43Sopenharmony_ci key_param.key_usage is HKS_KEY_USAGE_DECRYPT, key_param.key_mode is HKS_ALG_GCM; 4041bd4fe43Sopenharmony_ci key_param.key_pad is HKS_PADDING_NONE; 4051bd4fe43Sopenharmony_ci CNcomment:与key关联的秘钥的属性,约束条件:key_param.key_type为HKS_KEY_TYPE_AES,key_param.key_len为128或192或256; 4061bd4fe43Sopenharmony_ci key_param.key_usage是HKS_KEY_USAGE_DECRYPT,key_param.key_mode是HKS_ALG_GCM; 4071bd4fe43Sopenharmony_ci key_param.key_pad为HKS_PADDING_NONE。CNend 4081bd4fe43Sopenharmony_ci* @param crypt_param [IN] type #const struct hks_crypt_param *,Vector and additional data used for decryption. 4091bd4fe43Sopenharmony_ci CNcomment:解密使用的向量和附加数据。CNend 4101bd4fe43Sopenharmony_ci* @param plain_text [OUT] type #struct hks_blob *,Data plaintext。CNcomment:数据明文。CNend 4111bd4fe43Sopenharmony_ci* @param cipher_text_with_tag [IN] type #const struct hks_blob *,Data ciphertext CNcomment:数据密文。CNend 4121bd4fe43Sopenharmony_ci* @retval #0 Success. 4131bd4fe43Sopenharmony_ci* @retval #Other Failure. 4141bd4fe43Sopenharmony_ci* @par 依赖: 4151bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 4161bd4fe43Sopenharmony_ci* @see hks_aead_decrypt 4171bd4fe43Sopenharmony_ci*/ 4181bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_aead_decrypt(const struct hks_blob *key, 4191bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, 4201bd4fe43Sopenharmony_ci const struct hks_crypt_param *crypt_param, 4211bd4fe43Sopenharmony_ci struct hks_blob *plain_text, 4221bd4fe43Sopenharmony_ci const struct hks_blob *cipher_text_with_tag); 4231bd4fe43Sopenharmony_ci 4241bd4fe43Sopenharmony_ci/** 4251bd4fe43Sopenharmony_ci* @ingroup iot_hks 4261bd4fe43Sopenharmony_ci* @brief Key negotiation using X25519 algorithm. CNcomment:使用X25519算法进行秘钥协商。CNend 4271bd4fe43Sopenharmony_ci* 4281bd4fe43Sopenharmony_ci* @par 描述: 4291bd4fe43Sopenharmony_ci* Key negotiation using X25519 algorithm. CNcomment:使用X25519算法进行秘钥协商。CNend 4301bd4fe43Sopenharmony_ci* 4311bd4fe43Sopenharmony_ci* @attention None 4321bd4fe43Sopenharmony_ci* @param agreed_key [OUT] type #struct hks_blob *,Negotiation key calculated through X25519. 4331bd4fe43Sopenharmony_ci CNcomment:通过X25519计算出来的协商秘钥。CNend 4341bd4fe43Sopenharmony_ci* @param private_key_param [IN] type #const struct hks_key_param *,Local private key private_key attributes. 4351bd4fe43Sopenharmony_ci constraint condition:private_key_param.key_type is HKS_KEY_TYPE_ECC_KEYPAIR_CURVE25519 4361bd4fe43Sopenharmony_ci private_key_param.key_usage is HKS_KEY_USAGE_DERIVE 4371bd4fe43Sopenharmony_ci private_key_param.key_mode is the same as agreement_alg 4381bd4fe43Sopenharmony_ci CNcomment:本端私钥private_key的属性,约束条件:private_key_param.key_type为HKS_KEY_TYPE_ECC_KEYPAIR_CURVE25519 4391bd4fe43Sopenharmony_ci private_key_param.key_usage是HKS_KEY_USAGE_DERIVE 4401bd4fe43Sopenharmony_ci private_key_param.key_mode与Agreement_alg相同。CNend 4411bd4fe43Sopenharmony_ci* @param agreement_alg [IN] type #const uint32_t, 4421bd4fe43Sopenharmony_ci Algorithm for further deriving secret key based on negotiation secret key. 4431bd4fe43Sopenharmony_ci CNcomment:基于协商秘钥进一步派生秘钥的算法。CNend 4441bd4fe43Sopenharmony_ci* @param private_key [IN] type #const struct hks_blob *,Local X25519 private key。 4451bd4fe43Sopenharmony_ci CNcomment:本端X25519私钥。CNend 4461bd4fe43Sopenharmony_ci* @param peer_public_key [IN] type #const struct hks_blob *,Peer X25519 public key 4471bd4fe43Sopenharmony_ci CNcomment:对端X25519公钥。CNend 4481bd4fe43Sopenharmony_ci* @retval #0 Success. 4491bd4fe43Sopenharmony_ci* @retval #Other Failure. 4501bd4fe43Sopenharmony_ci* @par 依赖: 4511bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 4521bd4fe43Sopenharmony_ci* @see hks_key_agreement 4531bd4fe43Sopenharmony_ci*/ 4541bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_key_agreement(struct hks_blob *agreed_key, 4551bd4fe43Sopenharmony_ci const struct hks_key_param *private_key_param, 4561bd4fe43Sopenharmony_ci const uint32_t agreement_alg, const struct hks_blob *private_key, 4571bd4fe43Sopenharmony_ci const struct hks_blob *peer_public_key); 4581bd4fe43Sopenharmony_ci 4591bd4fe43Sopenharmony_ci/** 4601bd4fe43Sopenharmony_ci* @ingroup iot_hks 4611bd4fe43Sopenharmony_ci* @brief Key derivation. CNcomment:秘钥派生。CNend 4621bd4fe43Sopenharmony_ci* 4631bd4fe43Sopenharmony_ci* @par 描述: 4641bd4fe43Sopenharmony_ci* Derive the key using HKD512 algorithm based on SHA512. 4651bd4fe43Sopenharmony_ci The currently derived key is only used for AES encryption and decryption. 4661bd4fe43Sopenharmony_ci CNcomment:使用基于SHA512的HKDF算法派生秘钥,当前派生的秘钥仅用于AES加解密。CNend 4671bd4fe43Sopenharmony_ci* 4681bd4fe43Sopenharmony_ci* @attention None 4691bd4fe43Sopenharmony_ci* @param derived_key [OUT] type #struct hks_blob *,Derived key calculated through HKDF , 4701bd4fe43Sopenharmony_ci derived_key and data cannot be null, and size >= 16. 4711bd4fe43Sopenharmony_ci CNcomment:通过HKDF计算出来的派生秘钥 named_key和data不能为null,且大小> = 16。CNend 4721bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,Properties for derived keys constraint condition: 4731bd4fe43Sopenharmony_ci key_param.key_type is HKS_KEY_TYPE_DERIVE,key_param.key_usage is HKS_KEY_USAGE_DERIVE 4741bd4fe43Sopenharmony_ci key_param.key_mode is hks_alg_hkdf(HKS_ALG_HASH_SHA_256) or hks_alg_hkdf(HKS_ALG_HASH_SHA_512) 4751bd4fe43Sopenharmony_ci key_param.key_len is 128 or 256. 4761bd4fe43Sopenharmony_ci CNcomment:派生秘钥对应的属性,约束条件: 4771bd4fe43Sopenharmony_ci key_param.key_type为HKS_KEY_TYPE_DERIVE,key_param.key_usage为HKS_KEY_USAGE_DERIVE 4781bd4fe43Sopenharmony_ci key_param.key_mode为hks_alg_hkdf(HKS_ALG_HASH_SHA_256)或hks_alg_hkdf(HKS_ALG_HASH_SHA_512) 4791bd4fe43Sopenharmony_ci key_param.key_len是128或256。。CNend 4801bd4fe43Sopenharmony_ci* @param kdf_key [IN] type #const struct hks_blob *,The base key used to derive the key. 4811bd4fe43Sopenharmony_ci CNcomment:用于派生秘钥的基础秘钥。CNend 4821bd4fe43Sopenharmony_ci* @param salt [IN] type #const struct hks_blob *, 4831bd4fe43Sopenharmony_ci Derived salt value,salt.size must be greater than or equal to 16。 4841bd4fe43Sopenharmony_ci CNcomment:派生使用的盐值,salt.size必须大于或等于16。CNend 4851bd4fe43Sopenharmony_ci* @param label [IN] type #const struct hks_blob *,Derived label,constraint condition: 4861bd4fe43Sopenharmony_ci lable.size must be greater than or equal to 16 4871bd4fe43Sopenharmony_ci CNcomment:派生使用的label,约束条件:lable.size必须大于或等于16。CNend 4881bd4fe43Sopenharmony_ci* @retval #0 Success. 4891bd4fe43Sopenharmony_ci* @retval #Other Failure. 4901bd4fe43Sopenharmony_ci* @par 依赖: 4911bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 4921bd4fe43Sopenharmony_ci* @see hks_key_derivation 4931bd4fe43Sopenharmony_ci*/ 4941bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_key_derivation(struct hks_blob *derived_key, 4951bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, const struct hks_blob *kdf_key, 4961bd4fe43Sopenharmony_ci const struct hks_blob *salt, const struct hks_blob *label); 4971bd4fe43Sopenharmony_ci 4981bd4fe43Sopenharmony_ci/** 4991bd4fe43Sopenharmony_ci* @ingroup iot_hks 5001bd4fe43Sopenharmony_ci* @brief Generate message authentication code (MAC) based on SHA256 or SHA512. 5011bd4fe43Sopenharmony_ci CNcomment:基于SHA256或SHA512生成消息验证码(MAC)。CNend 5021bd4fe43Sopenharmony_ci* 5031bd4fe43Sopenharmony_ci* @par 描述: 5041bd4fe43Sopenharmony_ci* Generate message authentication code (MAC) based on SHA256 or SHA512. 5051bd4fe43Sopenharmony_ci CNcomment:基于SHA256或SHA512生成消息验证码(MAC)。CNend 5061bd4fe43Sopenharmony_ci* 5071bd4fe43Sopenharmony_ci* @attention None 5081bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob *,Keys involved in calculating HMAC, 5091bd4fe43Sopenharmony_ci data cannot be null,and size > 0. 5101bd4fe43Sopenharmony_ci CNcomment:参与计算HMAC的秘钥,数据不能为null,大小> 0。CNend 5111bd4fe43Sopenharmony_ci* @param alg [IN] type #const uint32_t,HMAC algorithm hks_alg_hmac(HKS_ALG_HASH_SHA_256) or 5121bd4fe43Sopenharmony_ci (HKS_ALG_HASH_SHA_512). 5131bd4fe43Sopenharmony_ci CNcomment:HMAC算法, hks_alg_hmac(HKS_ALG_HASH_SHA_256)或 (HKS_ALG_HASH_SHA_512)。CNend 5141bd4fe43Sopenharmony_ci* @param src_data [IN] type #const struct hks_blob *,src data data cannot be null, and size > 0. 5151bd4fe43Sopenharmony_ci CNcomment:源数据,数据不能为null,大小> 0。CNend 5161bd4fe43Sopenharmony_ci* @param output [OUT] type #struct hks_blob *,Generated message verification code, 5171bd4fe43Sopenharmony_ci output and output->data cannot be null constraint condition: 5181bd4fe43Sopenharmony_ci when alg is hks_alg_hmac(HKS_ALG_HASH_SHA_256), output->size must be greater than or 5191bd4fe43Sopenharmony_ci equal to 32 when alg is hks_alg_hmac(HKS_ALG_HASH_SHA_512), output->size must be greater than or equal to 64 5201bd4fe43Sopenharmony_ci CNcomment:生成的消息验证码,输出和输出->数据不能为空约束条件: 5211bd4fe43Sopenharmony_ci 当alg为hks_alg_hmac(HKS_ALG_HASH_SHA_256)时,output-> size必须大于或 5221bd4fe43Sopenharmony_ci 当alg为hks_alg_hmac(HKS_ALG_HASH_SHA_512)时等于32,则output-> size必须大于或等于64。CNend 5231bd4fe43Sopenharmony_ci* @retval #0 Success. 5241bd4fe43Sopenharmony_ci* @retval #Other Failure. 5251bd4fe43Sopenharmony_ci* @par 依赖: 5261bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 5271bd4fe43Sopenharmony_ci* @see hks_hmac 5281bd4fe43Sopenharmony_ci*/ 5291bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_hmac(const struct hks_blob *key, 5301bd4fe43Sopenharmony_ci const uint32_t alg, const struct hks_blob *src_data, 5311bd4fe43Sopenharmony_ci struct hks_blob *output); 5321bd4fe43Sopenharmony_ci 5331bd4fe43Sopenharmony_ci/** 5341bd4fe43Sopenharmony_ci* @ingroup iot_hks 5351bd4fe43Sopenharmony_ci* @brief Calculate the hash value of the data based on SHA256 or SHA512. 5361bd4fe43Sopenharmony_ci CNcomment:基于SHA256或SHA512计算数据的散列值。CNend 5371bd4fe43Sopenharmony_ci* 5381bd4fe43Sopenharmony_ci* @par 描述: 5391bd4fe43Sopenharmony_ci* Calculate the hash value of the data based on SHA256 or SHA512. 5401bd4fe43Sopenharmony_ci CNcomment:基于SHA256或SHA512计算数据的散列值。CNend 5411bd4fe43Sopenharmony_ci* 5421bd4fe43Sopenharmony_ci* @attention None 5431bd4fe43Sopenharmony_ci* @param alg [IN] type #const uint32_t,Hash algorithm, Only spuuort SHA256/SHA512. 5441bd4fe43Sopenharmony_ci CNcomment:哈希算法,仅支持SHA256 / SHA512。CNend 5451bd4fe43Sopenharmony_ci* @param src_data [IN] type #const struct hks_blob *,src data data cannot be null, and size > 0. 5461bd4fe43Sopenharmony_ci CNcomment:源数据,数据不能为null,大小> 0。CNend 5471bd4fe43Sopenharmony_ci* @param hash [OUT] type #struct hks_blob *,Generated message verification code , 5481bd4fe43Sopenharmony_ci hash and hash->data cannot be null constraint condition: 5491bd4fe43Sopenharmony_ci when alg is HKS_ALG_HASH_SHA_256, hash->size must be greater than or equal to 32 when alg is HKS_ALG_HASH_SHA_512, 5501bd4fe43Sopenharmony_ci hash->size must be greater than or equal to 64. 5511bd4fe43Sopenharmony_ci CNcomment:生成的消息验证码,hash和hash-> data不能为null约束条件:当alg为HKS_ALG_HASH_SHA_256时, 5521bd4fe43Sopenharmony_ci 当alg为HKS_ALG_HASH_SHA_512时,hash-> size必须大于或等于32,hash-> size必须大于或等于64。CNend 5531bd4fe43Sopenharmony_ci* @retval #0 Success. 5541bd4fe43Sopenharmony_ci* @retval #Other Failure. 5551bd4fe43Sopenharmony_ci* @par 依赖: 5561bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 5571bd4fe43Sopenharmony_ci* @see hks_hash 5581bd4fe43Sopenharmony_ci*/ 5591bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_hash(const uint32_t alg, 5601bd4fe43Sopenharmony_ci const struct hks_blob *src_data, struct hks_blob *hash); 5611bd4fe43Sopenharmony_ci 5621bd4fe43Sopenharmony_ci/** 5631bd4fe43Sopenharmony_ci* @ingroup iot_hks 5641bd4fe43Sopenharmony_ci* @brief Unsigned large integer modulo operation. CNcomment:无符号大整数模运算。CNend 5651bd4fe43Sopenharmony_ci* 5661bd4fe43Sopenharmony_ci* @par 描述: 5671bd4fe43Sopenharmony_ci* Unsigned large integer modulo operation. CNcomment:无符号大整数模运算。CNend 5681bd4fe43Sopenharmony_ci* 5691bd4fe43Sopenharmony_ci* @attention None 5701bd4fe43Sopenharmony_ci* @param x [OUT] type #struct hks_blob *,Modular result,x and x->data cannot be null, x->size >= n.size. 5711bd4fe43Sopenharmony_ci CNcomment:模运算结果,x和x-> data不能为null,x-> size> = n.size。CNend 5721bd4fe43Sopenharmony_ci* @param a [IN] type #const struct hks_blob *,Base data data cannot be null, size > 0. 5731bd4fe43Sopenharmony_ci CNcomment:底数, 数据不能为null,大小> 0。CNend 5741bd4fe43Sopenharmony_ci* @param e [IN] type #const struct hks_blob *,data cannot be null, size > 0. 5751bd4fe43Sopenharmony_ci CNcomment:幂, 数据不能为null,大小> 0。CNend 5761bd4fe43Sopenharmony_ci* @param n [IN] type #const struct hks_blob *,Modulus, data cannot be null, size > 0. 5771bd4fe43Sopenharmony_ci CNcomment:模数, 数据不能为null,大小> 0。CNend 5781bd4fe43Sopenharmony_ci* @retval #0 Success. 5791bd4fe43Sopenharmony_ci* @retval #Other Failure. 5801bd4fe43Sopenharmony_ci* @par 依赖: 5811bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 5821bd4fe43Sopenharmony_ci* @see hks_bn_exp_mod 5831bd4fe43Sopenharmony_ci*/ 5841bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_bn_exp_mod(struct hks_blob *x, 5851bd4fe43Sopenharmony_ci const struct hks_blob *a, const struct hks_blob *e, 5861bd4fe43Sopenharmony_ci const struct hks_blob *n); 5871bd4fe43Sopenharmony_ci 5881bd4fe43Sopenharmony_ci/** 5891bd4fe43Sopenharmony_ci* @ingroup iot_hks 5901bd4fe43Sopenharmony_ci* @brief Get public key alias list Interface. CNcomment:获取公钥别名列表接口。CNend 5911bd4fe43Sopenharmony_ci* 5921bd4fe43Sopenharmony_ci* @par 描述: 5931bd4fe43Sopenharmony_ci* Get public key alias list Interface. CNcomment:获取公钥别名列表接口。CNend 5941bd4fe43Sopenharmony_ci* 5951bd4fe43Sopenharmony_ci* @attention None 5961bd4fe43Sopenharmony_ci* @param key_alias_list [OUT] type #struct hks_blob *,struct hks_blob array, alloc and free memory by the caller. 5971bd4fe43Sopenharmony_ci CNcomment:用于存放别名,struct hks_blob数组,调用者分配和释放内存。CNend 5981bd4fe43Sopenharmony_ci* @param list_count [IN] type #uint32_t *,Indicates the number of available hks_blob_t caches, 5991bd4fe43Sopenharmony_ci public key alias number, alloc and free memory by the caller. 6001bd4fe43Sopenharmony_ci CNcomment:表示可用的hks_blob_t缓存数量,调用方的公钥别名号,分配和可用内存。CNend 6011bd4fe43Sopenharmony_ci* @retval #0 Success. 6021bd4fe43Sopenharmony_ci* @retval #Other Failure. 6031bd4fe43Sopenharmony_ci* @par 依赖: 6041bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 6051bd4fe43Sopenharmony_ci* @see hks_get_pub_key_alias_list 6061bd4fe43Sopenharmony_ci*/ 6071bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_get_pub_key_alias_list( 6081bd4fe43Sopenharmony_ci struct hks_blob *key_alias_list, uint32_t *list_count); 6091bd4fe43Sopenharmony_ci 6101bd4fe43Sopenharmony_ci/** 6111bd4fe43Sopenharmony_ci* @ingroup iot_hks 6121bd4fe43Sopenharmony_ci* @brief generate symmetric key. CNcomment:生成对称密钥。CNend 6131bd4fe43Sopenharmony_ci* 6141bd4fe43Sopenharmony_ci* @par 描述: 6151bd4fe43Sopenharmony_ci* generate symmetric key,Only AES-128/AES-192/AES-256 key generation is supported. 6161bd4fe43Sopenharmony_ci CNcomment:生成对称密钥,仅支持AES-128 / AES-192 / AES-256密钥生成。CNend 6171bd4fe43Sopenharmony_ci* 6181bd4fe43Sopenharmony_ci* @attention None 6191bd4fe43Sopenharmony_ci* @param output_key [OUT] type #struct hks_blob *,Key obtained.CNcomment:获取的key。CNend 6201bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,Need to generate key parameters. 6211bd4fe43Sopenharmony_ci CNcomment:需要生成key的参数。CNend 6221bd4fe43Sopenharmony_ci* @retval #0 Success. 6231bd4fe43Sopenharmony_ci* @retval #Other Failure. 6241bd4fe43Sopenharmony_ci* @par 依赖: 6251bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 6261bd4fe43Sopenharmony_ci* @see hks_generate_symmetric_key 6271bd4fe43Sopenharmony_ci*/ 6281bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_generate_symmetric_key(struct hks_blob *output_key, 6291bd4fe43Sopenharmony_ci const struct hks_key_param *key_param); 6301bd4fe43Sopenharmony_ci 6311bd4fe43Sopenharmony_ci/** 6321bd4fe43Sopenharmony_ci* @ingroup iot_hks 6331bd4fe43Sopenharmony_ci* @brief AES encryption, requires the use of the AES symmetric key generated above as an input parameter, 6341bd4fe43Sopenharmony_ci supports GCM CCM CBC mode, key length 128/192/256. 6351bd4fe43Sopenharmony_ci CNcomment:AES加密,要求使用上述生成AES对称的密钥作为入参,支持GCM CCM CBC模式,key长度128/192/256。CNend 6361bd4fe43Sopenharmony_ci* 6371bd4fe43Sopenharmony_ci* @par 描述: 6381bd4fe43Sopenharmony_ci* AES encryption, requires the use of the AES symmetric key generated above as an input parameter, 6391bd4fe43Sopenharmony_ci supports GCM CCM CBC mode, key length 128/192/256. 6401bd4fe43Sopenharmony_ci CNcomment:AES加密,要求使用上述生成AES对称的密钥作为入参,支持GCM CCM CBC模式,key长度128/192/256。CNend 6411bd4fe43Sopenharmony_ci* 6421bd4fe43Sopenharmony_ci* @attention None 6431bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob *,The key required for encryption, 6441bd4fe43Sopenharmony_ci the key to generate the AES symmetric key output as an input parameter. 6451bd4fe43Sopenharmony_ci CNcomment:加密所需密钥,需要为生成AES对称密钥输出的key作为入参。CNend 6461bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,Encryption key parameters. 6471bd4fe43Sopenharmony_ci CNcomment:加密密钥参数。CNend 6481bd4fe43Sopenharmony_ci* @param crypt_param [IN] type #const struct hks_crypt_param *,Encrypted information. CNcomment:加密信息。CNend 6491bd4fe43Sopenharmony_ci* @param plain_text [IN] type #const struct hks_blob *,plain_text.CNcomment:明文。CNend 6501bd4fe43Sopenharmony_ci* @param cipher_text_with_tag [OUT] type #struct hks_blob *,Encrypted ciphertext.CNcomment:加密后密文。CNend 6511bd4fe43Sopenharmony_ci* @retval #0 Success. 6521bd4fe43Sopenharmony_ci* @retval #Other Failure. 6531bd4fe43Sopenharmony_ci* @par 依赖: 6541bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 6551bd4fe43Sopenharmony_ci* @see hks_symmetric_encrypt 6561bd4fe43Sopenharmony_ci*/ 6571bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_symmetric_encrypt(const struct hks_blob *key, 6581bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, const struct hks_crypt_param *crypt_param, 6591bd4fe43Sopenharmony_ci const struct hks_blob *plain_text, struct hks_blob *cipher_text_with_tag); 6601bd4fe43Sopenharmony_ci 6611bd4fe43Sopenharmony_ci/** 6621bd4fe43Sopenharmony_ci* @ingroup iot_hks 6631bd4fe43Sopenharmony_ci* @brief AES decryption, requires the use of the above generated AES symmetric key as an input parameter, 6641bd4fe43Sopenharmony_ci supports GCM CCM CBC mode, key length 128/192/256. 6651bd4fe43Sopenharmony_ci CNcomment:AES解密,要求使用上述生成AES对称的密钥作为入参,支持GCM CCM CBC模式,key长度128/192/256。CNend 6661bd4fe43Sopenharmony_ci* 6671bd4fe43Sopenharmony_ci* @par 描述: 6681bd4fe43Sopenharmony_ci* AES decryption, requires the use of the above generated AES symmetric key as an input parameter, 6691bd4fe43Sopenharmony_ci supports GCM CCM CBC mode, key length 128/192/256. 6701bd4fe43Sopenharmony_ci CNcomment:AES解密,要求使用上述生成AES对称的密钥作为入参,支持GCM CCM CBC模式,key长度128/192/256。CNend 6711bd4fe43Sopenharmony_ci* 6721bd4fe43Sopenharmony_ci* @attention None 6731bd4fe43Sopenharmony_ci* @param key [IN] type #const struct hks_blob *,The key required for decryption needs to be the 6741bd4fe43Sopenharmony_ci input key for generating the AES symmetric key output. 6751bd4fe43Sopenharmony_ci CNcomment:解密所需密钥,需要为生成AES对称密钥输出的key作为入参。CNend 6761bd4fe43Sopenharmony_ci* @param key_param [IN] type #const struct hks_key_param *,decrypt key parameters. 6771bd4fe43Sopenharmony_ci CNcomment:解密密钥参数。CNend 6781bd4fe43Sopenharmony_ci* @param crypt_param [IN] type #const struct hks_crypt_param *,Decrypt information. CNcomment:解密信息。CNend 6791bd4fe43Sopenharmony_ci* @param plain_text [OUT] type #const struct hks_blob *,Plaintext after decryption.CNcomment:解密后明文。CNend 6801bd4fe43Sopenharmony_ci* @param cipher_text_with_tag [IN] type #struct hks_blob *,Ciphertext.CNcomment:密文。CNend 6811bd4fe43Sopenharmony_ci* @retval #0 Success. 6821bd4fe43Sopenharmony_ci* @retval #Other Failure. 6831bd4fe43Sopenharmony_ci* @par 依赖: 6841bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 6851bd4fe43Sopenharmony_ci* @see hks_symmetric_encrypt 6861bd4fe43Sopenharmony_ci*/ 6871bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_symmetric_decrypt(const struct hks_blob *key, 6881bd4fe43Sopenharmony_ci const struct hks_key_param *key_param, const struct hks_crypt_param *crypt_param, 6891bd4fe43Sopenharmony_ci struct hks_blob *plain_text, const struct hks_blob *cipher_text_with_tag); 6901bd4fe43Sopenharmony_ci 6911bd4fe43Sopenharmony_ci/** 6921bd4fe43Sopenharmony_ci* @ingroup iot_hks 6931bd4fe43Sopenharmony_ci* @brief get security capabilites. CNcomment:获得安全功能。CNend 6941bd4fe43Sopenharmony_ci* 6951bd4fe43Sopenharmony_ci* @par 描述: 6961bd4fe43Sopenharmony_ci* Get device security attributes, output as a json string, you can get information such as the 6971bd4fe43Sopenharmony_ci algorithm type supported by the device certificate. 6981bd4fe43Sopenharmony_ci CNcomment:获取设备安全属性,输出为json串,可以获取设备证书支持的算法类型等信息。CNend 6991bd4fe43Sopenharmony_ci* 7001bd4fe43Sopenharmony_ci* @attention None 7011bd4fe43Sopenharmony_ci* @param flag [IN] type #uint32_t,Reserved field, no assignment is required. 7021bd4fe43Sopenharmony_ci CNcomment:预留字段,当前不需要赋值。CNend 7031bd4fe43Sopenharmony_ci* @param capabilities [OUT] type #struct hks_blob *,Information obtained.CNcomment:获取到的信息。CNend 7041bd4fe43Sopenharmony_ci* @retval #0 Success. 7051bd4fe43Sopenharmony_ci* @retval #Other Failure. 7061bd4fe43Sopenharmony_ci* @par 依赖: 7071bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 7081bd4fe43Sopenharmony_ci* @see hks_get_security_capabilites 7091bd4fe43Sopenharmony_ci*/ 7101bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_get_security_capabilites(uint32_t flag, struct hks_blob *capabilities); 7111bd4fe43Sopenharmony_ci 7121bd4fe43Sopenharmony_ci/** 7131bd4fe43Sopenharmony_ci* @ingroup iot_hks 7141bd4fe43Sopenharmony_ci* @brief export device certs. CNcomment:导出设备证书。CNend 7151bd4fe43Sopenharmony_ci* 7161bd4fe43Sopenharmony_ci* @par 描述: 7171bd4fe43Sopenharmony_ci* export device certs. CNcomment:导出设备证书。CNend 7181bd4fe43Sopenharmony_ci* 7191bd4fe43Sopenharmony_ci* @attention None 7201bd4fe43Sopenharmony_ci* @param key_id [IN] type #uint8_t,Array index of device_identity field obtained with 7211bd4fe43Sopenharmony_ci hks_get_security_capabilites. 7221bd4fe43Sopenharmony_ci CNcomment:使用hks_get_security_capabilites获取的device_identity字段的数组下标。CNend 7231bd4fe43Sopenharmony_ci* @param cert_chain [OUT] type #hks_cert_chain *,Export certificate information. 7241bd4fe43Sopenharmony_ci CNcomment:导出证书信息。CNend 7251bd4fe43Sopenharmony_ci* @retval #0 Success. 7261bd4fe43Sopenharmony_ci* @retval #Other Failure. 7271bd4fe43Sopenharmony_ci* @par 依赖: 7281bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 7291bd4fe43Sopenharmony_ci* @see hks_export_device_certs 7301bd4fe43Sopenharmony_ci*/ 7311bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_export_device_certs(uint8_t key_id, struct hks_cert_chain *cert_chain); 7321bd4fe43Sopenharmony_ci 7331bd4fe43Sopenharmony_ci/** 7341bd4fe43Sopenharmony_ci* @ingroup iot_hks 7351bd4fe43Sopenharmony_ci* @brief sign with device key. CNcomment:用设备私钥签名。CNend 7361bd4fe43Sopenharmony_ci* 7371bd4fe43Sopenharmony_ci* @par 描述: 7381bd4fe43Sopenharmony_ci* sign with device key. CNcomment:用设备私钥签名。CNend 7391bd4fe43Sopenharmony_ci* 7401bd4fe43Sopenharmony_ci* @attention None 7411bd4fe43Sopenharmony_ci* @param key_id [IN] type #uint8_t,Array index of device_identity field obtained with 7421bd4fe43Sopenharmony_ci hks_get_security_capabilites. 7431bd4fe43Sopenharmony_ci CNcomment:使用hks_get_security_capabilites获取的device_identity字段的数组下标。CNend 7441bd4fe43Sopenharmony_ci* @param usage [IN] type #const struct hks_usage_spec *,Signing required parameters. 7451bd4fe43Sopenharmony_ci CNcomment:签名所需参数。CNend 7461bd4fe43Sopenharmony_ci* @param challenge [IN] type #const struct hks_blob *,Data to be signed. 7471bd4fe43Sopenharmony_ci CNcomment:待签名的数据。CNend 7481bd4fe43Sopenharmony_ci* @param signature [OUT] type #struct hks_blob *,Output data signature. 7491bd4fe43Sopenharmony_ci CNcomment:输出的数据签名。CNend 7501bd4fe43Sopenharmony_ci* @retval #0 Success. 7511bd4fe43Sopenharmony_ci* @retval #Other Failure. 7521bd4fe43Sopenharmony_ci* @par 依赖: 7531bd4fe43Sopenharmony_ci* @li hks_types.h:describes hks_types SDK interfaces.CNcomment:描述hks_types SDK的接口。CNend 7541bd4fe43Sopenharmony_ci* @see hks_sign_with_device_key 7551bd4fe43Sopenharmony_ci*/ 7561bd4fe43Sopenharmony_ciHKS_DLL_API_PUBLIC int32_t hks_sign_with_device_key(uint8_t key_id, 7571bd4fe43Sopenharmony_ci const struct hks_usage_spec *usage, const struct hks_blob *challenge, struct hks_blob *signature); 7581bd4fe43Sopenharmony_ci 7591bd4fe43Sopenharmony_ci 7601bd4fe43Sopenharmony_ci#ifdef __cplusplus 7611bd4fe43Sopenharmony_ci} 7621bd4fe43Sopenharmony_ci#endif 7631bd4fe43Sopenharmony_ci 7641bd4fe43Sopenharmony_ci#endif /* HKS_CLIENT_H */ 765