Mercurial > dropbear
comparison libtomcrypt/src/ciphers/aes/aes.c @ 1710:1ff2a1034c52
Fix whitespace changes vs upstream libtomcrypt
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 10 Jun 2020 23:01:33 +0800 |
parents | bf9c06b8dad9 |
children |
comparison
equal
deleted
inserted
replaced
1709:04155ce30759 | 1710:1ff2a1034c52 |
---|---|
8 */ | 8 */ |
9 | 9 |
10 /* AES implementation by Tom St Denis | 10 /* AES implementation by Tom St Denis |
11 * | 11 * |
12 * Derived from the Public Domain source code by | 12 * Derived from the Public Domain source code by |
13 | 13 |
14 --- | 14 --- |
15 * rijndael-alg-fst.c | 15 * rijndael-alg-fst.c |
16 * | 16 * |
17 * @version 3.0 (December 2000) | 17 * @version 3.0 (December 2000) |
18 * | 18 * |
19 * Optimised ANSI C code for the Rijndael cipher (now AES) | 19 * Optimised ANSI C code for the Rijndael cipher (now AES) |
24 --- | 24 --- |
25 */ | 25 */ |
26 /** | 26 /** |
27 @file aes.c | 27 @file aes.c |
28 Implementation of AES | 28 Implementation of AES |
29 */ | 29 */ |
30 | 30 |
31 #include "tomcrypt.h" | 31 #include "tomcrypt.h" |
32 | 32 |
33 #ifdef LTC_RIJNDAEL | 33 #ifdef LTC_RIJNDAEL |
34 | 34 |
35 #ifndef ENCRYPT_ONLY | 35 #ifndef ENCRYPT_ONLY |
36 | 36 |
37 #define SETUP rijndael_setup | 37 #define SETUP rijndael_setup |
38 #define ECB_ENC rijndael_ecb_encrypt | 38 #define ECB_ENC rijndael_ecb_encrypt |
39 #define ECB_DEC rijndael_ecb_decrypt | 39 #define ECB_DEC rijndael_ecb_decrypt |
40 #define ECB_DONE rijndael_done | 40 #define ECB_DONE rijndael_done |
123 { | 123 { |
124 int i; | 124 int i; |
125 ulong32 temp, *rk; | 125 ulong32 temp, *rk; |
126 #ifndef ENCRYPT_ONLY | 126 #ifndef ENCRYPT_ONLY |
127 ulong32 *rrk; | 127 ulong32 *rrk; |
128 #endif | 128 #endif |
129 LTC_ARGCHK(key != NULL); | 129 LTC_ARGCHK(key != NULL); |
130 LTC_ARGCHK(skey != NULL); | 130 LTC_ARGCHK(skey != NULL); |
131 | 131 |
132 if (keylen != 16 && keylen != 24 && keylen != 32) { | 132 if (keylen != 16 && keylen != 24 && keylen != 32) { |
133 return CRYPT_INVALID_KEYSIZE; | 133 return CRYPT_INVALID_KEYSIZE; |
134 } | 134 } |
135 | 135 |
136 if (num_rounds != 0 && num_rounds != (10 + ((keylen/8)-2)*2)) { | 136 if (num_rounds != 0 && num_rounds != (10 + ((keylen/8)-2)*2)) { |
137 return CRYPT_INVALID_ROUNDS; | 137 return CRYPT_INVALID_ROUNDS; |
138 } | 138 } |
139 | 139 |
140 skey->rijndael.Nr = 10 + ((keylen/8)-2)*2; | 140 skey->rijndael.Nr = 10 + ((keylen/8)-2)*2; |
141 | 141 |
142 /* setup the forward key */ | 142 /* setup the forward key */ |
143 i = 0; | 143 i = 0; |
144 rk = skey->rijndael.eK; | 144 rk = skey->rijndael.eK; |
145 LOAD32H(rk[0], key ); | 145 LOAD32H(rk[0], key ); |
146 LOAD32H(rk[1], key + 4); | 146 LOAD32H(rk[1], key + 4); |
161 } else if (keylen == 24) { | 161 } else if (keylen == 24) { |
162 LOAD32H(rk[4], key + 16); | 162 LOAD32H(rk[4], key + 16); |
163 LOAD32H(rk[5], key + 20); | 163 LOAD32H(rk[5], key + 20); |
164 for (;;) { | 164 for (;;) { |
165 #ifdef _MSC_VER | 165 #ifdef _MSC_VER |
166 temp = skey->rijndael.eK[rk - skey->rijndael.eK + 5]; | 166 temp = skey->rijndael.eK[rk - skey->rijndael.eK + 5]; |
167 #else | 167 #else |
168 temp = rk[5]; | 168 temp = rk[5]; |
169 #endif | 169 #endif |
170 rk[ 6] = rk[ 0] ^ setup_mix(temp) ^ rcon[i]; | 170 rk[ 6] = rk[ 0] ^ setup_mix(temp) ^ rcon[i]; |
171 rk[ 7] = rk[ 1] ^ rk[ 6]; | 171 rk[ 7] = rk[ 1] ^ rk[ 6]; |
183 LOAD32H(rk[5], key + 20); | 183 LOAD32H(rk[5], key + 20); |
184 LOAD32H(rk[6], key + 24); | 184 LOAD32H(rk[6], key + 24); |
185 LOAD32H(rk[7], key + 28); | 185 LOAD32H(rk[7], key + 28); |
186 for (;;) { | 186 for (;;) { |
187 #ifdef _MSC_VER | 187 #ifdef _MSC_VER |
188 temp = skey->rijndael.eK[rk - skey->rijndael.eK + 7]; | 188 temp = skey->rijndael.eK[rk - skey->rijndael.eK + 7]; |
189 #else | 189 #else |
190 temp = rk[7]; | 190 temp = rk[7]; |
191 #endif | 191 #endif |
192 rk[ 8] = rk[ 0] ^ setup_mix(temp) ^ rcon[i]; | 192 rk[ 8] = rk[ 0] ^ setup_mix(temp) ^ rcon[i]; |
193 rk[ 9] = rk[ 1] ^ rk[ 8]; | 193 rk[ 9] = rk[ 1] ^ rk[ 8]; |
207 /* this can't happen */ | 207 /* this can't happen */ |
208 /* coverity[dead_error_line] */ | 208 /* coverity[dead_error_line] */ |
209 return CRYPT_ERROR; | 209 return CRYPT_ERROR; |
210 } | 210 } |
211 | 211 |
212 #ifndef ENCRYPT_ONLY | 212 #ifndef ENCRYPT_ONLY |
213 /* setup the inverse key now */ | 213 /* setup the inverse key now */ |
214 rk = skey->rijndael.dK; | 214 rk = skey->rijndael.dK; |
215 rrk = skey->rijndael.eK + (28 + keylen) - 4; | 215 rrk = skey->rijndael.eK + (28 + keylen) - 4; |
216 | 216 |
217 /* apply the inverse MixColumn transform to all round keys but the first and the last: */ | 217 /* apply the inverse MixColumn transform to all round keys but the first and the last: */ |
218 /* copy first */ | 218 /* copy first */ |
219 *rk++ = *rrk++; | 219 *rk++ = *rrk++; |
220 *rk++ = *rrk++; | 220 *rk++ = *rrk++; |
221 *rk++ = *rrk++; | 221 *rk++ = *rrk++; |
222 *rk = *rrk; | 222 *rk = *rrk; |
223 rk -= 3; rrk -= 3; | 223 rk -= 3; rrk -= 3; |
224 | 224 |
225 for (i = 1; i < skey->rijndael.Nr; i++) { | 225 for (i = 1; i < skey->rijndael.Nr; i++) { |
226 rrk -= 4; | 226 rrk -= 4; |
227 rk += 4; | 227 rk += 4; |
228 #ifdef LTC_SMALL_CODE | 228 #ifdef LTC_SMALL_CODE |
229 temp = rrk[0]; | 229 temp = rrk[0]; |
230 rk[0] = setup_mix2(temp); | 230 rk[0] = setup_mix2(temp); |
231 temp = rrk[1]; | 231 temp = rrk[1]; |
232 rk[1] = setup_mix2(temp); | 232 rk[1] = setup_mix2(temp); |
233 temp = rrk[2]; | 233 temp = rrk[2]; |
257 rk[3] = | 257 rk[3] = |
258 Tks0[byte(temp, 3)] ^ | 258 Tks0[byte(temp, 3)] ^ |
259 Tks1[byte(temp, 2)] ^ | 259 Tks1[byte(temp, 2)] ^ |
260 Tks2[byte(temp, 1)] ^ | 260 Tks2[byte(temp, 1)] ^ |
261 Tks3[byte(temp, 0)]; | 261 Tks3[byte(temp, 0)]; |
262 #endif | 262 #endif |
263 | 263 |
264 } | 264 } |
265 | 265 |
266 /* copy last */ | 266 /* copy last */ |
267 rrk -= 4; | 267 rrk -= 4; |
268 rk += 4; | 268 rk += 4; |
270 *rk++ = *rrk++; | 270 *rk++ = *rrk++; |
271 *rk++ = *rrk++; | 271 *rk++ = *rrk++; |
272 *rk = *rrk; | 272 *rk = *rrk; |
273 #endif /* ENCRYPT_ONLY */ | 273 #endif /* ENCRYPT_ONLY */ |
274 | 274 |
275 return CRYPT_OK; | 275 return CRYPT_OK; |
276 } | 276 } |
277 | 277 |
278 /** | 278 /** |
279 Encrypts a block of text with AES | 279 Encrypts a block of text with AES |
280 @param pt The input plaintext (16 bytes) | 280 @param pt The input plaintext (16 bytes) |
281 @param ct The output ciphertext (16 bytes) | 281 @param ct The output ciphertext (16 bytes) |
282 @param skey The key as scheduled | 282 @param skey The key as scheduled |
283 @return CRYPT_OK if successful | 283 @return CRYPT_OK if successful |
284 */ | 284 */ |
285 #ifdef LTC_CLEAN_STACK | 285 #ifdef LTC_CLEAN_STACK |
286 static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) | 286 static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
287 #else | 287 #else |
288 int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) | 288 int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
289 #endif | 289 #endif |
290 { | 290 { |
291 ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; | 291 ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; |
292 int Nr, r; | 292 int Nr, r; |
293 | 293 |
294 LTC_ARGCHK(pt != NULL); | 294 LTC_ARGCHK(pt != NULL); |
295 LTC_ARGCHK(ct != NULL); | 295 LTC_ARGCHK(ct != NULL); |
296 LTC_ARGCHK(skey != NULL); | 296 LTC_ARGCHK(skey != NULL); |
297 | 297 |
298 Nr = skey->rijndael.Nr; | 298 Nr = skey->rijndael.Nr; |
299 rk = skey->rijndael.eK; | 299 rk = skey->rijndael.eK; |
300 | 300 |
301 /* | 301 /* |
302 * map byte array block to cipher state | 302 * map byte array block to cipher state |
303 * and add initial round key: | 303 * and add initial round key: |
304 */ | 304 */ |
305 LOAD32H(s0, pt ); s0 ^= rk[0]; | 305 LOAD32H(s0, pt ); s0 ^= rk[0]; |
333 Te0(byte(s3, 3)) ^ | 333 Te0(byte(s3, 3)) ^ |
334 Te1(byte(s0, 2)) ^ | 334 Te1(byte(s0, 2)) ^ |
335 Te2(byte(s1, 1)) ^ | 335 Te2(byte(s1, 1)) ^ |
336 Te3(byte(s2, 0)) ^ | 336 Te3(byte(s2, 0)) ^ |
337 rk[3]; | 337 rk[3]; |
338 if (r == Nr-2) { | 338 if (r == Nr-2) { |
339 break; | 339 break; |
340 } | 340 } |
341 s0 = t0; s1 = t1; s2 = t2; s3 = t3; | 341 s0 = t0; s1 = t1; s2 = t2; s3 = t3; |
342 } | 342 } |
343 rk += 4; | 343 rk += 4; |
434 STORE32H(s2, ct+8); | 434 STORE32H(s2, ct+8); |
435 s3 = | 435 s3 = |
436 (Te4_3[byte(t3, 3)]) ^ | 436 (Te4_3[byte(t3, 3)]) ^ |
437 (Te4_2[byte(t0, 2)]) ^ | 437 (Te4_2[byte(t0, 2)]) ^ |
438 (Te4_1[byte(t1, 1)]) ^ | 438 (Te4_1[byte(t1, 1)]) ^ |
439 (Te4_0[byte(t2, 0)]) ^ | 439 (Te4_0[byte(t2, 0)]) ^ |
440 rk[3]; | 440 rk[3]; |
441 STORE32H(s3, ct+12); | 441 STORE32H(s3, ct+12); |
442 | 442 |
443 return CRYPT_OK; | 443 return CRYPT_OK; |
444 } | 444 } |
445 | 445 |
446 #ifdef LTC_CLEAN_STACK | 446 #ifdef LTC_CLEAN_STACK |
447 int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) | 447 int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
448 { | 448 { |
449 int err = _rijndael_ecb_encrypt(pt, ct, skey); | 449 int err = _rijndael_ecb_encrypt(pt, ct, skey); |
450 burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2); | 450 burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2); |
451 return err; | 451 return err; |
452 } | 452 } |
453 #endif | 453 #endif |
454 | 454 |
455 #ifndef ENCRYPT_ONLY | 455 #ifndef ENCRYPT_ONLY |
456 | 456 |
457 /** | 457 /** |
458 Decrypts a block of text with AES | 458 Decrypts a block of text with AES |
459 @param ct The input ciphertext (16 bytes) | 459 @param ct The input ciphertext (16 bytes) |
460 @param pt The output plaintext (16 bytes) | 460 @param pt The output plaintext (16 bytes) |
461 @param skey The key as scheduled | 461 @param skey The key as scheduled |
462 @return CRYPT_OK if successful | 462 @return CRYPT_OK if successful |
463 */ | 463 */ |
464 #ifdef LTC_CLEAN_STACK | 464 #ifdef LTC_CLEAN_STACK |
465 static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 465 static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
466 #else | 466 #else |
467 int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 467 int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
468 #endif | 468 #endif |
469 { | 469 { |
470 ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; | 470 ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; |
471 int Nr, r; | 471 int Nr, r; |
472 | 472 |
473 LTC_ARGCHK(pt != NULL); | 473 LTC_ARGCHK(pt != NULL); |
474 LTC_ARGCHK(ct != NULL); | 474 LTC_ARGCHK(ct != NULL); |
475 LTC_ARGCHK(skey != NULL); | 475 LTC_ARGCHK(skey != NULL); |
476 | 476 |
477 Nr = skey->rijndael.Nr; | 477 Nr = skey->rijndael.Nr; |
478 rk = skey->rijndael.dK; | 478 rk = skey->rijndael.dK; |
479 | 479 |
480 /* | 480 /* |
481 * map byte array block to cipher state | 481 * map byte array block to cipher state |
512 Td1(byte(s2, 2)) ^ | 512 Td1(byte(s2, 2)) ^ |
513 Td2(byte(s1, 1)) ^ | 513 Td2(byte(s1, 1)) ^ |
514 Td3(byte(s0, 0)) ^ | 514 Td3(byte(s0, 0)) ^ |
515 rk[3]; | 515 rk[3]; |
516 if (r == Nr-2) { | 516 if (r == Nr-2) { |
517 break; | 517 break; |
518 } | 518 } |
519 s0 = t0; s1 = t1; s2 = t2; s3 = t3; | 519 s0 = t0; s1 = t1; s2 = t2; s3 = t3; |
520 } | 520 } |
521 rk += 4; | 521 rk += 4; |
522 | 522 |
523 #else | 523 #else |
524 | 524 |
525 /* | 525 /* |
526 * Nr - 1 full rounds: | 526 * Nr - 1 full rounds: |
527 */ | 527 */ |
528 r = Nr >> 1; | 528 r = Nr >> 1; |
622 return CRYPT_OK; | 622 return CRYPT_OK; |
623 } | 623 } |
624 | 624 |
625 | 625 |
626 #ifdef LTC_CLEAN_STACK | 626 #ifdef LTC_CLEAN_STACK |
627 int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 627 int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
628 { | 628 { |
629 int err = _rijndael_ecb_decrypt(ct, pt, skey); | 629 int err = _rijndael_ecb_decrypt(ct, pt, skey); |
630 burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2); | 630 burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2); |
631 return err; | 631 return err; |
632 } | 632 } |
638 */ | 638 */ |
639 int ECB_TEST(void) | 639 int ECB_TEST(void) |
640 { | 640 { |
641 #ifndef LTC_TEST | 641 #ifndef LTC_TEST |
642 return CRYPT_NOP; | 642 return CRYPT_NOP; |
643 #else | 643 #else |
644 int err; | 644 int err; |
645 static const struct { | 645 static const struct { |
646 int keylen; | 646 int keylen; |
647 unsigned char key[32], pt[16], ct[16]; | 647 unsigned char key[32], pt[16], ct[16]; |
648 } tests[] = { | 648 } tests[] = { |
649 { 16, | 649 { 16, |
650 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 650 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
651 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | 651 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
652 { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 652 { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
653 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 653 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
654 { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, | 654 { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, |
655 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a } | 655 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a } |
656 }, { | 656 }, { |
657 24, | 657 24, |
658 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 658 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
659 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 659 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
660 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, | 660 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, |
661 { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 661 { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
662 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 662 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
663 { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0, | 663 { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0, |
664 0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 } | 664 0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 } |
665 }, { | 665 }, { |
666 32, | 666 32, |
667 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 667 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
668 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 668 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
669 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | 669 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
670 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, | 670 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, |
671 { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 671 { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
672 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 672 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
673 { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, | 673 { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, |
674 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 } | 674 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 } |
675 } | 675 } |
676 }; | 676 }; |
677 | 677 |
678 symmetric_key key; | 678 symmetric_key key; |
679 unsigned char tmp[2][16]; | 679 unsigned char tmp[2][16]; |
680 int i, y; | 680 int i, y; |
681 | 681 |
682 for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) { | 682 for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) { |
683 zeromem(&key, sizeof(key)); | 683 zeromem(&key, sizeof(key)); |
684 if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) { | 684 if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) { |
685 return err; | 685 return err; |
686 } | 686 } |
687 | 687 |
688 rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key); | 688 rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key); |
689 rijndael_ecb_decrypt(tmp[0], tmp[1], &key); | 689 rijndael_ecb_decrypt(tmp[0], tmp[1], &key); |
690 if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "AES Encrypt", i) || | 690 if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "AES Encrypt", i) || |
691 compare_testvector(tmp[1], 16, tests[i].pt, 16, "AES Decrypt", i)) { | 691 compare_testvector(tmp[1], 16, tests[i].pt, 16, "AES Decrypt", i)) { |
692 return CRYPT_FAIL_TESTVECTOR; | 692 return CRYPT_FAIL_TESTVECTOR; |
693 } | 693 } |
694 | 694 |
695 /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ | 695 /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ |
696 for (y = 0; y < 16; y++) tmp[0][y] = 0; | 696 for (y = 0; y < 16; y++) tmp[0][y] = 0; |
697 for (y = 0; y < 1000; y++) rijndael_ecb_encrypt(tmp[0], tmp[0], &key); | 697 for (y = 0; y < 1000; y++) rijndael_ecb_encrypt(tmp[0], tmp[0], &key); |
698 for (y = 0; y < 1000; y++) rijndael_ecb_decrypt(tmp[0], tmp[0], &key); | 698 for (y = 0; y < 1000; y++) rijndael_ecb_decrypt(tmp[0], tmp[0], &key); |
699 for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR; | 699 for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR; |
700 } | 700 } |
701 return CRYPT_OK; | 701 return CRYPT_OK; |
702 #endif | 702 #endif |
703 } | 703 } |
704 | 704 |
705 #endif /* ENCRYPT_ONLY */ | 705 #endif /* ENCRYPT_ONLY */ |
706 | 706 |
707 | 707 |
708 /** Terminate the context | 708 /** Terminate the context |
709 @param skey The scheduled key | 709 @param skey The scheduled key |
710 */ | 710 */ |
711 void ECB_DONE(symmetric_key *skey) | 711 void ECB_DONE(symmetric_key *skey) |
712 { | 712 { |
713 LTC_UNUSED_PARAM(skey); | 713 LTC_UNUSED_PARAM(skey); |