1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
14 Add AAD to the CCM state
15 @param ccm The CCM state
16 @param adata The additional authentication data to add to the CCM state
17 @param adatalen The length of the AAD data.
18 @return CRYPT_OK on success
20 int ccm_add_aad(ccm_state *ccm,
21 const unsigned char *adata, unsigned long adatalen)
26 LTC_ARGCHK(ccm != NULL);
27 LTC_ARGCHK(adata != NULL);
29 if (ccm->aadlen < ccm->current_aadlen + adatalen) {
30 return CRYPT_INVALID_ARG;
32 ccm->current_aadlen += adatalen;
34 /* now add the data */
35 for (y = 0; y < adatalen; y++) {
37 /* full block so let's encrypt it */
38 if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
43 ccm->PAD[ccm->x++] ^= adata[y];
47 if (ccm->aadlen == ccm->current_aadlen) {
49 if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
61 /* ref: $Format:%D$ */
62 /* git commit: $Format:%H$ */
63 /* commit time: $Format:%ai$ */