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