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 Terminate a CCM stream
15 @param ccm The CCM state
16 @param tag [out] The destination for the MAC tag
17 @param taglen [in/out] The length of the MAC tag
18 @return CRYPT_OK on success
20 int ccm_done(ccm_state *ccm,
21 unsigned char *tag, unsigned long *taglen)
26 LTC_ARGCHK(ccm != NULL);
28 /* Check all data have been processed */
29 if (ccm->ptlen != ccm->current_ptlen) {
33 LTC_ARGCHK(tag != NULL);
34 LTC_ARGCHK(taglen != NULL);
37 if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
42 /* setup CTR for the TAG (zero the count) */
43 for (y = 15; y > 15 - ccm->L; y--) {
46 if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->ctr, ccm->CTRPAD, &ccm->K)) != CRYPT_OK) {
50 cipher_descriptor[ccm->cipher].done(&ccm->K);
53 for (x = 0; x < 16 && x < *taglen; x++) {
54 tag[x] = ccm->PAD[x] ^ ccm->CTRPAD[x];
63 /* ref: $Format:%D$ */
64 /* git commit: $Format:%H$ */
65 /* commit time: $Format:%ai$ */