3
|
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 * Tom St Denis, [email protected], http://libtomcrypt.org |
|
10 */ |
|
11 /* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */ |
|
12 #include "mycrypt.h" |
|
13 |
|
14 #ifdef OMAC |
|
15 |
|
16 int omac_memory(int cipher, |
|
17 const unsigned char *key, unsigned long keylen, |
|
18 const unsigned char *msg, unsigned long msglen, |
|
19 unsigned char *out, unsigned long *outlen) |
|
20 { |
|
21 int err; |
143
|
22 omac_state *omac; |
3
|
23 |
143
|
24 _ARGCHK(key != NULL); |
|
25 _ARGCHK(msg != NULL); |
|
26 _ARGCHK(out != NULL); |
3
|
27 _ARGCHK(outlen != NULL); |
|
28 |
143
|
29 /* allocate ram for omac state */ |
|
30 omac = XMALLOC(sizeof(omac_state)); |
|
31 if (omac == NULL) { |
|
32 return CRYPT_MEM; |
3
|
33 } |
|
34 |
143
|
35 /* omac process the message */ |
|
36 if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) { |
|
37 goto __ERR; |
|
38 } |
|
39 if ((err = omac_process(omac, msg, msglen)) != CRYPT_OK) { |
|
40 goto __ERR; |
|
41 } |
|
42 if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) { |
|
43 goto __ERR; |
|
44 } |
|
45 |
|
46 err = CRYPT_OK; |
|
47 __ERR: |
|
48 #ifdef CLEAN_STACK |
|
49 zeromem(omac, sizeof(omac_state)); |
|
50 #endif |
|
51 |
|
52 XFREE(omac); |
|
53 return err; |
3
|
54 } |
|
55 |
|
56 #endif |