hi_unf_cipher.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /******************************************************************************
  2. Copyright (C), 2015-2016, Hisilicon Tech. Co., Ltd.
  3. ******************************************************************************
  4. File Name : hi_tee_cipher.h
  5. Version : Initial Draft
  6. Author : Hisilicon multimedia software group
  7. Created : 2016/06/08
  8. Description :
  9. History :
  10. 1.Date : 2016/06/08
  11. Author : z00268517
  12. Modification: Created file
  13. *******************************************************************************/
  14. /**
  15. * \file
  16. * \brief Describes the API about the cipher.
  17. */
  18. #ifndef __HI_UNF_CIPHER_H__
  19. #define __HI_UNF_CIPHER_H__
  20. #include "hi_types.h"
  21. #ifdef __cplusplus
  22. #if __cplusplus
  23. extern "C" {
  24. #endif
  25. #endif /* __cplusplus */
  26. /*************************** Structure Definition ****************************/
  27. /** \addtogroup CIPHER */
  28. /** @{ */ /** <!-- [CIPHER] */
  29. /** max length of SM2, unit: word */
  30. #define SM2_LEN_IN_WROD (8)
  31. /** max length of SM2, unit: byte */
  32. #define SM2_LEN_IN_BYTE (SM2_LEN_IN_WROD * 4)
  33. /** CIPHER set IV for first package */
  34. #define CIPHER_IV_CHANGE_ONE_PKG (1)
  35. /** CIPHER set IV for first package */
  36. #define CIPHER_IV_CHANGE_ALL_PKG (2)
  37. //typedef unsigned long HI_SIZE_T;
  38. /** Cipher work mode */
  39. typedef enum hiHI_UNF_CIPHER_WORK_MODE_E
  40. {
  41. HI_UNF_CIPHER_WORK_MODE_ECB, /**<Electronic codebook (ECB) mode*/
  42. HI_UNF_CIPHER_WORK_MODE_CBC, /**<Cipher block chaining (CBC) mode*/
  43. HI_UNF_CIPHER_WORK_MODE_CFB, /**<Cipher feedback (CFB) mode*/
  44. HI_UNF_CIPHER_WORK_MODE_OFB, /**<Output feedback (OFB) mode*/
  45. HI_UNF_CIPHER_WORK_MODE_CTR, /**<Counter (CTR) mode*/
  46. HI_UNF_CIPHER_WORK_MODE_CCM, /**<Counter (CCM) mode*/
  47. HI_UNF_CIPHER_WORK_MODE_GCM, /**<Counter (GCM) mode*/
  48. HI_UNF_CIPHER_WORK_MODE_CBC_CTS, /**<Cipher block chaining CipherStealing mode*/
  49. HI_UNF_CIPHER_WORK_MODE_BUTT,
  50. HI_UNF_CIPHER_WORK_MODE_INVALID = 0xffffffff,
  51. }HI_UNF_CIPHER_WORK_MODE_E;
  52. /** Cipher algorithm */
  53. typedef enum hiHI_UNF_CIPHER_ALG_E
  54. {
  55. HI_UNF_CIPHER_ALG_DES = 0x0, /**< Data encryption standard (DES) algorithm */
  56. HI_UNF_CIPHER_ALG_3DES = 0x1, /**< 3DES algorithm */
  57. HI_UNF_CIPHER_ALG_AES = 0x2, /**< Advanced encryption standard (AES) algorithm */
  58. HI_UNF_CIPHER_ALG_SM1 = 0x3, /**<SM1 algorithm*/
  59. HI_UNF_CIPHER_ALG_SM4 = 0x4, /**<SM4 algorithm*/
  60. HI_UNF_CIPHER_ALG_DMA = 0x5, /**<DMA copy*/
  61. HI_UNF_CIPHER_ALG_BUTT = 0x6,
  62. HI_UNF_CIPHER_ALG_INVALID = 0xffffffff,
  63. }HI_UNF_CIPHER_ALG_E;
  64. /** Key length */
  65. typedef enum hiHI_UNF_CIPHER_KEY_LENGTH_E
  66. {
  67. HI_UNF_CIPHER_KEY_AES_128BIT = 0x0, /**< 128-bit key for the AES algorithm */
  68. HI_UNF_CIPHER_KEY_AES_192BIT = 0x1, /**< 192-bit key for the AES algorithm */
  69. HI_UNF_CIPHER_KEY_AES_256BIT = 0x2, /**< 256-bit key for the AES algorithm */
  70. HI_UNF_CIPHER_KEY_DES_3KEY = 0x2, /**< Three keys for the DES algorithm */
  71. HI_UNF_CIPHER_KEY_DES_2KEY = 0x3, /**< Two keys for the DES algorithm */
  72. HI_UNF_CIPHER_KEY_DEFAULT = 0x0, /**< default key length, DES-8, SM1-48, SM4-16 */
  73. HI_UNF_CIPHER_KEY_INVALID = 0xffffffff,
  74. }HI_UNF_CIPHER_KEY_LENGTH_E;
  75. /** Cipher bit width */
  76. typedef enum hiHI_UNF_CIPHER_BIT_WIDTH_E
  77. {
  78. HI_UNF_CIPHER_BIT_WIDTH_64BIT = 0x0, /**< 64-bit width */
  79. HI_UNF_CIPHER_BIT_WIDTH_8BIT = 0x1, /**< 8-bit width */
  80. HI_UNF_CIPHER_BIT_WIDTH_1BIT = 0x2, /**< 1-bit width */
  81. HI_UNF_CIPHER_BIT_WIDTH_128BIT = 0x3, /**< 128-bit width */
  82. HI_UNF_CIPHER_BIT_WIDTH_INVALID = 0xffffffff,
  83. }HI_UNF_CIPHER_BIT_WIDTH_E;
  84. /** Cipher control parameters */
  85. typedef struct hiTEE_CIPHER_CTRL_CHANGE_FLAG_S
  86. {
  87. HI_U32 bit1IV:2; /**< Initial Vector change flag, 0-don't set, 1-set IV for first package, 2-set IV for each package */
  88. HI_U32 bitsResv:30; /**< Reserved */
  89. }HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S;
  90. /** Key ladder selecting parameters */
  91. typedef enum hiTEE_CIPHER_CA_TYPE_E
  92. {
  93. HI_UNF_CIPHER_KEY_SRC_USER = 0x0, /**< User Key*/
  94. HI_UNF_CIPHER_KEY_SRC_KLAD_1, /**< KLAD Key 1*/
  95. HI_UNF_CIPHER_KEY_SRC_KLAD_2, /**< KLAD Key 2*/
  96. HI_UNF_CIPHER_KEY_SRC_KLAD_3, /**< KLAD Key 3*/
  97. HI_UNF_CIPHER_KEY_SRC_BUTT,
  98. HI_UNF_CIPHER_KEY_SRC_INVALID = 0xffffffff,
  99. }HI_UNF_CIPHER_CA_TYPE_E;
  100. /** Encryption/Decryption type selecting */
  101. typedef enum
  102. {
  103. HI_UNF_CIPHER_KLAD_TARGET_AES = 0x0, /**< Klad for AES*/
  104. HI_UNF_CIPHER_KLAD_TARGET_RSA, /**< Klad for RSA*/
  105. HI_UNF_CIPHER_KLAD_TARGET_BUTT,
  106. }HI_UNF_CIPHER_KLAD_TARGET_E;
  107. /** Encryption/Decryption type selecting */
  108. typedef enum
  109. {
  110. HI_UNF_CIPHER_TYPE_NORMAL = 0x0,
  111. HI_UNF_CIPHER_TYPE_COPY_AVOID,
  112. HI_UNF_CIPHER_TYPE_BUTT,
  113. HI_UNF_CIPHER_TYPE_INVALID = 0xffffffff,
  114. }HI_UNF_CIPHER_TYPE_E;
  115. /** Structure of the cipher type */
  116. typedef struct
  117. {
  118. HI_UNF_CIPHER_TYPE_E enCipherType;
  119. }HI_UNF_CIPHER_ATTS_S;
  120. /** sm1 round config */
  121. typedef enum hiHI_UNF_CIPHER_SM1_ROUND_E
  122. {
  123. HI_UNF_CIPHER_SM1_ROUND_08 = 0x00, /**< sm1 round 08 */
  124. HI_UNF_CIPHER_SM1_ROUND_10 = 0x01, /**< sm1 round 10 */
  125. HI_UNF_CIPHER_SM1_ROUND_12 = 0x02, /**< sm1 round 12 */
  126. HI_UNF_CIPHER_SM1_ROUND_14 = 0x03, /**< sm1 round 14 */
  127. HI_UNF_CIPHER_SM1_ROUND_BUTT,
  128. HI_UNF_CIPHER_SM1_ROUND_INVALID = 0xffffffff,
  129. }HI_UNF_CIPHER_SM1_ROUND_E;
  130. /** Structure of the cipher control information */
  131. typedef struct hiHI_UNF_CIPHER_CTRL_S
  132. {
  133. HI_U32 u32Key[8]; /**< Key input */
  134. HI_U32 u32IV[4]; /**< Initialization vector (IV) */
  135. HI_BOOL bKeyByCA; /**< Encryption using advanced conditional access (CA) or decryption using keys */
  136. HI_UNF_CIPHER_CA_TYPE_E enCaType; /**< Select keyladder type when using advanced CA */
  137. HI_UNF_CIPHER_ALG_E enAlg; /**< Cipher algorithm */
  138. HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */
  139. HI_UNF_CIPHER_WORK_MODE_E enWorkMode; /**< Operating mode */
  140. HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */
  141. HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /**< control information exchange choices, we default all would be change except they have been in the choices */
  142. } HI_UNF_CIPHER_CTRL_S;
  143. /** Structure of the cipher AES control information */
  144. typedef struct hiHI_UNF_CIPHER_CTRL_AES_S
  145. {
  146. HI_U32 u32EvenKey[8]; /**< Key input, default use this key*/
  147. HI_U32 u32OddKey[8]; /**< Key input, only valid for Multi encrypt/decrypt*/
  148. HI_U32 u32IV[4]; /**< Initialization vector (IV) */
  149. HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */
  150. HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */
  151. 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 */
  152. } HI_UNF_CIPHER_CTRL_AES_S;
  153. /** Structure of the cipher AES CCM/GCM control information */
  154. typedef struct hiHI_UNF_CIPHER_CTRL_AES_CCM_GCM_S
  155. {
  156. HI_U32 u32Key[8]; /**< Key input */
  157. HI_U32 u32IV[4]; /**< Initialization vector (IV) */
  158. HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */
  159. 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*/
  160. HI_U32 u32TagLen; /**< Tag lenght for CCM which is an element of {4,6,8,10,12,14,16}*/
  161. HI_U32 u32ALen; /**< Associated data for CCM and GCM*/
  162. HI_SIZE_T szAPhyAddr; /**< Physical address of Associated data for CCM and GCM*/
  163. } HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
  164. /** Structure of the cipher DES control information */
  165. typedef struct hiHI_UNF_CIPHER_CTRL_DES_S
  166. {
  167. HI_U32 u32Key[2]; /**< Key input */
  168. HI_U32 u32IV[2]; /**< Initialization vector (IV) */
  169. HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */
  170. 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 */
  171. } HI_UNF_CIPHER_CTRL_DES_S;
  172. /** Structure of the cipher 3DES control information */
  173. typedef struct hiHI_UNF_CIPHER_CTRL_3DES_S
  174. {
  175. HI_U32 u32Key[6]; /**< Key input */
  176. HI_U32 u32IV[2]; /**< Initialization vector (IV) */
  177. HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */
  178. HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen; /**< Key length */
  179. 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 */
  180. } HI_UNF_CIPHER_CTRL_3DES_S;
  181. /** Structure of the cipher SM1 control information */
  182. typedef struct hiHI_UNF_CIPHER_CTRL_SM1_S
  183. {
  184. HI_U32 u32EK[4]; /**< Key of EK input */
  185. HI_U32 u32AK[4]; /**< Key of AK input */
  186. HI_U32 u32SK[4]; /**< Key of SK input */
  187. HI_U32 u32IV[4]; /**< Initialization vector (IV) */
  188. HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth; /**< Bit width for encryption or decryption */
  189. HI_UNF_CIPHER_SM1_ROUND_E enSm1Round; /**< SM1 round number, should be 8, 10, 12 or 14*/
  190. 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 */
  191. } HI_UNF_CIPHER_CTRL_SM1_S;
  192. /** Structure of the cipher SM4 control information */
  193. typedef struct hiHI_UNF_CIPHER_CTRL_SM4_S
  194. {
  195. HI_U32 u32Key[4]; /**< Key input */
  196. HI_U32 u32IV[4]; /**< Initialization vector (IV) */
  197. 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 */
  198. } HI_UNF_CIPHER_CTRL_SM4_S;
  199. /** Expand Structure of the cipher control information */
  200. typedef struct hiHI_UNF_CIPHER_CTRL_EX_S
  201. {
  202. HI_UNF_CIPHER_ALG_E enAlg; /**< Cipher algorithm */
  203. HI_UNF_CIPHER_WORK_MODE_E enWorkMode; /**< Operating mode */
  204. HI_BOOL bKeyByCA; /**< Encryption using advanced conditional access (CA) or decryption using keys */
  205. /**< Parameter for special algorithm
  206. for AES, the pointer should point to HI_UNF_CIPHER_CTRL_AES_S;
  207. for AES_CCM or AES_GCM, the pointer should point to HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
  208. for DES, the pointer should point to HI_UNF_CIPHER_CTRL_DES_S;
  209. for 3DES, the pointer should point to HI_UNF_CIPHER_CTRL_3DES_S;
  210. for SM1, the pointer should point to HI_UNF_CIPHER_CTRL_SM1_S;
  211. for SM4, the pointer should point to HI_UNF_CIPHER_CTRL_SM4_S;
  212. */
  213. HI_VOID *pParam;
  214. } HI_UNF_CIPHER_CTRL_EX_S;
  215. /** Cipher data */
  216. typedef struct hiHI_UNF_CIPHER_DATA_S
  217. {
  218. HI_SIZE_T szSrcPhyAddr; /**< phy address of the original data */
  219. HI_SIZE_T szDestPhyAddr; /**< phy address of the purpose data */
  220. HI_U32 u32ByteLength; /**< cigher data length*/
  221. HI_BOOL bOddKey; /**< Use odd key or even key*/
  222. } HI_UNF_CIPHER_DATA_S;
  223. /** Hash algrithm type */
  224. typedef enum hiHI_UNF_CIPHER_HASH_TYPE_E
  225. {
  226. HI_UNF_CIPHER_HASH_TYPE_SHA1,
  227. HI_UNF_CIPHER_HASH_TYPE_SHA224,
  228. HI_UNF_CIPHER_HASH_TYPE_SHA256,
  229. HI_UNF_CIPHER_HASH_TYPE_SHA384,
  230. HI_UNF_CIPHER_HASH_TYPE_SHA512,
  231. HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA1,
  232. HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA224,
  233. HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA256,
  234. HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA384,
  235. HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA512,
  236. HI_UNF_CIPHER_HASH_TYPE_SM3,
  237. HI_UNF_CIPHER_HASH_TYPE_BUTT,
  238. HI_UNF_CIPHER_HASH_TYPE_INVALID = 0xffffffff,
  239. }HI_UNF_CIPHER_HASH_TYPE_E;
  240. /** Hash init struct input */
  241. typedef struct
  242. {
  243. HI_U8 *pu8HMACKey;
  244. HI_U32 u32HMACKeyLen;
  245. HI_UNF_CIPHER_HASH_TYPE_E eShaType;
  246. }HI_UNF_CIPHER_HASH_ATTS_S;
  247. typedef enum hiHI_UNF_CIPHER_RSA_ENC_SCHEME_E
  248. {
  249. HI_UNF_CIPHER_RSA_ENC_SCHEME_NO_PADDING, /**< without padding */
  250. HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_0, /**< PKCS#1 block type 0 padding*/
  251. HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_1, /**< PKCS#1 block type 1 padding*/
  252. HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_2, /**< PKCS#1 block type 2 padding*/
  253. HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA1, /**< PKCS#1 RSAES-OAEP-SHA1 padding*/
  254. HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA224, /**< PKCS#1 RSAES-OAEP-SHA224 padding*/
  255. HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA256, /**< PKCS#1 RSAES-OAEP-SHA256 padding*/
  256. HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA384, /**< PKCS#1 RSAES-OAEP-SHA384 padding*/
  257. HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA512, /**< PKCS#1 RSAES-OAEP-SHA512 padding*/
  258. HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_PKCS1_V1_5, /**< PKCS#1 RSAES-PKCS1_V1_5 padding*/
  259. HI_UNF_CIPHER_RSA_ENC_SCHEME_BUTT,
  260. HI_UNF_CIPHER_RSA_ENC_SCHEME_INVALID = 0xffffffff,
  261. }HI_UNF_CIPHER_RSA_ENC_SCHEME_E;
  262. typedef enum hiHI_UNF_CIPHER_RSA_SIGN_SCHEME_E
  263. {
  264. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA1 = 0x100, /**< PKCS#1 RSASSA_PKCS1_V15_SHA1 signature*/
  265. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA224, /**< PKCS#1 RSASSA_PKCS1_V15_SHA224 signature*/
  266. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA256, /**< PKCS#1 RSASSA_PKCS1_V15_SHA256 signature*/
  267. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA384, /**< PKCS#1 RSASSA_PKCS1_V15_SHA384 signature*/
  268. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA512, /**< PKCS#1 RSASSA_PKCS1_V15_SHA512 signature*/
  269. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA1, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA1 signature*/
  270. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA224, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA224 signature*/
  271. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA256, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature*/
  272. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA384, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA1 signature*/
  273. HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA512, /**< PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature*/
  274. HI_UNF_CIPHER_RSA_SIGN_SCHEME_BUTT,
  275. HI_UNF_CIPHER_RSA_SIGN_SCHEME_INVALID = 0xffffffff,
  276. }HI_UNF_CIPHER_RSA_SIGN_SCHEME_E;
  277. typedef struct
  278. {
  279. HI_U8 *pu8N; /**< point to public modulus */
  280. HI_U8 *pu8E; /**< point to public exponent */
  281. HI_U16 u16NLen; /**< length of public modulus, max value is 512Byte*/
  282. HI_U16 u16ELen; /**< length of public exponent, max value is 512Byte*/
  283. }HI_UNF_CIPHER_RSA_PUB_KEY_S;
  284. /** RSA private key struct */
  285. typedef struct
  286. {
  287. HI_U8 *pu8N; /*!< public modulus */
  288. HI_U8 *pu8E; /*!< public exponent */
  289. HI_U8 *pu8D; /*!< private exponent */
  290. HI_U8 *pu8P; /*!< 1st prime factor */
  291. HI_U8 *pu8Q; /*!< 2nd prime factor */
  292. HI_U8 *pu8DP; /*!< D % (P - 1) */
  293. HI_U8 *pu8DQ; /*!< D % (Q - 1) */
  294. HI_U8 *pu8QP; /*!< 1 / (Q % P) */
  295. HI_U16 u16NLen; /**< length of public modulus */
  296. HI_U16 u16ELen; /**< length of public exponent */
  297. HI_U16 u16DLen; /**< length of private exponent */
  298. HI_U16 u16PLen; /**< length of 1st prime factor */
  299. HI_U16 u16QLen; /**< length of 2nd prime factor */
  300. HI_U16 u16DPLen; /**< length of D % (P - 1) */
  301. HI_U16 u16DQLen; /**< length of D % (Q - 1) */
  302. HI_U16 u16QPLen; /**< length of 1 / (Q % P) */
  303. }HI_UNF_CIPHER_RSA_PRI_KEY_S;
  304. /** RSA public key encryption struct input */
  305. typedef struct
  306. {
  307. HI_UNF_CIPHER_RSA_ENC_SCHEME_E enScheme; /** RSA encryption scheme*/
  308. HI_UNF_CIPHER_RSA_PUB_KEY_S stPubKey; /** RSA private key struct */
  309. HI_UNF_CIPHER_CA_TYPE_E enCaType;
  310. }HI_UNF_CIPHER_RSA_PUB_ENC_S;
  311. /** RSA private key decryption struct input */
  312. typedef struct
  313. {
  314. HI_UNF_CIPHER_RSA_ENC_SCHEME_E enScheme; /** RSA encryption scheme */
  315. HI_UNF_CIPHER_RSA_PRI_KEY_S stPriKey; /** RSA public key struct */
  316. HI_UNF_CIPHER_CA_TYPE_E enCaType;
  317. }HI_UNF_CIPHER_RSA_PRI_ENC_S;
  318. /** RSA signature struct input */
  319. typedef struct
  320. {
  321. HI_UNF_CIPHER_RSA_SIGN_SCHEME_E enScheme; /** RSA signature scheme*/
  322. HI_UNF_CIPHER_RSA_PRI_KEY_S stPriKey; /** RSA private key struct */
  323. HI_UNF_CIPHER_CA_TYPE_E enCaType;
  324. }HI_UNF_CIPHER_RSA_SIGN_S;
  325. /** RSA signature verify struct input */
  326. typedef struct
  327. {
  328. HI_UNF_CIPHER_RSA_SIGN_SCHEME_E enScheme; /** RSA signature scheme*/
  329. HI_UNF_CIPHER_RSA_PUB_KEY_S stPubKey; /** RSA public key struct */
  330. }HI_UNF_CIPHER_RSA_VERIFY_S;
  331. /** @} */ /** <!-- ==== Structure Definition End ==== */
  332. #define HI_UNF_CIPHER_Open(HI_VOID) HI_UNF_CIPHER_Init(HI_VOID);
  333. #define HI_UNF_CIPHER_Close(HI_VOID) HI_UNF_CIPHER_DeInit(HI_VOID);
  334. /******************************* API Declaration *****************************/
  335. /** \addtogroup CIPHER */
  336. /** @{ */ /** <!-- [CIPHER] */
  337. /* ---CIPHER---*/
  338. /**
  339. \attention \n
  340. This API is used to start the cipher device.
  341. \param N/A
  342. \retval ::HI_SUCCESS Call this API successful.
  343. \retval ::HI_FAILURE Call this API fails.
  344. \retval ::HI_ERR_CIPHER_FAILED_INIT The cipher device fails to be initialized.
  345. \see \n
  346. N/A
  347. */
  348. HI_S32 HI_UNF_CIPHER_Init(HI_VOID);
  349. /**
  350. \brief Deinit the cipher device.
  351. \attention \n
  352. 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.
  353. \param N/A
  354. \retval ::HI_SUCCESS Call this API successful.
  355. \retval ::HI_FAILURE Call this API fails.
  356. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  357. \see \n
  358. N/A
  359. */
  360. HI_S32 HI_UNF_CIPHER_DeInit(HI_VOID);
  361. /**
  362. \brief Obtain a cipher handle for encryption and decryption.
  363. \param[in] cipher attributes
  364. \param[out] phCipher Cipher handle
  365. \retval ::HI_SUCCESS Call this API successful.
  366. \retval ::HI_FAILURE Call this API fails.
  367. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  368. \retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null.
  369. \retval ::HI_ERR_CIPHER_FAILED_GETHANDLE The cipher handle fails to be obtained, because there are no available cipher handles.
  370. \see \n
  371. N/A
  372. */
  373. HI_S32 HI_UNF_CIPHER_CreateHandle(HI_HANDLE* phCipher, const HI_UNF_CIPHER_ATTS_S *pstCipherAttr);
  374. /**
  375. \attention \n
  376. This API is used to destroy existing cipher handles.
  377. \param[in] hCipher Cipher handle
  378. \retval ::HI_SUCCESS Call this API successful.
  379. \retval ::HI_FAILURE Call this API fails.
  380. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  381. \see \n
  382. N/A
  383. */
  384. HI_S32 HI_UNF_CIPHER_DestroyHandle(HI_HANDLE hCipher);
  385. /**
  386. \brief Configures the cipher control information.
  387. \attention \n
  388. Before encryption or decryption, you must call this API to configure the cipher control information.
  389. The first 64-bit data and the last 64-bit data should not be the same when using TDES algorithm.
  390. \param[in] hCipher Cipher handle.
  391. \param[in] pstCtrl Cipher control information.
  392. \retval ::HI_SUCCESS Call this API successful.
  393. \retval ::HI_FAILURE Call this API fails.
  394. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  395. \retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null.
  396. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  397. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  398. \see \n
  399. N/A
  400. */
  401. HI_S32 HI_UNF_CIPHER_ConfigHandle(HI_HANDLE hCipher, const HI_UNF_CIPHER_CTRL_S* pstCtrl);
  402. /**
  403. \brief Configures the cipher control information.
  404. \attention \n
  405. Before encryption or decryption, you must call this API to configure the cipher control information.
  406. The first 64-bit data and the last 64-bit data should not be the same when using TDES algorithm.
  407. \param[in] hCipher Cipher handle.
  408. \param[in] pstExCtrl Cipher control information.
  409. \retval ::HI_SUCCESS Call this API successful.
  410. \retval ::HI_FAILURE Call this API fails.
  411. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  412. \retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null.
  413. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  414. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  415. \see \n
  416. N/A
  417. */
  418. HI_S32 HI_UNF_CIPHER_ConfigHandleEx(HI_HANDLE hCipher, const HI_UNF_CIPHER_CTRL_EX_S* pstExCtrl);
  419. /**
  420. \brief Performs encryption.
  421. \attention \n
  422. This API is used to perform encryption by using the cipher module.
  423. 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.
  424. \param[in] hCipher Cipher handle
  425. \param[in] u32SrcPhyAddr Physical address of the source data
  426. \param[in] u32DestPhyAddr Physical address of the target data
  427. \param[in] u32ByteLength Length of the encrypted data
  428. \retval ::HI_SUCCESS Call this API successful.
  429. \retval ::HI_FAILURE Call this API fails.
  430. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  431. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  432. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  433. \see \n
  434. N/A
  435. */
  436. HI_S32 HI_UNF_CIPHER_Encrypt(HI_HANDLE hCipher, HI_SIZE_T szSrcPhyAddr, HI_SIZE_T szDestPhyAddr, HI_U32 u32ByteLength);
  437. /**
  438. \brief Performs decryption.
  439. \attention \n
  440. This API is used to perform decryption by using the cipher module.
  441. 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.
  442. \param[in] hCipher Cipher handle.
  443. \param[in] u32SrcPhyAddr Physical address of the source data.
  444. \param[in] u32DestPhyAddr Physical address of the target data.
  445. \param[in] u32ByteLength Length of the decrypted data
  446. \retval ::HI_SUCCESS Call this API successful.
  447. \retval ::HI_FAILURE Call this API fails.
  448. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  449. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  450. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  451. \see \n
  452. N/A
  453. */
  454. HI_S32 HI_UNF_CIPHER_Decrypt(HI_HANDLE hCipher, HI_SIZE_T szSrcPhyAddr, HI_SIZE_T szDestPhyAddr, HI_U32 u32ByteLength);
  455. /**
  456. \brief Performs encryption.
  457. \attention \n
  458. This API is used to perform encryption by using the cipher module.
  459. 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.
  460. \param[in] hCipher Cipher handle
  461. \param[in] pu8SrcData: buffer of the source data.
  462. \param[in] pu8DestData: buffer of the target data
  463. \param[in] u32ByteLength Length of the encrypted data
  464. \retval ::HI_SUCCESS Call this API successful.
  465. \retval ::HI_FAILURE Call this API fails.
  466. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  467. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  468. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  469. \see \n
  470. N/A
  471. */
  472. HI_S32 HI_UNF_CIPHER_EncryptVir(HI_HANDLE hCipher, const HI_U8 *pu8SrcData, const HI_U8 *pu8DestData, HI_U32 u32ByteLength);
  473. /**
  474. \brief Performs decryption.
  475. \attention \n
  476. This API is used to perform decryption by using the cipher module.
  477. 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.
  478. \param[in] hCipher Cipher handle.
  479. \param[in] pu8SrcData: buffer of the source data.
  480. \param[in] pu8DestData: buffer of the target data
  481. \param[in] u32ByteLength Length of the decrypted data
  482. \retval ::HI_SUCCESS Call this API successful.
  483. \retval ::HI_FAILURE Call this API fails.
  484. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  485. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  486. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  487. \see \n
  488. N/A
  489. */
  490. HI_S32 HI_UNF_CIPHER_DecryptVir(HI_HANDLE hCipher, const HI_U8 *pu8SrcData, const HI_U8 *pu8DestData, HI_U32 u32ByteLength);
  491. /**
  492. \brief Encrypt multiple packaged data.
  493. \attention \n
  494. 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 customer 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.
  495. \param[in] hCipher cipher handle
  496. \param[in] pstDataPkg data package ready for cipher
  497. \param[in] u32DataPkgNum number of package ready for cipher
  498. \retval ::HI_SUCCESS Call this API successful.
  499. \retval ::HI_FAILURE Call this API fails.
  500. \retval ::HI_ERR_CIPHER_NOT_INIT cipher device have not been initialized
  501. \retval ::HI_ERR_CIPHER_INVALID_PARA parameter error
  502. \retval ::HI_ERR_CIPHER_INVALID_HANDLE handle invalid
  503. \retval ::HI_ERR_CIPHER_BUSY hardware is busy, it can not deal with all data package once time
  504. \see \n
  505. N/A
  506. */
  507. HI_S32 HI_UNF_CIPHER_EncryptMulti(HI_HANDLE hCipher, const HI_UNF_CIPHER_DATA_S *pstDataPkg, HI_U32 u32DataPkgNum);
  508. /**
  509. \brief Get the cipher control information.
  510. \param[in] hCipher Cipher handle.
  511. \param[in] pstCtrl Cipher control information.
  512. \retval ::HI_SUCCESS Call this API successful.
  513. \retval ::HI_FAILURE Call this API fails.
  514. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  515. \retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null.
  516. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  517. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  518. \see \n
  519. N/A
  520. */
  521. HI_S32 HI_UNF_CIPHER_GetHandleConfig(HI_HANDLE hCipher, HI_UNF_CIPHER_CTRL_S* pstCtrl);
  522. /**
  523. \brief Decrypt multiple packaged data.
  524. \attention \n
  525. 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.
  526. \param[in] hCipher cipher handle
  527. \param[in] pstDataPkg data package ready for cipher
  528. \param[in] u32DataPkgNum number of package ready for cipher
  529. \retval ::HI_SUCCESS Call this API successful.
  530. \retval ::HI_FAILURE Call this API fails.
  531. \retval ::HI_ERR_CIPHER_NOT_INIT cipher device have not been initialized
  532. \retval ::HI_ERR_CIPHER_INVALID_PARA parameter error
  533. \retval ::HI_ERR_CIPHER_INVALID_HANDLE handle invalid
  534. \retval ::HI_ERR_CIPHER_BUSY hardware is busy, it can not deal with all data package once time
  535. \see \n
  536. N/A
  537. */
  538. HI_S32 HI_UNF_CIPHER_DecryptMulti(HI_HANDLE hCipher, const HI_UNF_CIPHER_DATA_S *pstDataPkg, HI_U32 u32DataPkgNum);
  539. /**
  540. \brief Get the tag data of CCM/GCM.
  541. \attention \n
  542. This API is used to get the tag data of CCM/GCM.
  543. \param[in] hCipher cipher handle
  544. \param[out] pu8Tag tag data of CCM/GCM
  545. \param[in/out] pu32TagLen tag data length of CCM/GCM, the input should be 16 now.
  546. \retval ::HI_SUCCESS Call this API succussful.
  547. \retval ::HI_FAILURE Call this API fails.
  548. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  549. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  550. \see \n
  551. N/A
  552. */
  553. HI_S32 HI_UNF_CIPHER_GetTag(HI_HANDLE hCipher, HI_U8 *pu8Tag, HI_U32 *pu32TagLen);
  554. /**
  555. \brief Encrypt the clean key data by KLAD.
  556. \attention \n
  557. N/A
  558. \param[in] enRootKey klad root key.
  559. \param[in] pu8CleanKey clean key.
  560. \param[in] enTarget the module who to use this key.
  561. \param[out] pu8EcnryptKey encrypt key.
  562. \param[in] u32KeyLen clean key.
  563. \retval ::HI_SUCCESS Call this API successful.
  564. \retval ::HI_FAILURE Call this API fails.
  565. \retval ::HI_ERR_CIPHER_NOT_INIT The cipher device is not initialized.
  566. \retval ::HI_ERR_CIPHER_INVALID_POINT The pointer is null.
  567. \retval ::HI_ERR_CIPHER_INVALID_PARA The parameter is invalid.
  568. \retval ::HI_ERR_CIPHER_INVALID_HANDLE The handle is invalid.
  569. \see \n
  570. N/A
  571. */
  572. HI_S32 HI_UNF_CIPHER_KladEncryptKey(HI_UNF_CIPHER_CA_TYPE_E enRootKey,
  573. HI_UNF_CIPHER_KLAD_TARGET_E enTarget,
  574. const HI_U8 *pu8CleanKey, HI_U8* pu8EcnryptKey, HI_U32 u32KeyLen);
  575. /**
  576. \brief Get the random number.
  577. \attention \n
  578. This API is used to obtain the random number from the hardware.
  579. \param[out] pu32RandomNumber Point to the random number.
  580. \retval ::HI_SUCCESS Call this API successful.
  581. \retval ::HI_FAILURE Call this API fails.
  582. \see \n
  583. N/A
  584. */
  585. HI_S32 HI_UNF_CIPHER_GetRandomNumber(HI_U32 *pu32RandomNumber);
  586. /**
  587. \brief Init the hash module, if other program is using the hash module, the API will return failure.
  588. \attention \n
  589. N/A
  590. \param[in] pstHashAttr: The hash calculating structure input.
  591. \param[out] pHashHandle: The output hash handle.
  592. \retval ::HI_SUCCESS Call this API successful.
  593. \retval ::HI_FAILURE Call this API fails.
  594. \see \n
  595. N/A
  596. */
  597. HI_S32 HI_UNF_CIPHER_HashInit(const HI_UNF_CIPHER_HASH_ATTS_S *pstHashAttr, HI_HANDLE *pHashHandle);
  598. /**
  599. \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 aligned except for the last block.
  600. \attention \n
  601. N/A
  602. \param[in] hHashHandl: Hash handle.
  603. \param[in] pu8InputData: The input data buffer.
  604. \param[in] u32InputDataLen: The input data length, attention: the block length input must be 64bytes aligned except the last block!
  605. \retval ::HI_SUCCESS Call this API successful.
  606. \retval ::HI_FAILURE Call this API fails.
  607. \see \n
  608. N/A
  609. */
  610. HI_S32 HI_UNF_CIPHER_HashUpdate(HI_HANDLE hHashHandle, const HI_U8 *pu8InputData, HI_U32 u32InputDataLen);
  611. /**
  612. \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 interrupt the calculation, this API should also be call to close the handle.
  613. \attention \n
  614. N/A
  615. \param[in] hHashHandle: Hash handle.
  616. \param[out] pu8OutputHash: The final output hash value.
  617. \retval ::HI_SUCCESS Call this API successful.
  618. \retval ::HI_FAILURE Call this API fails.
  619. \see \n
  620. N/A
  621. */
  622. HI_S32 HI_UNF_CIPHER_HashFinal(HI_HANDLE hHashHandle, HI_U8 *pu8OutputHash);
  623. /**
  624. \brief RSA encryption a plaintext with a RSA public key.
  625. \attention \n
  626. N/A
  627. \param[in] pstRsaEnc: encryption struct.
  628. \param[in] pu8Input: input data to be encryption
  629. \param[out] u32InLen: length of input data to be encryption
  630. \param[out] pu8Output: output data to be encryption
  631. \param[out] pu32OutLen: length of output data to be encryption
  632. \retval ::HI_SUCCESS Call this API successful.
  633. \retval ::HI_FAILURE Call this API fails.
  634. \see \n
  635. N/A
  636. */
  637. HI_S32 HI_UNF_CIPHER_RsaPublicEncrypt(const HI_UNF_CIPHER_RSA_PUB_ENC_S *pstRsaEnc,
  638. const HI_U8 *pu8Input, HI_U32 u32InLen,
  639. HI_U8 *pu8Output, HI_U32 *pu32OutLen);
  640. /**
  641. \brief RSA decryption a ciphertext with a RSA private key.
  642. \attention \n
  643. N/A
  644. \param[in] pstRsaDec: decryption struct.
  645. \param[in] pu8Input: input data to be decryption
  646. \param[out] u32InLen: length of input data to be decryption
  647. \param[out] pu8Output: output data to be decryption
  648. \param[out] pu32OutLen: length of output data to be decryption
  649. \retval ::HI_SUCCESS Call this API successful.
  650. \retval ::HI_FAILURE Call this API fails.
  651. \see \n
  652. N/A
  653. */
  654. HI_S32 HI_UNF_CIPHER_RsaPrivateDecrypt(const HI_UNF_CIPHER_RSA_PRI_ENC_S *pstRsaDec,
  655. const HI_U8 *pu8Input, HI_U32 u32InLen,
  656. HI_U8 *pu8Output, HI_U32 *pu32OutLen);
  657. /**
  658. \brief RSA encryption a plaintext with a RSA private key.
  659. \attention \n
  660. N/A
  661. \param[in] pstRsaSign: encryption struct.
  662. \param[in] pu8Input: input data to be encryption
  663. \param[out] u32InLen: length of input data to be encryption
  664. \param[out] pu8Output: output data to be encryption
  665. \param[out] pu32OutLen: length of output data to be encryption
  666. \retval ::HI_SUCCESS Call this API successful.
  667. \retval ::HI_FAILURE Call this API fails.
  668. \see \n
  669. N/A
  670. */
  671. HI_S32 HI_UNF_CIPHER_RsaPrivateEncrypt(const HI_UNF_CIPHER_RSA_PRI_ENC_S *pstRsaEnc,
  672. const HI_U8 *pu8Input, HI_U32 u32InLen,
  673. HI_U8 *pu8Output, HI_U32 *pu32OutLen);
  674. /**
  675. \brief RSA decryption a ciphertext with a RSA public key.
  676. \attention \n
  677. N/A
  678. \param[in] pstRsaVerify: decryption struct.
  679. \param[in] pu8Input: input data to be decryption
  680. \param[out] u32InLen: length of input data to be decryption
  681. \param[out] pu8Output: output data to be decryption
  682. \param[out] pu32OutLen: length of output data to be decryption
  683. \retval ::HI_SUCCESS Call this API successful.
  684. \retval ::HI_FAILURE Call this API fails.
  685. \see \n
  686. N/A
  687. */
  688. HI_S32 HI_UNF_CIPHER_RsaPublicDecrypt(const HI_UNF_CIPHER_RSA_PUB_ENC_S *pstRsaDec,
  689. const HI_U8 *pu8Input, HI_U32 u32InLen,
  690. HI_U8 *pu8Output, HI_U32 *pu32OutLen);
  691. /**
  692. \brief RSA signature a context with appendix, where a signer's RSA private key is used.
  693. \attention \n
  694. N/A
  695. \param[in] pstRsaSign: signature struct.
  696. \param[in] pu8Input: input context to be signature.
  697. \param[in] u32InLen: length of input context to be signature
  698. \param[in] pu8HashData: hash value of context,if NULL, let pu8HashData = Hash(context) automatically
  699. \param[out] pu8OutSign: output message of signature
  700. \param[out] pu32OutSignLen: length of message of signature
  701. \retval ::HI_SUCCESS Call this API successful.
  702. \retval ::HI_FAILURE Call this API fails.
  703. \see \n
  704. N/A
  705. */
  706. HI_S32 HI_UNF_CIPHER_RsaSign(const HI_UNF_CIPHER_RSA_SIGN_S *pstRsaSign,
  707. const HI_U8 *pu8InData, HI_U32 u32InDataLen,
  708. const HI_U8 *pu8HashData,
  709. HI_U8 *pu8OutSign, HI_U32 *pu32OutSignLen);
  710. /**
  711. \brief RSA signature verification a context with appendix, where a signer's RSA public key is used.
  712. \attention \n
  713. N/A
  714. \param[in] pstRsaVerify: signature verification struct.
  715. \param[in] pu8Input: input context to be signature verification, maybe null
  716. \param[in] u32InLen: length of input context to be signature
  717. \param[in] pu8HashData: hash value of context,if NULL, let pu8HashData = Hash(context) automatically
  718. \param[in] pu8InSign: message of signature
  719. \param[in] pu32InSignLen: length of message of signature
  720. \retval ::HI_SUCCESS Call this API successful.
  721. \retval ::HI_FAILURE Call this API fails.
  722. \see \n
  723. N/A
  724. */
  725. HI_S32 HI_UNF_CIPHER_RsaVerify(const HI_UNF_CIPHER_RSA_VERIFY_S *pstRsaVerify,
  726. const HI_U8 *pu8InData, HI_U32 u32InDataLen,
  727. const HI_U8 *pu8HashData,
  728. const HI_U8 *pu8InSign, HI_U32 u32InSignLen);
  729. /** @} */ /** <!-- ==== API declaration end ==== */
  730. #ifdef __cplusplus
  731. #if __cplusplus
  732. }
  733. #endif
  734. #endif /* __cplusplus */
  735. #endif /* __HI_UNF_CIPHER_H__ */