diff options
author | thead_admin <occ_thead@service.alibaba.com> | 2023-01-04 13:12:02 +0800 |
---|---|---|
committer | thead_admin <occ_thead@service.alibaba.com> | 2023-01-04 13:12:02 +0800 |
commit | 02deb8b059118cd2b0fb3c8bbb6d73fd1f87115a (patch) | |
tree | 0392294a5f997b777b05c8373dd2fe062a751296 /lib/sec_library/include/aes.h | |
parent | 0c8e009c3a52c6a29b00cf70d368d5c082639197 (diff) |
Linux_SDK_V1.0.3Linux_SDK_V1.0.3
Diffstat (limited to 'lib/sec_library/include/aes.h')
-rw-r--r-- | lib/sec_library/include/aes.h | 171 |
1 files changed, 131 insertions, 40 deletions
diff --git a/lib/sec_library/include/aes.h b/lib/sec_library/include/aes.h index ea90660a..04d8fd06 100644 --- a/lib/sec_library/include/aes.h +++ b/lib/sec_library/include/aes.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2021 Alibaba Group Holding Limited + * Copyright (C) 2017-2020 Alibaba Group Holding Limited */ /****************************************************************************** @@ -14,7 +14,7 @@ #define _DRV_AES_H_ #include <stdint.h> -#include <drv/common.h> +#include "common.h" #ifdef __cplusplus extern "C" { @@ -27,10 +27,70 @@ typedef enum { AES_KEY_LEN_BITS_256 ///< 256 Data bits } csi_aes_key_bits_t; +typedef enum{ + AES_MODE_ECB = 0, + AES_MODE_CBC = 0x20000020, + AES_MODE_CTR = 0x200001c0, + AES_MODE_CFB = 0x20000400, + AES_MODE_GCM = 0x20030040, + AES_MODE_CCM = 0x21D40040, + AES_MODE_OFB = 0x24000000, +} aes_mode_t; + +#define AES_KEY_LEN_BYTES_32 32 +#define AES_KEY_LEN_BYTES_24 24 +#define AES_KEY_LEN_BYTES_16 16 + +#define AES_CRYPTO_CTRL_CBC_256 0x20000038 +#define AES_CRYPTO_CTRL_CBC_192 0x20000030 +#define AES_CRYPTO_CTRL_CBC_128 0x20000028 +#define AES_CRYPTO_CTRL_ECB_256 0x00000018 +#define AES_CRYPTO_CTRL_ECB_192 0x00000010 +#define AES_CRYPTO_CTRL_ECB_128 0x00000008 + +#define AES_BLOCK_IV_SIZE 16 +#define AES_BLOCK_TAG_SIZE 16 +#define AES_BLOCK_CRYPTO_SIZE 16 + +#define AES_DIR_ENCRYPT 1 +#define AES_DIR_DECRYPT 0 + +#define KEY_128_BITS 0x8 +#define KEY_192_BITS 0x10 +#define KEY_256_BITS 0x18 + +#define AES_DMA_ENABLE 1 +#define AES_DMA_DISABLE 0 + + +typedef enum{ + AES_CRYPTO_ECB_256_MODE = 0, + AES_CRYPTO_ECB_192_MODE, + AES_CRYPTO_ECB_128_MODE, + AES_CRYPTO_CBC_256_MODE, + AES_CRYPTO_CBC_192_MODE, + AES_CRYPTO_CBC_128_MODE, +} csi_aes_mode_t; + +typedef struct { + uint32_t busy : 1; ///< Calculate busy flag + uint32_t error : 1; ///< Calculate error flag +} csi_aes_state_t; + +typedef struct { + uint32_t key_len_byte; + uint8_t key[32]; ///< Data block being processed + uint32_t sca; + uint32_t is_kdf; + uint32_t is_dma; +} csi_aes_context_t; + /** \brief AES Ctrl Block */ typedef struct { + csi_aes_state_t state; + csi_aes_context_t context; csi_dev_t dev; void *priv; } csi_aes_t; @@ -97,7 +157,7 @@ csi_error_t csi_aes_ecb_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t si \param[in] iv Init vector \return Error code \ref Csi_error_t */ -csi_error_t csi_aes_cbc_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv); +csi_error_t csi_aes_cbc_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv) ; /** \brief AES cbc decrypt @@ -161,10 +221,9 @@ csi_error_t csi_aes_cfb8_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t s \param[out] out Pointer to the result data \param[in] size The source data size \param[in] iv Init vector - \param[out] num The number of the 128-bit block we have used \return Error code \ref csi_error_t */ -csi_error_t csi_aes_cfb128_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv, uint32_t *num); +csi_error_t csi_aes_cfb128_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv); /** \brief AES cfb128 encrypt @@ -173,10 +232,9 @@ csi_error_t csi_aes_cfb128_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t \param[out] out Pointer to the result data \param[in] size The source data size \param[in] iv Init vector - \param[out] num The number of the 128-bit block we have used \return Error code \ref csi_error_t */ -csi_error_t csi_aes_cfb128_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv, uint32_t *num); +csi_error_t csi_aes_cfb128_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv); /** \brief AES ofb encrypt @@ -185,22 +243,22 @@ csi_error_t csi_aes_cfb128_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t \param[out] out Pointer to the result data \param[in] size The source data size \param[in] iv Init vector - \param[out] num The number of the 128-bit block we have used + \param[in] key_len key bits \return Error code \ref csi_error_t */ -csi_error_t csi_aes_ofb_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv, uint32_t *num); +csi_error_t csi_aes_ofb_encrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv); /** - \brief AES ofb decrypt - \param[in] aes Handle to operate - \param[in] in Pointer to the source data - \param[out] out Pointer to the result data - \param[in] size The source data size - \param[in] iv Init vector - \param[out] num The number of the 128-bit block we have used - \return Error code \ref csi_error_t + \brief Aes ofb decrypt + \param[in] dev_aes dev_aes handle to operate + \param[in] in Pointer to the Source data + \param[out] out Pointer to the Result data + \param[in] size the Source data size + \param[in] iv init vector + \param[in] key_len key bits + \return error code \ref csi_error_t */ -csi_error_t csi_aes_ofb_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t size, void *iv, uint32_t *num); +csi_error_t csi_aes_ofb_decrypt(csi_aes_t *aes, void *in, void *out,uint32_t size, void *iv); /** \brief AES ctr encrypt @@ -208,20 +266,10 @@ csi_error_t csi_aes_ofb_decrypt(csi_aes_t *aes, void *in, void *out, uint32_t si \param[in] in Pointer to the source data \param[out] out Pointer to the result data \param[in] size The source data size - \param[in] nonce_counter Pointer to the 128-bit nonce and counter - \param[in] stream_block Pointer to the saved stream-block for resuming \param[in] iv Init vector - \param[out] num The number of the 128-bit block we have used \return Error code \ref csi_error_t */ -csi_error_t csi_aes_ctr_encrypt(csi_aes_t *aes, - void *in, - void *out, - uint32_t size, - uint8_t nonce_counter[16], - uint8_t stream_block[16], - void *iv, - uint32_t *num); +csi_error_t csi_aes_ctr_encrypt(csi_aes_t *aes,void *in,void *out,uint32_t size,void *iv); /** \brief AES ctr decrypt @@ -229,20 +277,56 @@ csi_error_t csi_aes_ctr_encrypt(csi_aes_t *aes, \param[in] in Pointer to the source data \param[out] out Pointer to the result data \param[in] size The source data size - \param[in] nonce_counter Pointer to the 128-bit nonce and counter - \param[in] stream_block Pointer to the saved stream-block for resuming \param[in] iv Init vecotr - \param[out] num The number of the 128-bit block we have used \return Error code \ref csi_error_t */ -csi_error_t csi_aes_ctr_decrypt(csi_aes_t *aes, - void *in, - void *out, - uint32_t size, - uint8_t nonce_counter[16], - uint8_t stream_block[16], - void *iv, - uint32_t *num); +csi_error_t csi_aes_ctr_decrypt(csi_aes_t *aes,void *in,void *out,uint32_t size,void *iv); + +/** + \brief Aes gcm encrypt + \param[in] dev_aes dev_aes handle to operate + \param[in] in Pointer to the Source data + \param[out] out Pointer to the Result data + \param[in] size the Source data size + \param[in] iv init vector + \return error code \ref csi_error_t +*/ +csi_error_t csi_aes_gcm_encrypt(csi_aes_t *aes, void *in, void *out,uint32_t size, uint32_t add_len, void *iv); + +/** + \brief Aes gcm decrypt + \param[in] dev_aes dev_aes handle to operate + \param[in] in Pointer to the Source data. + \param[out] out Pointer to the Result data + \param[in] size the Source data size + \param[in] iv init vecotr + \return error code \ref csi_error_t +*/ +csi_error_t csi_aes_gcm_decrypt(csi_aes_t *aes, void *in, void *out,uint32_t size, uint32_t add_len, void *iv); + +/** + \brief Aes ccm encrypt + \param[in] dev_aes dev_aes handle to operate + \param[in] in Pointer to the Source data + \param[out] out Pointer to the Result data + \param[in] size the Source data size + \param[in] iv init vector + \param[in] tag_out tag output + \return error code \ref csi_error_t +*/ +csi_error_t csi_aes_ccm_encrypt(csi_aes_t *aes, void *in, void *out,uint32_t size, uint32_t add_len, void *iv, uint8_t *tag_out); + +/** + \brief Aes ccm decrypt + \param[in] dev_aes dev_aes handle to operate + \param[in] in Pointer to the Source data + \param[out] out Pointer to the Result data + \param[in] size the Source data size + \param[in] iv init vecotr + \param[in] tag_out tag output + \return error code \ref csi_error_t +*/ +csi_error_t csi_aes_ccm_decrypt(csi_aes_t *aes, void *in, void *out,uint32_t size, uint32_t add_len, void *iv, uint8_t *tag_out); /** \brief Enable AES power manage @@ -258,6 +342,13 @@ csi_error_t csi_aes_enable_pm(csi_aes_t *aes); */ void csi_aes_disable_pm(csi_aes_t *aes); +/** + \brief Config AES mode dma or slave + \param[in] dam_en zero disable dma, not zero enable dma + \return None +*/ +void csi_aes_dma_enable(csi_aes_t *aes, uint8_t dma_en); + #ifdef __cplusplus } #endif |