11bd4fe43Sopenharmony_ci/*
21bd4fe43Sopenharmony_ci * @file hi_cipher.h
31bd4fe43Sopenharmony_ci *
41bd4fe43Sopenharmony_ci * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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/** @defgroup iot_cipher Cipher APIs
191bd4fe43Sopenharmony_ci * @ingroup iot_romboot
201bd4fe43Sopenharmony_ci */
211bd4fe43Sopenharmony_ci#ifndef __HI_CIPHER_H__
221bd4fe43Sopenharmony_ci#define __HI_CIPHER_H__
231bd4fe43Sopenharmony_ci
241bd4fe43Sopenharmony_ci#include <hi_types.h>
251bd4fe43Sopenharmony_ci#include <hi_boot_err.h>
261bd4fe43Sopenharmony_ci
271bd4fe43Sopenharmony_ci#ifdef __cplusplus
281bd4fe43Sopenharmony_ci#if __cplusplus
291bd4fe43Sopenharmony_ciextern "C" {
301bd4fe43Sopenharmony_ci#endif
311bd4fe43Sopenharmony_ci#endif  /* __cplusplus */
321bd4fe43Sopenharmony_ci
331bd4fe43Sopenharmony_ci#define PKE_LEN_32_BYTES             32
341bd4fe43Sopenharmony_ci#define PKE_LEN_256_BYTES            256
351bd4fe43Sopenharmony_ci#define PKE_LEN_384_BYTES            384
361bd4fe43Sopenharmony_ci#define PKE_LEN_512_BYTES            512
371bd4fe43Sopenharmony_ci#define RSA_KEY_LEN_2048             256
381bd4fe43Sopenharmony_ci#define AES_MAX_KEY_IN_WORD          16
391bd4fe43Sopenharmony_ci#define AES_IV_LEN_IN_WORD           4
401bd4fe43Sopenharmony_ci#define KDF_KEY_LEN_IN_BYTES         32
411bd4fe43Sopenharmony_ci
421bd4fe43Sopenharmony_ci/**
431bd4fe43Sopenharmony_ci* @ingroup iot_cipher
441bd4fe43Sopenharmony_ci* Rsa sign and veriry scheme
451bd4fe43Sopenharmony_ci*/
461bd4fe43Sopenharmony_citypedef enum {
471bd4fe43Sopenharmony_ci    HI_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA256 = 0x00,   /* PKCS#1 RSASSA_PKCS1_V15_SHA256 signature */
481bd4fe43Sopenharmony_ci    HI_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA256,          /* PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature */
491bd4fe43Sopenharmony_ci    HI_CIPHER_RSA_SIGN_SCHEME_MAX,
501bd4fe43Sopenharmony_ci    HI_CIPHER_RSA_SIGN_SCHEME_INVALID = 0xffffffff,
511bd4fe43Sopenharmony_ci}hi_cipher_rsa_sign_scheme;
521bd4fe43Sopenharmony_ci
531bd4fe43Sopenharmony_ci/**
541bd4fe43Sopenharmony_ci* @ingroup iot_cipher
551bd4fe43Sopenharmony_ci* Aes key from
561bd4fe43Sopenharmony_ci*/
571bd4fe43Sopenharmony_citypedef enum {
581bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_FROM_CPU = 0x00,
591bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_FROM_KDF,
601bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_FROM_MAX,
611bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_FROM_INVALID = 0xffffffff,
621bd4fe43Sopenharmony_ci}hi_cipher_aes_key_from;
631bd4fe43Sopenharmony_ci
641bd4fe43Sopenharmony_ci/**
651bd4fe43Sopenharmony_ci* @ingroup iot_cipher
661bd4fe43Sopenharmony_ci* Aes work mode
671bd4fe43Sopenharmony_ci*/
681bd4fe43Sopenharmony_citypedef enum {
691bd4fe43Sopenharmony_ci    HI_CIPHER_AES_WORK_MODE_ECB = 0x00,    /* Electronic codebook (ECB) mode, ECB has been considered insecure and
701bd4fe43Sopenharmony_ci                                               it is recommended not to use it. */
711bd4fe43Sopenharmony_ci    HI_CIPHER_AES_WORK_MODE_CBC,            /* Cipher block chaining (CBC) mode. */
721bd4fe43Sopenharmony_ci    HI_CIPHER_AES_WORK_MODE_CTR,            /* Counter (CTR) mode. */
731bd4fe43Sopenharmony_ci    HI_CIPHER_AES_WORK_MODE_XTS,            /* XTS-AES (XTS) mode. */
741bd4fe43Sopenharmony_ci    HI_CIPHER_AES_WORK_MODE_MAX,
751bd4fe43Sopenharmony_ci    HI_CIPHER_AES_WORK_MODE_INVALID = 0xffffffff,
761bd4fe43Sopenharmony_ci}hi_cipher_aes_work_mode;
771bd4fe43Sopenharmony_ci
781bd4fe43Sopenharmony_ci/**
791bd4fe43Sopenharmony_ci* @ingroup iot_cipher
801bd4fe43Sopenharmony_ci* Aes key length
811bd4fe43Sopenharmony_ci*/
821bd4fe43Sopenharmony_citypedef enum {
831bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_LENGTH_128BIT  = 0x00,
841bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_LENGTH_192BIT,
851bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_LENGTH_256BIT,
861bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_LENGTH_512BIT,             /* 512bit, just used for xts. */
871bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_LENGTH_MAX,
881bd4fe43Sopenharmony_ci    HI_CIPHER_AES_KEY_LENGTH_INVALID = 0xffffffff,
891bd4fe43Sopenharmony_ci}hi_cipher_aes_key_length;
901bd4fe43Sopenharmony_ci
911bd4fe43Sopenharmony_ci/**
921bd4fe43Sopenharmony_ci* @ingroup iot_cipher
931bd4fe43Sopenharmony_ci* Rsa public key verify
941bd4fe43Sopenharmony_ci*/
951bd4fe43Sopenharmony_citypedef struct {
961bd4fe43Sopenharmony_ci    hi_cipher_rsa_sign_scheme scheme;  /* The rsa sign type */
971bd4fe43Sopenharmony_ci    hi_u8 *e;                          /* The public exponent */
981bd4fe43Sopenharmony_ci    hi_u8 *n;                          /* The modulus */
991bd4fe43Sopenharmony_ci    hi_u32 klen;                       /* The key length */
1001bd4fe43Sopenharmony_ci} hi_cipher_rsa_verify;
1011bd4fe43Sopenharmony_ci
1021bd4fe43Sopenharmony_ci/**
1031bd4fe43Sopenharmony_ci* @ingroup iot_cipher
1041bd4fe43Sopenharmony_ci* Struct of ecc curves parameters
1051bd4fe43Sopenharmony_ci*/
1061bd4fe43Sopenharmony_citypedef struct {
1071bd4fe43Sopenharmony_ci    const hi_u8 *p;   /* Finite field: equal to p in case of prime field curves or equal to 2^n in case of binary
1081bd4fe43Sopenharmony_ci                         field curves. */
1091bd4fe43Sopenharmony_ci    const hi_u8 *a;   /* Curve parameter a (q-3 in Suite B). */
1101bd4fe43Sopenharmony_ci    const hi_u8 *b;   /* Curve parameter b. */
1111bd4fe43Sopenharmony_ci    const hi_u8 *gx;  /* X coordinates of G which is a base point on the curve. */
1121bd4fe43Sopenharmony_ci    const hi_u8 *gy;  /* Y coordinates of G which is a base point on the curve. */
1131bd4fe43Sopenharmony_ci    const hi_u8 *n;   /* Prime which is the order of G point. */
1141bd4fe43Sopenharmony_ci    hi_u32 h;         /* Cofactor, which is the order of the elliptic curve divided by the order of the point G. For
1151bd4fe43Sopenharmony_ci                         the Suite B curves, h = 1. */
1161bd4fe43Sopenharmony_ci    hi_u32 ksize;     /* Ecc key size in bytes. It corresponds to the size in bytes of the prime, should be 32bytes. */
1171bd4fe43Sopenharmony_ci}hi_cipher_ecc_param;
1181bd4fe43Sopenharmony_ci
1191bd4fe43Sopenharmony_ci/**
1201bd4fe43Sopenharmony_ci* @ingroup iot_cipher
1211bd4fe43Sopenharmony_ci* Struct of ecc verify
1221bd4fe43Sopenharmony_ci*/
1231bd4fe43Sopenharmony_citypedef struct {
1241bd4fe43Sopenharmony_ci    const hi_u8 *px;   /* Ecdh X coordinates of the generated public key, the caller ensures it is padded with leading
1251bd4fe43Sopenharmony_ci                          zeros if the effective size of this key is smaller than ecc key size. */
1261bd4fe43Sopenharmony_ci    const hi_u8 *py;   /* Ecdh Y coordinates of the generated public key, the caller ensures it is padded with leading
1271bd4fe43Sopenharmony_ci                          zeros if the effective size of this key is smaller than ecc key size. */
1281bd4fe43Sopenharmony_ci    const hi_u8 *hash; /* Input hash data for ecc verify. */
1291bd4fe43Sopenharmony_ci    hi_u32 hash_len;   /* The length of hash data, just 32 bytes is valid data. */
1301bd4fe43Sopenharmony_ci    const hi_u8 *r;    /* Output ecc sign result R, its length is ecc key size. */
1311bd4fe43Sopenharmony_ci    const hi_u8 *s;    /* Output ecc sign result S, its length is ecc key size. */
1321bd4fe43Sopenharmony_ci    hi_u8 *out_r;      /* Output verify r data for security. */
1331bd4fe43Sopenharmony_ci}hi_cipher_ecc_verify;
1341bd4fe43Sopenharmony_ci
1351bd4fe43Sopenharmony_ci/**
1361bd4fe43Sopenharmony_ci* @ingroup iot_cipher
1371bd4fe43Sopenharmony_ci* Struct of rsa verify
1381bd4fe43Sopenharmony_ci*/
1391bd4fe43Sopenharmony_citypedef struct {
1401bd4fe43Sopenharmony_ci    hi_u8 *hash;        /* The input hash value will be changed after hi_cipher_rsa_verify_hash execution,
1411bd4fe43Sopenharmony_ci                           the correct value should be input before each verification */
1421bd4fe43Sopenharmony_ci    hi_u8 *out_hash;
1431bd4fe43Sopenharmony_ci    hi_u32 hash_len;
1441bd4fe43Sopenharmony_ci    const hi_u8 *sign;
1451bd4fe43Sopenharmony_ci    hi_u32 sign_len;
1461bd4fe43Sopenharmony_ci} hi_cipher_rsa_data;
1471bd4fe43Sopenharmony_ci
1481bd4fe43Sopenharmony_ci/**
1491bd4fe43Sopenharmony_ci* @ingroup iot_cipher
1501bd4fe43Sopenharmony_ci* Aes ctrl struct
1511bd4fe43Sopenharmony_ci*/
1521bd4fe43Sopenharmony_citypedef struct {
1531bd4fe43Sopenharmony_ci    hi_u32 key[AES_MAX_KEY_IN_WORD];     /* Key input. */
1541bd4fe43Sopenharmony_ci    hi_u32 iv[AES_IV_LEN_IN_WORD];       /* Initialization vector (IV). */
1551bd4fe43Sopenharmony_ci    hi_bool random_en;                   /* Enable random delay or not. */
1561bd4fe43Sopenharmony_ci    hi_cipher_aes_key_from key_from;     /* Key from, When using kdf key, no nead to configure the input key. */
1571bd4fe43Sopenharmony_ci    hi_cipher_aes_work_mode work_mode;   /* Work mode. */
1581bd4fe43Sopenharmony_ci    hi_cipher_aes_key_length key_len;    /* Key length. aes-ecb/cbc/ctr support 128/192/256 bits key, ccm just support
1591bd4fe43Sopenharmony_ci                                            128 bits key, xts just support 256/512 bits key. */
1601bd4fe43Sopenharmony_ci}hi_cipher_aes_ctrl;
1611bd4fe43Sopenharmony_ci
1621bd4fe43Sopenharmony_ci/**
1631bd4fe43Sopenharmony_ci* @ingroup iot_cipher
1641bd4fe43Sopenharmony_ci* Kdf key type
1651bd4fe43Sopenharmony_ci*/
1661bd4fe43Sopenharmony_citypedef enum {
1671bd4fe43Sopenharmony_ci    HI_CIPHER_SSS_KDF_KEY_DEVICE  = 0x0, /* kdf device key derivation. */
1681bd4fe43Sopenharmony_ci    HI_CIPHER_SSS_KDF_KEY_STORAGE,       /* kdf storage key derivation. */
1691bd4fe43Sopenharmony_ci    HI_CIPHER_SSS_KDF_KEY_MAX,
1701bd4fe43Sopenharmony_ci    HI_CIPHER_SSS_KDF_KEY_INVALID = 0xFFFFFFFF,
1711bd4fe43Sopenharmony_ci}hi_cipher_kdf_mode;
1721bd4fe43Sopenharmony_ci
1731bd4fe43Sopenharmony_ci/**
1741bd4fe43Sopenharmony_ci* @ingroup iot_cipher
1751bd4fe43Sopenharmony_ci* Kdf ctrl struct
1761bd4fe43Sopenharmony_ci*/
1771bd4fe43Sopenharmony_citypedef struct {
1781bd4fe43Sopenharmony_ci    const hi_u8 *salt;                   /* salt for kdf key derivation. */
1791bd4fe43Sopenharmony_ci    hi_u32 salt_len;                     /* salt_len should be 16 bytes for kdf device key derivation,
1801bd4fe43Sopenharmony_ci                                            32 bytes for kdf storage key derivation. */
1811bd4fe43Sopenharmony_ci    hi_u8 key[KDF_KEY_LEN_IN_BYTES];     /* just used for kdf device key. */
1821bd4fe43Sopenharmony_ci    hi_cipher_kdf_mode kdf_mode;         /* kdf mode for key derivation. */
1831bd4fe43Sopenharmony_ci    hi_u32 kdf_cnt;                      /**< kdf cnt for iteration.It is recommended that the number of iterations be
1841bd4fe43Sopenharmony_ci        not less than 10000 times, if performance requirement, no less than 1000
1851bd4fe43Sopenharmony_ci        times,  and not more than 0xffff times. */
1861bd4fe43Sopenharmony_ci    hi_u8 result[KDF_KEY_LEN_IN_BYTES];  /* output for kdf device key derivation. */
1871bd4fe43Sopenharmony_ci}hi_cipher_kdf_ctrl;
1881bd4fe43Sopenharmony_ci
1891bd4fe43Sopenharmony_ci/**
1901bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
1911bd4fe43Sopenharmony_ci* @brief          Initializes the Cipher module. CNcomment:Cipher 模块初始化。CNend
1921bd4fe43Sopenharmony_ci*
1931bd4fe43Sopenharmony_ci* @par 描述:
1941bd4fe43Sopenharmony_ci*                 Initializes the Cipher module.
1951bd4fe43Sopenharmony_ciCNcomment:Cipher模块初始化。CNend
1961bd4fe43Sopenharmony_ci*
1971bd4fe43Sopenharmony_ci* @attention      This function must be called before using cipher module.
1981bd4fe43Sopenharmony_ciCNcomment:使用Cipher模块算法前调用本接口初始化。CNend
1991bd4fe43Sopenharmony_ci* @param          None
2001bd4fe43Sopenharmony_ci*
2011bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
2021bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
2031bd4fe43Sopenharmony_ci* @par 依赖:
2041bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
2051bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
2061bd4fe43Sopenharmony_ci* @see            hi_cipher_init。
2071bd4fe43Sopenharmony_ci*/
2081bd4fe43Sopenharmony_cihi_u32 hi_cipher_init(hi_void);
2091bd4fe43Sopenharmony_ci
2101bd4fe43Sopenharmony_ci/**
2111bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
2121bd4fe43Sopenharmony_ci* @brief          Deinitializes the Cipher module. CNcomment:Cipher 模块去初始化。CNend
2131bd4fe43Sopenharmony_ci*
2141bd4fe43Sopenharmony_ci* @par 描述:
2151bd4fe43Sopenharmony_ci*                 Deinitializes the Cipher module, does NOT support multi-tasks.
2161bd4fe43Sopenharmony_ciCNcomment:Cipher模块去初始化,不支持多任务。CNend
2171bd4fe43Sopenharmony_ci*
2181bd4fe43Sopenharmony_ci* @attention      This function could be called after using Cipher module finished.
2191bd4fe43Sopenharmony_ciCNcomment:结束使用Cipher模块算法后调用本接口去初始化。CNend
2201bd4fe43Sopenharmony_ci* @param          None
2211bd4fe43Sopenharmony_ci*
2221bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
2231bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
2241bd4fe43Sopenharmony_ci* @par 依赖:
2251bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
2261bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
2271bd4fe43Sopenharmony_ci* @see            hi_cipher_deinit。
2281bd4fe43Sopenharmony_ci*/
2291bd4fe43Sopenharmony_cihi_u32 hi_cipher_deinit(hi_void);
2301bd4fe43Sopenharmony_ci
2311bd4fe43Sopenharmony_ci/**
2321bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
2331bd4fe43Sopenharmony_ci* @brief          Settings of AES. CNcomment:AES算法参数配置。CNend
2341bd4fe43Sopenharmony_ci*
2351bd4fe43Sopenharmony_ci* @par 描述:
2361bd4fe43Sopenharmony_ci*                 Configure of AES. CNcomment:AES算法参数配置。CNend
2371bd4fe43Sopenharmony_ci*
2381bd4fe43Sopenharmony_ci* @attention      None
2391bd4fe43Sopenharmony_ci* @param          ctrl        [IN]  type #hi_cipher_aes_ctrl *,AES parameters. CNcomment:AES算法参数配置。CNend
2401bd4fe43Sopenharmony_ci*
2411bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
2421bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
2431bd4fe43Sopenharmony_ci* @par 依赖:
2441bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
2451bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
2461bd4fe43Sopenharmony_ci* @see            hi_cipher_aes_config。
2471bd4fe43Sopenharmony_ci*/
2481bd4fe43Sopenharmony_cihi_u32 hi_cipher_aes_config(hi_cipher_aes_ctrl *ctrl);
2491bd4fe43Sopenharmony_ci
2501bd4fe43Sopenharmony_ci/**
2511bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
2521bd4fe43Sopenharmony_ci* @brief          Encryption/Decryption of AES, if execution fails, hi_cipher_aes_destroy_config must be called to
2531bd4fe43Sopenharmony_cirelease resources.
2541bd4fe43Sopenharmony_ciCNcomment:AES算法加解密,如果执行失败,必须调用hi_cipher_aes_destroy_config接口释放资源。CNend
2551bd4fe43Sopenharmony_ci*
2561bd4fe43Sopenharmony_ci* @par 描述:
2571bd4fe43Sopenharmony_ci*                 Encryption/Decryption of AES. CNcomment:AES算法加解密。CNend
2581bd4fe43Sopenharmony_ci*
2591bd4fe43Sopenharmony_ci* @attention      无。
2601bd4fe43Sopenharmony_ci* @param          src_addr    [IN]  type #uintptr_t,Input data source address.
2611bd4fe43Sopenharmony_ciCNcomment:待加密或解密的源数据物理地址,地址要求4对齐。CNend
2621bd4fe43Sopenharmony_ci* @param          dest_addr   [OUT] type #uintptr_t,output data physical address, the address must be
2631bd4fe43Sopenharmony_cialigned in 4 bytes.
2641bd4fe43Sopenharmony_ciCNcomment:加密或解密结果数据物理地址,地址要求4对齐。CNend
2651bd4fe43Sopenharmony_ci* @param          length      [IN]  type #hi_u32,data length, ECB/CBC/CTR/XTS must be aligned in 16 bytes.
2661bd4fe43Sopenharmony_ciCNcomment:数据长度, ECB/CBC/CTR/XTS要求16bytes对齐。CNend
2671bd4fe43Sopenharmony_ci* @param          encrypt     [IN]  type #hi_bool,options of encryption/decryption, HI_TRUE is for encryption,
2681bd4fe43Sopenharmony_ciHI_FALSE is for decryption.CNcomment:加解密配置选项,配置HI_TRUE为加密,配置HI_FALSE为解密。CNend
2691bd4fe43Sopenharmony_ci*
2701bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
2711bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
2721bd4fe43Sopenharmony_ci* @par 依赖:
2731bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
2741bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
2751bd4fe43Sopenharmony_ci* @see            hi_cipher_aes_crypto。
2761bd4fe43Sopenharmony_ci*/
2771bd4fe43Sopenharmony_cihi_u32 hi_cipher_aes_crypto(uintptr_t src_addr, uintptr_t dest_addr, hi_u32 length, hi_bool encrypt);
2781bd4fe43Sopenharmony_ci
2791bd4fe43Sopenharmony_ci/**
2801bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
2811bd4fe43Sopenharmony_ci* @brief          Destory AES configures. CNcomment:AES算法销毁配置的参数CNend
2821bd4fe43Sopenharmony_ci*
2831bd4fe43Sopenharmony_ci* @par 描述:
2841bd4fe43Sopenharmony_ci*                 Destory AES configures. CNcomment:AES算法销毁配置的参数CNend
2851bd4fe43Sopenharmony_ci*
2861bd4fe43Sopenharmony_ci* @attention      In pair with hi_cipher_aes_config.CNcomment:与参数配置成对使用CNend
2871bd4fe43Sopenharmony_ci* @param          None
2881bd4fe43Sopenharmony_ci
2891bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
2901bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
2911bd4fe43Sopenharmony_ci* @par 依赖:
2921bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
2931bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
2941bd4fe43Sopenharmony_ci* @see            hi_cipher_aes_destroy_config。
2951bd4fe43Sopenharmony_ci*/
2961bd4fe43Sopenharmony_cihi_u32 hi_cipher_aes_destroy_config(hi_void);
2971bd4fe43Sopenharmony_ci
2981bd4fe43Sopenharmony_ci/**
2991bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
3001bd4fe43Sopenharmony_ci* @brief          Settings of HASH.CNcomment:HASH算法参数配置CNend
3011bd4fe43Sopenharmony_ci*
3021bd4fe43Sopenharmony_ci* @par 描述:
3031bd4fe43Sopenharmony_ci*                 Settings of HASH, this function should be called before calculating.
3041bd4fe43Sopenharmony_ciCNcomment:HASH算法参数配置,HASH计算前调用
3051bd4fe43Sopenharmony_ci*
3061bd4fe43Sopenharmony_ci* @attention      None
3071bd4fe43Sopenharmony_ci* @param  atts    [IN]        type #const hi_cipher_hash_atts *,HASH attribute.CNcomment:HASH算法类型配置。CNend
3081bd4fe43Sopenharmony_ci
3091bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
3101bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
3111bd4fe43Sopenharmony_ci* @par 依赖:
3121bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
3131bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
3141bd4fe43Sopenharmony_ci* @see            hi_cipher_hash_start。
3151bd4fe43Sopenharmony_ci*/
3161bd4fe43Sopenharmony_cihi_u32 hi_cipher_hash_start(hi_void);
3171bd4fe43Sopenharmony_ci
3181bd4fe43Sopenharmony_ci/**
3191bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
3201bd4fe43Sopenharmony_ci* @brief          Calculating by HASH.CNcomment:HASH计算CNend
3211bd4fe43Sopenharmony_ci*
3221bd4fe43Sopenharmony_ci* @par 描述:
3231bd4fe43Sopenharmony_ci*                 Hash calculation. Multiple segments can be calculated,Maximum 10KB per segment.
3241bd4fe43Sopenharmony_ciCNcomment:HASH计算,支持多段计算,每段最长10KB。CNend
3251bd4fe43Sopenharmony_ci*
3261bd4fe43Sopenharmony_ci* @attention      None
3271bd4fe43Sopenharmony_ci* @param          src_addr    [IN]  type #uintptr_t,Data address to be calculated by HASH.
3281bd4fe43Sopenharmony_ciCNcomment:待HASH计算的数据地址。CNend
3291bd4fe43Sopenharmony_ci* @param          length      [IN]  type #hi_u32,Data length to be calculated by HASH,maximum is 10KB.
3301bd4fe43Sopenharmony_ciCNcomment:待HASH计算的数据长度,最长10KB。CNend
3311bd4fe43Sopenharmony_ci*
3321bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
3331bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
3341bd4fe43Sopenharmony_ci* @par 依赖:
3351bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
3361bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
3371bd4fe43Sopenharmony_ci* @see            hi_cipher_hash_update。
3381bd4fe43Sopenharmony_ci*/
3391bd4fe43Sopenharmony_cihi_u32 hi_cipher_hash_update(uintptr_t src_addr, hi_u32 length);
3401bd4fe43Sopenharmony_ci
3411bd4fe43Sopenharmony_ci/**
3421bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
3431bd4fe43Sopenharmony_ci* @brief          HASH calculation finished.CNcomment:HASH计算结束CNend
3441bd4fe43Sopenharmony_ci*
3451bd4fe43Sopenharmony_ci* @par 描述:
3461bd4fe43Sopenharmony_ci*                 Ouput results after HASH finished calculating.CNcomment:HASH计算结束,
3471bd4fe43Sopenharmony_ci输出计算结果。CNend
3481bd4fe43Sopenharmony_ci*
3491bd4fe43Sopenharmony_ci* @attention      None
3501bd4fe43Sopenharmony_ci*
3511bd4fe43Sopenharmony_ci* @param          out          [OUT]  type #hi_u8 *,Pointer to the output of the HASH calculation result.
3521bd4fe43Sopenharmony_ciCNcomment:HASH计算结果输出指针。CNend
3531bd4fe43Sopenharmony_ci* @param          out_len      [IN]   type #hi_u32,HASH The output pointer of the calculation result points to
3541bd4fe43Sopenharmony_ci*                              the space length. The output length must be greater than or equal to 32 bytes.
3551bd4fe43Sopenharmony_ciCNcomment:HASH计算结果输出指针指向空间长度,要求输出长度满足不小于32bytes。CNend
3561bd4fe43Sopenharmony_ci*
3571bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
3581bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
3591bd4fe43Sopenharmony_ci* @par 依赖:
3601bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
3611bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
3621bd4fe43Sopenharmony_ci* @see            hi_cipher_hash_final。
3631bd4fe43Sopenharmony_ci*/
3641bd4fe43Sopenharmony_cihi_u32 hi_cipher_hash_final(hi_u8 *out, hi_u32 out_len);
3651bd4fe43Sopenharmony_ci
3661bd4fe43Sopenharmony_ci/**
3671bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
3681bd4fe43Sopenharmony_ci* @brief          HASH calculation.CNcomment:HASH计算CNend
3691bd4fe43Sopenharmony_ci*
3701bd4fe43Sopenharmony_ci* @par 描述:
3711bd4fe43Sopenharmony_ci*                 Performs hash calculation on a segment of data and outputs the hash result.
3721bd4fe43Sopenharmony_ciCNcomment:对一段数据做HASH计算,并输出HASH结果。CNend
3731bd4fe43Sopenharmony_ci*
3741bd4fe43Sopenharmony_ci* @attention      None
3751bd4fe43Sopenharmony_ci*
3761bd4fe43Sopenharmony_ci* @param          input        [IN]  type #uintptr_t,Enter the data address. The address must be 4-bytes-aligned.
3771bd4fe43Sopenharmony_ciCNcomment:输入数据地址,地址要求4对齐。CNend
3781bd4fe43Sopenharmony_ci* @param          input_len    [IN]  type #hi_u32, Input data length.CNcomment:输入数据长度。CNend
3791bd4fe43Sopenharmony_ci* @param          hash         [OUT] type #hi_u8 *,Output the hash result. The length is 32 bytes.
3801bd4fe43Sopenharmony_ciCNcomment:输出HASH结果, 长度为 32 bytes。CNend
3811bd4fe43Sopenharmony_ci* @param          hash_len     [IN]  type #hi_u32, BUF length of the hash result. The value must be greater than or
3821bd4fe43Sopenharmony_ci*                              equal to 32 bytes.CNcomment:输出HASH结果的BUF长度,需要满足不小于32bytes。CNend
3831bd4fe43Sopenharmony_ci*
3841bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
3851bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
3861bd4fe43Sopenharmony_ci* @par 依赖:
3871bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
3881bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
3891bd4fe43Sopenharmony_ci* @see            hi_cipher_hash_sha256。
3901bd4fe43Sopenharmony_ci*/
3911bd4fe43Sopenharmony_cihi_u32 hi_cipher_hash_sha256(uintptr_t input, hi_u32 input_len, hi_u8 *hash, hi_u32 hash_len);
3921bd4fe43Sopenharmony_ci
3931bd4fe43Sopenharmony_ci/**
3941bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
3951bd4fe43Sopenharmony_ci* @brief          KDF calculation.CNcomment:KDF算法计算。CNend
3961bd4fe43Sopenharmony_ci*
3971bd4fe43Sopenharmony_ci* @par 描述:
3981bd4fe43Sopenharmony_ci*                 KDF calculation.CNcomment:KDF算法计算。CNend
3991bd4fe43Sopenharmony_ci*
4001bd4fe43Sopenharmony_ci* @attention      None
4011bd4fe43Sopenharmony_ci* @param          ctrl        [IN] type  #hi_cipher_kdf_ctrl*,Poninter to KDF algorithm parameter configuration
4021bd4fe43Sopenharmony_ci                              control structure.CNcomment:KDF算法参数配置控制结构体。CNend
4031bd4fe43Sopenharmony_ci*
4041bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
4051bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
4061bd4fe43Sopenharmony_ci* @par 依赖:
4071bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
4081bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
4091bd4fe43Sopenharmony_ci* @see            hi_cipher_kdf_key_derive。
4101bd4fe43Sopenharmony_ci*/
4111bd4fe43Sopenharmony_cihi_u32 hi_cipher_kdf_key_derive(hi_cipher_kdf_ctrl *ctrl);
4121bd4fe43Sopenharmony_ci
4131bd4fe43Sopenharmony_ci/**
4141bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
4151bd4fe43Sopenharmony_ci* @brief          Rsa Signature Verification.CNcomment:Rsa 签名结果校验CNend
4161bd4fe43Sopenharmony_ci*
4171bd4fe43Sopenharmony_ci* @par 描述:
4181bd4fe43Sopenharmony_ci*                 Rsa Signature Verification.CNcomment:Rsa 签名结果校验。CNend
4191bd4fe43Sopenharmony_ci*
4201bd4fe43Sopenharmony_ci* @attention      None
4211bd4fe43Sopenharmony_ci* @param          rsa_verify  [IN]   type #hi_cipher_rsa_verify *,Structure of the Rsa signature result
4221bd4fe43Sopenharmony_ci*                              verification algorithm.CNcomment:Rsa签名结果校验算法结构体。CNend
4231bd4fe43Sopenharmony_ci* @param          hash        [IN]   type #const hi_u8 *,Hash data to be checked.
4241bd4fe43Sopenharmony_ciCNcomment:待校验的HASH数据。CNend
4251bd4fe43Sopenharmony_ci* @param          hash_len    [IN]   type #hi_u32, Indicates the length of the hash data to be verified.
4261bd4fe43Sopenharmony_ci*                              The value is 32 bytes valid data.
4271bd4fe43Sopenharmony_ciCNcomment:待校验的HASH数据的长度,为32bytes有效数据。CNend
4281bd4fe43Sopenharmony_ci* @param          sign        [IN]   type #const hi_u8 *,Signature input pointer.CNcomment:签名输入指针。CNend
4291bd4fe43Sopenharmony_ci* @param          sign_len    [IN]   type #hi_u32,Length of the signature result. The length is the same as the
4301bd4fe43Sopenharmony_ci*                              length of the key.CNcomment:签名结果长度, 长度与key的长度相同。CNend
4311bd4fe43Sopenharmony_ci*
4321bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
4331bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
4341bd4fe43Sopenharmony_ci* @par 依赖:
4351bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
4361bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
4371bd4fe43Sopenharmony_ci* @see            hi_cipher_rsa_verify_hash。
4381bd4fe43Sopenharmony_ci*/
4391bd4fe43Sopenharmony_cihi_u32 hi_cipher_rsa_verify_hash(const hi_cipher_rsa_verify *rsa_verify, hi_cipher_rsa_data *pack);
4401bd4fe43Sopenharmony_ci
4411bd4fe43Sopenharmony_ci/**
4421bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
4431bd4fe43Sopenharmony_ci* @brief          Ecdsa Signature Verification.CNcomment:Ecdsa 签名结果校验CNend
4441bd4fe43Sopenharmony_ci*
4451bd4fe43Sopenharmony_ci* @par 描述:
4461bd4fe43Sopenharmony_ci*                 Ecdsa Signature Verification.CNcomment:Ecdsa 签名结果校验。CNend
4471bd4fe43Sopenharmony_ci*
4481bd4fe43Sopenharmony_ci* @attention      None
4491bd4fe43Sopenharmony_ci* @param          ecc          [IN]   type #const hi_cipher_ecc_param *,ECC elliptic curve parameter. If the length
4501bd4fe43Sopenharmony_ci*                              is less than the size of the key, add 0 before the key.
4511bd4fe43Sopenharmony_ciCNcomment:ECC椭圆曲线参数,长度不足Key的大小,前面补0。CNend
4521bd4fe43Sopenharmony_ci* @param          verify       [IN]   type #const hi_cipher_ecc_verify *,Pointer to structure of the ECC public key
4531bd4fe43Sopenharmony_ci*                              verification parameter.CNcomment:ECC公钥验证参数结构体。CNend
4541bd4fe43Sopenharmony_ci*
4551bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
4561bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
4571bd4fe43Sopenharmony_ci* @par 依赖:
4581bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
4591bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
4601bd4fe43Sopenharmony_ci* @see            hi_cipher_ecc_sign_hash。
4611bd4fe43Sopenharmony_ci*/
4621bd4fe43Sopenharmony_cihi_u32 hi_cipher_ecc_verify_hash(hi_cipher_ecc_param *ecc, hi_cipher_ecc_verify *verify);
4631bd4fe43Sopenharmony_ci
4641bd4fe43Sopenharmony_ci/**
4651bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
4661bd4fe43Sopenharmony_ci* @brief          TRNG Obtain a random number.CNcomment:TRNG获取随机数CNend
4671bd4fe43Sopenharmony_ci*
4681bd4fe43Sopenharmony_ci* @par 描述:
4691bd4fe43Sopenharmony_ci*                 TRNG Obtain a random number. Only one word size can be obtained at a time.
4701bd4fe43Sopenharmony_ciCNcomment:TRNG获取随机数,每次只能获取一个WORD大小的随机数。CNend
4711bd4fe43Sopenharmony_ci*
4721bd4fe43Sopenharmony_ci* @attention      None
4731bd4fe43Sopenharmony_ci* @param          randnum      [OUT]  type #hi_u32 *,Random number output pointer.
4741bd4fe43Sopenharmony_ciCNcomment:随机数输出指针。CNend
4751bd4fe43Sopenharmony_ci*
4761bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
4771bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
4781bd4fe43Sopenharmony_ci* @par 依赖:
4791bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
4801bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
4811bd4fe43Sopenharmony_ci* @see            hi_cipher_trng_get_random。
4821bd4fe43Sopenharmony_ci*/
4831bd4fe43Sopenharmony_cihi_u32 hi_cipher_trng_get_random(hi_u32 *randnum);
4841bd4fe43Sopenharmony_ci
4851bd4fe43Sopenharmony_ci/**
4861bd4fe43Sopenharmony_ci* @ingroup        iot_cipher
4871bd4fe43Sopenharmony_ci* @brief          TRNG Obtain a random number.CNcomment:TRNG获取随机数CNend
4881bd4fe43Sopenharmony_ci*
4891bd4fe43Sopenharmony_ci* @par 描述:
4901bd4fe43Sopenharmony_ci*                 The TRNG obtains the random number and obtains the random number of multiple bytes at a time.
4911bd4fe43Sopenharmony_ciCNcomment:TRNG获取随机数,每次获取多个byte的随机数。CNend
4921bd4fe43Sopenharmony_ci*
4931bd4fe43Sopenharmony_ci* @attention      None
4941bd4fe43Sopenharmony_ci* @param          randbyte     [OUT]  type #hi_u8 *,Random number output pointer.
4951bd4fe43Sopenharmony_ciCNcomment:随机数输出指针。CNend
4961bd4fe43Sopenharmony_ci* @param          size         [IN]   type #hi_u32,Length of the obtained random number.
4971bd4fe43Sopenharmony_ciCNcomment:获取的随机数长度。CNend
4981bd4fe43Sopenharmony_ci*
4991bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS   Success
5001bd4fe43Sopenharmony_ci* @retval #Other            Failure. For details, see hi_boot_err.h.
5011bd4fe43Sopenharmony_ci* @par 依赖:
5021bd4fe43Sopenharmony_ci*                 @li hi_cipher.h:Describes Cipher module APIs.
5031bd4fe43Sopenharmony_ciCNcomment:文件用于描述Cipher模块相关接口。CNend
5041bd4fe43Sopenharmony_ci* @see            hi_cipher_trng_get_random。
5051bd4fe43Sopenharmony_ci*/
5061bd4fe43Sopenharmony_cihi_u32 hi_cipher_trng_get_random_bytes(hi_u8 *randbyte, hi_u32 size);
5071bd4fe43Sopenharmony_ci
5081bd4fe43Sopenharmony_ci#ifdef __cplusplus
5091bd4fe43Sopenharmony_ci#if __cplusplus
5101bd4fe43Sopenharmony_ci}
5111bd4fe43Sopenharmony_ci#endif
5121bd4fe43Sopenharmony_ci#endif  /* __cplusplus */
5131bd4fe43Sopenharmony_ci
5141bd4fe43Sopenharmony_ci#endif /* __HI_CIPHER_H__ */
515