5.3.2.2 Crypto_Aead_AesCcm_Cipher
crypto_Aead_Status_E Crypto_Aead_AesCcm_Cipher(
st_Crypto_Aead_AesCcm_ctx *ptr_aesCcmCtx_st,
crypto_CipherOper_E cipherOper_en,
uint8_t *ptr_inputData,
uint32_t dataLen,
uint8_t *ptr_outData,
uint8_t *ptr_nonce,
uint32_t nonceLen,
uint8_t *ptr_authTag,
uint32_t authTagLen,
uint8_t *ptr_aad,
uint32_t aadLen
);
Description
This API performs AES-CCM encryption or decryption. Before using it, initialize the context by calling the Crypto_Aead_AesCcm_Init function.
Parameters
No. | Argument Type | Argument Name | Type | Description |
---|---|---|---|---|
1 | st_Crypto_Aead_AesCcm_ctx* | ptr_aesCcmCtx_st | Input | AES-CCM algorithm context. |
2 | crypto_CipherOper_E | cipherOper_en | Input | Selection cipher operation is encryption or decryption. |
3 | uint8_t* | ptr_inputData | Input | Input data to encrypt or decrypt. |
4 | uint32_t | dataLen | Input | Length of plain data or cipher data in bytes. |
5 | uint8_t* | ptr_outData | Output | Pointer to store cipher text/plain text as output. |
6 | uint8_t* | ptr_nonce | Input | Pointer for the Nonce value. |
7 | uint32_t | nonceLen | Input | Length of Nonce between 7 to 13 bytes. |
8 | uint8_t* | ptr_authTag | Output/Input | Pointer to store authentication tag value. Provide value while decryption operation. |
9 | uint32_t | authTagLen | Input | Length of Authentication tag between 4 to 16 bytes. |
10 | uint8_t* | ptr_aad | Input | Pointer for additional authentication data. It is optional to use, so it can be NULL also. |
11 | uint32_t | aadLen | Input | Length of additional data in bytes, as it is optional so it can be 0 also. |
Returns
Return Type | Description |
---|---|
crypto_Aead_Status_E | Function returns the status of the API. |
Example
#define sessionID 1
crypto_Hash_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_HW_INTERNAL;
crypto_CipherOper_E cipherOper_en = CRYPTO_CIOP_ENCRYPT;
st_Crypto_Aead_AesCcm_ctx AesCcm_ctx;
uint8_t inputData[32] = {/*data*/};
uint32_t dataLen = sizeof(inputData);
uint8_t key[32] = {/*data*/};
uint32_t keyLen = sizeof(key);
uint8_t outData[64];
uint8_t nonce[32] = {/*data*/};
uint32_t nonceLen = sizeof(nonce);
uint8_t authTag[32] = {/*data*/};
uint32_t authTagLen = 16; //tag length 4-16
uint8_t aad[32] = {/*data*/};
uint32_t aadLen = sizeof(aad);
status = Crypto_Aead_AesCcm_Init(
&AesCcm_ctx,
handlerType_en,
key,
keyLen,
sessionID
);
status = Crypto_Aead_AesCcm_Cipher(
&AesCcm_ctx,
cipherOper_en,
inputData,
dataLen,
outData,
nonce,
nonceLen,
authTag,
authTagLen,
aad,
aadLen
);