comparison src/encauth/ocb/ocb_done_decrypt.c @ 191:1c15b283127b libtomcrypt-orig

Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 13:23:02 +0000
parents
children 39d5d58461d6
comparison
equal deleted inserted replaced
143:5d99163f7e32 191:1c15b283127b
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