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 TypeArgument NameTypeDescription
1st_Crypto_Aead_AesCcm_ctx*ptr_aesCcmCtx_stInputAES-CCM algorithm context.
2crypto_CipherOper_EcipherOper_enInputSelection cipher operation is encryption or decryption.
3uint8_t*ptr_inputDataInputInput data to encrypt or decrypt.
4uint32_tdataLenInputLength of plain data or cipher data in bytes.
5uint8_t*ptr_outDataOutputPointer to store cipher text/plain text as output.
6uint8_t*ptr_nonceInputPointer for the Nonce value.
7uint32_tnonceLenInputLength of Nonce between 7 to 13 bytes.
8uint8_t*ptr_authTagOutput/InputPointer to store authentication tag value. Provide value while decryption operation.
9uint32_tauthTagLenInputLength of Authentication tag between 4 to 16 bytes.
10uint8_t*ptr_aadInputPointer for additional authentication data. It is optional to use, so it can be NULL also.
11uint32_taadLenInputLength of additional data in bytes, as it is optional so it can be 0 also.

Returns

Return TypeDescription
crypto_Aead_Status_EFunction 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
    );