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 /* OCB Implementation by Tom St Denis */ |
|
13 #include "mycrypt.h" |
|
14 |
|
15 #ifdef OCB_MODE |
|
16 |
|
17 int ocb_done_decrypt(ocb_state *ocb, |
|
18 const unsigned char *ct, unsigned long ctlen, |
|
19 unsigned char *pt, |
|
20 const unsigned char *tag, unsigned long taglen, int *res) |
|
21 { |
|
22 int err; |
143
|
23 unsigned char *tagbuf; |
3
|
24 unsigned long tagbuflen; |
|
25 |
|
26 _ARGCHK(ocb != NULL); |
|
27 _ARGCHK(pt != NULL); |
|
28 _ARGCHK(ct != NULL); |
|
29 _ARGCHK(tag != NULL); |
|
30 _ARGCHK(res != NULL); |
|
31 |
143
|
32 /* default to failed */ |
3
|
33 *res = 0; |
|
34 |
143
|
35 /* allocate memory */ |
|
36 tagbuf = XMALLOC(MAXBLOCKSIZE); |
|
37 if (tagbuf == NULL) { |
|
38 return CRYPT_MEM; |
|
39 } |
|
40 |
|
41 tagbuflen = MAXBLOCKSIZE; |
3
|
42 if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) { |
143
|
43 goto __ERR; |
3
|
44 } |
|
45 |
|
46 if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) { |
|
47 *res = 1; |
|
48 } |
|
49 |
143
|
50 err = CRYPT_OK; |
|
51 __ERR: |
3
|
52 #ifdef CLEAN_STACK |
143
|
53 zeromem(tagbuf, MAXBLOCKSIZE); |
3
|
54 #endif |
|
55 |
143
|
56 XFREE(tagbuf); |
|
57 |
|
58 return err; |
3
|
59 } |
|
60 |
|
61 #endif |
|
62 |