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