comparison libtomcrypt/src/modes/lrw/lrw_start.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 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file lrw_start.c 12 @file lrw_start.c
17 15
18 #ifdef LTC_LRW_MODE 16 #ifdef LTC_LRW_MODE
19 17
20 /** 18 /**
21 Initialize the LRW context 19 Initialize the LRW context
22 @param cipher The cipher desired, must be a 128-bit block cipher 20 @param cipher The cipher desired, must be a 128-bit block cipher
23 @param IV The index value, must be 128-bits 21 @param IV The index value, must be 128-bits
24 @param key The cipher key 22 @param key The cipher key
25 @param keylen The length of the cipher key in octets 23 @param keylen The length of the cipher key in octets
26 @param tweak The tweak value (second key), must be 128-bits 24 @param tweak The tweak value (second key), must be 128-bits
27 @param num_rounds The number of rounds for the cipher (0 == default) 25 @param num_rounds The number of rounds for the cipher (0 == default)
28 @param lrw [out] The LRW state 26 @param lrw [out] The LRW state
29 @return CRYPT_OK on success. 27 @return CRYPT_OK on success.
30 */ 28 */
31 int lrw_start( int cipher, 29 int lrw_start( int cipher,
32 const unsigned char *IV, 30 const unsigned char *IV,
33 const unsigned char *key, int keylen, 31 const unsigned char *key, int keylen,
34 const unsigned char *tweak, 32 const unsigned char *tweak,
35 int num_rounds, 33 int num_rounds,
36 symmetric_LRW *lrw) 34 symmetric_LRW *lrw)
37 { 35 {
38 int err; 36 int err;
39 #ifdef LRW_TABLES 37 #ifdef LTC_LRW_TABLES
40 unsigned char B[16]; 38 unsigned char B[16];
41 int x, y, z, t; 39 int x, y, z, t;
42 #endif 40 #endif
43 41
44 LTC_ARGCHK(IV != NULL); 42 LTC_ARGCHK(IV != NULL);
45 LTC_ARGCHK(key != NULL); 43 LTC_ARGCHK(key != NULL);
46 LTC_ARGCHK(tweak != NULL); 44 LTC_ARGCHK(tweak != NULL);
47 LTC_ARGCHK(lrw != NULL); 45 LTC_ARGCHK(lrw != NULL);
48 46
49 #ifdef LTC_FAST 47 #ifdef LTC_FAST
50 if (16 % sizeof(LTC_FAST_TYPE)) { 48 if (16 % sizeof(LTC_FAST_TYPE)) {
51 return CRYPT_INVALID_ARG; 49 return CRYPT_INVALID_ARG;
52 } 50 }
67 lrw->cipher = cipher; 65 lrw->cipher = cipher;
68 66
69 /* copy the IV and tweak */ 67 /* copy the IV and tweak */
70 XMEMCPY(lrw->tweak, tweak, 16); 68 XMEMCPY(lrw->tweak, tweak, 16);
71 69
72 #ifdef LRW_TABLES 70 #ifdef LTC_LRW_TABLES
73 /* setup tables */ 71 /* setup tables */
74 /* generate the first table as it has no shifting (from which we make the other tables) */ 72 /* generate the first table as it has no shifting (from which we make the other tables) */
75 zeromem(B, 16); 73 zeromem(B, 16);
76 for (y = 0; y < 256; y++) { 74 for (y = 0; y < 256; y++) {
77 B[0] = y; 75 B[0] = y;
86 for (z = 15; z > 0; z--) { 84 for (z = 15; z > 0; z--) {
87 lrw->PC[x][y][z] = lrw->PC[x-1][y][z-1]; 85 lrw->PC[x][y][z] = lrw->PC[x-1][y][z-1];
88 } 86 }
89 lrw->PC[x][y][0] = gcm_shift_table[t<<1]; 87 lrw->PC[x][y][0] = gcm_shift_table[t<<1];
90 lrw->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1]; 88 lrw->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1];
91 } 89 }
92 } 90 }
93 #endif 91 #endif
94 92
95 /* generate first pad */ 93 /* generate first pad */
96 return lrw_setiv(IV, 16, lrw); 94 return lrw_setiv(IV, 16, lrw);
97 } 95 }
98 96
99 97
100 #endif 98 #endif
101 /* $Source$ */ 99 /* ref: $Format:%D$ */
102 /* $Revision$ */ 100 /* git commit: $Format:%H$ */
103 /* $Date$ */ 101 /* commit time: $Format:%ai$ */