11 #define U8a(x) GETBYTE(x,3) 12 #define U8b(x) GETBYTE(x,2) 13 #define U8c(x) GETBYTE(x,1) 14 #define U8d(x) GETBYTE(x,0) 17 #define f1(l, r, km, kr) \ 18 t = rotlVariable(km + r, kr); \ 19 l ^= ((S[0][U8a(t)] ^ S[1][U8b(t)]) - \ 20 S[2][U8c(t)]) + S[3][U8d(t)]; 21 #define f2(l, r, km, kr) \ 22 t = rotlVariable(km ^ r, kr); \ 23 l ^= ((S[0][U8a(t)] - S[1][U8b(t)]) + \ 24 S[2][U8c(t)]) ^ S[3][U8d(t)]; 25 #define f3(l, r, km, kr) \ 26 t = rotlVariable(km - r, kr); \ 27 l ^= ((S[0][U8a(t)] + S[1][U8b(t)]) ^ \ 28 S[2][U8c(t)]) - S[3][U8d(t)]; 30 #define F1(l, r, i, j) f1(l, r, K[i], K[i+j]) 31 #define F2(l, r, i, j) f2(l, r, K[i], K[i+j]) 32 #define F3(l, r, i, j) f3(l, r, K[i], K[i+j]) 106 #define x(i) GETBYTE(X[i/4], 3-i%4) 107 #define z(i) GETBYTE(Z[i/4], 3-i%4) 110 for (i=0; i<=16; i+=16)
113 Z[0] = X[0] ^
S[4][
x(0xD)] ^
S[5][
x(0xF)] ^
S[6][
x(0xC)] ^
S[7][
x(0xE)] ^
S[6][
x(0x8)];
114 Z[1] = X[2] ^ S[4][
z(0x0)] ^ S[5][
z(0x2)] ^ S[6][
z(0x1)] ^ S[7][
z(0x3)] ^ S[7][
x(0xA)];
115 Z[2] = X[3] ^ S[4][
z(0x7)] ^ S[5][
z(0x6)] ^ S[6][
z(0x5)] ^ S[7][
z(0x4)] ^ S[4][
x(0x9)];
116 Z[3] = X[1] ^ S[4][
z(0xA)] ^ S[5][
z(0x9)] ^ S[6][
z(0xB)] ^ S[7][
z(0x8)] ^ S[5][
x(0xB)];
117 K[i+0] = S[4][
z(0x8)] ^ S[5][
z(0x9)] ^ S[6][
z(0x7)] ^ S[7][
z(0x6)] ^ S[4][
z(0x2)];
118 K[i+1] = S[4][
z(0xA)] ^ S[5][
z(0xB)] ^ S[6][
z(0x5)] ^ S[7][
z(0x4)] ^ S[5][
z(0x6)];
119 K[i+2] = S[4][
z(0xC)] ^ S[5][
z(0xD)] ^ S[6][
z(0x3)] ^ S[7][
z(0x2)] ^ S[6][
z(0x9)];
120 K[i+3] = S[4][
z(0xE)] ^ S[5][
z(0xF)] ^ S[6][
z(0x1)] ^ S[7][
z(0x0)] ^ S[7][
z(0xC)];
121 X[0] = Z[2] ^ S[4][
z(0x5)] ^ S[5][
z(0x7)] ^ S[6][
z(0x4)] ^ S[7][
z(0x6)] ^ S[6][
z(0x0)];
122 X[1] = Z[0] ^ S[4][
x(0x0)] ^ S[5][
x(0x2)] ^ S[6][
x(0x1)] ^ S[7][
x(0x3)] ^ S[7][
z(0x2)];
123 X[2] = Z[1] ^ S[4][
x(0x7)] ^ S[5][
x(0x6)] ^ S[6][
x(0x5)] ^ S[7][
x(0x4)] ^ S[4][
z(0x1)];
124 X[3] = Z[3] ^ S[4][
x(0xA)] ^ S[5][
x(0x9)] ^ S[6][
x(0xB)] ^ S[7][
x(0x8)] ^ S[5][
z(0x3)];
125 K[i+4] = S[4][
x(0x3)] ^ S[5][
x(0x2)] ^ S[6][
x(0xC)] ^ S[7][
x(0xD)] ^ S[4][
x(0x8)];
126 K[i+5] = S[4][
x(0x1)] ^ S[5][
x(0x0)] ^ S[6][
x(0xE)] ^ S[7][
x(0xF)] ^ S[5][
x(0xD)];
127 K[i+6] = S[4][
x(0x7)] ^ S[5][
x(0x6)] ^ S[6][
x(0x8)] ^ S[7][
x(0x9)] ^ S[6][
x(0x3)];
128 K[i+7] = S[4][
x(0x5)] ^ S[5][
x(0x4)] ^ S[6][
x(0xA)] ^ S[7][
x(0xB)] ^ S[7][
x(0x7)];
129 Z[0] = X[0] ^ S[4][
x(0xD)] ^ S[5][
x(0xF)] ^ S[6][
x(0xC)] ^ S[7][
x(0xE)] ^ S[6][
x(0x8)];
130 Z[1] = X[2] ^ S[4][
z(0x0)] ^ S[5][
z(0x2)] ^ S[6][
z(0x1)] ^ S[7][
z(0x3)] ^ S[7][
x(0xA)];
131 Z[2] = X[3] ^ S[4][
z(0x7)] ^ S[5][
z(0x6)] ^ S[6][
z(0x5)] ^ S[7][
z(0x4)] ^ S[4][
x(0x9)];
132 Z[3] = X[1] ^ S[4][
z(0xA)] ^ S[5][
z(0x9)] ^ S[6][
z(0xB)] ^ S[7][
z(0x8)] ^ S[5][
x(0xB)];
133 K[i+8] = S[4][
z(0x3)] ^ S[5][
z(0x2)] ^ S[6][
z(0xC)] ^ S[7][
z(0xD)] ^ S[4][
z(0x9)];
134 K[i+9] = S[4][
z(0x1)] ^ S[5][
z(0x0)] ^ S[6][
z(0xE)] ^ S[7][
z(0xF)] ^ S[5][
z(0xC)];
135 K[i+10] = S[4][
z(0x7)] ^ S[5][
z(0x6)] ^ S[6][
z(0x8)] ^ S[7][
z(0x9)] ^ S[6][
z(0x2)];
136 K[i+11] = S[4][
z(0x5)] ^ S[5][
z(0x4)] ^ S[6][
z(0xA)] ^ S[7][
z(0xB)] ^ S[7][
z(0x6)];
137 X[0] = Z[2] ^ S[4][
z(0x5)] ^ S[5][
z(0x7)] ^ S[6][
z(0x4)] ^ S[7][
z(0x6)] ^ S[6][
z(0x0)];
138 X[1] = Z[0] ^ S[4][
x(0x0)] ^ S[5][
x(0x2)] ^ S[6][
x(0x1)] ^ S[7][
x(0x3)] ^ S[7][
z(0x2)];
139 X[2] = Z[1] ^ S[4][
x(0x7)] ^ S[5][
x(0x6)] ^ S[6][
x(0x5)] ^ S[7][
x(0x4)] ^ S[4][
z(0x1)];
140 X[3] = Z[3] ^ S[4][
x(0xA)] ^ S[5][
x(0x9)] ^ S[6][
x(0xB)] ^ S[7][
x(0x8)] ^ S[5][
z(0x3)];
141 K[i+12] = S[4][
x(0x8)] ^ S[5][
x(0x9)] ^ S[6][
x(0x7)] ^ S[7][
x(0x6)] ^ S[4][
x(0x3)];
142 K[i+13] = S[4][
x(0xA)] ^ S[5][
x(0xB)] ^ S[6][
x(0x5)] ^ S[7][
x(0x4)] ^ S[5][
x(0x7)];
143 K[i+14] = S[4][
x(0xC)] ^ S[5][
x(0xD)] ^ S[6][
x(0x3)] ^ S[7][
x(0x2)] ^ S[6][
x(0x8)];
144 K[i+15] = S[4][
x(0xE)] ^ S[5][
x(0xF)] ^ S[6][
x(0x1)] ^ S[7][
x(0x0)] ^ S[7][
x(0xD)];
147 for (i=16; i<32; i++)
154 { 0x5a827999, 0xd151d6a1, 0x482133a9, 0xbef090b1, 0x35bfedb9, 0xac8f4ac1,
155 0x235ea7c9, 0x9a2e04d1, 0x10fd61d9, 0x87ccbee1, 0xfe9c1be9, 0x756b78f1,
156 0xec3ad5f9, 0x630a3301, 0xd9d99009, 0x50a8ed11, 0xc7784a19, 0x3e47a721,
157 0xb5170429, 0x2be66131, 0xa2b5be39, 0x19851b41, 0x90547849, 0x0723d551},
158 { 0xc95c653a, 0x402bc242, 0xb6fb1f4a, 0x2dca7c52, 0xa499d95a, 0x1b693662,
159 0x9238936a, 0x0907f072, 0x7fd74d7a, 0xf6a6aa82, 0x6d76078a, 0xe4456492,
160 0x5b14c19a, 0xd1e41ea2, 0x48b37baa, 0xbf82d8b2, 0x365235ba, 0xad2192c2,
161 0x23f0efca, 0x9ac04cd2, 0x118fa9da, 0x885f06e2, 0xff2e63ea, 0x75fdc0f2},
162 { 0x383650db, 0xaf05ade3, 0x25d50aeb, 0x9ca467f3, 0x1373c4fb, 0x8a432203,
163 0x01127f0b, 0x77e1dc13, 0xeeb1391b, 0x65809623, 0xdc4ff32b, 0x531f5033,
164 0xc9eead3b, 0x40be0a43, 0xb78d674b, 0x2e5cc453, 0xa52c215b, 0x1bfb7e63,
165 0x92cadb6b, 0x099a3873, 0x8069957b, 0xf738f283, 0x6e084f8b, 0xe4d7ac93},
166 { 0xa7103c7c, 0x1ddf9984, 0x94aef68c, 0x0b7e5394, 0x824db09c, 0xf91d0da4,
167 0x6fec6aac, 0xe6bbc7b4, 0x5d8b24bc, 0xd45a81c4, 0x4b29decc, 0xc1f93bd4,
168 0x38c898dc, 0xaf97f5e4, 0x266752ec, 0x9d36aff4, 0x14060cfc, 0x8ad56a04,
169 0x01a4c70c, 0x78742414, 0xef43811c, 0x6612de24, 0xdce23b2c, 0x53b19834},
170 { 0x15ea281d, 0x8cb98525, 0x0388e22d, 0x7a583f35, 0xf1279c3d, 0x67f6f945,
171 0xdec6564d, 0x5595b355, 0xcc65105d, 0x43346d65, 0xba03ca6d, 0x30d32775,
172 0xa7a2847d, 0x1e71e185, 0x95413e8d, 0x0c109b95, 0x82dff89d, 0xf9af55a5,
173 0x707eb2ad, 0xe74e0fb5, 0x5e1d6cbd, 0xd4ecc9c5, 0x4bbc26cd, 0xc28b83d5},
174 { 0x84c413be, 0xfb9370c6, 0x7262cdce, 0xe9322ad6, 0x600187de, 0xd6d0e4e6,
175 0x4da041ee, 0xc46f9ef6, 0x3b3efbfe, 0xb20e5906, 0x28ddb60e, 0x9fad1316,
176 0x167c701e, 0x8d4bcd26, 0x041b2a2e, 0x7aea8736, 0xf1b9e43e, 0x68894146,
177 0xdf589e4e, 0x5627fb56, 0xccf7585e, 0x43c6b566, 0xba96126e, 0x31656f76},
178 { 0xf39dff5f, 0x6a6d5c67, 0xe13cb96f, 0x580c1677, 0xcedb737f, 0x45aad087,
179 0xbc7a2d8f, 0x33498a97, 0xaa18e79f, 0x20e844a7, 0x97b7a1af, 0x0e86feb7,
180 0x85565bbf, 0xfc25b8c7, 0x72f515cf, 0xe9c472d7, 0x6093cfdf, 0xd7632ce7,
181 0x4e3289ef, 0xc501e6f7, 0x3bd143ff, 0xb2a0a107, 0x296ffe0f, 0xa03f5b17},
182 { 0x6277eb00, 0xd9474808, 0x5016a510, 0xc6e60218, 0x3db55f20, 0xb484bc28,
183 0x2b541930, 0xa2237638, 0x18f2d340, 0x8fc23048, 0x06918d50, 0x7d60ea58,
184 0xf4304760, 0x6affa468, 0xe1cf0170, 0x589e5e78, 0xcf6dbb80, 0x463d1888,
185 0xbd0c7590, 0x33dbd298, 0xaaab2fa0, 0x217a8ca8, 0x9849e9b0, 0x0f1946b8}
189 {19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11, 19, 27, 3, 11},
190 {4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28, 4, 12, 20, 28},
191 {21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13, 21, 29, 5, 13},
192 {6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30, 6, 14, 22, 30},
193 {23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15, 23, 31, 7, 15},
194 {8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0, 8, 16, 24, 0},
195 {25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17, 25, 1, 9, 17},
196 {10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2, 10, 18, 26, 2}
200 F1(block[2],block[3],8*i+4,-4); \ 201 F2(block[1],block[2],8*i+5,-4); \ 202 F3(block[0],block[1],8*i+6,-4); \ 203 F1(block[3],block[0],8*i+7,-4); 206 F1(block[3],block[0],8*i+7,-4); \ 207 F3(block[0],block[1],8*i+6,-4); \ 208 F2(block[1],block[2],8*i+5,-4); \ 209 F1(block[2],block[3],8*i+4,-4); 217 Block::Get(inBlock)(block[0])(block[1])(block[2])(block[3]);
235 Block::Put(xorBlock, outBlock)(block[0])(block[1])(block[2])(block[3]);
244 f1(kappa[6],kappa[7],t_m[0][i],t_r[0][i]);
245 f2(kappa[5],kappa[6],t_m[1][i],t_r[1][i]);
246 f3(kappa[4],kappa[5],t_m[2][i],t_r[2][i]);
247 f1(kappa[3],kappa[4],t_m[3][i],t_r[3][i]);
248 f2(kappa[2],kappa[3],t_m[4][i],t_r[4][i]);
249 f3(kappa[1],kappa[2],t_m[5][i],t_r[5][i]);
250 f1(kappa[0],kappa[1],t_m[6][i],t_r[6][i]);
251 f2(kappa[7],kappa[0],t_m[7][i],t_r[7][i]);
261 for(
int i=0; i<12; ++i)
266 K[8*i]=kappa[0] & 31;
267 K[8*i+1]=kappa[2] & 31;
268 K[8*i+2]=kappa[4] & 31;
269 K[8*i+3]=kappa[6] & 31;
278 for(
int j=0; j<6; ++j)
280 for(
int i=0; i<4; ++i)
void SecureWipeBuffer(T *buf, size_t n)
Sets each element of an array to 0.
void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
Utility functions for the Crypto++ library.
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
FixedSizeSecBlock< word32, 32 > K
static void Omega(int i, word32 kappa[8])
#define NAMESPACE_BEGIN(x)
static GetBlock< T, B, GA > Get(const void *block)
static const word32 t_m[8][24]
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
BlockGetAndPut< word32, BigEndian > Block
Classes for the CAST-128 and CAST-256 block ciphers.
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
void AssertValidKeyLength(size_t length) const
Validates the key length.
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
#define CRYPTOPP_ASSERT(exp)
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
static const word32 S[8][256]
Interface for retrieving values given their names.
static const unsigned int t_r[8][24]