5.5.2.4 Crypto_Aead_AesGcm_Final
crypto_Aead_Status_E Crypto_Aead_AesGcm_Final(
st_crypto_Aead_AesGcm_Ctx *ptr_aesGcmCtx_st,
uint8_t *ptr_authTag,
uint32_t authTagLen
);
Description
This API is used to obtain the authentication tag for AES-GCM encryption. To use it, first initialize the context by calling the Crypto_Aead_AesGcm_Init function. If additional authentication data (AAD) is required, add it using the Crypto_Aead_AesGcm_AddAadData call; otherwise, skip this API call. Then, proceed with ciphering the data using Crypto_Aead_AesGcm_Cipher. Finally, call this API to get the authentication tag.
Parameters
No. | Argument Type | Argument Name | Type | Description |
---|---|---|---|---|
1 | st_Crypto_Aead_AesGcm_ctx* | ptr_aesGcmCtx_st | Input | AES-GCM Algorithm context |
2 | uint8_t* | ptr_authTag | Output/Input | Pointer to store authentication tag value |
3 | uint8_t* | authTagLen | Input | Authentication tag length in bytes, range 12-16 bytes |
Returns
Return Type | Description |
---|---|
crypto_Aead_Status_E | Function returns the status of the API. |
Example
#define sessionID 1
crypto_Aead_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_HW_INTERNAL;
crypto_CipherOper_E cipherOper_en = CRYPTO_CIOP_ENCRYPT;
st_Crypto_Aead_AesGcm_ctx AesGcm_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 initVect[32] = {/*data*/};
uint32_t initVectLen = sizeof(initVect);
uint8_t authTag[32] = {/*data*/};
uint32_t authTagLen = 16; // auth tag length of 12-16 bytes
uint8_t aad[32] = {/*data*/};
uint32_t aadLen = sizeof(aad);
status = Crypto_Aead_AesGcm_Init(
&AesGcm_ctx,
handlerType_en,
cipherOper_en,
key,
keyLen,
initVect,
initVectLen,
sessionID
);
status = Crypto_Aead_AesGcm_Cipher(
&AesGcm_ctx,
inputData,
dataLen,
outData
);
status = Crypto_Aead_AesGcm_AddAadData(
&AesGcm_ctx,
aad,
aadLen
);
status = Crypto_Aead_AesGcm_Final(
&AesGcm_ctx,
authTag,
authTagLen
);