]> pd.if.org Git - zpackage/blob - libtomcrypt/src/encauth/ocb/ocb_done_decrypt.c
remove ltc ciphers
[zpackage] / libtomcrypt / src / encauth / ocb / ocb_done_decrypt.c
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
10 /**
11    @file ocb_done_decrypt.c
12    OCB implementation, terminate decryption, by Tom St Denis
13 */
14 #include "tomcrypt.h"
15
16 #ifdef LTC_OCB_MODE
17
18 /**
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
28 */
29 int ocb_done_decrypt(ocb_state *ocb,
30                      const unsigned char *ct,  unsigned long ctlen,
31                            unsigned char *pt,
32                      const unsigned char *tag, unsigned long taglen, int *stat)
33 {
34    int err;
35    unsigned char *tagbuf;
36    unsigned long tagbuflen;
37
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);
43
44    /* default to failed */
45    *stat = 0;
46
47    /* allocate memory */
48    tagbuf = XMALLOC(MAXBLOCKSIZE);
49    if (tagbuf == NULL) {
50       return CRYPT_MEM;
51    }
52
53    tagbuflen = MAXBLOCKSIZE;
54    if ((err = s_ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
55       goto LBL_ERR;
56    }
57
58    if (taglen <= tagbuflen && XMEM_NEQ(tagbuf, tag, taglen) == 0) {
59       *stat = 1;
60    }
61
62    err = CRYPT_OK;
63 LBL_ERR:
64 #ifdef LTC_CLEAN_STACK
65    zeromem(tagbuf, MAXBLOCKSIZE);
66 #endif
67
68    XFREE(tagbuf);
69
70    return err;
71 }
72
73 #endif
74
75
76 /* ref:         $Format:%D$ */
77 /* git commit:  $Format:%H$ */
78 /* commit time: $Format:%ai$ */