Mercurial > dropbear
comparison libtomcrypt/src/modes/lrw/lrw_process.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_process.c | 12 @file lrw_process.c |
28 */ | 26 */ |
29 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw) | 27 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw) |
30 { | 28 { |
31 unsigned char prod[16]; | 29 unsigned char prod[16]; |
32 int x, err; | 30 int x, err; |
33 #ifdef LRW_TABLES | 31 #ifdef LTC_LRW_TABLES |
34 int y; | 32 int y; |
35 #endif | 33 #endif |
36 | 34 |
37 LTC_ARGCHK(pt != NULL); | 35 LTC_ARGCHK(pt != NULL); |
38 LTC_ARGCHK(ct != NULL); | 36 LTC_ARGCHK(ct != NULL); |
47 XMEMCPY(prod, lrw->pad, 16); | 45 XMEMCPY(prod, lrw->pad, 16); |
48 | 46 |
49 /* increment IV */ | 47 /* increment IV */ |
50 for (x = 15; x >= 0; x--) { | 48 for (x = 15; x >= 0; x--) { |
51 lrw->IV[x] = (lrw->IV[x] + 1) & 255; | 49 lrw->IV[x] = (lrw->IV[x] + 1) & 255; |
52 if (lrw->IV[x]) { | 50 if (lrw->IV[x]) { |
53 break; | 51 break; |
54 } | 52 } |
55 } | 53 } |
56 | 54 |
57 /* update pad */ | 55 /* update pad */ |
58 #ifdef LRW_TABLES | 56 #ifdef LTC_LRW_TABLES |
59 /* for each byte changed we undo it's affect on the pad then add the new product */ | 57 /* for each byte changed we undo it's affect on the pad then add the new product */ |
60 for (; x < 16; x++) { | 58 for (; x < 16; x++) { |
61 #ifdef LTC_FAST | 59 #ifdef LTC_FAST |
62 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { | 60 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { |
63 *((LTC_FAST_TYPE *)(lrw->pad + y)) ^= *((LTC_FAST_TYPE *)(&lrw->PC[x][lrw->IV[x]][y])) ^ *((LTC_FAST_TYPE *)(&lrw->PC[x][(lrw->IV[x]-1)&255][y])); | 61 *(LTC_FAST_TYPE_PTR_CAST(lrw->pad + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][lrw->IV[x]][y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][(lrw->IV[x]-1)&255][y])); |
64 } | 62 } |
65 #else | 63 #else |
66 for (y = 0; y < 16; y++) { | 64 for (y = 0; y < 16; y++) { |
67 lrw->pad[y] ^= lrw->PC[x][lrw->IV[x]][y] ^ lrw->PC[x][(lrw->IV[x]-1)&255][y]; | 65 lrw->pad[y] ^= lrw->PC[x][lrw->IV[x]][y] ^ lrw->PC[x][(lrw->IV[x]-1)&255][y]; |
68 } | 66 } |
73 #endif | 71 #endif |
74 | 72 |
75 /* xor prod */ | 73 /* xor prod */ |
76 #ifdef LTC_FAST | 74 #ifdef LTC_FAST |
77 for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { | 75 for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { |
78 *((LTC_FAST_TYPE *)(ct + x)) = *((LTC_FAST_TYPE *)(pt + x)) ^ *((LTC_FAST_TYPE *)(prod + x)); | 76 *(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(pt + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x)); |
79 } | 77 } |
80 #else | 78 #else |
81 for (x = 0; x < 16; x++) { | 79 for (x = 0; x < 16; x++) { |
82 ct[x] = pt[x] ^ prod[x]; | 80 ct[x] = pt[x] ^ prod[x]; |
83 } | 81 } |
90 } | 88 } |
91 } else { | 89 } else { |
92 if ((err = cipher_descriptor[lrw->cipher].ecb_decrypt(ct, ct, &lrw->key)) != CRYPT_OK) { | 90 if ((err = cipher_descriptor[lrw->cipher].ecb_decrypt(ct, ct, &lrw->key)) != CRYPT_OK) { |
93 return err; | 91 return err; |
94 } | 92 } |
95 } | 93 } |
96 | 94 |
97 /* xor prod */ | 95 /* xor prod */ |
98 #ifdef LTC_FAST | 96 #ifdef LTC_FAST |
99 for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { | 97 for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { |
100 *((LTC_FAST_TYPE *)(ct + x)) = *((LTC_FAST_TYPE *)(ct + x)) ^ *((LTC_FAST_TYPE *)(prod + x)); | 98 *(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(ct + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x)); |
101 } | 99 } |
102 #else | 100 #else |
103 for (x = 0; x < 16; x++) { | 101 for (x = 0; x < 16; x++) { |
104 ct[x] = ct[x] ^ prod[x]; | 102 ct[x] = ct[x] ^ prod[x]; |
105 } | 103 } |
106 #endif | 104 #endif |
107 | 105 |
108 /* move to next */ | 106 /* move to next */ |
109 pt += 16; | 107 pt += 16; |
110 ct += 16; | 108 ct += 16; |
111 len -= 16; | 109 len -= 16; |
112 } | 110 } |
113 | 111 |
114 return CRYPT_OK; | 112 return CRYPT_OK; |
115 } | 113 } |
116 | 114 |
117 #endif | 115 #endif |
118 /* $Source$ */ | 116 /* ref: $Format:%D$ */ |
119 /* $Revision$ */ | 117 /* git commit: $Format:%H$ */ |
120 /* $Date$ */ | 118 /* commit time: $Format:%ai$ */ |