comparison libtomcrypt/src/encauth/chachapoly/chacha20poly1305_done.c @ 1478:3a933956437e coverity

update coverity
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 23:49:22 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1439:8d24733026c5 1478:3a933956437e
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9
10 #include "tomcrypt.h"
11
12 #ifdef LTC_CHACHA20POLY1305_MODE
13
14 /**
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
20 */
21 int chacha20poly1305_done(chacha20poly1305_state *st, unsigned char *tag, unsigned long *taglen)
22 {
23 unsigned char padzero[16] = { 0 };
24 unsigned long padlen;
25 unsigned char buf[16];
26 int err;
27
28 LTC_ARGCHK(st != NULL);
29
30 padlen = 16 - (unsigned long)(st->ctlen % 16);
31 if (padlen < 16) {
32 if ((err = poly1305_process(&st->poly, padzero, padlen)) != CRYPT_OK) return err;
33 }
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;
39 return CRYPT_OK;
40 }
41
42 #endif
43
44 /* ref: $Format:%D$ */
45 /* git commit: $Format:%H$ */
46 /* commit time: $Format:%ai$ */