Mercurial > dropbear
comparison src/encauth/ocb/ocb_done_decrypt.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05
Re-import libtomcrypt 1.05 for cleaner propagating.
From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 12:58:00 +0000 |
parents | |
children | d5faf4814ddb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 280:59400faa4b44 |
---|---|
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 /** | |
13 @file ocb_done_decrypt.c | |
14 OCB implementation, terminate decryption, by Tom St Denis | |
15 */ | |
16 #include "tomcrypt.h" | |
17 | |
18 #ifdef OCB_MODE | |
19 | |
20 /** | |
21 Terminate a decrypting OCB state | |
22 @param ocb The OCB state | |
23 @param ct The ciphertext (if any) | |
24 @param ctlen The length of the ciphertext (octets) | |
25 @param pt [out] The plaintext | |
26 @param tag The authentication tag (to compare against) | |
27 @param taglen The length of the authentication tag provided | |
28 @param stat [out] The result of the tag comparison | |
29 @return CRYPT_OK if the process was successful regardless if the tag is valid | |
30 */ | |
31 int ocb_done_decrypt(ocb_state *ocb, | |
32 const unsigned char *ct, unsigned long ctlen, | |
33 unsigned char *pt, | |
34 const unsigned char *tag, unsigned long taglen, int *stat) | |
35 { | |
36 int err; | |
37 unsigned char *tagbuf; | |
38 unsigned long tagbuflen; | |
39 | |
40 LTC_ARGCHK(ocb != NULL); | |
41 LTC_ARGCHK(pt != NULL); | |
42 LTC_ARGCHK(ct != NULL); | |
43 LTC_ARGCHK(tag != NULL); | |
44 LTC_ARGCHK(stat != NULL); | |
45 | |
46 /* default to failed */ | |
47 *stat = 0; | |
48 | |
49 /* allocate memory */ | |
50 tagbuf = XMALLOC(MAXBLOCKSIZE); | |
51 if (tagbuf == NULL) { | |
52 return CRYPT_MEM; | |
53 } | |
54 | |
55 tagbuflen = MAXBLOCKSIZE; | |
56 if ((err = s_ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) { | |
57 goto LBL_ERR; | |
58 } | |
59 | |
60 if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) { | |
61 *stat = 1; | |
62 } | |
63 | |
64 err = CRYPT_OK; | |
65 LBL_ERR: | |
66 #ifdef LTC_CLEAN_STACK | |
67 zeromem(tagbuf, MAXBLOCKSIZE); | |
68 #endif | |
69 | |
70 XFREE(tagbuf); | |
71 | |
72 return err; | |
73 } | |
74 | |
75 #endif | |
76 | |
77 | |
78 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_done_decrypt.c,v $ */ | |
79 /* $Revision: 1.3 $ */ | |
80 /* $Date: 2005/05/05 14:35:58 $ */ |