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 /* The implementation is based on:
12 * Public Domain poly1305 from Andrew Moon
13 * https://github.com/floodyberry/poly1305-donna
14 */
15
16 #include "tomcrypt_private.h"
17
18 #ifdef LTC_POLY1305
19
20 /**
21 POLY1305 a block of memory to produce the authentication tag
22 @param key The secret key
23 @param keylen The length of the secret key (octets)
24 @param in The data to POLY1305
25 @param inlen The length of the data to POLY1305 (octets)
26 @param mac [out] Destination of the authentication tag
27 @param maclen [in/out] Max size and resulting size of authentication tag
28 @return CRYPT_OK if successful
29 */
poly1305_memory(const unsigned char * key,unsigned long keylen,const unsigned char * in,unsigned long inlen,unsigned char * mac,unsigned long * maclen)30 int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen)
31 {
32 poly1305_state st;
33 int err;
34
35 LTC_ARGCHK(key != NULL);
36 LTC_ARGCHK(in != NULL);
37 LTC_ARGCHK(mac != NULL);
38 LTC_ARGCHK(maclen != NULL);
39
40 if ((err = poly1305_init(&st, key, keylen)) != CRYPT_OK) { goto LBL_ERR; }
41 if ((err = poly1305_process(&st, in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
42 err = poly1305_done(&st, mac, maclen);
43 LBL_ERR:
44 #ifdef LTC_CLEAN_STACK
45 zeromem(&st, sizeof(poly1305_state));
46 #endif
47 return err;
48 }
49
50 #endif
51
52 /* ref: $Format:%D$ */
53 /* git commit: $Format:%H$ */
54 /* commit time: $Format:%ai$ */
55