comparison libtomcrypt/src/encauth/eax/eax_decrypt_verify_memory.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 9
12 /** 10 /**
13 @file eax_decrypt_verify_memory.c 11 @file eax_decrypt_verify_memory.c
14 EAX implementation, decrypt block of memory, by Tom St Denis 12 EAX implementation, decrypt block of memory, by Tom St Denis
55 LTC_ARGCHK(tag != NULL); 53 LTC_ARGCHK(tag != NULL);
56 54
57 /* default to zero */ 55 /* default to zero */
58 *stat = 0; 56 *stat = 0;
59 57
58 /* limit taglen */
59 taglen = MIN(taglen, MAXBLOCKSIZE);
60
60 /* allocate ram */ 61 /* allocate ram */
61 buf = XMALLOC(taglen); 62 buf = XMALLOC(taglen);
62 eax = XMALLOC(sizeof(*eax)); 63 eax = XMALLOC(sizeof(*eax));
63 if (eax == NULL || buf == NULL) { 64 if (eax == NULL || buf == NULL) {
64 if (eax != NULL) { 65 if (eax != NULL) {
75 } 76 }
76 77
77 if ((err = eax_decrypt(eax, ct, pt, ctlen)) != CRYPT_OK) { 78 if ((err = eax_decrypt(eax, ct, pt, ctlen)) != CRYPT_OK) {
78 goto LBL_ERR; 79 goto LBL_ERR;
79 } 80 }
80 81
81 buflen = taglen; 82 buflen = taglen;
82 if ((err = eax_done(eax, buf, &buflen)) != CRYPT_OK) { 83 if ((err = eax_done(eax, buf, &buflen)) != CRYPT_OK) {
83 goto LBL_ERR; 84 goto LBL_ERR;
84 } 85 }
85 86
86 /* compare tags */ 87 /* compare tags */
87 if (buflen >= taglen && XMEMCMP(buf, tag, taglen) == 0) { 88 if (buflen >= taglen && XMEM_NEQ(buf, tag, taglen) == 0) {
88 *stat = 1; 89 *stat = 1;
89 } 90 }
90 91
91 err = CRYPT_OK; 92 err = CRYPT_OK;
92 LBL_ERR: 93 LBL_ERR:
93 #ifdef LTC_CLEAN_STACK 94 #ifdef LTC_CLEAN_STACK
94 zeromem(buf, taglen); 95 zeromem(buf, taglen);
95 zeromem(eax, sizeof(*eax)); 96 zeromem(eax, sizeof(*eax));
101 return err; 102 return err;
102 } 103 }
103 104
104 #endif 105 #endif
105 106
106 /* $Source$ */ 107 /* ref: $Format:%D$ */
107 /* $Revision$ */ 108 /* git commit: $Format:%H$ */
108 /* $Date$ */ 109 /* commit time: $Format:%ai$ */