]> pd.if.org Git - zpackage/blob - libtomcrypt/src/mac/f9/f9_memory.c
70c694b31bf2bb4e66b2689bcc0f4ad5078d74fc
[zpackage] / libtomcrypt / src / mac / f9 / f9_memory.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
11 /**
12   @file f9_process.c
13   f9 Support, Process a block through F9-MAC
14 */
15
16 #ifdef LTC_F9_MODE
17
18 /** f9-MAC a block of memory
19   @param cipher     Index of cipher to use
20   @param key        [in]  Secret key
21   @param keylen     Length of key in octets
22   @param in         [in]  Message to MAC
23   @param inlen      Length of input in octets
24   @param out        [out] Destination for the MAC tag
25   @param outlen     [in/out] Output size and final tag size
26   Return CRYPT_OK on success.
27 */
28 int f9_memory(int cipher,
29                const unsigned char *key, unsigned long keylen,
30                const unsigned char *in,  unsigned long inlen,
31                      unsigned char *out, unsigned long *outlen)
32 {
33    f9_state *f9;
34    int         err;
35
36    /* is the cipher valid? */
37    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
38       return err;
39    }
40
41    /* Use accelerator if found */
42    if (cipher_descriptor[cipher].f9_memory != NULL) {
43       return cipher_descriptor[cipher].f9_memory(key, keylen, in, inlen, out, outlen);
44    }
45
46    f9 = XCALLOC(1, sizeof(*f9));
47    if (f9 == NULL) {
48       return CRYPT_MEM;
49    }
50
51    if ((err = f9_init(f9, cipher, key, keylen)) != CRYPT_OK) {
52      goto done;
53    }
54
55    if ((err = f9_process(f9, in, inlen)) != CRYPT_OK) {
56      goto done;
57    }
58
59    err = f9_done(f9, out, outlen);
60 done:
61    XFREE(f9);
62    return err;
63 }
64
65 #endif
66
67 /* ref:         $Format:%D$ */
68 /* git commit:  $Format:%H$ */
69 /* commit time: $Format:%ai$ */