]> pd.if.org Git - zpackage/blob - libtomcrypt/src/encauth/chachapoly/chacha20poly1305_add_aad.c
commit files needed for zpm-fetchurl
[zpackage] / libtomcrypt / src / encauth / chachapoly / chacha20poly1305_add_aad.c
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   Add AAD to the ChaCha20Poly1305 state
16   @param st     The ChaCha20Poly1305 state
17   @param in     The additional authentication data to add to the ChaCha20Poly1305 state
18   @param inlen  The length of the ChaCha20Poly1305 data.
19   @return CRYPT_OK on success
20  */
21 int chacha20poly1305_add_aad(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen)
22 {
23    int err;
24
25    if (inlen == 0) return CRYPT_OK; /* nothing to do */
26    LTC_ARGCHK(st != NULL);
27
28    if (st->aadflg == 0) return CRYPT_ERROR;
29    if ((err = poly1305_process(&st->poly, in, inlen)) != CRYPT_OK) return err;
30    st->aadlen += (ulong64)inlen;
31    return CRYPT_OK;
32 }
33
34 #endif
35
36 /* ref:         $Format:%D$ */
37 /* git commit:  $Format:%H$ */
38 /* commit time: $Format:%ai$ */