1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 
4 #include "tomcrypt_private.h"
5 
6 #ifdef LTC_CHACHA20POLY1305_MODE
7 
8 /**
9   Add AAD to the ChaCha20Poly1305 state
10   @param st     The ChaCha20Poly1305 state
11   @param in     The additional authentication data to add to the ChaCha20Poly1305 state
12   @param inlen  The length of the ChaCha20Poly1305 data.
13   @return CRYPT_OK on success
14  */
chacha20poly1305_add_aad(chacha20poly1305_state * st,const unsigned char * in,unsigned long inlen)15 int chacha20poly1305_add_aad(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen)
16 {
17    int err;
18 
19    if (inlen == 0) return CRYPT_OK; /* nothing to do */
20    LTC_ARGCHK(st != NULL);
21 
22    if (st->aadflg == 0) return CRYPT_ERROR;
23    if ((err = poly1305_process(&st->poly, in, inlen)) != CRYPT_OK) return err;
24    st->aadlen += (ulong64)inlen;
25    return CRYPT_OK;
26 }
27 
28 #endif
29