Mercurial > dropbear
comparison ocb_done_decrypt.c @ 143:5d99163f7e32 libtomcrypt-orig
import of libtomcrypt 0.99
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:34:45 +0000 |
parents | 7faae8f46238 |
children |
comparison
equal
deleted
inserted
replaced
15:6362d3854bb4 | 143:5d99163f7e32 |
---|---|
18 const unsigned char *ct, unsigned long ctlen, | 18 const unsigned char *ct, unsigned long ctlen, |
19 unsigned char *pt, | 19 unsigned char *pt, |
20 const unsigned char *tag, unsigned long taglen, int *res) | 20 const unsigned char *tag, unsigned long taglen, int *res) |
21 { | 21 { |
22 int err; | 22 int err; |
23 unsigned char tagbuf[MAXBLOCKSIZE]; | 23 unsigned char *tagbuf; |
24 unsigned long tagbuflen; | 24 unsigned long tagbuflen; |
25 | 25 |
26 _ARGCHK(ocb != NULL); | 26 _ARGCHK(ocb != NULL); |
27 _ARGCHK(pt != NULL); | 27 _ARGCHK(pt != NULL); |
28 _ARGCHK(ct != NULL); | 28 _ARGCHK(ct != NULL); |
29 _ARGCHK(tag != NULL); | 29 _ARGCHK(tag != NULL); |
30 _ARGCHK(res != NULL); | 30 _ARGCHK(res != NULL); |
31 | 31 |
32 /* default to failed */ | |
32 *res = 0; | 33 *res = 0; |
33 | 34 |
34 tagbuflen = sizeof(tagbuf); | 35 /* allocate memory */ |
36 tagbuf = XMALLOC(MAXBLOCKSIZE); | |
37 if (tagbuf == NULL) { | |
38 return CRYPT_MEM; | |
39 } | |
40 | |
41 tagbuflen = MAXBLOCKSIZE; | |
35 if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) { | 42 if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) { |
36 return err; | 43 goto __ERR; |
37 } | 44 } |
38 | 45 |
39 if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) { | 46 if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) { |
40 *res = 1; | 47 *res = 1; |
41 } | 48 } |
42 | 49 |
50 err = CRYPT_OK; | |
51 __ERR: | |
43 #ifdef CLEAN_STACK | 52 #ifdef CLEAN_STACK |
44 zeromem(tagbuf, sizeof(tagbuf)); | 53 zeromem(tagbuf, MAXBLOCKSIZE); |
45 #endif | 54 #endif |
46 | 55 |
47 return CRYPT_OK; | 56 XFREE(tagbuf); |
57 | |
58 return err; | |
48 } | 59 } |
49 | 60 |
50 #endif | 61 #endif |
51 | 62 |