hpm_sdp_drv.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * Copyright (c) 2021-2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SDP_DRV_H
  8. #define HPM_SDP_DRV_H
  9. /**
  10. * @brief SDP driver APIs
  11. * @defgroup sdp_interface SDP driver APIs
  12. * @ingroup sdp_interfaces
  13. * @{
  14. *
  15. */
  16. #include "hpm_common.h"
  17. #include "hpm_sdp_regs.h"
  18. #include "hpm_soc_feature.h"
  19. /***********************************************************************************************************************
  20. * Definitions
  21. **********************************************************************************************************************/
  22. /**
  23. * @brief SDP AES key bit options
  24. */
  25. typedef enum {
  26. sdp_aes_keybits_128 = 0, /**< 128 bit AES key */
  27. sdp_aes_keybits_256 = 1, /**< 256 bit AES key */
  28. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  29. sdp_sm4_keybits_128 = sdp_aes_keybits_128, /* SM4 Key bits */
  30. #endif
  31. } sdp_crypto_key_bits_t;
  32. typedef sdp_crypto_key_bits_t sdp_aes_key_bits_t;
  33. typedef sdp_crypto_key_bits_t sdp_sm4_key_bits_t;
  34. /**
  35. * @brief Crypto operation option
  36. */
  37. typedef enum {
  38. sdp_aes_op_encrypt, /**< AES Encrypt operation */
  39. sdp_aes_op_decrypt, /**< AES Decrypt operation */
  40. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  41. sdp_sm4_op_encrypt = sdp_aes_op_encrypt, /**< SM4 Encrypt operation */
  42. sdp_sm4_op_decrypt = sdp_aes_op_decrypt, /**< SM4 Decrypt operation */
  43. #endif
  44. } sdp_crypto_op_t;
  45. typedef sdp_crypto_op_t sdp_aes_op_t;
  46. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  47. typedef sdp_crypto_op_t sdp_sm4_op_t;
  48. #endif
  49. /**
  50. * @brief SDP Crypto algorithms
  51. *
  52. */
  53. typedef enum {
  54. sdp_crypto_alg_aes = 0, /**< AES */
  55. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  56. sdp_crypto_alg_sm4 = 1, /**< SM4 */
  57. #endif
  58. } sdp_crypto_alg_t;
  59. /**
  60. * @brief SDP Crypto modes
  61. */
  62. typedef enum {
  63. sdp_crypto_mode_ecb = 0, /*!< ECB mode */
  64. sdp_crypto_mode_cbc = 1, /*!< CBC mode */
  65. } sdp_crypto_mode_t;
  66. /**
  67. * @brief SDP Data Swap modes
  68. */
  69. typedef enum {
  70. sdp_swap_mode_none = 0, /*!< No data swap */
  71. sdp_swap_mode_bytes_in_word = 1, /*!< Swap bytes within one word */
  72. sdp_swap_mode_word_swap = 2, /*!< Swap words in one crypto block (16-bytes) */
  73. sdp_swap_mode_switch_endian = 3, /*!< Swap the data-endian in one crypto block (16-bytes) */
  74. } sdp_data_swap_mode_t;
  75. /**
  76. * @brief SDP HASH calculation mode
  77. */
  78. typedef enum {
  79. sdp_calc_hash_for_input = 0, /*!< Calculate HASH before doing crypto operation */
  80. sdp_calc_hash_for_output = 1, /*!< Calculate HASH after doing crypto operation */
  81. } sdp_calc_hash_mode_t;
  82. /**
  83. * @brief SDP HASH algorithm definitions
  84. */
  85. typedef enum {
  86. sdp_hash_alg_sha1 = 0, /**< SDP SHA1 */
  87. sdp_hash_alg_crc32 = 1, /**< SDP CRC32 */
  88. sdp_hash_alg_sha256 = 2, /**< SDP SHA256 */
  89. #if defined(SDP_HAS_SM3_SUPPORT) && (SDP_HAS_SM3_SUPPORT == 1)
  90. sdp_hash_alg_sm3 = 8, /**< SDP SM3 */
  91. sdp_hash_alg_max = sdp_hash_alg_sm3,
  92. #else
  93. sdp_hash_alg_max = sdp_hash_alg_sha256,
  94. #endif
  95. } sdp_hash_alg_t;
  96. #define HASH_BLOCK_SIZE (64U) /**< Hash block size in bytes */
  97. #define AES_BLOCK_SIZE (16U) /**< AES block size in bytes */
  98. #define AES_128_KEY_SIZE (0x10U) /**< AES 128-bit key size in bytes */
  99. #define AES_256_KEY_SIZE (0x20U) /**< AES 256-bit key size in bytes */
  100. #define SM4_BLOCK_SIZE (AES_BLOCK_SIZE) /**< SM4 block size in bytes */
  101. #define SM4_KEY_SIZE (AES_128_KEY_SIZE) /**< SM4 Key size in bytes */
  102. /**
  103. * @brief Bitfield definitions for the PKT_CTRL
  104. */
  105. #define SDP_PKT_CTRL_DERSEMA_MASK (1U << 2)
  106. #define SDP_PKT_CTRL_CHAIN_MASK (1U << 3)
  107. #define SDP_PKT_CTRL_HASHINIT_MASK (1U << 4)
  108. #define SDP_PKT_CTRL_HASHFINISH_MASK (1U << 5)
  109. #define SDP_PKT_CTRL_CIPHIV_MASK (1U << 6)
  110. /**
  111. * @brief SDP Command Packet structure
  112. */
  113. typedef struct _sdp_packet_struct {
  114. struct _sdp_packet_struct *next_cmd;
  115. union {
  116. struct {
  117. uint32_t RESERVED0: 1;
  118. uint32_t PKTINT: 1; /**< Packet interrupt flag */
  119. uint32_t DCRSEMA: 1; /**< Decrement Semaphore flag */
  120. uint32_t CHAIN: 1; /**< Chain Packet flag */
  121. uint32_t HASHINIT: 1; /**< Hash initialize flag */
  122. uint32_t HASHFINISH: 1; /**< Hash finish flag */
  123. uint32_t CIPHIV: 1; /**< Cipher IV flag */
  124. uint32_t RESERVED1: 17;
  125. uint32_t PKTTAG: 8; /**< Packet tag flag, not used */
  126. };
  127. uint32_t PKT_CTRL; /**< Packet control word */
  128. } pkt_ctrl;
  129. uint32_t src_addr; /**< Source address */
  130. uint32_t dst_addr; /**< Destination address */
  131. uint32_t buf_size; /**< Data buffer size in bytes */
  132. uint32_t reserved[3];
  133. } sdp_pkt_struct_t;
  134. /**
  135. * @brief SDP AES context structure
  136. */
  137. typedef struct {
  138. uint8_t key_idx; /**< AES key index */
  139. uint8_t key_bits; /**< AES key bits */
  140. uint16_t crypto_algo;
  141. sdp_pkt_struct_t sdp_pkt; /**< SDP packet for AES operation */
  142. uint32_t buf0[AES_BLOCK_SIZE / sizeof(uint32_t)]; /**< buf0 */
  143. uint32_t buf1[AES_BLOCK_SIZE / sizeof(uint32_t)]; /**< buf1 */
  144. uint32_t buf2[AES_BLOCK_SIZE / sizeof(uint32_t)]; /**< buf2 */
  145. uint32_t buf3[AES_BLOCK_SIZE / sizeof(uint32_t)]; /**< buf3 */
  146. } sdp_crypto_ctx_t;
  147. typedef sdp_crypto_ctx_t sdp_aes_ctx_t;
  148. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  149. typedef sdp_crypto_ctx_t sdp_sm4_ctx_t;
  150. #endif
  151. /**
  152. * @brief SDP DMA context
  153. */
  154. typedef struct {
  155. sdp_pkt_struct_t sdp_pkt; /**< SDP packet for DMA operation (memset/memcpy) */
  156. } sdp_dma_ctx_t;
  157. /**
  158. * @brief SDP HASH context
  159. */
  160. typedef struct {
  161. sdp_pkt_struct_t sdp_pkt; /**< SDP packet for HASH operation */
  162. uint32_t internal[64]; /**< internal buffer */
  163. } sdp_hash_ctx_t;
  164. /**
  165. * @brief SDP error status definitions
  166. */
  167. enum {
  168. status_sdp_no_crypto_support = MAKE_STATUS(status_group_sdp, 0), /**< The crypto algorithm is not supported */
  169. status_sdp_no_hash_support = MAKE_STATUS(status_group_sdp, 1), /**< The hash algorithm is not supported */
  170. status_sdp_invalid_key_src = MAKE_STATUS(status_group_sdp, 2), /**< Invalid AES key source */
  171. status_sdp_error_packet = MAKE_STATUS(status_group_sdp, 3), /**< Error packet */
  172. status_sdp_aes_busy = MAKE_STATUS(status_group_sdp, 4), /**< AES engine is busy */
  173. status_sdp_hash_busy = MAKE_STATUS(status_group_sdp, 5), /**< HASH engine is busy */
  174. status_sdp_error_setup = MAKE_STATUS(status_group_sdp, 6), /**< Error setup in SDP IP */
  175. status_sdp_error_src = MAKE_STATUS(status_group_sdp, 7), /**< Error source address */
  176. status_sdp_error_dst = MAKE_STATUS(status_group_sdp, 8), /**< Error destination address */
  177. status_sdp_error_hash = MAKE_STATUS(status_group_sdp, 9), /**< Error Hash digest */
  178. status_sdp_error_chain = MAKE_STATUS(status_group_sdp, 10), /**< Error packet chain */
  179. status_sdp_error_invalid_mac = MAKE_STATUS(status_group_sdp, 11),/**< Invalid Message Authentication Code (MAC) */
  180. status_sdp_invalid_alg = MAKE_STATUS(status_group_sdp, 12), /**< Invalid algorithm */
  181. };
  182. /**
  183. * @brief SDP Operations
  184. */
  185. typedef enum {
  186. sdp_op_invalid = 0,
  187. sdp_op_cipher_only = SDP_SDPCR_CIPHEN_MASK,
  188. sdp_op_hash_only = SDP_SDPCR_HASHEN_MASK,
  189. sdp_op_memcpy_only = SDP_SDPCR_MCPEN_MASK,
  190. sdp_op_memfill_only = SDP_SDPCR_CONFEN_MASK,
  191. sdp_op_cipher_hash = SDP_SDPCR_CIPHEN_MASK | SDP_SDPCR_HASHEN_MASK,
  192. sdp_op_copy_hash = SDP_SDPCR_MCPEN_MASK | SDP_SDPCR_HASHEN_MASK,
  193. } sdp_operation_t;
  194. /**
  195. * @brief SDP Action Structure
  196. */
  197. typedef struct {
  198. sdp_operation_t op; /*!< SDP operation */
  199. sdp_data_swap_mode_t input_swap_mode; /*!< SDP input data swap mode */
  200. sdp_data_swap_mode_t output_swap_mode; /*!< SDP output data swap mode */
  201. struct {
  202. sdp_hash_alg_t hash_alg; /*!< SDP HASH algorithm */
  203. bool hash_check; /*!< Enable HASH verify mode */
  204. };
  205. struct {
  206. sdp_crypto_alg_t crypto_alg; /*!< SDP Crypto Algorithm */
  207. sdp_crypto_mode_t crypto_mode; /*!< SDP Crypto mode */
  208. uint16_t key_bits; /*!< SDP crypto key bits */
  209. uint8_t key_index; /*!< SDP key index */
  210. sdp_crypto_op_t crypto_op; /*!< SDP Crypto operation mode */
  211. sdp_data_swap_mode_t key_swap_mode; /*!< SDP Key swap mode */
  212. sdp_calc_hash_mode_t hash_mode; /*!< SDP Hash calculation mode */
  213. };
  214. } sdp_action_t;
  215. #ifdef __cplusplus
  216. extern "C"
  217. {
  218. #endif
  219. /***********************************************************************************************************************
  220. * Prototypes
  221. **********************************************************************************************************************/
  222. /**
  223. * @brief Enable SDP interrupt
  224. * @param [in] base SDP base address
  225. */
  226. static inline void sdp_enable_interrupt(SDP_Type *base)
  227. {
  228. base->SDPCR |= SDP_SDPCR_INTEN_MASK;
  229. }
  230. /**
  231. * @brief Disable SDP interrupt
  232. * @param [in] base SDP base address
  233. */
  234. static inline void sdp_disable_interrupt(SDP_Type *base)
  235. {
  236. base->SDPCR &= ~SDP_SDPCR_INTEN_MASK;
  237. }
  238. /**
  239. * @brief Set the Crypto Key Index in SDP
  240. * @param [in] base SDP base address
  241. * @param [in] key_index SDP key index
  242. */
  243. static inline void sdp_set_key_index(SDP_Type *base, uint32_t key_index)
  244. {
  245. base->KEYADDR = SDP_KEYADDR_INDEX_SET(key_index);
  246. }
  247. /**
  248. * @brief Write SDP key to specified SDP Key RAM
  249. * @param [in] base SDP base address
  250. * @param [in] key_index Key Index
  251. * @param [in] key_bits Key bits, valid value: 128, 256
  252. * @param [in] crypto_key Crypto Key buffer
  253. */
  254. static inline void sdp_write_key(SDP_Type *base, uint32_t key_index, uint32_t key_bits, const uint32_t *crypto_key)
  255. {
  256. if (key_bits == 256) {
  257. uint32_t actual_key_index = key_index * 2;
  258. for (uint32_t i = 0; i < 2; i++) {
  259. sdp_set_key_index(base, actual_key_index++);
  260. for (uint32_t j = 0; j < 4; j++) {
  261. base->KEYDAT = *crypto_key++;
  262. }
  263. }
  264. } else {
  265. sdp_set_key_index(base, key_index);
  266. for (uint32_t j = 0; j < 4; j++) {
  267. base->KEYDAT = *crypto_key++;
  268. }
  269. }
  270. }
  271. /**
  272. * @brief Write the HASH digest result to SDP
  273. * @param [in] base SDP base address
  274. * @param [in] digest HASH digest
  275. * @param [in] num_words Digest size in words
  276. */
  277. static inline void sdp_write_hash_digest(SDP_Type *base, const uint32_t *digest, uint32_t num_words)
  278. {
  279. for (uint32_t i = 0; i < num_words; i++) {
  280. base->HASWRD[i] = *digest++;
  281. }
  282. }
  283. /**
  284. * @brief Read the HASH digest result from SDP
  285. * @param [in] base SDP base address
  286. * @param [out] digest HASH digest
  287. * @param [in] num_words Digest size in words
  288. */
  289. static inline void sdp_get_hash_digest(SDP_Type *base, uint32_t *digest, uint32_t num_words)
  290. {
  291. for (uint32_t i = 0; i < num_words; i++) {
  292. *digest++ = base->HASWRD[i];
  293. }
  294. }
  295. /**
  296. * @brief Write the cipher IV to SDP
  297. * @param [in] base SDP base address
  298. * @param [in] iv Initial vector
  299. */
  300. static inline void sdp_write_cipher_iv(SDP_Type *base, const uint32_t *iv)
  301. {
  302. for (uint32_t i = 0; i < 4; i++) {
  303. base->CIPHIV[i] = *iv++;
  304. }
  305. }
  306. /**
  307. * @brief Clear SDP status
  308. * @param [in] base SDP base address
  309. * @param [in] mask Status Mask
  310. */
  311. static inline void sdp_clear_status(SDP_Type *base, uint32_t mask)
  312. {
  313. base->STA = mask;
  314. }
  315. /**
  316. * @brief Get SDP status
  317. * @param [in] base SDP base address
  318. *
  319. * @return SDP status
  320. */
  321. static inline uint32_t sdp_get_status(SDP_Type *base)
  322. {
  323. return base->STA;
  324. }
  325. /**
  326. * @brief Initialize the SDP controller
  327. * @param [in] base SDP base address
  328. * @return API execution status.
  329. */
  330. hpm_stat_t sdp_init(SDP_Type *base);
  331. /**
  332. * @brief De-initialize the SDP controller
  333. * @param [in] base SDP base address
  334. * @return API execution status.
  335. */
  336. hpm_stat_t sdp_deinit(SDP_Type *base);
  337. /**
  338. * @brief Set the AES key for the SDP AES operation
  339. * @param [in] base SDP base address
  340. * @param [in] aes_ctx AES operation context
  341. * @param [in] key AES key
  342. * @param [in] key_bits AES key-bit option
  343. * @param [in] key_idx AES key index
  344. * @return API execution status.
  345. */
  346. hpm_stat_t sdp_aes_set_key(SDP_Type *base,
  347. sdp_aes_ctx_t *aes_ctx,
  348. const uint8_t *key,
  349. sdp_aes_key_bits_t key_bits,
  350. uint32_t key_idx);
  351. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  352. /**
  353. * @brief Set the SM4 key for the SDP SM4 operation
  354. * @param [in] base SDP base address
  355. * @param [in] sm4_ctx AES operation context
  356. * @param [in] key SM4 key
  357. * @param [in] key_bits SM4 key-bit option
  358. * @param [in] key_idx AES key index
  359. * @return API execution status.
  360. */
  361. hpm_stat_t sdp_sm4_set_key(SDP_Type *base,
  362. sdp_sm4_ctx_t *sm4_ctx,
  363. const uint8_t *key,
  364. sdp_sm4_key_bits_t key_bits,
  365. uint32_t key_idx);
  366. #endif
  367. /**
  368. * @brief Perform the basic AES ECB operation
  369. * @param [in] base SDP base address
  370. * @param [in] aes_ctx AES operation context
  371. * @param [in] op AES operation option
  372. * @param [in] len AES data length in bytes
  373. * @param [in] in Input buffer
  374. * @param [out] out Output buffer
  375. * @return API execution status.
  376. */
  377. hpm_stat_t sdp_aes_crypt_ecb(SDP_Type *base,
  378. sdp_aes_ctx_t *aes_ctx,
  379. sdp_aes_op_t op,
  380. uint32_t len,
  381. const uint8_t *in,
  382. uint8_t *out);
  383. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  384. /**
  385. * @brief Perform the basic SM4 ECB operation
  386. * @param [in] base SDP base address
  387. * @param [in] sm4_ctx SM4 operation context
  388. * @param [in] op SM4 operation option
  389. * @param [in] len SM4 data length in bytes
  390. * @param [in] in Input buffer
  391. * @param [out] out Output buffer
  392. * @return API execution status.
  393. */
  394. #define sdp_sm4_crypt_ecb sdp_aes_crypt_ecb
  395. #endif
  396. /**
  397. * @brief Perform the AES CBC operation
  398. * @param [in] base SDP base address
  399. * @param [in] aes_ctx AES operation context
  400. * @param [in] op AES operation option
  401. * @param [in] length AES data length in bytes
  402. * @param [in] iv Initial vector/nonce
  403. * @param [in] input Input buffer
  404. * @param [out] output Output buffer
  405. * @return API execution status.
  406. */
  407. hpm_stat_t sdp_aes_crypt_cbc(SDP_Type *base,
  408. sdp_aes_ctx_t *aes_ctx,
  409. sdp_aes_op_t op,
  410. uint32_t length,
  411. const uint8_t iv[16],
  412. const uint8_t *input,
  413. uint8_t *output);
  414. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  415. /**
  416. * @brief Perform the SM4 CBC operation
  417. * @param [in] base SM4 base address
  418. * @param [in] sm4_ctx SM4 operation context
  419. * @param [in] op SM4 operation option
  420. * @param [in] length SM4 data length in bytes
  421. * @param [in] iv Initial vector/nonce
  422. * @param [in] input Input buffer
  423. * @param [out] output Output buffer
  424. * @return API execution status.
  425. */
  426. #define sdp_sm4_crypt_cbc sdp_aes_crypt_cbc
  427. #endif
  428. /**
  429. * @brief Perform the AES-CTR operation
  430. * See NIST Special Publication800-38A for more details
  431. * @param [in] base SDP base address
  432. * @param [in] aes_ctx AES operation context
  433. * @param [in] nonce_counter AES-CTR nonce/counter
  434. * @param [in] input Input buffer
  435. * @param [out] output Output buffer
  436. * @param [in] length Length of data for AES-CTR operation
  437. * @return API execution status.
  438. */
  439. hpm_stat_t sdp_aes_crypt_ctr(SDP_Type *base,
  440. sdp_aes_ctx_t *aes_ctx,
  441. uint8_t *nonce_counter,
  442. uint8_t *input,
  443. uint8_t *output,
  444. uint32_t length);
  445. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  446. /**
  447. * @brief Perform the SM4-CTR operation
  448. * @param [in] base SDP base address
  449. * @param [in] sm4_ctx SM4 operation context
  450. * @param [in] nonce_counter SM4-CTR nonce/counter
  451. * @param [in] input Input buffer
  452. * @param [out] output Output buffer
  453. * @param [in] length Length of data for SM4-CTR operation
  454. * @return API execution status.
  455. */
  456. #define sdp_sm4_crypt_ctr sdp_aes_crypt_ctr
  457. #endif
  458. /**
  459. * @brief Perform the AES-CCM generate and encrypt
  460. * See NIST Special Publication 800-38C for more details
  461. * @param [in] base SDP base address
  462. * @param [in] aes_ctx AES operation context
  463. * @param [in] input_len Input data length in bytes
  464. * @param [in] iv Initial vector
  465. * @param [in] iv_len Initial vector length in bytes
  466. * @param [in] aad Additional Authentication data
  467. * @param [in] aad_len Additional authentication data size
  468. * @param [in] input Input data buffer
  469. * @param [out] output Output buffer
  470. * @param [out] tag MAC buffer
  471. * @param [in] tag_len Tag/MAC size in bytes
  472. * @return API execution status.
  473. */
  474. hpm_stat_t sdp_aes_ccm_generate_encrypt(SDP_Type *base,
  475. sdp_aes_ctx_t *aes_ctx,
  476. uint32_t input_len,
  477. const uint8_t *iv,
  478. uint32_t iv_len,
  479. const uint8_t *aad,
  480. uint32_t aad_len,
  481. const uint8_t *input,
  482. uint8_t *output,
  483. uint8_t *tag,
  484. uint32_t tag_len);
  485. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  486. /**
  487. * @brief Perform the SM4-CCM generate and encrypt
  488. * See NIST Special Publication 800-38C for more details
  489. * @param [in] base SDP base address
  490. * @param [in] sm4_ctx SM4 operation context
  491. * @param [in] input_len Input data length in bytes
  492. * @param [in] iv Initial vector
  493. * @param [in] iv_len Initial vector length in bytes
  494. * @param [in] aad Additional Authentication data
  495. * @param [in] aad_len Additional authentication data size
  496. * @param [in] input Input data buffer
  497. * @param [out] output Output buffer
  498. * @param [out] tag MAC buffer
  499. * @param [in] tag_len Tag/MAC size in bytes
  500. * @return API execution status.
  501. */
  502. #define sdp_sm4_ccm_generate_encrypt sdp_aes_ccm_generate_encrypt
  503. #endif
  504. /**
  505. * @brief Perform the AES-CCM decrypt and verify
  506. * See NIST Special Publication 800-38C for more details
  507. * @param [in] base SDP base address
  508. * @param [in] aes_ctx AES operation context
  509. * @param [in] input_len Input data length in bytes
  510. * @param [in] iv Initial vector
  511. * @param [in] iv_len Initial vector length in bytes
  512. * @param [in] aad Additional Authentication data
  513. * @param [in] aad_len Additional authentication data size
  514. * @param [in] input Input data buffer
  515. * @param [out] output Output buffer
  516. * @param [in] tag MAC buffer
  517. * @param [in] tag_len Tag/MAC size in bytes
  518. * @return API execution status.
  519. */
  520. hpm_stat_t sdp_aes_ccm_decrypt_verify(SDP_Type *base,
  521. sdp_aes_ctx_t *aes_ctx,
  522. uint32_t input_len,
  523. const uint8_t *iv,
  524. uint32_t iv_len,
  525. const uint8_t *aad,
  526. uint32_t aad_len,
  527. const uint8_t *input,
  528. uint8_t *output,
  529. const uint8_t *tag,
  530. uint32_t tag_len);
  531. #if defined(SDP_HAS_SM4_SUPPORT) && (SDP_HAS_SM4_SUPPORT == 1)
  532. /**
  533. * @brief Perform the SM4-CCM decrypt and verify
  534. * @param [in] base SDP base address
  535. * @param [in] sm4_ctx SM4 operation context
  536. * @param [in] input_len Input data length in bytes
  537. * @param [in] iv Initial vector
  538. * @param [in] iv_len Initial vector length in bytes
  539. * @param [in] aad Additional Authentication data
  540. * @param [in] aad_len Additional authentication data size
  541. * @param [in] input Input data buffer
  542. * @param [out] output Output buffer
  543. * @param [in] tag MAC buffer
  544. * @param [in] tag_len Tag/MAC size in bytes
  545. * @return API execution status.
  546. */
  547. #define sdp_sm4_ccm_decrypt_verify sdp_aes_ccm_decrypt_verify
  548. #endif
  549. /**
  550. * @brief Perform the DMA accelerated memcpy
  551. * @param [in] base SDP base address
  552. * @param [in] sdp_ctx SDP DMA context
  553. * @param [out] dst Destination address for memcpy operation
  554. * @param [in] src Source address for memcpy operation
  555. * @param [in] length Length of the data to be copied
  556. * @return API execution status.
  557. */
  558. hpm_stat_t sdp_memcpy(SDP_Type *base, sdp_dma_ctx_t *sdp_ctx, void *dst, const void *src, uint32_t length);
  559. /**
  560. * @brief Perform the DMA accelerated memset
  561. * @param [in] base SDP base address
  562. * @param [in] sdp_ctx SDP DMA context
  563. * @param [out] dst SDP destination address for memset operation
  564. * @param [in] pattern pattern for memset operation
  565. * @param [in] length length of the memory for memset operation
  566. * @return API execution status.
  567. */
  568. hpm_stat_t sdp_memset(SDP_Type *base, sdp_dma_ctx_t *sdp_ctx, void *dst, uint8_t pattern, uint32_t length);
  569. /**
  570. * @brief Initialize the HASH engine
  571. * @param [in] base SDP base address
  572. * @param [in] hash_ctx HASH operation context
  573. * @param [in] alg Hash algorithm
  574. * @return API execution status. status_success or status_invalid_argument
  575. */
  576. hpm_stat_t sdp_hash_init(SDP_Type *base, sdp_hash_ctx_t *hash_ctx, sdp_hash_alg_t alg);
  577. /**
  578. * @brief Compute the HASH digest
  579. * @param [in] base SDP base address
  580. * @param [in] hash_ctx HASH operation context
  581. * @param [in] data Data for HASH computing
  582. * @param [in] length Data size for HASH computing
  583. *
  584. * @return API execution status.
  585. */
  586. hpm_stat_t sdp_hash_update(SDP_Type *base, sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length);
  587. /**
  588. * @brief Finish the HASH calculation and output the digest
  589. * @param [in] base SDP base address
  590. * @param [in] hash_ctx HASH operation context
  591. * @param [out] digest Digest buffer
  592. *
  593. * @return API execution status.
  594. */
  595. hpm_stat_t sdp_hash_finish(SDP_Type *base, sdp_hash_ctx_t *hash_ctx, uint8_t *digest);
  596. /**
  597. * @brief Wait until the SDP operation gets done
  598. * @param [in] base SDP base address
  599. *
  600. * @return API execution status.
  601. */
  602. hpm_stat_t sdp_wait_done(SDP_Type *base);
  603. /**
  604. * @brief Trigger SDP operation via the specified SDP packet description
  605. * @note 1. The Command Packet List should be in non-cacheable memory
  606. * 2. This is a non-blocking API, users should confirm whether action completed or not by checking STA register
  607. * in SDP
  608. * @param [in] base SDP base address
  609. * @param [in] action SDP action
  610. * @param [in] cmd_pkt SDP Command packet description
  611. *
  612. * @return API execution status.
  613. */
  614. hpm_stat_t sdp_trigger_action(SDP_Type *base, const sdp_action_t *action, const sdp_pkt_struct_t *cmd_pkt);
  615. #ifdef __cplusplus
  616. }
  617. #endif
  618. /**
  619. * @}
  620. */
  621. #endif /* HPM_SDP_DRV_H */