1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 
11 #include "tomcrypt_private.h"
12 
13 #ifdef LTC_CHACHA20POLY1305_MODE
14 
15 /**
16   Add AAD to the ChaCha20Poly1305 state
17   @param st     The ChaCha20Poly1305 state
18   @param in     The additional authentication data to add to the ChaCha20Poly1305 state
19   @param inlen  The length of the ChaCha20Poly1305 data.
20   @return CRYPT_OK on success
21  */
chacha20poly1305_add_aad(chacha20poly1305_state * st,const unsigned char * in,unsigned long inlen)22 int chacha20poly1305_add_aad(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen)
23 {
24    int err;
25 
26    if (inlen == 0) return CRYPT_OK; /* nothing to do */
27    LTC_ARGCHK(st != NULL);
28 
29    if (st->aadflg == 0) return CRYPT_ERROR;
30    if ((err = poly1305_process(&st->poly, in, inlen)) != CRYPT_OK) return err;
31    st->aadlen += (ulong64)inlen;
32    return CRYPT_OK;
33 }
34 
35 #endif
36 
37 /* ref:         $Format:%D$ */
38 /* git commit:  $Format:%H$ */
39 /* commit time: $Format:%ai$ */
40