• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, tomstdenis@gmail.com, http://libtomcrypt.com
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 */
ocb_done_decrypt(ocb_state * ocb,const unsigned char * ct,unsigned long ctlen,unsigned char * pt,const unsigned char * tag,unsigned long taglen,int * stat)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 && XMEMCMP(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.5 $ */
80 /* $Date: 2006/11/01 09:28:17 $ */
81