Mercurial > dropbear
comparison libtomcrypt/src/encauth/ocb/ocb_done_decrypt.c @ 297:79bf1023cf11 agent-client
propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712)
to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 21 Mar 2006 16:20:59 +0000 |
parents | 1b9e69c058d2 |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
225:ca7e76d981d9 | 297:79bf1023cf11 |
---|---|
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 $ */ |