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
12 #ifdef LTC_CHACHA20POLY1305_MODE
15 Terminate a ChaCha20Poly1305 stream
16 @param st The ChaCha20Poly1305 state
17 @param tag [out] The destination for the MAC tag
18 @param taglen [in/out] The length of the MAC tag
19 @return CRYPT_OK on success
21 int chacha20poly1305_done(chacha20poly1305_state *st, unsigned char *tag, unsigned long *taglen)
23 unsigned char padzero[16] = { 0 };
25 unsigned char buf[16];
28 LTC_ARGCHK(st != NULL);
30 padlen = 16 - (unsigned long)(st->ctlen % 16);
32 if ((err = poly1305_process(&st->poly, padzero, padlen)) != CRYPT_OK) return err;
34 STORE64L(st->aadlen, buf);
35 STORE64L(st->ctlen, buf + 8);
36 if ((err = poly1305_process(&st->poly, buf, 16)) != CRYPT_OK) return err;
37 if ((err = poly1305_done(&st->poly, tag, taglen)) != CRYPT_OK) return err;
38 if ((err = chacha_done(&st->chacha)) != CRYPT_OK) return err;
44 /* ref: $Format:%D$ */
45 /* git commit: $Format:%H$ */
46 /* commit time: $Format:%ai$ */