comparison libtomcrypt/src/mac/poly1305/poly1305_memory_multi.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
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 #include <stdarg.h>
17
18 #ifdef LTC_POLY1305
19
20 /**
21 POLY1305 multiple blocks 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 mac [out] Destination of the authentication tag
25 @param maclen [in/out] Max size and resulting size of authentication tag
26 @param in The data to POLY1305
27 @param inlen The length of the data to POLY1305 (octets)
28 @param ... tuples of (data,len) pairs to POLY1305, terminated with a (NULL,x) (x=don't care)
29 @return CRYPT_OK if successful
30 */
31 int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...)
32 {
33 poly1305_state st;
34 int err;
35 va_list args;
36 const unsigned char *curptr;
37 unsigned long curlen;
38
39 LTC_ARGCHK(key != NULL);
40 LTC_ARGCHK(in != NULL);
41 LTC_ARGCHK(mac != NULL);
42 LTC_ARGCHK(maclen != NULL);
43
44 va_start(args, inlen);
45 curptr = in;
46 curlen = inlen;
47 if ((err = poly1305_init(&st, key, keylen)) != CRYPT_OK) { goto LBL_ERR; }
48 for (;;) {
49 if ((err = poly1305_process(&st, curptr, curlen)) != CRYPT_OK) { goto LBL_ERR; }
50 curptr = va_arg(args, const unsigned char*);
51 if (curptr == NULL) break;
52 curlen = va_arg(args, unsigned long);
53 }
54 err = poly1305_done(&st, mac, maclen);
55 LBL_ERR:
56 #ifdef LTC_CLEAN_STACK
57 zeromem(&st, sizeof(poly1305_state));
58 #endif
59 va_end(args);
60 return err;
61 }
62
63 #endif
64
65 /* ref: $Format:%D$ */
66 /* git commit: $Format:%H$ */
67 /* commit time: $Format:%ai$ */