1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
11 @file ocb_done_decrypt.c
12 OCB implementation, terminate decryption, by Tom St Denis
19 Terminate a decrypting OCB state
20 @param ocb The OCB state
21 @param ct The ciphertext (if any)
22 @param ctlen The length of the ciphertext (octets)
23 @param pt [out] The plaintext
24 @param tag The authentication tag (to compare against)
25 @param taglen The length of the authentication tag provided
26 @param stat [out] The result of the tag comparison
27 @return CRYPT_OK if the process was successful regardless if the tag is valid
29 int ocb_done_decrypt(ocb_state *ocb,
30 const unsigned char *ct, unsigned long ctlen,
32 const unsigned char *tag, unsigned long taglen, int *stat)
35 unsigned char *tagbuf;
36 unsigned long tagbuflen;
38 LTC_ARGCHK(ocb != NULL);
39 LTC_ARGCHK(pt != NULL);
40 LTC_ARGCHK(ct != NULL);
41 LTC_ARGCHK(tag != NULL);
42 LTC_ARGCHK(stat != NULL);
44 /* default to failed */
48 tagbuf = XMALLOC(MAXBLOCKSIZE);
53 tagbuflen = MAXBLOCKSIZE;
54 if ((err = s_ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
58 if (taglen <= tagbuflen && XMEM_NEQ(tagbuf, tag, taglen) == 0) {
64 #ifdef LTC_CLEAN_STACK
65 zeromem(tagbuf, MAXBLOCKSIZE);
76 /* ref: $Format:%D$ */
77 /* git commit: $Format:%H$ */
78 /* commit time: $Format:%ai$ */