]> pd.if.org Git - zpackage/blob - libtomcrypt/src/mac/omac/omac_memory.c
remove f8 lrw xts modes
[zpackage] / libtomcrypt / src / mac / omac / omac_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 omac_memory.c
13   OMAC1 support, process a block of memory, Tom St Denis
14 */
15
16 #ifdef LTC_OMAC
17
18 /**
19    OMAC a block of memory
20    @param cipher    The index of the desired cipher
21    @param key       The secret key
22    @param keylen    The length of the secret key (octets)
23    @param in        The data to send through OMAC
24    @param inlen     The length of the data to send through OMAC (octets)
25    @param out       [out] The destination of the authentication tag
26    @param outlen    [in/out]  The max size and resulting size of the authentication tag (octets)
27    @return CRYPT_OK if successful
28 */
29 int omac_memory(int cipher,
30                 const unsigned char *key, unsigned long keylen,
31                 const unsigned char *in,  unsigned long inlen,
32                       unsigned char *out, unsigned long *outlen)
33 {
34    int err;
35    omac_state *omac;
36
37    LTC_ARGCHK(key    != NULL);
38    LTC_ARGCHK(in     != NULL);
39    LTC_ARGCHK(out    != NULL);
40    LTC_ARGCHK(outlen != NULL);
41
42    /* is the cipher valid? */
43    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
44       return err;
45    }
46
47    /* Use accelerator if found */
48    if (cipher_descriptor[cipher].omac_memory != NULL) {
49       return cipher_descriptor[cipher].omac_memory(key, keylen, in, inlen, out, outlen);
50    }
51
52    /* allocate ram for omac state */
53    omac = XMALLOC(sizeof(omac_state));
54    if (omac == NULL) {
55       return CRYPT_MEM;
56    }
57
58    /* omac process the message */
59    if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
60       goto LBL_ERR;
61    }
62    if ((err = omac_process(omac, in, inlen)) != CRYPT_OK) {
63       goto LBL_ERR;
64    }
65    if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
66       goto LBL_ERR;
67    }
68
69    err = CRYPT_OK;
70 LBL_ERR:
71 #ifdef LTC_CLEAN_STACK
72    zeromem(omac, sizeof(omac_state));
73 #endif
74
75    XFREE(omac);
76    return err;
77 }
78
79 #endif
80
81 /* ref:         $Format:%D$ */
82 /* git commit:  $Format:%H$ */
83 /* commit time: $Format:%ai$ */