]> pd.if.org Git - zpackage/blob - libtomcrypt/src/encauth/eax/eax_decrypt.c
b1407163ccd7210062d7be3b064204b08286ab1f
[zpackage] / libtomcrypt / src / encauth / eax / eax_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 eax_decrypt.c
12     EAX implementation, decrypt block, by Tom St Denis
13 */
14 #include "tomcrypt.h"
15
16 #ifdef LTC_EAX_MODE
17
18 /**
19    Decrypt data with the EAX protocol
20    @param eax     The EAX state
21    @param ct      The ciphertext
22    @param pt      [out] The plaintext
23    @param length  The length (octets) of the ciphertext
24    @return CRYPT_OK if successful
25 */
26 int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt,
27                 unsigned long length)
28 {
29    int err;
30
31    LTC_ARGCHK(eax != NULL);
32    LTC_ARGCHK(pt  != NULL);
33    LTC_ARGCHK(ct  != NULL);
34
35    /* omac ciphertext */
36    if ((err = omac_process(&eax->ctomac, ct, length)) != CRYPT_OK) {
37       return err;
38    }
39
40    /* decrypt  */
41    return ctr_decrypt(ct, pt, length, &eax->ctr);
42 }
43
44 #endif
45
46 /* ref:         $Format:%D$ */
47 /* git commit:  $Format:%H$ */
48 /* commit time: $Format:%ai$ */