comparison libtomcrypt/src/encauth/ocb/ocb_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 ocb_decrypt_verify_memory.c 11 @file ocb_decrypt_verify_memory.c
14 OCB implementation, helper to decrypt block of memory, by Tom St Denis 12 OCB implementation, helper to decrypt block of memory, by Tom St Denis
15 */ 13 */
16 #include "tomcrypt.h" 14 #include "tomcrypt.h"
17 15
18 #ifdef LTC_OCB_MODE 16 #ifdef LTC_OCB_MODE
19 17
31 @param stat [out] The result of the tag comparison (1==valid, 0==invalid) 29 @param stat [out] The result of the tag comparison (1==valid, 0==invalid)
32 @return CRYPT_OK if successful regardless of the tag comparison 30 @return CRYPT_OK if successful regardless of the tag comparison
33 */ 31 */
34 int ocb_decrypt_verify_memory(int cipher, 32 int ocb_decrypt_verify_memory(int cipher,
35 const unsigned char *key, unsigned long keylen, 33 const unsigned char *key, unsigned long keylen,
36 const unsigned char *nonce, 34 const unsigned char *nonce,
37 const unsigned char *ct, unsigned long ctlen, 35 const unsigned char *ct, unsigned long ctlen,
38 unsigned char *pt, 36 unsigned char *pt,
39 const unsigned char *tag, unsigned long taglen, 37 const unsigned char *tag, unsigned long taglen,
40 int *stat) 38 int *stat)
41 { 39 {
54 if (ocb == NULL) { 52 if (ocb == NULL) {
55 return CRYPT_MEM; 53 return CRYPT_MEM;
56 } 54 }
57 55
58 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) { 56 if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
59 goto LBL_ERR; 57 goto LBL_ERR;
60 } 58 }
61 59
62 while (ctlen > (unsigned long)ocb->block_len) { 60 while (ctlen > (unsigned long)ocb->block_len) {
63 if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) { 61 if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) {
64 goto LBL_ERR; 62 goto LBL_ERR;
65 } 63 }
66 ctlen -= ocb->block_len; 64 ctlen -= ocb->block_len;
67 pt += ocb->block_len; 65 pt += ocb->block_len;
68 ct += ocb->block_len; 66 ct += ocb->block_len;
69 } 67 }
71 err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat); 69 err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat);
72 LBL_ERR: 70 LBL_ERR:
73 #ifdef LTC_CLEAN_STACK 71 #ifdef LTC_CLEAN_STACK
74 zeromem(ocb, sizeof(ocb_state)); 72 zeromem(ocb, sizeof(ocb_state));
75 #endif 73 #endif
76 74
77 XFREE(ocb); 75 XFREE(ocb);
78 76
79 return err; 77 return err;
80 } 78 }
81 79
82 #endif 80 #endif
83 81
84 /* $Source$ */ 82 /* ref: $Format:%D$ */
85 /* $Revision$ */ 83 /* git commit: $Format:%H$ */
86 /* $Date$ */ 84 /* commit time: $Format:%ai$ */