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 |
|
12 /* PMAC implementation by Tom St Denis */ |
|
13 #include "mycrypt.h" |
|
14 |
|
15 #ifdef PMAC |
|
16 |
|
17 int pmac_memory(int cipher, |
|
18 const unsigned char *key, unsigned long keylen, |
|
19 const unsigned char *msg, unsigned long msglen, |
|
20 unsigned char *out, unsigned long *outlen) |
|
21 { |
|
22 int err; |
143
|
23 pmac_state *pmac; |
3
|
24 |
|
25 _ARGCHK(key != NULL); |
|
26 _ARGCHK(msg != NULL); |
|
27 _ARGCHK(out != NULL); |
|
28 _ARGCHK(outlen != NULL); |
|
29 |
143
|
30 /* allocate ram for pmac state */ |
|
31 pmac = XMALLOC(sizeof(pmac_state)); |
|
32 if (pmac == NULL) { |
|
33 return CRYPT_MEM; |
3
|
34 } |
143
|
35 |
|
36 if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) { |
|
37 goto __ERR; |
3
|
38 } |
143
|
39 if ((err = pmac_process(pmac, msg, msglen)) != CRYPT_OK) { |
|
40 goto __ERR; |
|
41 } |
|
42 if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) { |
|
43 goto __ERR; |
3
|
44 } |
|
45 |
143
|
46 err = CRYPT_OK; |
|
47 __ERR: |
|
48 #ifdef CLEAN_STACK |
|
49 zeromem(pmac, sizeof(pmac_state)); |
|
50 #endif |
|
51 |
|
52 XFREE(pmac); |
|
53 return err; |
3
|
54 } |
|
55 |
|
56 #endif |