comparison libtomcrypt/src/modes/lrw/lrw_setiv.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1457:32f990cc96b1 1511:5916af64acd4
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 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file lrw_setiv.c 12 @file lrw_setiv.c
25 @return CRYPT_OK if successful 23 @return CRYPT_OK if successful
26 */ 24 */
27 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw) 25 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
28 { 26 {
29 int err; 27 int err;
30 #ifdef LRW_TABLES 28 #ifdef LTC_LRW_TABLES
31 unsigned char T[16]; 29 unsigned char T[16];
32 int x, y; 30 int x, y;
33 #endif 31 #endif
34 LTC_ARGCHK(IV != NULL); 32 LTC_ARGCHK(IV != NULL);
35 LTC_ARGCHK(lrw != NULL); 33 LTC_ARGCHK(lrw != NULL);
49 if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL && cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) { 47 if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL && cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) {
50 /* we have accelerators, let's bail since they don't use lrw->pad anyways */ 48 /* we have accelerators, let's bail since they don't use lrw->pad anyways */
51 return CRYPT_OK; 49 return CRYPT_OK;
52 } 50 }
53 51
54 #ifdef LRW_TABLES 52 #ifdef LTC_LRW_TABLES
55 XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16); 53 XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16);
56 for (x = 1; x < 16; x++) { 54 for (x = 1; x < 16; x++) {
57 #ifdef LTC_FAST 55 #ifdef LTC_FAST
58 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { 56 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
59 *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&lrw->PC[x][IV[x]][y])); 57 *(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][IV[x]][y]));
60 } 58 }
61 #else 59 #else
62 for (y = 0; y < 16; y++) { 60 for (y = 0; y < 16; y++) {
63 T[y] ^= lrw->PC[x][IV[x]][y]; 61 T[y] ^= lrw->PC[x][IV[x]][y];
64 } 62 }
65 #endif 63 #endif
66 } 64 }
67 XMEMCPY(lrw->pad, T, 16); 65 XMEMCPY(lrw->pad, T, 16);
68 #else 66 #else
69 gcm_gf_mult(lrw->tweak, IV, lrw->pad); 67 gcm_gf_mult(lrw->tweak, IV, lrw->pad);
70 #endif 68 #endif
71 69
72 return CRYPT_OK; 70 return CRYPT_OK;
73 } 71 }
74 72
75 73
76 #endif 74 #endif
77 /* $Source$ */ 75 /* ref: $Format:%D$ */
78 /* $Revision$ */ 76 /* git commit: $Format:%H$ */
79 /* $Date$ */ 77 /* commit time: $Format:%ai$ */