Files
HiSTBLinuxV100R005C00SPC060/source/msp/include/hi_unf_cipher.h
T
2024-08-12 23:07:35 +08:00

1309 lines
83 KiB
C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __HI_UNF_CIPHER_H__
#define __HI_UNF_CIPHER_H__
#include "hi_type.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
/*************************** Structure Definition ****************************/
/** \addtogroup CIPHER */
/** @{ */ /** <!-- [CIPHER] */
/** max length of SM2, unit: word */
/** CNcomment: SM2数据长度,单位word */
#define SM2_LEN_IN_WROD (8)
/** max length of SM2, unit: byte */
/** CNcomment: SM2数据长度,单位byte */
#define SM2_LEN_IN_BYTE (SM2_LEN_IN_WROD * 4)
/** CIPHER set IV for first package */
/** CNcomment: CIPHER 只更新一个数据包的IV */
#define CIPHER_IV_CHANGE_ONE_PKG (1)
/** CIPHER set IV for first package */
/** CNcomment: CIPHER 更新所有数据包的IV */
#define CIPHER_IV_CHANGE_ALL_PKG (2)
/** Cipher work mode */
/** CNcomment:CIPHER工作模式 */
typedef enum hiHI_UNF_CIPHER_WORK_MODE_E
{
HI_UNF_CIPHER_WORK_MODE_ECB, /**<Electronic codebook (ECB) mode, ECB has been considered insecure and it is recommended not to use it.*/ /**< CNcomment:ECB模式,ECB被认为是不安全算法,建议不要使用它。*/
HI_UNF_CIPHER_WORK_MODE_CBC, /**<Cipher block chaining (CBC) mode*/ /**< CNcomment:CBC模式 */
HI_UNF_CIPHER_WORK_MODE_CFB, /**<Cipher feedback (CFB) mode*/ /**< CNcomment:CFB模式 */
HI_UNF_CIPHER_WORK_MODE_OFB, /**<Output feedback (OFB) mode*/ /**< CNcomment:OFB模式 */
HI_UNF_CIPHER_WORK_MODE_CTR, /**<Counter (CTR) mode*/ /**< CNcomment:CTR模式 */
HI_UNF_CIPHER_WORK_MODE_CCM, /**<Counter (CCM) mode*/ /**< CNcomment:CCM模式 */
HI_UNF_CIPHER_WORK_MODE_GCM, /**<Counter (GCM) mode*/ /**< CNcomment:GCM模式 */
HI_UNF_CIPHER_WORK_MODE_BUTT
}HI_UNF_CIPHER_WORK_MODE_E;
/** Cipher algorithm */
/** CNcomment:CIPHER加密算法 */
typedef enum hiHI_UNF_CIPHER_ALG_E
{
HI_UNF_CIPHER_ALG_DES = 0x0, /**< Data encryption standard (DES) algorithm,DES has been considered insecure and it is recommended not to use it. */ /**< CNcomment: DES算法,被认为是不安全算法,建议不要使用它。*/
HI_UNF_CIPHER_ALG_3DES = 0x1, /**< 3DES algorithm */ /**< CNcomment: 3DES算法 */
HI_UNF_CIPHER_ALG_AES = 0x2, /**< Advanced encryption standard (AES) algorithm */ /**< CNcomment: AES算法 */
HI_UNF_CIPHER_ALG_SM1 = 0x3, /**<SM1 algorithm*/ /**< CNcomment: SM1算法 */
HI_UNF_CIPHER_ALG_SM4 = 0x4, /**<SM4 algorithm*/ /**< CNcomment: SM4算法 */
HI_UNF_CIPHER_ALG_DMA = 0x5, /**<DMA copy*/ /**< CNcomment: DMA拷贝 */
HI_UNF_CIPHER_ALG_BUTT = 0x6
}HI_UNF_CIPHER_ALG_E;
/** Key length */
/** CNcomment: 密钥长度 */
typedef enum hiHI_UNF_CIPHER_KEY_LENGTH_E
{
HI_UNF_CIPHER_KEY_AES_128BIT = 0x0, /**< 128-bit key for the AES algorithm */ /**< CNcomment:AES运算方式下采用128bit密钥长度 */
HI_UNF_CIPHER_KEY_AES_192BIT = 0x1, /**< 192-bit key for the AES algorithm */ /**< CNcomment:AES运算方式下采用192bit密钥长度 */
HI_UNF_CIPHER_KEY_AES_256BIT = 0x2, /**< 256-bit key for the AES algorithm */ /**< CNcomment:AES运算方式下采用256bit密钥长度 */
HI_UNF_CIPHER_KEY_DES_3KEY = 0x2, /**< Three keys for the DES algorithm */ /**< CNcomment:DES运算方式下采用3个key */
HI_UNF_CIPHER_KEY_DES_2KEY = 0x3, /**< Two keys for the DES algorithm */ /**< CNcomment: DES运算方式下采用2个key */
HI_UNF_CIPHER_KEY_DEFAULT = 0x0, /**< default key length, DES-8, SM1-48, SM4-16 */ /**< CNcomment: 默认Key长度,DES-8, SM1-48, SM4-16*/
}HI_UNF_CIPHER_KEY_LENGTH_E;
/** Cipher bit width */
/** CNcomment: 加密位宽 */
typedef enum hiHI_UNF_CIPHER_BIT_WIDTH_E
{
HI_UNF_CIPHER_BIT_WIDTH_64BIT = 0x0, /**< 64-bit width */ /**< CNcomment:64bit位宽 */
HI_UNF_CIPHER_BIT_WIDTH_8BIT = 0x1, /**< 8-bit width */ /**< CNcomment:8bit位宽 */
HI_UNF_CIPHER_BIT_WIDTH_1BIT = 0x2, /**< 1-bit width */ /**< CNcomment:1bit位宽 */
HI_UNF_CIPHER_BIT_WIDTH_128BIT = 0x3, /**< 128-bit width */ /**< CNcomment:128bit位宽 */
}HI_UNF_CIPHER_BIT_WIDTH_E;
/** Cipher control parameters */
/** CNcomment:加密控制参数变更标志 */
typedef struct hiUNF_CIPHER_CTRL_CHANGE_FLAG_S
{
HI_U32 bit1IV:4; /**< Initial Vector change flag, 0-don't set, 1-set IV for first package, 2-set IV for each package */ /**< CNcomment:向量变更, 0-不设置,1-只设置第一个包,2-每个包都设置 */
HI_U32 bitsResv:28; /**< Reserved */ /**< CNcomment:保留 */
}HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S;
/** Key ladder selecting parameters */
/** CNcomment:使用哪个key ladder标志 */
typedef enum hiUNF_CIPHER_CA_TYPE_E
{
HI_UNF_CIPHER_CA_TYPE_R2R = 0x0, /**< Using R2R key ladder */ /**< CNcomment:使用R2R key ladder */
HI_UNF_CIPHER_CA_TYPE_SP, /**< Using SP key ladder */ /**< CNcomment:使用SP key ladder */
HI_UNF_CIPHER_CA_TYPE_CSA2, /**< Using CSA2 key ladder */ /**< CNcomment:使用CSA2 key ladder */
HI_UNF_CIPHER_CA_TYPE_CSA3, /**< Using CSA3 key ladder */ /**< CNcomment:使用CSA3 key ladder */
HI_UNF_CIPHER_CA_TYPE_MISC, /**< Using MISC ladder */ /**< CNcomment:使用SP key ladder */
HI_UNF_CIPHER_CA_TYPE_GDRM, /**< Using GDRM ladder */ /**< CNcomment:使用GDRM key ladder */
HI_UNF_CIPHER_CA_TYPE_BLPK, /**< Using BLPK ladder */ /**< CNcomment:使用BLPK key ladder */
HI_UNF_CIPHER_CA_TYPE_LPK, /**< Using LPK ladder */ /**< CNcomment:使用LPK key ladder */
HI_UNF_CIPHER_CA_TYPE_IRDETO_HCA, /**< Using high level code authentication key ladder*/ /**< CNcomment:上层应用校验keyladder*/
HI_UNF_CIPHER_CA_TYPE_STBROOTKEY, /**< Useing for AntiCopy With STB_Root_Key */ /**< CNcomment:使用STB_Root_Key加解密,用于防拷贝 */
HI_UNF_CIPHER_CA_TYPE_SECSTORE, /**< Using SECSTORE keyladder */ /**< CNcomment:使用SecStore key ladder */
HI_UNF_CIPHER_CA_TYPE_BUTT
}HI_UNF_CIPHER_CA_TYPE_E;
/** Encryption/Decryption type selecting */
/** CNcomment:CIPHE加解密类型选择 */
typedef enum
{
HI_UNF_CIPHER_TYPE_NORMAL = 0x0, /**< Create normal channel */ /**< CNcomment: 创建普通通道 */
HI_UNF_CIPHER_TYPE_COPY_AVOID, /**< Create special channel for avoid copy */ /**< CNcomment: 创建防止被拷贝的专用通道 */
HI_UNF_CIPHER_TYPE_NONSEC, /**< Create unsecured channel, for internal use only */ /**< CNcomment: 创建保留的非安全通道,仅限内部使用 */
HI_UNF_CIPHER_TYPE_BUTT,
}HI_UNF_CIPHER_TYPE_E;
/** Structure of the cipher type */
/** CNcomment:加密类型结构 */
typedef struct
{
HI_UNF_CIPHER_TYPE_E enCipherType;
}HI_UNF_CIPHER_ATTS_S;
/** sm1 round config */
/** CNcomment: sm1计算的轮数 */
typedef enum hiHI_UNF_CIPHER_SM1_ROUND_E
{
HI_UNF_CIPHER_SM1_ROUND_08 = 0x00, /**< sm1 round 08 */ /**< CNcomment:SM1计算的轮数为08 */
HI_UNF_CIPHER_SM1_ROUND_10 = 0x01, /**< sm1 round 10 */ /**< CNcomment:SM1计算的轮数为10 */
HI_UNF_CIPHER_SM1_ROUND_12 = 0x02, /**< sm1 round 12 */ /**< CNcomment:SM1计算的轮数为12 */
HI_UNF_CIPHER_SM1_ROUND_14 = 0x03, /**< sm1 round 14 */ /**< CNcomment:SM1计算的轮数为14 */
HI_UNF_CIPHER_SM1_ROUND_BUTT,
}HI_UNF_CIPHER_SM1_ROUND_E;
/** Structure of the cipher control information */
/** CNcomment:加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_S
{
HI_U32 u32Key[8]; /**< Key input */ /**< CNcomment:输入密钥 */
HI_U32 u32IV[4]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_BOOL bKeyByCA; /**< Encryption using advanced conditional access (CA) or decryption using keys */ /**< CNcomment:是否使用高安全CA加密或解密Key */
HI_UNF_CIPHER_CA_TYPE_E enCaType; /**< Select keyladder type when using advanced CA */ /**< CNcomment:使用高安全CA时,选择何种类型的keyladder */
HI_UNF_CIPHER_ALG_E enAlg; /**< Cipher algorithm */ /**< CNcomment:加密算法 */
HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */ /**< CNcomment:加密或解密的位宽 */
HI_UNF_CIPHER_WORK_MODE_E enWorkMode; /**< Operating mode */ /**< CNcomment:工作模式 */
HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */ /**< CNcomment:密钥长度 */
HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all woulde be change except they have been in the choices */ /**< CNcomment:控制信息变更选项,选项中没有标识的项默认全部变更 */
} HI_UNF_CIPHER_CTRL_S;
/** Structure of the cipher AES control information */
/** CNcomment:AES加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_AES_S
{
HI_U32 u32EvenKey[8]; /**< Key input, default use this key*/ /**< CNcomment:输入偶密钥, 默认使用偶密钥 */
HI_U32 u32OddKey[8]; /**< Key input, only valid for Multi encrypt/decrypt*/ /**< CNcomment:输入奇密钥, 只对多包加解密有效 */
HI_U32 u32IV[4]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */ /**< CNcomment:加密或解密的位宽 */
HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */ /**< CNcomment:密钥长度 */
HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all woulde be change except they have been in the choices */ /**< CNcomment:控制信息变更选项,选项中没有标识的项默认全部变更 */
} HI_UNF_CIPHER_CTRL_AES_S;
/** Structure of the cipher AES CCM/GCM control information */
/** CNcomment:AES CCM/GCM 加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_AES_CCM_GCM_S
{
HI_U32 u32Key[8]; /**< Key input */ /**< CNcomment:输入密钥 */
HI_U32 u32IV[4]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */ /**< CNcomment:密钥长度 */
HI_U32 u32IVLen; /**< IV lenght for CCM/GCM, which is an element of {4,6,8,10,12,14,16} for CCM, and is an element of [1-16] for GCM*/ /**< CNcomment: CCM/GCM的IV长度,CCM的取值范围{7, 8, 9, 10, 11, 12, 13}, GCM的取值范围[1-16]*/
HI_U32 u32TagLen; /**< Tag lenght for CCM which is an element of {4,6,8,10,12,14,16}*/ /**< CNcomment: CCM的TAG长度,取值范围{4,6,8,10,12,14,16}*/
HI_U32 u32ALen; /**< Associated data for CCM and GCM*/ /**< CNcomment: CCM/GCM的关联数据长度*/
HI_U32 u32APhyAddr; /**< Physical address of Associated data for CCM and GCM*/ /**< CNcomment: CCM/GCM的关联数据长度*/
} HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
/** Structure of the cipher DES control information */
/** CNcomment:DES加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_DES_S
{
HI_U32 u32Key[2]; /**< Key input */ /**< CNcomment:输入偶密钥 */
HI_U32 u32IV[2]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */ /**< CNcomment:加密或解密的位宽 */
HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all woulde be change except they have been in the choices */ /**< CNcomment:控制信息变更选项,选项中没有标识的项默认全部变更 */
} HI_UNF_CIPHER_CTRL_DES_S;
/** Structure of the cipher 3DES control information */
/** CNcomment:3DES加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_3DES_S
{
HI_U32 u32Key[6]; /**< Key input */ /**< CNcomment:输入偶密钥 */
HI_U32 u32IV[2]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */ /**< CNcomment:加密或解密的位宽 */
HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */ /**< CNcomment:密钥长度 */
HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all woulde be change except they have been in the choices */ /**< CNcomment:控制信息变更选项,选项中没有标识的项默认全部变更 */
} HI_UNF_CIPHER_CTRL_3DES_S;
/** Structure of the cipher SM1 control information */
/** CNcomment:SM1加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_SM1_S
{
HI_U32 u32EK[4]; /**< Key of EK input */ /**< CNcomment:输入密钥EK */
HI_U32 u32AK[4]; /**< Key of AK input */ /**< CNcomment:输入密钥AK */
HI_U32 u32SK[4]; /**< Key of SK input */ /**< CNcomment:输入密钥SK */
HI_U32 u32IV[4]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */ /**< CNcomment:加密或解密的位宽 */
HI_UNF_CIPHER_SM1_ROUND_E enSm1Round; /**< SM1 round number, should be 8, 10, 12 or 14*/ /**< CNcomment:sm1计算的轮数配置 */
HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all woulde be change except they have been in the choices */ /**< CNcomment:控制信息变更选项,选项中没有标识的项默认全部变更 */
} HI_UNF_CIPHER_CTRL_SM1_S;
/** Structure of the cipher SM4 control information */
/** CNcomment:SM4加密控制信息结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_SM4_S
{
HI_U32 u32Key[4]; /**< Key input */ /**< CNcomment:输入密钥 */
HI_U32 u32IV[4]; /**< Initialization vector (IV) */ /**< CNcomment:初始向量 */
HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all woulde be change except they have been in the choices */ /**< CNcomment:控制信息变更选项,选项中没有标识的项默认全部变更 */
} HI_UNF_CIPHER_CTRL_SM4_S;
/** Expand Structure of the cipher control information */
/** CNcomment:加密控制信息扩展结构 */
typedef struct hiHI_UNF_CIPHER_CTRL_EX_S
{
HI_UNF_CIPHER_ALG_E enAlg; /**< Cipher algorithm */ /**< CNcomment:加密算法 */
HI_UNF_CIPHER_WORK_MODE_E enWorkMode; /**< Operating mode */ /**< CNcomment:工作模式 */
HI_BOOL bKeyByCA; /**< Encryption using advanced conditional access (CA) or decryption using keys */ /**< CNcomment:是否使用高安全CA加密或解密Key */
/**< Parameter for special algorithm
for AES, the pointer should point to HI_UNF_CIPHER_CTRL_AES_S;
for AES_CCM or AES_GCM, the pointer should point to HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
for DES, the pointer should point to HI_UNF_CIPHER_CTRL_DES_S;
for 3DES, the pointer should point to HI_UNF_CIPHER_CTRL_3DES_S;
for SM1, the pointer should point to HI_UNF_CIPHER_CTRL_SM1_S;
for SM4, the pointer should point to HI_UNF_CIPHER_CTRL_SM4_S;
*/
/**< CNcomment: 算法的专用参数
对于 AES, 指针应指向 HI_UNF_CIPHER_CTRL_AES_S;
对于 AES_CCM 或 AES_GCM, 指针应指向 HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
对于 DES, 指针应指向 HI_UNF_CIPHER_CTRL_DES_S;
对于 3DES, 指针应指向 HI_UNF_CIPHER_CTRL_3DES_S;
对于 SM1, 指针应指向 HI_UNF_CIPHER_CTRL_SM1_S;
对于 SM4, 指针应指向 HI_UNF_CIPHER_CTRL_SM4_S;
*/
HI_VOID *pParam;
} HI_UNF_CIPHER_CTRL_EX_S;
/** Cipher data */
/** CNcomment:加解密数据 */
typedef struct hiHI_UNF_CIPHER_DATA_S
{
HI_U32 u32SrcPhyAddr; /**< phy address of the original data */ /**< CNcomment:源数据物理地址 */
HI_U32 u32DestPhyAddr; /**< phy address of the purpose data */ /**< CNcomment:目的数据物理地址 */
HI_U32 u32ByteLength; /**< cigher data length*/ /**< CNcomment:加解密数据长度 */
HI_BOOL bOddKey; /**< Use odd key or even key*/ /**< CNcomment:是否使用奇密钥 */
} HI_UNF_CIPHER_DATA_S;
/** Hash algrithm type */
/** CNcomment:哈希算法类型 */
typedef enum hiHI_UNF_CIPHER_HASH_TYPE_E
{
HI_UNF_CIPHER_HASH_TYPE_SHA1,
HI_UNF_CIPHER_HASH_TYPE_SHA256,
HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA1,
HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA256,
HI_UNF_CIPHER_HASH_TYPE_IRDETO_CBCMAC,
HI_UNF_CIPHER_HASH_TYPE_SHA224,
HI_UNF_CIPHER_HASH_TYPE_SHA384,
HI_UNF_CIPHER_HASH_TYPE_SHA512,
HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA224,
HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA384,
HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA512,
HI_UNF_CIPHER_HASH_TYPE_SM3,
HI_UNF_CIPHER_HASH_TYPE_BUTT,
}HI_UNF_CIPHER_HASH_TYPE_E;
/** Hash init struct input */
/** CNcomment:哈希算法初始化输入结构体 */
typedef struct
{
HI_U8 *pu8HMACKey;
HI_U32 u32HMACKeyLen;
HI_UNF_CIPHER_HASH_TYPE_E eShaType;
}HI_UNF_CIPHER_HASH_ATTS_S;
typedef enum hiHI_UNF_CIPHER_RSA_ENC_SCHEME_E
{
HI_UNF_CIPHER_RSA_ENC_SCHEME_NO_PADDING, /**< without padding */ /**< CNcomment: 不填充 */
HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_0, /**< PKCS#1 block type 0 padding*/ /**< CNcomment: PKCS#1的block type 0填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_1, /**< PKCS#1 block type 1 padding*/ /**< CNcomment: PKCS#1的block type 1填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_2, /**< PKCS#1 block type 2 padding*/ /**< CNcomment: PKCS#1的block type 2填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA1, /**< PKCS#1 RSAES-OAEP-SHA1 padding*/ /**< CNcomment: PKCS#1的RSAES-OAEP-SHA1填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA224, /**< PKCS#1 RSAES-OAEP-SHA224 padding*/ /**< CNcomment: PKCS#1的RSAES-OAEP-SHA224填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA256, /**< PKCS#1 RSAES-OAEP-SHA256 padding*/ /**< CNcomment: PKCS#1的RSAES-OAEP-SHA256填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA384, /**< PKCS#1 RSAES-OAEP-SHA384 padding*/ /**< CNcomment: PKCS#1的RSAES-OAEP-SHA384填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA512, /**< PKCS#1 RSAES-OAEP-SHA512 padding*/ /**< CNcomment: PKCS#1的RSAES-OAEP-SHA512填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_PKCS1_V1_5, /**< PKCS#1 RSAES-PKCS1_V1_5 padding*/ /**< CNcomment: PKCS#1的PKCS1_V1_5填充方式*/
HI_UNF_CIPHER_RSA_ENC_SCHEME_BUTT,
}HI_UNF_CIPHER_RSA_ENC_SCHEME_E;
typedef enum hiHI_UNF_CIPHER_RSA_SIGN_SCHEME_E
{
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA1 = 0x100, /**< PKCS#1 RSASSA_PKCS1_V15_SHA1 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_V15_SHA1签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA224, /**< PKCS#1 RSASSA_PKCS1_V15_SHA224 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_V15_SHA224签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA256, /**< PKCS#1 RSASSA_PKCS1_V15_SHA256 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_V15_SHA256签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA384, /**< PKCS#1 RSASSA_PKCS1_V15_SHA384 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_V15_SHA384签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA512, /**< PKCS#1 RSASSA_PKCS1_V15_SHA512 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_V15_SHA512签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA1, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA1 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_PSS_SHA1签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA224, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA224 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_PSS_SHA224签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA256, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_PSS_SHA256签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA384, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA1 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_PSS_SHA384签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA512, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature*/ /**< CNcomment: PKCS#1 RSASSA_PKCS1_PSS_SHA512签名算法*/
HI_UNF_CIPHER_RSA_SIGN_SCHEME_BUTT,
}HI_UNF_CIPHER_RSA_SIGN_SCHEME_E;
typedef struct
{
HI_U8 *pu8N; /**< point to public modulus */ /**< CNcomment: 指向RSA公钥N的指针*/
HI_U8 *pu8E; /**< point to public exponent */ /**< CNcomment: 指向RSA公钥E的指针*/
HI_U16 u16NLen; /**< length of public modulus, max value is 512Byte*/ /**< CNcomment: RSA公钥N的长度, 最大为512Byte*/
HI_U16 u16ELen; /**< length of public exponent, max value is 512Byte*/ /**< CNcomment: RSA公钥E的长度, 最大为512Byte*/
}HI_UNF_CIPHER_RSA_PUB_KEY_S;
/** RSA private key struct */
/** CNcomment:RSA私钥结构体 */
typedef struct
{
HI_U8 *pu8N; /*!< public modulus */ /**< CNcomment: 指向RSA公钥N的指针*/
HI_U8 *pu8E; /*!< public exponent */ /**< CNcomment: 指向RSA公钥E的指针*/
HI_U8 *pu8D; /*!< private exponent */ /**< CNcomment: 指向RSA私钥D的指针*/
HI_U8 *pu8P; /*!< 1st prime factor */ /**< CNcomment: 指向RSA私钥P的指针*/
HI_U8 *pu8Q; /*!< 2nd prime factor */ /**< CNcomment: 指向RSA私钥Q的指针*/
HI_U8 *pu8DP; /*!< D % (P - 1) */ /**< CNcomment: 指向RSA私钥DP的指针*/
HI_U8 *pu8DQ; /*!< D % (Q - 1) */ /**< CNcomment: 指向RSA私钥DQ的指针*/
HI_U8 *pu8QP; /*!< 1 / (Q % P) */ /**< CNcomment: 指向RSA私钥QP的指针*/
HI_U16 u16NLen; /**< length of public modulus */ /**< CNcomment: RSA公钥N的长度*/
HI_U16 u16ELen; /**< length of public exponent */ /**< CNcomment: RSA公钥E的长度*/
HI_U16 u16DLen; /**< length of private exponent */ /**< CNcomment: RSA私钥D的长度*/
HI_U16 u16PLen; /**< length of 1st prime factor,should be half of u16NLen */ /**< CNcomment: RSA私钥P的长度,必须为u16NLen长度的1/2*/
HI_U16 u16QLen; /**< length of 2nd prime factor,should be half of u16NLen */ /**< CNcomment: RSA私钥Q的长度,必须为u16NLen长度的1/2*/
HI_U16 u16DPLen; /**< length of D % (P - 1),should be half of u16NLen */ /**< CNcomment: RSA私钥DP的长度,必须为u16NLen长度的1/2*/
HI_U16 u16DQLen; /**< length of D % (Q - 1),should be half of u16NLen */ /**< CNcomment: RSA私钥DQ的长度,必须为u16NLen长度的1/2*/
HI_U16 u16QPLen; /**< length of 1 / (Q % P),should be half of u16NLen */ /**< CNcomment: RSA私钥QP的长度,必须为u16NLen长度的1/2*/
}HI_UNF_CIPHER_RSA_PRI_KEY_S;
/** RSA public key encryption struct input */
/** CNcomment:RSA 公钥加解密算法参数结构体 */
typedef struct
{
HI_UNF_CIPHER_RSA_ENC_SCHEME_E enScheme; /** RSA encryption scheme*/ /** CNcomment:RSA数据加解密算法策略*/
HI_UNF_CIPHER_RSA_PUB_KEY_S stPubKey; /** RSA private key struct */ /** CNcomment:RSA私钥结构体 */
}HI_UNF_CIPHER_RSA_PUB_ENC_S;
/** RSA private key decryption struct input */
/** CNcomment:RSA 私钥解密算法参数结构体 */
typedef struct
{
HI_UNF_CIPHER_RSA_ENC_SCHEME_E enScheme; /** RSA encryption scheme */ /** CNcomment:RSA数据加解密算法*/
HI_UNF_CIPHER_RSA_PRI_KEY_S stPriKey; /** RSA private key struct */ /** CNcomment:RSA私钥结构体 */
}HI_UNF_CIPHER_RSA_PRI_ENC_S;
/** RSA signature struct input */
/** CNcomment:RSA签名算法参数结构体 */
typedef struct
{
HI_UNF_CIPHER_RSA_SIGN_SCHEME_E enScheme; /** RSA signature scheme*/ /** CNcomment:RSA数据签名策略*/
HI_UNF_CIPHER_RSA_PRI_KEY_S stPriKey; /** RSA private key struct */ /** CNcomment:RSA私钥结构体 */
}HI_UNF_CIPHER_RSA_SIGN_S;
/** RSA signature verify struct input */
/** CNcomment:RSA签名验证算法参数输入结构体 */
typedef struct
{
HI_UNF_CIPHER_RSA_SIGN_SCHEME_E enScheme; /** RSA signature scheme*/ /** CNcomment:RSA数据签名策略*/
HI_UNF_CIPHER_RSA_PUB_KEY_S stPubKey; /** RSA public key struct */ /** CNcomment:RSA公钥结构体 */
}HI_UNF_CIPHER_RSA_VERIFY_S;
/** SM2 signature struct input */
/** CNcomment: SM2签名算法参数结构体 */
typedef struct hiHI_UNF_CIPHER_SM2_SIGN_S
{
HI_U32 u32d[SM2_LEN_IN_WROD];
HI_U32 u32Px[SM2_LEN_IN_WROD];
HI_U32 u32Py[SM2_LEN_IN_WROD];
HI_U8 *pu8Id;
HI_U16 u16IdLen;
}HI_UNF_CIPHER_SM2_SIGN_S;
/** SM2 signature verify struct input */
/** CNcomment: SM2签名验证算法参数输入结构体 */
typedef struct hiHI_UNF_CIPHER_SM2_VERIFY_S
{
HI_U32 u32Px[SM2_LEN_IN_WROD];
HI_U32 u32Py[SM2_LEN_IN_WROD];
HI_U8 *pu8Id;
HI_U16 u16IdLen;
}HI_UNF_CIPHER_SM2_VERIFY_S;
/** SM2 publuc key encryption struct input */
/** CNcomment: SM2公钥加密算法参数结构体 */
typedef struct hiHI_UNF_CIPHER_SM2_ENC_S
{
HI_U32 u32Px[SM2_LEN_IN_WROD];
HI_U32 u32Py[SM2_LEN_IN_WROD];
}HI_UNF_CIPHER_SM2_ENC_S;
/** SM2 private key decryption struct input */
/** CNcomment: SM2私钥解密算法参数结构体 */
typedef struct hiHI_UNF_CIPHER_SM2_DEC_S
{
HI_U32 u32d[SM2_LEN_IN_WROD];
}HI_UNF_CIPHER_SM2_DEC_S;
/** SM2 key generate struct input */
/** CNcomment: SM2密钥生成算法参数结构体 */
typedef struct hiHI_UNF_CIPHER_SM2_KEY_S
{
HI_U32 u32d[SM2_LEN_IN_WROD];
HI_U32 u32Px[SM2_LEN_IN_WROD];
HI_U32 u32Py[SM2_LEN_IN_WROD];
}HI_UNF_CIPHER_SM2_KEY_S;
/** Elliptic curve domain parameters. */
/** CNcomment: ECC椭圆曲线参数 */
typedef struct
{
HI_U8 *pu8p; /** Finite field: equal to p in case of prime field curves or equal to 2^n in case of binary field curves.*/
HI_U8 *pu8a; /** Curve parameter a (q-3 in Suite B).*/
HI_U8 *pu8b; /** Curve parameter b*/
HI_U8 *pu8GX;/** X coordinates of G which is a base point on the curve.*/
HI_U8 *pu8GY;/** Y coordinates of G which is a base point on the curve.*/
HI_U8 *pu8n; /** Prime which is the order of G point.*/
HI_U32 u32h; /**< Cofactor, which is the order of the elliptic curve divided by the order of the point G. For the Suite B curves, h = 1.*/
HI_U32 u32keySize; /**< Key size in bytes. It corresponds to the size in bytes of the prime pu8n*/
} HI_UNF_CIPHER_ECC_PARAM_S;
/** CENC subsample struct input */
/** CNcomment: CENC subsample 参数结构体 */
typedef struct hiHI_UNF_CIPHER_SUBSAMPLE_S
{
HI_U32 u32ClearHeaderLen;
HI_U32 u32PayLoadLen;
HI_U32 u32PayloadPatternEncryptLen;
HI_U32 u32PayloadPatternClearLen;
HI_U32 u32PayloadPatternOffsetLen;
}HI_UNF_CIPHER_SUBSAMPLE_S;
typedef struct hiHI_UNF_CIPHER_SUBSAMPLE_EX_S
{
HI_U32 u32ClearHeaderLen;
HI_U32 u32PayLoadLen;
HI_U32 u32PayloadPatternEncryptLen;
HI_U32 u32PayloadPatternClearLen;
HI_U32 u32PayloadPatternOffsetLen;
HI_U32 u32IvChange;
HI_U32 u32IV[4];
}HI_UNF_CIPHER_SUBSAMPLE_EX_S;
/** @} */ /** <!-- ==== Structure Definition End ==== */
#define HI_UNF_CIPHER_Open(HI_VOID) HI_UNF_CIPHER_Init(HI_VOID);
#define HI_UNF_CIPHER_Close(HI_VOID) HI_UNF_CIPHER_DeInit(HI_VOID);
#define HI_UNF_CIPHER_HASH_TYPE_CBCMAC HI_UNF_CIPHER_HASH_TYPE_IRDETO_CBCMAC
#define HI_UNF_CIPHER_CA_TYPE_HCA HI_UNF_CIPHER_CA_TYPE_IRDETO_HCA
/******************************* API Declaration *****************************/
/** \addtogroup CIPHER */
/** @{ */ /** <!-- [CIPHER] */
/* ---CIPHER---*/
/**
\brief Init the cipher device. CNcomment:初始化CIPHER设备。 CNend
\attention \n
This API is used to start the cipher device.
CNcomment:调用此接口初始化CIPHER设备。 CNend
\param N/A CNcomment:无 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_FAILED_INIT The cipher device fails to be initialized. CNcomment:CIPHER设备初始化失败 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Init(HI_VOID);
/**
\brief Deinit the cipher device.
CNcomment:\brief 去初始化CIPHER设备。 CNend
\attention \n
This API is used to stop the cipher device. If this API is called repeatedly, HI_SUCCESS is returned, but only the first operation takes effect.
CNcomment:调用此接口关闭CIPHER设备。重复关闭返回成功,第一次起作用。 CNend
\param N/A CNcomment:无 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_DeInit(HI_VOID);
/**
\brief Obtain a cipher handle for encryption and decryption.
CNcomment:创建一路Cipher句柄。 CNend
\param[in] cipher attributes CNcomment:cipher 属性。 CNend
\param[out] phCipher Cipher handle CNcomment:CIPHER句柄。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment: API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null. CNcomment:指针参数为空 CNend
\retval ::HI_ERR_CIPHER_FAILED_GETHANDLE The cipher handle fails to be obtained, because there are no available cipher handles. CNcomment: 获取CIPHER句柄失败,没有空闲的CIPHER句柄 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_CreateHandle(HI_HANDLE* phCipher, const HI_UNF_CIPHER_ATTS_S *pstCipherAttr);
/**
\brief Destroy the existing cipher handle. CNcomment:销毁已存在的CIPHER句柄。 CNend
\attention \n
This API is used to destroy existing cipher handles.
CNcomment:调用此接口销毁已经创建的CIPHER句柄。 CNend
\param[in] hCipher Cipher handle CNcomment:CIPHER句柄。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_DestroyHandle(HI_HANDLE hCipher);
/**
\brief Configures the cipher control information.
CNcomment:\brief 配置CIPHER控制信息。 CNend
\attention \n
Before encryption or decryption, you must call this API or HI_UNF_CIPHER_ConfigHandleEx to configure the cipher control information.
The first 64-bit data and the last 64-bit data should not be the same when using TDES algorithm.
Support AES/DES/3DES/SM4 algorithm, support ECB/CBC/CTR/OFB/CFB mode.
CNcomment:进行加密解密前必须先使用此接口或HI_UNF_CIPHER_ConfigHandleEx配置CIPHER的控制信息。
使用TDES算法时,输入密钥的前后64 bit数据不能相同。
支持 AES/DES/3DES/SM4 算法, ECB/CBC/CTR/OFB/CFB 模式.CNend
\param[in] hCipher Cipher handle. CNcomment:CIPHER句柄 CNend
\param[in] pstCtrl Cipher control information. CNcomment:CIPHER控制信息 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null. CNcomment:指针参数为空 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid. CNcomment:句柄非法 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_ConfigHandle(HI_HANDLE hCipher, HI_UNF_CIPHER_CTRL_S* pstCtrl);
/**
\brief Configures the cipher control information.
CNcomment:\brief 配置CIPHER控制信息。 CNend
\attention \n
Before encryption or decryption, you must call this API or HI_UNF_CIPHER_ConfigHandle to configure the cipher control information.
The first 64-bit data and the last 64-bit data should not be the same when using TDES algorithm.
Support AES/DES/3DES/SM1/SM4 algorithm, support ECB/CBC/CTR/OFB/CFB/CCM/GCM mode.
CNcomment:进行加密解密前必须先使用此接口或HI_UNF_CIPHER_ConfigHandle配置CIPHER的控制信息。
使用TDES算法时,输入密钥的前后64 bit数据不能相同。
支持 AES/DES/3DES/SM1/SM4 算法, ECB/CBC/CTR/OFB/CFB/CCM/GCM 模式.CNend
\param[in] hCipher Cipher handle. CNcomment:CIPHER句柄 CNend
\param[in] pstExCtrl Cipher control information. CNcomment:CIPHER扩展控制信息 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null. CNcomment:指针参数为空 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid. CNcomment:句柄非法 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_ConfigHandleEx(HI_HANDLE hCipher, HI_UNF_CIPHER_CTRL_EX_S* pstExCtrl);
/**
\brief Performs encryption.
CNcomment:\brief 进行加密。 CNend
\attention \n
This API is used to perform encryption by using the cipher module.
The length of the encrypted data should be a multiple of 8 in TDES mode and 16 in AES mode. Besides, the length can not be bigger than 0xFFFFF.After this operation, the result will affect next operation.If you want to remove vector, you need to config IV(config pstCtrl->stChangeFlags.bit1IV with 1) by transfering HI_UNF_CIPHER_ConfigHandle.
CNcomment:使用CIPHER进行加密操作。TDES模式下加密的数据长度应当是8的倍数,AES下应当是16的倍数。此外,加密数据长度不能长于0xFFFFF。本次操作完成后,此次操作的向量运算结果会作用于下一次操作,如果要清除向量,需要在下次加密操作之前调用HI_UNF_CIPHER_ConfigHandle重新配置IV(需要设置pstCtrl->stChangeFlags.bit1IV为1)。 CNend
\param[in] hCipher Cipher handle CNcomment:CIPHER句柄 CNend
\param[in] u32SrcPhyAddr Physical address of the source data CNcomment:源数据物理地址 CNend
\param[in] u32DestPhyAddr Physical address of the target data CNcomment:目的数据物理地址 CNend
\param[in] u32ByteLength Length of the encrypted data CNcomment:加密数据长度 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid. CNcomment:句柄非法 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Encrypt(HI_HANDLE hCipher, HI_U32 u32SrcPhyAddr, HI_U32 u32DestPhyAddr, HI_U32 u32ByteLength);
/**
\brief Performs decryption.
CNcomment:\brief 进行解密 CNend
\attention \n
This API is used to perform decryption by using the cipher module.
The length of the decrypted data should be a multiple of 8 in TDES mode and 16 in AES mode. Besides, the length can not be bigger than 0xFFFFF.After this operation, the result will affect next operation.If you want to remove vector, you need to config IV(config pstCtrl->stChangeFlags.bit1IV with 1) by transfering HI_UNF_CIPHER_ConfigHandle.
CNcomment:使用CIPHER进行解密操作。TDES模式下解密的数据长度应当是8的倍数,AES下应当是16的倍数。此外,解密数据长度不能长于0xFFFFF。本次操作完成后,此次操作的向量运算结果会作用于下一次操作,如果要清除向量,需要在下次解密操作之前调用HI_UNF_CIPHER_ConfigHandle重新配置IV(需要设置pstCtrl->stChangeFlags.bit1IV为1)。 CNend
\param[in] hCipher Cipher handle. CNcomment:CIPHER句柄 CNend
\param[in] u32SrcPhyAddr Physical address of the source data. CNcomment:源数据物理地址 CNend
\param[in] u32DestPhyAddr Physical address of the target data. CNcomment:目的数据物理地址 CNend
\param[in] u32ByteLength Length of the decrypted data CNcomment:解密数据长度 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid. CNcomment:句柄非法 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Decrypt(HI_HANDLE hCipher, HI_U32 u32SrcPhyAddr, HI_U32 u32DestPhyAddr, HI_U32 u32ByteLength);
/**
\brief Encrypt multiple packaged data.
CNcomment:\brief 进行多个包数据的加密。 CNend
\attention \n
You can not encrypt more than 128 data package one time. When HI_ERR_CIPHER_BUSY return, the data package you send will not be deal, the custmer should decrease the number of data package or run cipher again.Note:When encrypting more than one packaged data, every one package will be calculated using initial vector configured by HI_UNF_CIPHER_ConfigHandle.Previous result will not affect the later result.
CNcomment:每次加密的数据包个数最多不能超过128个。返回HI_ERR_CIPHER_BUSY的时候,送入数据包一个也不会被处理,用户需要减少送入的数据包的数量或者再次尝试加密。注意: 对于多个包的操作,每个包都使用HI_UNF_CIPHER_ConfigHandle配置的向量进行运算,前一个包的向量运算结果不会作用于下一个包的运算,每个包都是独立运算的。前一次函数调用的结果也不会影响后一次函数调用的运算结果。 CNend
\param[in] hCipher cipher handle CNcomment:CIPHER句柄。 CNend
\param[in] pstDataPkg data package ready for cipher CNcomment:待加密的数据包。 CNend
\param[in] u32DataPkgNum number of package ready for cipher CNcomment:待加密的数据包个数。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT cipher device have not been initialized CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA parameter error CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE handle invalid CNcomment:句柄非法 CNend
\retval ::HI_ERR_CIPHER_BUSY hardware is busy, it can not deal with all data package once time CNcomment:硬件正忙,无法一次性处理全部的数据包 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_EncryptMulti(HI_HANDLE hCipher, HI_UNF_CIPHER_DATA_S *pstDataPkg, HI_U32 u32DataPkgNum);
/**
\brief Decrypt multiple packaged data.
CNcomment:\brief 进行多个包数据的解密。 CNend
\attention \n
You can not decrypt more than 128 data package one time.When HI_ERR_CIPHER_BUSY return, the data package you send will not be deal, the custmer should decrease the number of data package or run cipher again.Note:When decrypting more than one packaged data, every one package will be calculated using initial vector configured by HI_UNF_CIPHER_ConfigHandle.Previous result will not affect the later result.
CNcomment:每次解密的数据包个数最多不能超过128个。返回HI_ERR_CIPHER_BUSY的时候,送入数据包一个也不会被处理,用户需要减少送入的数据包的数量或者再次尝试解密。注意: 对于多个包的操作,每个包都使用HI_UNF_CIPHER_ConfigHandle配置的向量进行运算,前一个包的向量运算结果不会作用于下一个包的运算,每个包都是独立运算的,前一次函数调用的结果也不会影响后一次函数调用的运算结果。 CNend
\param[in] hCipher cipher handle CNcomment:CIPHER句柄。 CNend
\param[in] pstDataPkg data package ready for cipher CNcomment:待解密的数据包。 CNend
\param[in] u32DataPkgNum number of package ready for cipher CNcomment:待解密的数据包个数。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT cipher device have not been initialized CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA parameter error CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE handle invalid CNcomment:句柄非法 CNend
\retval ::HI_ERR_CIPHER_BUSY hardware is busy, it can not deal with all data package once time CNcomment:硬件正忙,无法一次性处理全部的数据包 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_DecryptMulti(HI_HANDLE hCipher, HI_UNF_CIPHER_DATA_S *pstDataPkg, HI_U32 u32DataPkgNum);
/**
\brief Get the tag data of CCM/GCM.
CNcomment:\brief 获取CCM/GCM的TAG数据。 CNend
\attention \n
This API is used to get the tag data of CCM/GCM.
\param[in] hCipher cipher handle CNcomment:CIPHER句柄。 CNend
\param[out] pu8Tag tag data of CCM/GCM CNcomment:TAG指针 CNend
\param[in/out] pu32TagLen tag data length of CCM/GCM, the input should be 16 now. CNcomment:TAG数据长度,输入需设置为16 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_GetTag(HI_HANDLE hCipher, HI_U8 *pu8Tag, HI_U32 *pu32TagLen);
/**
\brief Get the random number.
CNcomment:\brief 获取随机数。 CNend
\attention \n
This API is used to obtain the random number from the hardware.
CNcomment:调用此接口用于获取随机数。 CNend
\param[out] pu32RandomNumber Point to the random number. CNcomment:随机数数值。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment: API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_GetRandomNumber(HI_U32 *pu32RandomNumber);
/**
\brief Get the random bytes.
CNcomment:\brief 获取随机数。 CNend
\attention \n
This API is used to obtain the random number from the hardware.
CNcomment:调用此接口用于获取随机数。 CNend
\param[out] pu32RandomNumber Point to the random number. CNcomment:随机数数值。 CNend
\param[in] u32Bytes size of the random bytes. CNcomment:随机数大小。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment: API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_GetMultiRandomBytes(HI_U8 *pu8RandomByte, HI_U32 u32Bytes);
/**
\brief Get the AES CBC-MAC value.
CNcomment:\brief 获取数据的AES CBC-MAC值。 CNend
\attention \n
This API is used to obtain the AES CBC-MAC value.
CNcomment:调用此接口用于获取AES CBC-MAC值。 CNend
\param[in] hCipherHandle: The cipher handle. CNcomment:Cipher句柄。 CNend
\param[in] pInputData: input data. CNcomment:输入数据。 CNend
\param[in] u32InputDataLen: input data length,the length should be multiple of 16 bytes if it is not the last block. CNcomment:输入数据的长度,如果不是最后一个block,则必须为16个byte的倍数。 CNend
\param[in] bIsLastBlock: Whether this block is last block or not. CNcomment:是否最后一个block。 CNend
\param[out] pOutputMAC: output CBC-MAC value,the length of pOutputMAC should be 16. CNcomment:输出的CBC-MAC。 输出长度为16。CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_CalcMAC(HI_HANDLE hCipherHandle, HI_U8 *pInputData, HI_U32 u32InputDataLen,
HI_U8 *pOutputMAC, HI_BOOL bIsLastBlock);
/**
\brief Init the hash module, if other program is using the hash module, the API will return failure.
CNcomment:\brief 初始化HASH模块,如果有其他程序正在使用HASH模块,返回失败状态。 CNend
\attention \n
N/A
\param[in] pstHashAttr: The hash calculating structure input. CNcomment:用于计算hash的结构体参数 CNend
\param[out] pHashHandle: The output hash handle. CNcomment:输出的hash句柄 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment: API系统调用失败 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_HashInit(HI_UNF_CIPHER_HASH_ATTS_S *pstHashAttr, HI_HANDLE *pHashHandle);
/**
\brief Calculate the hash, if the size of the data to be calculated is very big and the DDR ram is not enough, this API can calculate the data one block by one block. Attention: The input block length must be 64bytes alingned except for the last block.
CNcomment:\brief 计算hash值,如果需要计算的数据量比较大,该接口可以实现一个block一个block的计算,避免数据量比较大的情况下,内存不足的问题。 特别注意,除了最后一个block,前面的每一轮输入的长度都必须是64字节对齐。CNend
\attention \n
N/A
\param[in] hHashHandl: Hash handle. CNcomment:Hash句柄。 CNend
\param[in] pu8InputData: The input data buffer. CNcomment:输入数据缓冲 CNend
\param[in] u32InputDataLen: The input data length, attention: the block length input must be 64bytes aligned except the last block! CNcomment:输入数据的长度。重要: 输入数据块的长度必须是64字节对齐,最后一个block无此限制。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_HashUpdate(HI_HANDLE hHashHandle, HI_U8 *pu8InputData, HI_U32 u32InputDataLen);
/**
\brief Get the final hash value, after calculate all of the data, call this API to get the final hash value and close the handle.If there is some reason need to interupt the calculation, this API should also be call to close the handle.
CNcomment:获取hash值,在计算完所有的数据后,调用这个接口获取最终的hash值,该接口同时会关闭hash句柄。如果在计算过程中,需要中断计算,也必须调用该接口关闭hash句柄。 CNend
\attention \n
N/A
\param[in] hHashHandle: Hash handle. CNcomment:Hash句柄。 CNend
\param[out] pu8OutputHash: The final output hash value,and its length depends on hash type, it is 20 for sha1,28 for sha224,32 for sha256 or sm3,48 for sha384,64 for sha512.
CNcomment:输出的hash值,长度由hash类型决定,sha1时输出长度20,sha224输出长度28,sha256和上sm3输出长度32,sha384输出长度48,sha512输出长度64。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_HashFinal(HI_HANDLE hHashHandle, HI_U8 *pu8OutputHash);
/**
\brief RSA encryption a plaintext with a RSA public key.
CNcomment:使用RSA公钥加密一段明文。 CNend
\attention \n
N/A
\param[in] pstRsaEnc: encryption struct. CNcomment:加密属性结构体。 CNend
\param[in] pu8Input: input data to be encryption CNcomment: 待加密的数据。 CNend
\param[out] u32InLen: length of input data to be encryption CNcomment: 待加密的数据长度。 CNend
\param[out] pu8Output: output data to be encryption CNcomment: 加密结果数据。 CNend
\param[out] pu32OutLen: length of output data to be encryption CNcomment: 加密结果的数据长度。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaPublicEncrypt(HI_UNF_CIPHER_RSA_PUB_ENC_S *pstRsaEnc,
HI_U8 *pu8Input, HI_U32 u32InLen,
HI_U8 *pu8Output, HI_U32 *pu32OutLen);
/**
\brief RSA decryption a ciphertext with a RSA private key.
CNcomment:使用RSA私钥解密一段密文。 CNend
\attention \n
N/A
\param[in] pstRsaDec: decryption struct. CNcomment: 公钥解密属性结构体。 CNend
\param[in] pu8Input: input data to be decryption CNcomment: 待解密的数据。 CNend
\param[out] u32InLen: length of input data to be decryption CNcomment: 待解密的数据长度。 CNend
\param[out] pu8Output: output data to be decryption CNcomment: 解密结果数据。 CNend
\param[out] pu32OutLen: length of output data to be decryption CNcomment: 解密结果的数据长度。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaPrivateDecrypt(HI_UNF_CIPHER_RSA_PRI_ENC_S *pstRsaDec,
HI_U8 *pu8Input, HI_U32 u32InLen,
HI_U8 *pu8Output, HI_U32 *pu32OutLen);
/**
\brief RSA encryption a plaintext with a RSA private key.
CNcomment:使用RSA私钥加密一段明文。 CNend
\attention \n
N/A
\param[in] pstRsaSign: encryption struct. CNcomment:加密属性结构体。 CNend
\param[in] pu8Input: input data to be encryption CNcomment: 待加密的数据。 CNend
\param[out] u32InLen: length of input data to be encryption CNcomment: 待加密的数据长度。 CNend
\param[out] pu8Output: output data to be encryption CNcomment: 加密结果数据。 CNend
\param[out] pu32OutLen: length of output data to be encryption CNcomment: 加密结果的数据长度。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaPrivateEncrypt(HI_UNF_CIPHER_RSA_PRI_ENC_S *pstRsaEnc,
HI_U8 *pu8Input, HI_U32 u32InLen,
HI_U8 *pu8Output, HI_U32 *pu32OutLen);
/**
\brief RSA decryption a ciphertext with a RSA public key.
CNcomment:使用RSA公钥解密一段密文。 CNend
\attention \n
N/A
\param[in] pstRsaVerify: decryption struct. CNcomment: 解密属性结构体。 CNend
\param[in] pu8Input: input data to be decryption CNcomment: 待解密的数据。 CNend
\param[out] u32InLen: length of input data to be decryption CNcomment: 待解密的数据长度。 CNend
\param[out] pu8Output: output data to be decryption CNcomment: 解密结果数据。 CNend
\param[out] pu32OutLen: length of output data to be decryption CNcomment: 解密结果的数据长度。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaPublicDecrypt(HI_UNF_CIPHER_RSA_PUB_ENC_S *pstRsaDec,
HI_U8 *pu8Input, HI_U32 u32InLen,
HI_U8 *pu8Output, HI_U32 *pu32OutLen);
/**
\brief RSA signature a context with appendix, where a signer’s RSA private key is used.
CNcomment:使用RSA私钥签名一段文本。 CNend
\attention \n
N/A
\param[in] pstRsaSign: signature struct. CNcomment: 签名属性结构体。 CNend
\param[in] pu8Input: input context to be signature,maybe null CNcomment: 待签名的数据, 如果pu8HashData不为空,则该指空可以为空。 CNend
\param[in] u32InLen: length of input context to be signature CNcomment: 待签名的数据长度。 CNend
\param[in] pu8HashData: hash value of context,if NULL, let pu8HashData = Hash(context) automatically,its length depends on hash type, it is 20 for sha1,28 for sha224,32 for sha256 or sm3,48 for sha384,64 for sha512. Ncomment: 待签名文本的HASH摘要,
CNcomment:输出的hash摘要,长度由hash类型决定,sha1时输出长度20,sha224输出长度28,sha256和上sm3输出长度32,sha384输出长度48,sha512输出长度64。如果为空,则自动计算文本的HASH摘要。 CNend
\param[out] pu8OutSign: output message of signature CNcomment: 签名信息。 CNend
\param[out] pu32OutSignLen: length of message of signature CNcomment: 签名信息的数据长度。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaSign(HI_UNF_CIPHER_RSA_SIGN_S *pstRsaSign,
HI_U8 *pu8InData, HI_U32 u32InDataLen,
HI_U8 *pu8HashData,
HI_U8 *pu8OutSign, HI_U32 *pu32OutSignLen);
/**
\brief RSA signature verification a context with appendix, where a signer’s RSA public key is used.
CNcomment:使用RSA公钥签名验证一段文本。 CNend
\attention \n
N/A
\param[in] pstRsaVerify: signature verification struct. CNcomment: 签名验证属性结构体。 CNend
\param[in] pu8Input: input context to be signature verification,maybe null CNcomment: 待签名验证的数据, 如果pu8HashData不为空,则该指空可以为空。 CNend
\param[in] u32InLen: length of input context to be signature CNcomment: 待签名验证的数据长度。 CNend
\param[in] pu8HashData: hash value of context,if NULL, let pu8HashData = Hash(context) automatically,its length depends on hash type, it is 20 for sha1,28 for sha224,32 for sha256 or sm3,48 for sha384,64 for sha512. Ncomment: 待签名文本的HASH摘要,
CNcomment:输出的hash摘要,长度由hash类型决定,sha1时输出长度20,sha224输出长度28,sha256和上sm3输出长度32,sha384输出长度48,sha512输出长度64。 Ncomment: 待签名文本的HASH摘要,如果为空,则自动计算文本的HASH摘要。 CNend
\param[in] pu8InSign: message of signature CNcomment: 签名信息。 CNend
\param[in] pu32InSignLen: length of message of signature CNcomment: 签名信息的数据长度。 CNend
\retval ::HI_SUCCESS Call this API successful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaVerify(HI_UNF_CIPHER_RSA_VERIFY_S *pstRsaVerify,
HI_U8 *pu8InData, HI_U32 u32InDataLen,
HI_U8 *pu8HashData,
HI_U8 *pu8InSign, HI_U32 u32InSignLen);
/**
\brief Generate a RSA private key.
CNcomment:生成一个RSA私钥。 CNend
\attention \n
N/A
\param[in] u32NumBits: bit numbers of the integer public modulus. CNcomment: RSA密钥N的位宽。 CNend
\param[in] u32Exponent: value of public exponent. CNcomment: RSA密钥E值。 CNend
\param[out] ptRsaPriKey: private key struct. CNcomment: RSA私钥。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaGenKey(HI_U32 u32NumBits, HI_U32 u32Exponent, HI_UNF_CIPHER_RSA_PRI_KEY_S *pstRsaPriKey);
/**
\brief Computes CRT parameters dP, dQ and qInv from the two primes p and q and the public exponent e.
CNcomment: 根据p和q参数,计算CRT参数dP, dQ 和 qInv 。 CNend
\attention \n
N/A
\param[in] u32NumBits: bit numbers of the integer public modulus. CNcomment: RSA密钥N的位宽。 CNend
\param[in] u32Exponent: value of public exponent. CNcomment: RSA密钥E值。 CNend
\param[in] pu8P Buffer containing the prime number p used as input parameter for the computation of CRT parameters. The buffer is allocated by the caller and is u32NumBits/2 bytes long. CNcomment: CRT的p参数,长度为u32NumBits/2. CNend
\param[in] pu8Q Buffer containing the prime number q used as input parameter for the computation of CRT parameters. The buffer is allocated by the caller and is u32NumBits/2 bytes long. CNcomment: CRT的q参数,长度为u32NumBits/2. CNend
\param[out] pu8DP Buffer where to store the CRT exponent dP computed. The buffer is allocated by the caller and is u32NumBits/2 bytes long. CNcomment: CRT的dP参数,长度为u32NumBits/2. CNend
\param[out] pu8DQ Buffer where to store the CRT exponent dQ computed. The buffer is allocated by the caller and is u32NumBits/2 bytes long. CNcomment: CRT的dQ参数,长度为u32NumBits/2. CNend
\param[out] pu8QP Buffer where to store the CRT exponent qInv computed. The buffer is allocated by the caller and is u32NumBits/2 bytes long. CNcomment: CRT的qInv参数,长度为u32NumBits/2. CNend
\param[out] ptRsaPriKey: private key struct. CNcomment: RSA私钥。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_RsaComputeCrtParams(HI_U32 u32NumBits, HI_U32 u32Exponent, HI_U8 *pu8P,
HI_U8 *pu8Q, HI_U8 *pu8DP, HI_U8 *pu8DQ, HI_U8 *pu8QP);
/**
\brief SM2 signature a context with appendix, where a signer’s SM2 private key is used.
CNcomment:使用SM2私钥签名一段文本。 CNend
\attention \n
N/A
\param[in] pstSm2Sign: signature struct. CNcomment: 签名属性结构体。 CNend
\param[in] pu8Msg: input context to be signature,maybe null CNcomment: 待签名的数据, 如果pu8HashData不为空,则该指空可以为空。 CNend
\param[in] u32MsgLen: length of input context to be signature CNcomment: 待签名的数据长度。 CNend
\param[out] pu8R: The R value of the signature result,its length is 32.CNcomment: 签名结果的R值,长度32。 CNend
\param[out] pu8S: The S value of the signature result,its length is 32.CNcomment: 签名结果的S值,长度32。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Sm2Sign(HI_UNF_CIPHER_SM2_SIGN_S *pstSm2Sign, HI_U8 *pu8Msg, HI_U32 u32MsgLen, HI_U8 *pu8R, HI_U8 *pu8S);
/**
\brief SM2 signature verification a context with appendix, where a signer’s SM2 public key is used.
CNcomment:使用SM2公钥签名验证一段文本。 CNend
\attention \n
N/A
\param[in] pstSm2Verify: signature verification struct. CNcomment: 签名验证属性结构体。 CNend
\param[in] pu8Msg: input context to be signature verification,maybe null CNcomment: 待签名验证的数据, 如果pu8HashData不为空,则该指空可以为空。 CNend
\param[in] u32MsgLen: length of input context to be signature CNcomment: 待签名验证的数据长度。 CNend
\param[in] pu8R: The R value of the signature result,its length is 32. CNcomment: 签名结果的R值,长度32。 CNend
\param[in] pu8S: The S value of the signature result,its length is 32. CNcomment: 签名结果的S值,长度32。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Sm2Verify(HI_UNF_CIPHER_SM2_VERIFY_S *pstSm2Verify, HI_U8 *pu8Msg, HI_U32 u32MsgLen, HI_U8 *pu8R, HI_U8 *pu8S);
/**
\brief SM2 encryption a plaintext with a RSA public key.
CNcomment:使用SM2公钥加密一段明文。 CNend
\attention \n
N/A
\param[in] pstSm2Enc: encryption struct. CNcomment: 加密属性结构体。 CNend
\param[in] pu8Msg: input data to be encryption CNcomment: 待加密的数据。 CNend
\param[in] u32MsgLen: length of input data to be encryption CNcomment: 待加密的数据长度。 CNend
\param[out] pu8C: output data to be encryption CNcomment: 加密结果数据。 CNend
\param[out] pu32Clen: length of output data to be encryption CNcomment: 加密结果的数据长度。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Sm2Encrypt(HI_UNF_CIPHER_SM2_ENC_S *pstSm2Enc, HI_U8 *pu8Msg, HI_U32 u32MsgLen, HI_U8 *pu8C, HI_U32 *pu32Clen);
/**
\brief RSA decryption a ciphertext with a SM2 private key.
CNcomment:使用SM2私钥解密一段密文。 CNend
\attention \n
N/A
\param[in] pstSm2Dec: decryption struct. CNcomment: 公钥解密属性结构体。 CNend
\param[in] pu8C: input data to be decryption CNcomment: 待解密的数据。 CNend
\param[out] u32Clen: length of input data to be decryption CNcomment: 待解密的数据长度。 CNend
\param[out] pu8Msg: output data to be decryption CNcomment: 解密结果数据。 CNend
\param[out] pu32MsgLen: length of output data to be decryption CNcomment: 解密结果的数据长度。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Sm2Decrypt(HI_UNF_CIPHER_SM2_DEC_S *pstSm2Dec, HI_U8 *pu8C, HI_U32 u32Clen, HI_U8 *pu8Msg, HI_U32 *pu32MsgLen);
/**
\brief Generate a SM2 key pair.
CNcomment:生成一个SM2密钥对。 CNend
\attention \n
N/A
\param[out] pstSm2Key: key pair struct. CNcomment: SM2密钥对。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_Sm2GenKey(HI_UNF_CIPHER_SM2_KEY_S *pstSm2Key);
/**
\brief CENC decryption a ciphertext.
CNcomment: CENC格式解密一段密文。 CNend
\attention \n
This API is used to perform decryption ciphertext base on CENC format.
CNcomment:使用CIPHER进行CENC格式解密操作。 CNend
\param[in] hCipher Cipher handle CNcomment:CIPHER句柄 CNend
\param[in] u8Key key for cipher decryption,its length should be 16. CNcomment:CIPHER 解密密钥,长度为16. CNend
\param[in] u8IV iv for cipher decryption,its length should be 16. CNcomment:CIPHER 解密IV ,长度为16.CNend
\param[in] u32NonSecInputPhyAddr non-secure Physical address of the source data CNcomment:源数据非安全物理地址 CNend
\param[in] u32SecOutputPhyAddr secure Physical address of the target data CNcomment:目的数据安全物理地址 CNend
\param[in] u32ByteLength Length of the decrypted data CNcomment:加密数据长度 CNend
\param[in] u32FirstEncrypt offset of the first encrypt block data CNcomment:第一个加密数据的偏移地址,0~15 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid. CNcomment:句柄非法 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_CENCDecrypt(HI_HANDLE hCipher, HI_U8 *pu8Key, HI_U8 *pu8IV,
HI_U32 u32NonSecInPhyAddr, HI_U32 u32SecOutPhyAddr, HI_U32 u32ByteLength,
HI_U32 u32FirstEncryptOffset,
HI_UNF_CIPHER_SUBSAMPLE_S *pstSubSample, HI_U32 u32SubsampleNum);
/**
\brief CENC decryption a ciphertext.
CNcomment: CENC格式解密一段密文。 CNend
\attention \n
This API is used to perform decryption ciphertext base on CENC format.
CNcomment:使用CIPHER进行CENC格式解密操作。 CNend
\param[in] hCipher Cipher handle CNcomment:CIPHER句柄 CNend
\param[in] u8Key key for cipher decryption,its length should be 16. CNcomment:CIPHER 解密密钥 CNend
\param[in] bOddKey use odd key or not CNcomment:CIPHER 是否使用odd key CNend
\param[in] u32NonSecInputPhyAddr non-secure Physical address of the source data CNcomment:源数据非安全物理地址 CNend
\param[in] u32SecOutputPhyAddr secure Physical address of the target data CNcomment:目的数据安全物理地址 CNend
\param[in] u32ByteLength Length of the decrypted data CNcomment:加密数据长度 CNend
\param[in] u32FirstEncrypt offset of the first encrypt block data CNcomment:第一个加密数据的偏移地址,0~15 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败 CNend
\retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized. CNcomment:CIPHER设备未初始化 CNend
\retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid. CNcomment:参数错误 CNend
\retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid. CNcomment:句柄非法 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_CENCDecryptEx(HI_HANDLE hCipher, HI_U8 *pu8Key, HI_BOOL bOddKey,
HI_U32 u32NonSecInPhyAddr, HI_U32 u32SecOutPhyAddr, HI_U32 u32ByteLength,
HI_U32 u32FirstEncryptOffset,
HI_UNF_CIPHER_SUBSAMPLE_EX_S *pstSubSample, HI_U32 u32SubsampleNum);
/**
\brief Compute Diffie-Hellman shared secret as otherPubKey^privKey mod p.
CNcomment: 计算DH共享密钥。 CNend
\attention \n
N/A
\param[in] pu8P: Buffer containing the DH prime modulus p used for the operation. CNcomment: DH参数p. CNend
\param[in] pu8PrivKey: Buffer containing the DH private key. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: DH私钥,长度不足Key的大小,前面补0。 CNend
\param[in] pu8OtherPubKey: Buffer containing the DH public key of the other peer. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: 对方的DH公钥,长度不足Key的大小,前面补0。 CNend
\param[out] pu8SharedSecret: Buffer where to write the computed shared secret. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: DH共享密钥,长度不足Key的大小,前面补0。 CNend
\param[in] u32KeySize: DH key size. CNcomment: DH密钥长度. CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_DhComputeKey(HI_U8 * pu8P, HI_U8 *pu8PrivKey, HI_U8 *pu8OtherPubKey,
HI_U8 *pu8SharedSecret, HI_U32 u32KeySize);
/**
\brief Generate Diffie-Hellman public/private key pair from g and p parameters. The public key is equal to g^x mod p, where x is random number considered as the private key.
CNcomment: 生成DH公私密钥对。 CNend
\attention \n
N/A
\param[in] pu8G: Buffer containing the DH generator g used for the operation. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: DH的g参数,长度不足Key的大小,前面补0。 CNend
\param[in] pu8P: Buffer containing the DH generator p used for the operation. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: DH的p参数,长度不足Key的大小,前面补0。 CNend
\param[in] pu8InputPrivKey: Buffer containing an optional input private key from which the public has to be generated. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. If no private key is provided as input (\c pu8InputPrivKey=NULL), function generates a random private key and stores it in pu8OutputPrivKey this buffer. CNcomment: DH的私钥,长度不足Key的大小,前面补0, 如果为空指针,该函数将生成一个私钥放到pu8OutputPrivKey中。 CNend
\param[out] pu8OutputPrivKey: Buffer where to write the generated private key, in case no private key is provided as input (pu8InputPrivKey==NULL). It must be padded with leading zeros if the effective size of the private key is smaller than the buffer size. CNcomment: DH的私钥,长度不足Key的大小,前面补0, 如果pu8InputPrivKey为空指针,该函数将生成一个私钥放到这个buffer中。 CNend
\param[in] u32KeySize: DH key size. CNcomment: DH密钥长度. CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_DhGenKey(HI_U8 *pu8G, HI_U8 *pu8P, HI_U8 *pu8InputPrivKey,
HI_U8 *pu8OutputPrivKey, HI_U8 *pu8PubKey,
HI_U32 u32KeySize);
/**
\brief Compute ECDH shared secret key. This key corresponds to the X coordinates of the computed P point.
CNcomment: 计算ECC DH共享密钥。 CNend
\attention \n
N/A
\param[in] pstParams: Elliptic curve domain parameters. The caller is in charge padding each buffer with leading zeros if the effective size of the domain parameter conveyed is smaller than pstParams->keySize. CNcomment: ECC椭圆曲线参数,长度不足Key的大小,前面补0. CNend
\param[in] pu8PrivKey: Buffer containing the ECDH private key. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: ECDH私钥,长度不足Key的大小,前面补0。 CNend
\param[in] pu8OtherPubKeyX: Buffer containing the X coordinates of other peer's ECDH public key. It is padded by the caller with leading zeros if the effective size of the public key X coordinates is smaller than the buffer size. CNcomment: 对方的ECDH公钥的X坐标,长度不足Key的大小,前面补0。 CNend
\param[in] pu8OtherPubKeyY: Buffer containing the Y coordinates of other peer's ECDH public key. It is padded by the caller with leading zeros if the effective size of the public key Y coordinates is smaller than the buffer size. CNcomment: 对方的ECDH公钥的Y坐标,长度不足Key的大小,前面补0。 CNend
\param[out] pu8SharedSecret: Buffer where to write the computed shared secret. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: ECDH共享密钥,长度不足Key的大小,前面补0。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_EcdhComputeKey(HI_UNF_CIPHER_ECC_PARAM_S *pstParams, HI_U8 *pu8PrivKey,
HI_U8 *pu8OtherPubKeyX, HI_U8 *pu8OtherPubKeyY,
HI_U8 *pu8SharedSecret);
/**
\brief Generate ECC public/private key pair.
CNcomment: 生成ECDH公私密钥对。 CNend
\attention \n
N/A
\param[in] pstParams: Elliptic curve domain parameters. The caller is in charge padding each buffer with leading zeros if the effective size of the domain parameter conveyed is smaller than pstParams->keySize. CNcomment: ECC椭圆曲线参数,长度不足Key的大小,前面补0. CNend
\param[in] pu8InputPrivKey: Buffer containing an optional input private key from which the public has to be generated. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. If no private key is provided as input (\c pu8InputPrivKey=NULL), function generates a random private key and stores it in pu8OutputPrivKey this buffer. CNcomment: ECC的私钥,长度不足Key的大小,前面补0, 如果为空指针,该函数将生成一个私钥放到pu8OutputPrivKey中。 CNend
\param[out] pu8OutputPrivKey: Buffer where to write the generated private key, in case no private key is provided as input (pu8InputPrivKey==NULL). It must be padded with leading zeros if the effective size of the private key is smaller than the buffer size. CNcomment: ECC的私钥,长度不足Key的大小,前面补0, 如果pu8InputPrivKey为空指针,该函数将生成一个私钥放到这个buffer中。 CNend
\pu8PubKeyX[out] Buffer where to write the X coordinates of the generated public key. It must be padded with leading zeros if the effective size of the public key X coordinates is smaller than the buffer size. CNcomment: ECC公钥X坐标. CNend
\pu8PubKeyX[out] Buffer where to write the Y coordinates of the generated public key. It must be padded with leading zeros if the effective size of the public key X coordinates is smaller than the buffer size. CNcomment: ECC公钥Y坐标. CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_EccGenKey(HI_UNF_CIPHER_ECC_PARAM_S *pstParams, HI_U8 *pu8InputPrivKey,
HI_U8 *pu8OutputPrivKey, HI_U8 *pu8PubKeyX, HI_U8 *pu8PubKeyY);
/**
\brief Sign a message with ECDSA algorithm and returns an uncompressed signature made of the pair (r, s).
CNcomment: ECDSA签名。 CNend
\attention \n
N/A
\param[in] pstParams: Elliptic curve domain parameters. The caller is in charge padding each buffer with leading zeros if the effective size of the domain parameter conveyed is smaller than pstParams->keySize. CNcomment: ECC椭圆曲线参数,长度不足Key的大小,前面补0. CNend
\param[in] pu8PrivKey: Buffer containing the ECDH private key. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: ECDH私钥,长度不足Key的大小,前面补0。 CNend
\param[in] enShaType: One of the hash algorithm. CNcomment: HASH 算法类型。 CNend
\param[in] pu8Message: Message to be signed. CNcomment: 待签名消息。 CNend
\param[in] Size in bytes of message to be signed. CNcomment: 待签名消息的长度。 CNend
\param[out] pu8SigR: Buffer where to write the uncompressed r component of the resulting signature. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: 签名结果的R值。 CNend
\param[out] pu8SigS: Buffer where to write the uncompressed s component of the resulting signature. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: 签名结果的S值。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_EcdsaSign(HI_UNF_CIPHER_ECC_PARAM_S *pstParams, HI_U8 *pu8PrivKey,
HI_UNF_CIPHER_HASH_TYPE_E enShaType,
HI_U8 *pu8Message, HI_U32 u32MessageSize,
HI_U8 *pu8SigR, HI_U8 *pu8SigS);
/**
\brief Verify an ECDSA signature made of an uncompressed pair (r, s).
CNcomment: ECDSA签名验证。 CNend
\attention \n
N/A
\param[in] pstParams: Elliptic curve domain parameters. The caller is in charge padding each buffer with leading zeros if the effective size of the domain parameter conveyed is smaller than pstParams->keySize. CNcomment: ECC椭圆曲线参数,长度不足Key的大小,前面补0. CNend
\pu8PubKeyX[out] Buffer where to write the X coordinates of the generated public key. It must be padded with leading zeros if the effective size of the public key X coordinates is smaller than the buffer size. CNcomment: ECC公钥X坐标. CNend
\pu8PubKeyX[out] Buffer where to write the Y coordinates of the generated public key. It must be padded with leading zeros if the effective size of the public key X coordinates is smaller than the buffer size. CNcomment: ECC公钥Y坐标. CNend
\param[in] enShaType: One of the hash algorithm. CNcomment: HASH 算法类型。 CNend
\param[in] pu8Message: Message to be signed. CNcomment: 待签名消息。 CNend
\param[in] Size in bytes of message to be signed. CNcomment: 待签名消息的长度。 CNend
\param[in] pu8SigR: Buffer where to write the uncompressed r component of the resulting signature. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: 签名结果的R值。 CNend
\param[in] pu8SigS: Buffer where to write the uncompressed s component of the resulting signature. The caller ensures it is padded with leading zeros if the effective size of this key is smaller than the u32KeySize. CNcomment: 签名结果的S值。 CNend
\retval ::HI_SUCCESS Call this API succussful. CNcomment:API系统调用成功。 CNend
\retval ::HI_FAILURE Call this API fails. CNcomment:API系统调用失败。 CNend
\see \n
N/A
*/
HI_S32 HI_UNF_CIPHER_EcdsaVerify(HI_UNF_CIPHER_ECC_PARAM_S *pstParams,
HI_U8 *pu8PubKeyX, HI_U8 *pu8PubKeyY,
HI_UNF_CIPHER_HASH_TYPE_E enShaType,
HI_U8 *pu8Message, HI_U32 u32MessageSize,
HI_U8 *pu8SigR, HI_U8 *pu8SigS);
/** @} */ /** <!-- ==== API declaration end ==== */
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* __HI_UNF_CIPHER_H__ */