]> pd.if.org Git - zpackage/blob - libtomcrypt/src/mac/f9/f9_memory_multi.c
remove md2 md4 md5 hashes
[zpackage] / libtomcrypt / src / mac / f9 / f9_memory_multi.c
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 f9_memory_multi.c
14   f9 support, process multiple blocks of memory, Tom St Denis
15 */
16
17 #ifdef LTC_F9_MODE
18
19 /**
20    f9 multiple blocks of memory
21    @param cipher    The index of the desired cipher
22    @param key       The secret key
23    @param keylen    The length of the secret key (octets)
24    @param out       [out] The destination of the authentication tag
25    @param outlen    [in/out]  The max size and resulting size of the authentication tag (octets)
26    @param in        The data to send through f9
27    @param inlen     The length of the data to send through f9 (octets)
28    @param ...       tuples of (data,len) pairs to f9, terminated with a (NULL,x) (x=don't care)
29    @return CRYPT_OK if successful
30 */
31 int f9_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    f9_state          *f9;
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 f9 state */
48    f9 = XMALLOC(sizeof(f9_state));
49    if (f9 == NULL) {
50       return CRYPT_MEM;
51    }
52
53    /* f9 process the message */
54    if ((err = f9_init(f9, cipher, key, keylen)) != CRYPT_OK) {
55       goto LBL_ERR;
56    }
57    va_start(args, inlen);
58    curptr = in;
59    curlen = inlen;
60    for (;;) {
61       /* process buf */
62       if ((err = f9_process(f9, curptr, curlen)) != CRYPT_OK) {
63          goto LBL_ERR;
64       }
65       /* step to next */
66       curptr = va_arg(args, const unsigned char*);
67       if (curptr == NULL) {
68          break;
69       }
70       curlen = va_arg(args, unsigned long);
71    }
72    if ((err = f9_done(f9, out, outlen)) != CRYPT_OK) {
73       goto LBL_ERR;
74    }
75 LBL_ERR:
76 #ifdef LTC_CLEAN_STACK
77    zeromem(f9, sizeof(f9_state));
78 #endif
79    XFREE(f9);
80    va_end(args);
81    return err;
82 }
83
84 #endif
85
86 /* ref:         $Format:%D$ */
87 /* git commit:  $Format:%H$ */
88 /* commit time: $Format:%ai$ */