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 #include "tomcrypt.h"
10 #include <stdarg.h>
11
12 /**
13 @file pmac_memory_multi.c
14 PMAC implementation, process multiple blocks of memory, by Tom St Denis
15 */
16
17 #ifdef LTC_PMAC
18
19 /**
20 PMAC multiple blocks of memory
21 @param cipher The index of the cipher desired
22 @param key The secret key
23 @param keylen The length of the secret key (octets)
24 @param out [out] Destination for the authentication tag
25 @param outlen [in/out] The max size and resulting size of the authentication tag
26 @param in The data you wish to send through PMAC
27 @param inlen The length of data you wish to send through PMAC (octets)
28 @param ... tuples of (data,len) pairs to PMAC, terminated with a (NULL,x) (x=don't care)
29 @return CRYPT_OK if successful
30 */
pmac_memory_multi(int cipher,const unsigned char * key,unsigned long keylen,unsigned char * out,unsigned long * outlen,const unsigned char * in,unsigned long inlen,...)31 int pmac_memory_multi(int cipher,
32 const unsigned char *key, unsigned long keylen,
33 unsigned char *out, unsigned long *outlen,
34 const unsigned char *in, unsigned long inlen, ...)
35 {
36 int err;
37 pmac_state *pmac;
38 va_list args;
39 const unsigned char *curptr;
40 unsigned long curlen;
41
42 LTC_ARGCHK(key != NULL);
43 LTC_ARGCHK(in != NULL);
44 LTC_ARGCHK(out != NULL);
45 LTC_ARGCHK(outlen != NULL);
46
47 /* allocate ram for pmac state */
48 pmac = XMALLOC(sizeof(pmac_state));
49 if (pmac == NULL) {
50 return CRYPT_MEM;
51 }
52
53 if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
54 goto LBL_ERR;
55 }
56 va_start(args, inlen);
57 curptr = in;
58 curlen = inlen;
59 for (;;) {
60 /* process buf */
61 if ((err = pmac_process(pmac, curptr, curlen)) != CRYPT_OK) {
62 goto LBL_ERR;
63 }
64 /* step to next */
65 curptr = va_arg(args, const unsigned char*);
66 if (curptr == NULL) {
67 break;
68 }
69 curlen = va_arg(args, unsigned long);
70 }
71 if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
72 goto LBL_ERR;
73 }
74 LBL_ERR:
75 #ifdef LTC_CLEAN_STACK
76 zeromem(pmac, sizeof(pmac_state));
77 #endif
78 XFREE(pmac);
79 va_end(args);
80 return err;
81 }
82
83 #endif
84
85 /* ref: HEAD -> master, tag: v1.18.2 */
86 /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
87 /* commit time: 2018-07-01 22:49:01 +0200 */
88