PolarSSL v1.2.8
test_suite_aes.ecb.c
Go to the documentation of this file.
1 #include "fct.h"
2 #include <polarssl/config.h>
3 
4 #include <polarssl/aes.h>
5 
6 #ifdef _MSC_VER
7 #include <basetsd.h>
8 typedef UINT32 uint32_t;
9 #else
10 #include <inttypes.h>
11 #endif
12 
13 /*
14  * 32-bit integer manipulation macros (big endian)
15  */
16 #ifndef GET_UINT32_BE
17 #define GET_UINT32_BE(n,b,i) \
18 { \
19  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
20  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
21  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
22  | ( (uint32_t) (b)[(i) + 3] ); \
23 }
24 #endif
25 
26 #ifndef PUT_UINT32_BE
27 #define PUT_UINT32_BE(n,b,i) \
28 { \
29  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
30  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
31  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
32  (b)[(i) + 3] = (unsigned char) ( (n) ); \
33 }
34 #endif
35 
36 int unhexify(unsigned char *obuf, const char *ibuf)
37 {
38  unsigned char c, c2;
39  int len = strlen(ibuf) / 2;
40  assert(!(strlen(ibuf) %1)); // must be even number of bytes
41 
42  while (*ibuf != 0)
43  {
44  c = *ibuf++;
45  if( c >= '0' && c <= '9' )
46  c -= '0';
47  else if( c >= 'a' && c <= 'f' )
48  c -= 'a' - 10;
49  else if( c >= 'A' && c <= 'F' )
50  c -= 'A' - 10;
51  else
52  assert( 0 );
53 
54  c2 = *ibuf++;
55  if( c2 >= '0' && c2 <= '9' )
56  c2 -= '0';
57  else if( c2 >= 'a' && c2 <= 'f' )
58  c2 -= 'a' - 10;
59  else if( c2 >= 'A' && c2 <= 'F' )
60  c2 -= 'A' - 10;
61  else
62  assert( 0 );
63 
64  *obuf++ = ( c << 4 ) | c2;
65  }
66 
67  return len;
68 }
69 
70 void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
71 {
72  unsigned char l, h;
73 
74  while (len != 0)
75  {
76  h = (*ibuf) / 16;
77  l = (*ibuf) % 16;
78 
79  if( h < 10 )
80  *obuf++ = '0' + h;
81  else
82  *obuf++ = 'a' + h - 10;
83 
84  if( l < 10 )
85  *obuf++ = '0' + l;
86  else
87  *obuf++ = 'a' + l - 10;
88 
89  ++ibuf;
90  len--;
91  }
92 }
93 
103 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
104 {
105  size_t i;
106 
107  if( rng_state != NULL )
108  rng_state = NULL;
109 
110  for( i = 0; i < len; ++i )
111  output[i] = rand();
112 
113  return( 0 );
114 }
115 
121 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
122 {
123  if( rng_state != NULL )
124  rng_state = NULL;
125 
126  memset( output, 0, len );
127 
128  return( 0 );
129 }
130 
131 typedef struct
132 {
133  unsigned char *buf;
134  size_t length;
135 } rnd_buf_info;
136 
148 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
149 {
150  rnd_buf_info *info = (rnd_buf_info *) rng_state;
151  size_t use_len;
152 
153  if( rng_state == NULL )
154  return( rnd_std_rand( NULL, output, len ) );
155 
156  use_len = len;
157  if( len > info->length )
158  use_len = info->length;
159 
160  if( use_len )
161  {
162  memcpy( output, info->buf, use_len );
163  info->buf += use_len;
164  info->length -= use_len;
165  }
166 
167  if( len - use_len > 0 )
168  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
169 
170  return( 0 );
171 }
172 
180 typedef struct
181 {
182  uint32_t key[16];
183  uint32_t v0, v1;
185 
194 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
195 {
196  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
197  uint32_t i, *k, sum, delta=0x9E3779B9;
198  unsigned char result[4];
199 
200  if( rng_state == NULL )
201  return( rnd_std_rand( NULL, output, len ) );
202 
203  k = info->key;
204 
205  while( len > 0 )
206  {
207  size_t use_len = ( len > 4 ) ? 4 : len;
208  sum = 0;
209 
210  for( i = 0; i < 32; i++ )
211  {
212  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
213  sum += delta;
214  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
215  }
216 
217  PUT_UINT32_BE( info->v0, result, 0 );
218  memcpy( output, result, use_len );
219  len -= use_len;
220  }
221 
222  return( 0 );
223 }
224 
225 
227 {
228 #ifdef POLARSSL_AES_C
229 
230 
231  FCT_SUITE_BGN(test_suite_aes)
232  {
233 
234  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_1)
235  {
236  unsigned char key_str[100];
237  unsigned char src_str[100];
238  unsigned char dst_str[100];
239  unsigned char output[100];
240  aes_context ctx;
241  int key_len;
242 
243  memset(key_str, 0x00, 100);
244  memset(src_str, 0x00, 100);
245  memset(dst_str, 0x00, 100);
246  memset(output, 0x00, 100);
247 
248  key_len = unhexify( key_str, "00000000000000000000000000000000" );
249  unhexify( src_str, "f34481ec3cc627bacd5dc3fb08f273e6" );
250 
251  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
252  if( 0 == 0 )
253  {
254  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
255  hexify( dst_str, output, 16 );
256 
257  fct_chk( strcmp( (char *) dst_str, "0336763e966d92595a567cc9ce537f5e" ) == 0 );
258  }
259  }
260  FCT_TEST_END();
261 
262 
263  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_2)
264  {
265  unsigned char key_str[100];
266  unsigned char src_str[100];
267  unsigned char dst_str[100];
268  unsigned char output[100];
269  aes_context ctx;
270  int key_len;
271 
272  memset(key_str, 0x00, 100);
273  memset(src_str, 0x00, 100);
274  memset(dst_str, 0x00, 100);
275  memset(output, 0x00, 100);
276 
277  key_len = unhexify( key_str, "00000000000000000000000000000000" );
278  unhexify( src_str, "9798c4640bad75c7c3227db910174e72" );
279 
280  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
281  if( 0 == 0 )
282  {
283  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
284  hexify( dst_str, output, 16 );
285 
286  fct_chk( strcmp( (char *) dst_str, "a9a1631bf4996954ebc093957b234589" ) == 0 );
287  }
288  }
289  FCT_TEST_END();
290 
291 
292  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_3)
293  {
294  unsigned char key_str[100];
295  unsigned char src_str[100];
296  unsigned char dst_str[100];
297  unsigned char output[100];
298  aes_context ctx;
299  int key_len;
300 
301  memset(key_str, 0x00, 100);
302  memset(src_str, 0x00, 100);
303  memset(dst_str, 0x00, 100);
304  memset(output, 0x00, 100);
305 
306  key_len = unhexify( key_str, "00000000000000000000000000000000" );
307  unhexify( src_str, "96ab5c2ff612d9dfaae8c31f30c42168" );
308 
309  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
310  if( 0 == 0 )
311  {
312  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
313  hexify( dst_str, output, 16 );
314 
315  fct_chk( strcmp( (char *) dst_str, "ff4f8391a6a40ca5b25d23bedd44a597" ) == 0 );
316  }
317  }
318  FCT_TEST_END();
319 
320 
321  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_4)
322  {
323  unsigned char key_str[100];
324  unsigned char src_str[100];
325  unsigned char dst_str[100];
326  unsigned char output[100];
327  aes_context ctx;
328  int key_len;
329 
330  memset(key_str, 0x00, 100);
331  memset(src_str, 0x00, 100);
332  memset(dst_str, 0x00, 100);
333  memset(output, 0x00, 100);
334 
335  key_len = unhexify( key_str, "e0000000000000000000000000000000" );
336  unhexify( src_str, "00000000000000000000000000000000" );
337 
338  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
339  if( 0 == 0 )
340  {
341  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
342  hexify( dst_str, output, 16 );
343 
344  fct_chk( strcmp( (char *) dst_str, "72a1da770f5d7ac4c9ef94d822affd97" ) == 0 );
345  }
346  }
347  FCT_TEST_END();
348 
349 
350  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_5)
351  {
352  unsigned char key_str[100];
353  unsigned char src_str[100];
354  unsigned char dst_str[100];
355  unsigned char output[100];
356  aes_context ctx;
357  int key_len;
358 
359  memset(key_str, 0x00, 100);
360  memset(src_str, 0x00, 100);
361  memset(dst_str, 0x00, 100);
362  memset(output, 0x00, 100);
363 
364  key_len = unhexify( key_str, "f0000000000000000000000000000000" );
365  unhexify( src_str, "00000000000000000000000000000000" );
366 
367  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
368  if( 0 == 0 )
369  {
370  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
371  hexify( dst_str, output, 16 );
372 
373  fct_chk( strcmp( (char *) dst_str, "970014d634e2b7650777e8e84d03ccd8" ) == 0 );
374  }
375  }
376  FCT_TEST_END();
377 
378 
379  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_6)
380  {
381  unsigned char key_str[100];
382  unsigned char src_str[100];
383  unsigned char dst_str[100];
384  unsigned char output[100];
385  aes_context ctx;
386  int key_len;
387 
388  memset(key_str, 0x00, 100);
389  memset(src_str, 0x00, 100);
390  memset(dst_str, 0x00, 100);
391  memset(output, 0x00, 100);
392 
393  key_len = unhexify( key_str, "f8000000000000000000000000000000" );
394  unhexify( src_str, "00000000000000000000000000000000" );
395 
396  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
397  if( 0 == 0 )
398  {
399  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
400  hexify( dst_str, output, 16 );
401 
402  fct_chk( strcmp( (char *) dst_str, "f17e79aed0db7e279e955b5f493875a7" ) == 0 );
403  }
404  }
405  FCT_TEST_END();
406 
407 
408  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_7)
409  {
410  unsigned char key_str[100];
411  unsigned char src_str[100];
412  unsigned char dst_str[100];
413  unsigned char output[100];
414  aes_context ctx;
415  int key_len;
416 
417  memset(key_str, 0x00, 100);
418  memset(src_str, 0x00, 100);
419  memset(dst_str, 0x00, 100);
420  memset(output, 0x00, 100);
421 
422  key_len = unhexify( key_str, "fffffffffffff0000000000000000000" );
423  unhexify( src_str, "00000000000000000000000000000000" );
424 
425  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
426  if( 0 == 0 )
427  {
428  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
429  hexify( dst_str, output, 16 );
430 
431  fct_chk( strcmp( (char *) dst_str, "7b90785125505fad59b13c186dd66ce3" ) == 0 );
432  }
433  }
434  FCT_TEST_END();
435 
436 
437  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_8)
438  {
439  unsigned char key_str[100];
440  unsigned char src_str[100];
441  unsigned char dst_str[100];
442  unsigned char output[100];
443  aes_context ctx;
444  int key_len;
445 
446  memset(key_str, 0x00, 100);
447  memset(src_str, 0x00, 100);
448  memset(dst_str, 0x00, 100);
449  memset(output, 0x00, 100);
450 
451  key_len = unhexify( key_str, "fffffffffffff8000000000000000000" );
452  unhexify( src_str, "00000000000000000000000000000000" );
453 
454  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
455  if( 0 == 0 )
456  {
457  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
458  hexify( dst_str, output, 16 );
459 
460  fct_chk( strcmp( (char *) dst_str, "8b527a6aebdaec9eaef8eda2cb7783e5" ) == 0 );
461  }
462  }
463  FCT_TEST_END();
464 
465 
466  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_9)
467  {
468  unsigned char key_str[100];
469  unsigned char src_str[100];
470  unsigned char dst_str[100];
471  unsigned char output[100];
472  aes_context ctx;
473  int key_len;
474 
475  memset(key_str, 0x00, 100);
476  memset(src_str, 0x00, 100);
477  memset(dst_str, 0x00, 100);
478  memset(output, 0x00, 100);
479 
480  key_len = unhexify( key_str, "fffffffffffffc000000000000000000" );
481  unhexify( src_str, "00000000000000000000000000000000" );
482 
483  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
484  if( 0 == 0 )
485  {
486  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
487  hexify( dst_str, output, 16 );
488 
489  fct_chk( strcmp( (char *) dst_str, "43fdaf53ebbc9880c228617d6a9b548b" ) == 0 );
490  }
491  }
492  FCT_TEST_END();
493 
494 
495  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_10)
496  {
497  unsigned char key_str[100];
498  unsigned char src_str[100];
499  unsigned char dst_str[100];
500  unsigned char output[100];
501  aes_context ctx;
502  int key_len;
503 
504  memset(key_str, 0x00, 100);
505  memset(src_str, 0x00, 100);
506  memset(dst_str, 0x00, 100);
507  memset(output, 0x00, 100);
508 
509  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffc000" );
510  unhexify( src_str, "00000000000000000000000000000000" );
511 
512  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
513  if( 0 == 0 )
514  {
515  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
516  hexify( dst_str, output, 16 );
517 
518  fct_chk( strcmp( (char *) dst_str, "70c46bb30692be657f7eaa93ebad9897" ) == 0 );
519  }
520  }
521  FCT_TEST_END();
522 
523 
524  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_11)
525  {
526  unsigned char key_str[100];
527  unsigned char src_str[100];
528  unsigned char dst_str[100];
529  unsigned char output[100];
530  aes_context ctx;
531  int key_len;
532 
533  memset(key_str, 0x00, 100);
534  memset(src_str, 0x00, 100);
535  memset(dst_str, 0x00, 100);
536  memset(output, 0x00, 100);
537 
538  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffe000" );
539  unhexify( src_str, "00000000000000000000000000000000" );
540 
541  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
542  if( 0 == 0 )
543  {
544  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
545  hexify( dst_str, output, 16 );
546 
547  fct_chk( strcmp( (char *) dst_str, "323994cfb9da285a5d9642e1759b224a" ) == 0 );
548  }
549  }
550  FCT_TEST_END();
551 
552 
553  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_12)
554  {
555  unsigned char key_str[100];
556  unsigned char src_str[100];
557  unsigned char dst_str[100];
558  unsigned char output[100];
559  aes_context ctx;
560  int key_len;
561 
562  memset(key_str, 0x00, 100);
563  memset(src_str, 0x00, 100);
564  memset(dst_str, 0x00, 100);
565  memset(output, 0x00, 100);
566 
567  key_len = unhexify( key_str, "fffffffffffffffffffffffffffff000" );
568  unhexify( src_str, "00000000000000000000000000000000" );
569 
570  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
571  if( 0 == 0 )
572  {
573  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
574  hexify( dst_str, output, 16 );
575 
576  fct_chk( strcmp( (char *) dst_str, "1dbf57877b7b17385c85d0b54851e371" ) == 0 );
577  }
578  }
579  FCT_TEST_END();
580 
581 
582  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_13)
583  {
584  unsigned char key_str[100];
585  unsigned char src_str[100];
586  unsigned char dst_str[100];
587  unsigned char output[100];
588  aes_context ctx;
589  int key_len;
590 
591  memset(key_str, 0x00, 100);
592  memset(src_str, 0x00, 100);
593  memset(dst_str, 0x00, 100);
594  memset(output, 0x00, 100);
595 
596  key_len = unhexify( key_str, "00000000000000000000000000000000" );
597  unhexify( src_str, "ffffffffffffffc00000000000000000" );
598 
599  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
600  if( 0 == 0 )
601  {
602  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
603  hexify( dst_str, output, 16 );
604 
605  fct_chk( strcmp( (char *) dst_str, "3a4d354f02bb5a5e47d39666867f246a" ) == 0 );
606  }
607  }
608  FCT_TEST_END();
609 
610 
611  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_14)
612  {
613  unsigned char key_str[100];
614  unsigned char src_str[100];
615  unsigned char dst_str[100];
616  unsigned char output[100];
617  aes_context ctx;
618  int key_len;
619 
620  memset(key_str, 0x00, 100);
621  memset(src_str, 0x00, 100);
622  memset(dst_str, 0x00, 100);
623  memset(output, 0x00, 100);
624 
625  key_len = unhexify( key_str, "00000000000000000000000000000000" );
626  unhexify( src_str, "ffffffffffffffe00000000000000000" );
627 
628  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
629  if( 0 == 0 )
630  {
631  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
632  hexify( dst_str, output, 16 );
633 
634  fct_chk( strcmp( (char *) dst_str, "d451b8d6e1e1a0ebb155fbbf6e7b7dc3" ) == 0 );
635  }
636  }
637  FCT_TEST_END();
638 
639 
640  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_15)
641  {
642  unsigned char key_str[100];
643  unsigned char src_str[100];
644  unsigned char dst_str[100];
645  unsigned char output[100];
646  aes_context ctx;
647  int key_len;
648 
649  memset(key_str, 0x00, 100);
650  memset(src_str, 0x00, 100);
651  memset(dst_str, 0x00, 100);
652  memset(output, 0x00, 100);
653 
654  key_len = unhexify( key_str, "00000000000000000000000000000000" );
655  unhexify( src_str, "fffffffffffffff00000000000000000" );
656 
657  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
658  if( 0 == 0 )
659  {
660  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
661  hexify( dst_str, output, 16 );
662 
663  fct_chk( strcmp( (char *) dst_str, "6898d4f42fa7ba6a10ac05e87b9f2080" ) == 0 );
664  }
665  }
666  FCT_TEST_END();
667 
668 
669  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_16)
670  {
671  unsigned char key_str[100];
672  unsigned char src_str[100];
673  unsigned char dst_str[100];
674  unsigned char output[100];
675  aes_context ctx;
676  int key_len;
677 
678  memset(key_str, 0x00, 100);
679  memset(src_str, 0x00, 100);
680  memset(dst_str, 0x00, 100);
681  memset(output, 0x00, 100);
682 
683  key_len = unhexify( key_str, "00000000000000000000000000000000" );
684  unhexify( src_str, "ffffffffffffffffffffffffe0000000" );
685 
686  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
687  if( 0 == 0 )
688  {
689  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
690  hexify( dst_str, output, 16 );
691 
692  fct_chk( strcmp( (char *) dst_str, "082eb8be35f442fb52668e16a591d1d6" ) == 0 );
693  }
694  }
695  FCT_TEST_END();
696 
697 
698  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_17)
699  {
700  unsigned char key_str[100];
701  unsigned char src_str[100];
702  unsigned char dst_str[100];
703  unsigned char output[100];
704  aes_context ctx;
705  int key_len;
706 
707  memset(key_str, 0x00, 100);
708  memset(src_str, 0x00, 100);
709  memset(dst_str, 0x00, 100);
710  memset(output, 0x00, 100);
711 
712  key_len = unhexify( key_str, "00000000000000000000000000000000" );
713  unhexify( src_str, "fffffffffffffffffffffffff0000000" );
714 
715  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
716  if( 0 == 0 )
717  {
718  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
719  hexify( dst_str, output, 16 );
720 
721  fct_chk( strcmp( (char *) dst_str, "e656f9ecf5fe27ec3e4a73d00c282fb3" ) == 0 );
722  }
723  }
724  FCT_TEST_END();
725 
726 
727  FCT_TEST_BGN(aes_128_ecb_encrypt_nist_kat_18)
728  {
729  unsigned char key_str[100];
730  unsigned char src_str[100];
731  unsigned char dst_str[100];
732  unsigned char output[100];
733  aes_context ctx;
734  int key_len;
735 
736  memset(key_str, 0x00, 100);
737  memset(src_str, 0x00, 100);
738  memset(dst_str, 0x00, 100);
739  memset(output, 0x00, 100);
740 
741  key_len = unhexify( key_str, "00000000000000000000000000000000" );
742  unhexify( src_str, "fffffffffffffffffffffffff8000000" );
743 
744  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
745  if( 0 == 0 )
746  {
747  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
748  hexify( dst_str, output, 16 );
749 
750  fct_chk( strcmp( (char *) dst_str, "2ca8209d63274cd9a29bb74bcd77683a" ) == 0 );
751  }
752  }
753  FCT_TEST_END();
754 
755 
756  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_1)
757  {
758  unsigned char key_str[100];
759  unsigned char src_str[100];
760  unsigned char dst_str[100];
761  unsigned char output[100];
762  aes_context ctx;
763  int key_len;
764 
765  memset(key_str, 0x00, 100);
766  memset(src_str, 0x00, 100);
767  memset(dst_str, 0x00, 100);
768  memset(output, 0x00, 100);
769 
770  key_len = unhexify( key_str, "00000000000000000000000000000000" );
771  unhexify( src_str, "db4f1aa530967d6732ce4715eb0ee24b" );
772 
773  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
774  if( 0 == 0 )
775  {
776  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
777  hexify( dst_str, output, 16 );
778 
779  fct_chk( strcmp( (char *) dst_str, "ff000000000000000000000000000000" ) == 0 );
780  }
781  }
782  FCT_TEST_END();
783 
784 
785  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_2)
786  {
787  unsigned char key_str[100];
788  unsigned char src_str[100];
789  unsigned char dst_str[100];
790  unsigned char output[100];
791  aes_context ctx;
792  int key_len;
793 
794  memset(key_str, 0x00, 100);
795  memset(src_str, 0x00, 100);
796  memset(dst_str, 0x00, 100);
797  memset(output, 0x00, 100);
798 
799  key_len = unhexify( key_str, "00000000000000000000000000000000" );
800  unhexify( src_str, "a81738252621dd180a34f3455b4baa2f" );
801 
802  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
803  if( 0 == 0 )
804  {
805  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
806  hexify( dst_str, output, 16 );
807 
808  fct_chk( strcmp( (char *) dst_str, "ff800000000000000000000000000000" ) == 0 );
809  }
810  }
811  FCT_TEST_END();
812 
813 
814  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_3)
815  {
816  unsigned char key_str[100];
817  unsigned char src_str[100];
818  unsigned char dst_str[100];
819  unsigned char output[100];
820  aes_context ctx;
821  int key_len;
822 
823  memset(key_str, 0x00, 100);
824  memset(src_str, 0x00, 100);
825  memset(dst_str, 0x00, 100);
826  memset(output, 0x00, 100);
827 
828  key_len = unhexify( key_str, "00000000000000000000000000000000" );
829  unhexify( src_str, "77e2b508db7fd89234caf7939ee5621a" );
830 
831  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
832  if( 0 == 0 )
833  {
834  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
835  hexify( dst_str, output, 16 );
836 
837  fct_chk( strcmp( (char *) dst_str, "ffc00000000000000000000000000000" ) == 0 );
838  }
839  }
840  FCT_TEST_END();
841 
842 
843  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_4)
844  {
845  unsigned char key_str[100];
846  unsigned char src_str[100];
847  unsigned char dst_str[100];
848  unsigned char output[100];
849  aes_context ctx;
850  int key_len;
851 
852  memset(key_str, 0x00, 100);
853  memset(src_str, 0x00, 100);
854  memset(dst_str, 0x00, 100);
855  memset(output, 0x00, 100);
856 
857  key_len = unhexify( key_str, "00000000000000000000000000000000" );
858  unhexify( src_str, "dc43be40be0e53712f7e2bf5ca707209" );
859 
860  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
861  if( 0 == 0 )
862  {
863  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
864  hexify( dst_str, output, 16 );
865 
866  fct_chk( strcmp( (char *) dst_str, "6a118a874519e64e9963798a503f1d35" ) == 0 );
867  }
868  }
869  FCT_TEST_END();
870 
871 
872  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_5)
873  {
874  unsigned char key_str[100];
875  unsigned char src_str[100];
876  unsigned char dst_str[100];
877  unsigned char output[100];
878  aes_context ctx;
879  int key_len;
880 
881  memset(key_str, 0x00, 100);
882  memset(src_str, 0x00, 100);
883  memset(dst_str, 0x00, 100);
884  memset(output, 0x00, 100);
885 
886  key_len = unhexify( key_str, "00000000000000000000000000000000" );
887  unhexify( src_str, "92beedab1895a94faa69b632e5cc47ce" );
888 
889  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
890  if( 0 == 0 )
891  {
892  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
893  hexify( dst_str, output, 16 );
894 
895  fct_chk( strcmp( (char *) dst_str, "cb9fceec81286ca3e989bd979b0cb284" ) == 0 );
896  }
897  }
898  FCT_TEST_END();
899 
900 
901  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_6)
902  {
903  unsigned char key_str[100];
904  unsigned char src_str[100];
905  unsigned char dst_str[100];
906  unsigned char output[100];
907  aes_context ctx;
908  int key_len;
909 
910  memset(key_str, 0x00, 100);
911  memset(src_str, 0x00, 100);
912  memset(dst_str, 0x00, 100);
913  memset(output, 0x00, 100);
914 
915  key_len = unhexify( key_str, "00000000000000000000000000000000" );
916  unhexify( src_str, "459264f4798f6a78bacb89c15ed3d601" );
917 
918  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
919  if( 0 == 0 )
920  {
921  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
922  hexify( dst_str, output, 16 );
923 
924  fct_chk( strcmp( (char *) dst_str, "b26aeb1874e47ca8358ff22378f09144" ) == 0 );
925  }
926  }
927  FCT_TEST_END();
928 
929 
930  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_7)
931  {
932  unsigned char key_str[100];
933  unsigned char src_str[100];
934  unsigned char dst_str[100];
935  unsigned char output[100];
936  aes_context ctx;
937  int key_len;
938 
939  memset(key_str, 0x00, 100);
940  memset(src_str, 0x00, 100);
941  memset(dst_str, 0x00, 100);
942  memset(output, 0x00, 100);
943 
944  key_len = unhexify( key_str, "b69418a85332240dc82492353956ae0c" );
945  unhexify( src_str, "a303d940ded8f0baff6f75414cac5243" );
946 
947  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
948  if( 0 == 0 )
949  {
950  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
951  hexify( dst_str, output, 16 );
952 
953  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
954  }
955  }
956  FCT_TEST_END();
957 
958 
959  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_8)
960  {
961  unsigned char key_str[100];
962  unsigned char src_str[100];
963  unsigned char dst_str[100];
964  unsigned char output[100];
965  aes_context ctx;
966  int key_len;
967 
968  memset(key_str, 0x00, 100);
969  memset(src_str, 0x00, 100);
970  memset(dst_str, 0x00, 100);
971  memset(output, 0x00, 100);
972 
973  key_len = unhexify( key_str, "71b5c08a1993e1362e4d0ce9b22b78d5" );
974  unhexify( src_str, "c2dabd117f8a3ecabfbb11d12194d9d0" );
975 
976  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
977  if( 0 == 0 )
978  {
979  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
980  hexify( dst_str, output, 16 );
981 
982  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
983  }
984  }
985  FCT_TEST_END();
986 
987 
988  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_9)
989  {
990  unsigned char key_str[100];
991  unsigned char src_str[100];
992  unsigned char dst_str[100];
993  unsigned char output[100];
994  aes_context ctx;
995  int key_len;
996 
997  memset(key_str, 0x00, 100);
998  memset(src_str, 0x00, 100);
999  memset(dst_str, 0x00, 100);
1000  memset(output, 0x00, 100);
1001 
1002  key_len = unhexify( key_str, "e234cdca2606b81f29408d5f6da21206" );
1003  unhexify( src_str, "fff60a4740086b3b9c56195b98d91a7b" );
1004 
1005  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1006  if( 0 == 0 )
1007  {
1008  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1009  hexify( dst_str, output, 16 );
1010 
1011  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1012  }
1013  }
1014  FCT_TEST_END();
1015 
1016 
1017  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_10)
1018  {
1019  unsigned char key_str[100];
1020  unsigned char src_str[100];
1021  unsigned char dst_str[100];
1022  unsigned char output[100];
1023  aes_context ctx;
1024  int key_len;
1025 
1026  memset(key_str, 0x00, 100);
1027  memset(src_str, 0x00, 100);
1028  memset(dst_str, 0x00, 100);
1029  memset(output, 0x00, 100);
1030 
1031  key_len = unhexify( key_str, "ffffffffffffffff0000000000000000" );
1032  unhexify( src_str, "84be19e053635f09f2665e7bae85b42d" );
1033 
1034  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1035  if( 0 == 0 )
1036  {
1037  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1038  hexify( dst_str, output, 16 );
1039 
1040  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1041  }
1042  }
1043  FCT_TEST_END();
1044 
1045 
1046  FCT_TEST_BGN(aes_128_ecb_decrypt_nist_kat_11)
1047  {
1048  unsigned char key_str[100];
1049  unsigned char src_str[100];
1050  unsigned char dst_str[100];
1051  unsigned char output[100];
1052  aes_context ctx;
1053  int key_len;
1054 
1055  memset(key_str, 0x00, 100);
1056  memset(src_str, 0x00, 100);
1057  memset(dst_str, 0x00, 100);
1058  memset(output, 0x00, 100);
1059 
1060  key_len = unhexify( key_str, "ffffffffffffffff8000000000000000" );
1061  unhexify( src_str, "32cd652842926aea4aa6137bb2be2b5e" );
1062 
1063  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1064  if( 0 == 0 )
1065  {
1066  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1067  hexify( dst_str, output, 16 );
1068 
1069  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1070  }
1071  }
1072  FCT_TEST_END();
1073 
1074 
1075  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_1)
1076  {
1077  unsigned char key_str[100];
1078  unsigned char src_str[100];
1079  unsigned char dst_str[100];
1080  unsigned char output[100];
1081  aes_context ctx;
1082  int key_len;
1083 
1084  memset(key_str, 0x00, 100);
1085  memset(src_str, 0x00, 100);
1086  memset(dst_str, 0x00, 100);
1087  memset(output, 0x00, 100);
1088 
1089  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1090  unhexify( src_str, "fffffffffffffffffffff80000000000" );
1091 
1092  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1093  if( 0 == 0 )
1094  {
1095  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1096  hexify( dst_str, output, 16 );
1097 
1098  fct_chk( strcmp( (char *) dst_str, "156f07767a85a4312321f63968338a01" ) == 0 );
1099  }
1100  }
1101  FCT_TEST_END();
1102 
1103 
1104  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_2)
1105  {
1106  unsigned char key_str[100];
1107  unsigned char src_str[100];
1108  unsigned char dst_str[100];
1109  unsigned char output[100];
1110  aes_context ctx;
1111  int key_len;
1112 
1113  memset(key_str, 0x00, 100);
1114  memset(src_str, 0x00, 100);
1115  memset(dst_str, 0x00, 100);
1116  memset(output, 0x00, 100);
1117 
1118  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1119  unhexify( src_str, "fffffffffffffffffffffc0000000000" );
1120 
1121  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1122  if( 0 == 0 )
1123  {
1124  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1125  hexify( dst_str, output, 16 );
1126 
1127  fct_chk( strcmp( (char *) dst_str, "15eec9ebf42b9ca76897d2cd6c5a12e2" ) == 0 );
1128  }
1129  }
1130  FCT_TEST_END();
1131 
1132 
1133  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_3)
1134  {
1135  unsigned char key_str[100];
1136  unsigned char src_str[100];
1137  unsigned char dst_str[100];
1138  unsigned char output[100];
1139  aes_context ctx;
1140  int key_len;
1141 
1142  memset(key_str, 0x00, 100);
1143  memset(src_str, 0x00, 100);
1144  memset(dst_str, 0x00, 100);
1145  memset(output, 0x00, 100);
1146 
1147  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1148  unhexify( src_str, "fffffffffffffffffffffe0000000000" );
1149 
1150  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1151  if( 0 == 0 )
1152  {
1153  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1154  hexify( dst_str, output, 16 );
1155 
1156  fct_chk( strcmp( (char *) dst_str, "db0d3a6fdcc13f915e2b302ceeb70fd8" ) == 0 );
1157  }
1158  }
1159  FCT_TEST_END();
1160 
1161 
1162  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_4)
1163  {
1164  unsigned char key_str[100];
1165  unsigned char src_str[100];
1166  unsigned char dst_str[100];
1167  unsigned char output[100];
1168  aes_context ctx;
1169  int key_len;
1170 
1171  memset(key_str, 0x00, 100);
1172  memset(src_str, 0x00, 100);
1173  memset(dst_str, 0x00, 100);
1174  memset(output, 0x00, 100);
1175 
1176  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1177  unhexify( src_str, "51719783d3185a535bd75adc65071ce1" );
1178 
1179  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1180  if( 0 == 0 )
1181  {
1182  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1183  hexify( dst_str, output, 16 );
1184 
1185  fct_chk( strcmp( (char *) dst_str, "4f354592ff7c8847d2d0870ca9481b7c" ) == 0 );
1186  }
1187  }
1188  FCT_TEST_END();
1189 
1190 
1191  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_5)
1192  {
1193  unsigned char key_str[100];
1194  unsigned char src_str[100];
1195  unsigned char dst_str[100];
1196  unsigned char output[100];
1197  aes_context ctx;
1198  int key_len;
1199 
1200  memset(key_str, 0x00, 100);
1201  memset(src_str, 0x00, 100);
1202  memset(dst_str, 0x00, 100);
1203  memset(output, 0x00, 100);
1204 
1205  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1206  unhexify( src_str, "26aa49dcfe7629a8901a69a9914e6dfd" );
1207 
1208  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1209  if( 0 == 0 )
1210  {
1211  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1212  hexify( dst_str, output, 16 );
1213 
1214  fct_chk( strcmp( (char *) dst_str, "d5e08bf9a182e857cf40b3a36ee248cc" ) == 0 );
1215  }
1216  }
1217  FCT_TEST_END();
1218 
1219 
1220  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_6)
1221  {
1222  unsigned char key_str[100];
1223  unsigned char src_str[100];
1224  unsigned char dst_str[100];
1225  unsigned char output[100];
1226  aes_context ctx;
1227  int key_len;
1228 
1229  memset(key_str, 0x00, 100);
1230  memset(src_str, 0x00, 100);
1231  memset(dst_str, 0x00, 100);
1232  memset(output, 0x00, 100);
1233 
1234  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1235  unhexify( src_str, "941a4773058224e1ef66d10e0a6ee782" );
1236 
1237  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1238  if( 0 == 0 )
1239  {
1240  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1241  hexify( dst_str, output, 16 );
1242 
1243  fct_chk( strcmp( (char *) dst_str, "067cd9d3749207791841562507fa9626" ) == 0 );
1244  }
1245  }
1246  FCT_TEST_END();
1247 
1248 
1249  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_7)
1250  {
1251  unsigned char key_str[100];
1252  unsigned char src_str[100];
1253  unsigned char dst_str[100];
1254  unsigned char output[100];
1255  aes_context ctx;
1256  int key_len;
1257 
1258  memset(key_str, 0x00, 100);
1259  memset(src_str, 0x00, 100);
1260  memset(dst_str, 0x00, 100);
1261  memset(output, 0x00, 100);
1262 
1263  key_len = unhexify( key_str, "d2926527e0aa9f37b45e2ec2ade5853ef807576104c7ace3" );
1264  unhexify( src_str, "00000000000000000000000000000000" );
1265 
1266  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1267  if( 0 == 0 )
1268  {
1269  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1270  hexify( dst_str, output, 16 );
1271 
1272  fct_chk( strcmp( (char *) dst_str, "dd619e1cf204446112e0af2b9afa8f8c" ) == 0 );
1273  }
1274  }
1275  FCT_TEST_END();
1276 
1277 
1278  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_8)
1279  {
1280  unsigned char key_str[100];
1281  unsigned char src_str[100];
1282  unsigned char dst_str[100];
1283  unsigned char output[100];
1284  aes_context ctx;
1285  int key_len;
1286 
1287  memset(key_str, 0x00, 100);
1288  memset(src_str, 0x00, 100);
1289  memset(dst_str, 0x00, 100);
1290  memset(output, 0x00, 100);
1291 
1292  key_len = unhexify( key_str, "982215f4e173dfa0fcffe5d3da41c4812c7bcc8ed3540f93" );
1293  unhexify( src_str, "00000000000000000000000000000000" );
1294 
1295  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1296  if( 0 == 0 )
1297  {
1298  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1299  hexify( dst_str, output, 16 );
1300 
1301  fct_chk( strcmp( (char *) dst_str, "d4f0aae13c8fe9339fbf9e69ed0ad74d" ) == 0 );
1302  }
1303  }
1304  FCT_TEST_END();
1305 
1306 
1307  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_9)
1308  {
1309  unsigned char key_str[100];
1310  unsigned char src_str[100];
1311  unsigned char dst_str[100];
1312  unsigned char output[100];
1313  aes_context ctx;
1314  int key_len;
1315 
1316  memset(key_str, 0x00, 100);
1317  memset(src_str, 0x00, 100);
1318  memset(dst_str, 0x00, 100);
1319  memset(output, 0x00, 100);
1320 
1321  key_len = unhexify( key_str, "98c6b8e01e379fbd14e61af6af891596583565f2a27d59e9" );
1322  unhexify( src_str, "00000000000000000000000000000000" );
1323 
1324  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1325  if( 0 == 0 )
1326  {
1327  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1328  hexify( dst_str, output, 16 );
1329 
1330  fct_chk( strcmp( (char *) dst_str, "19c80ec4a6deb7e5ed1033dda933498f" ) == 0 );
1331  }
1332  }
1333  FCT_TEST_END();
1334 
1335 
1336  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_10)
1337  {
1338  unsigned char key_str[100];
1339  unsigned char src_str[100];
1340  unsigned char dst_str[100];
1341  unsigned char output[100];
1342  aes_context ctx;
1343  int key_len;
1344 
1345  memset(key_str, 0x00, 100);
1346  memset(src_str, 0x00, 100);
1347  memset(dst_str, 0x00, 100);
1348  memset(output, 0x00, 100);
1349 
1350  key_len = unhexify( key_str, "fffffffffffffffffffffffffff800000000000000000000" );
1351  unhexify( src_str, "00000000000000000000000000000000" );
1352 
1353  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1354  if( 0 == 0 )
1355  {
1356  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1357  hexify( dst_str, output, 16 );
1358 
1359  fct_chk( strcmp( (char *) dst_str, "8dd274bd0f1b58ae345d9e7233f9b8f3" ) == 0 );
1360  }
1361  }
1362  FCT_TEST_END();
1363 
1364 
1365  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_11)
1366  {
1367  unsigned char key_str[100];
1368  unsigned char src_str[100];
1369  unsigned char dst_str[100];
1370  unsigned char output[100];
1371  aes_context ctx;
1372  int key_len;
1373 
1374  memset(key_str, 0x00, 100);
1375  memset(src_str, 0x00, 100);
1376  memset(dst_str, 0x00, 100);
1377  memset(output, 0x00, 100);
1378 
1379  key_len = unhexify( key_str, "fffffffffffffffffffffffffffc00000000000000000000" );
1380  unhexify( src_str, "00000000000000000000000000000000" );
1381 
1382  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1383  if( 0 == 0 )
1384  {
1385  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1386  hexify( dst_str, output, 16 );
1387 
1388  fct_chk( strcmp( (char *) dst_str, "9d6bdc8f4ce5feb0f3bed2e4b9a9bb0b" ) == 0 );
1389  }
1390  }
1391  FCT_TEST_END();
1392 
1393 
1394  FCT_TEST_BGN(aes_192_ecb_encrypt_nist_kat_12)
1395  {
1396  unsigned char key_str[100];
1397  unsigned char src_str[100];
1398  unsigned char dst_str[100];
1399  unsigned char output[100];
1400  aes_context ctx;
1401  int key_len;
1402 
1403  memset(key_str, 0x00, 100);
1404  memset(src_str, 0x00, 100);
1405  memset(dst_str, 0x00, 100);
1406  memset(output, 0x00, 100);
1407 
1408  key_len = unhexify( key_str, "fffffffffffffffffffffffffffe00000000000000000000" );
1409  unhexify( src_str, "00000000000000000000000000000000" );
1410 
1411  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1412  if( 0 == 0 )
1413  {
1414  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1415  hexify( dst_str, output, 16 );
1416 
1417  fct_chk( strcmp( (char *) dst_str, "fd5548bcf3f42565f7efa94562528d46" ) == 0 );
1418  }
1419  }
1420  FCT_TEST_END();
1421 
1422 
1423  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_1)
1424  {
1425  unsigned char key_str[100];
1426  unsigned char src_str[100];
1427  unsigned char dst_str[100];
1428  unsigned char output[100];
1429  aes_context ctx;
1430  int key_len;
1431 
1432  memset(key_str, 0x00, 100);
1433  memset(src_str, 0x00, 100);
1434  memset(dst_str, 0x00, 100);
1435  memset(output, 0x00, 100);
1436 
1437  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffff000000000000000" );
1438  unhexify( src_str, "bb2852c891c5947d2ed44032c421b85f" );
1439 
1440  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1441  if( 0 == 0 )
1442  {
1443  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1444  hexify( dst_str, output, 16 );
1445 
1446  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1447  }
1448  }
1449  FCT_TEST_END();
1450 
1451 
1452  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_2)
1453  {
1454  unsigned char key_str[100];
1455  unsigned char src_str[100];
1456  unsigned char dst_str[100];
1457  unsigned char output[100];
1458  aes_context ctx;
1459  int key_len;
1460 
1461  memset(key_str, 0x00, 100);
1462  memset(src_str, 0x00, 100);
1463  memset(dst_str, 0x00, 100);
1464  memset(output, 0x00, 100);
1465 
1466  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffff800000000000000" );
1467  unhexify( src_str, "1b9f5fbd5e8a4264c0a85b80409afa5e" );
1468 
1469  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1470  if( 0 == 0 )
1471  {
1472  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1473  hexify( dst_str, output, 16 );
1474 
1475  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1476  }
1477  }
1478  FCT_TEST_END();
1479 
1480 
1481  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_3)
1482  {
1483  unsigned char key_str[100];
1484  unsigned char src_str[100];
1485  unsigned char dst_str[100];
1486  unsigned char output[100];
1487  aes_context ctx;
1488  int key_len;
1489 
1490  memset(key_str, 0x00, 100);
1491  memset(src_str, 0x00, 100);
1492  memset(dst_str, 0x00, 100);
1493  memset(output, 0x00, 100);
1494 
1495  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffc00000000000000" );
1496  unhexify( src_str, "30dab809f85a917fe924733f424ac589" );
1497 
1498  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1499  if( 0 == 0 )
1500  {
1501  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1502  hexify( dst_str, output, 16 );
1503 
1504  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1505  }
1506  }
1507  FCT_TEST_END();
1508 
1509 
1510  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_4)
1511  {
1512  unsigned char key_str[100];
1513  unsigned char src_str[100];
1514  unsigned char dst_str[100];
1515  unsigned char output[100];
1516  aes_context ctx;
1517  int key_len;
1518 
1519  memset(key_str, 0x00, 100);
1520  memset(src_str, 0x00, 100);
1521  memset(dst_str, 0x00, 100);
1522  memset(output, 0x00, 100);
1523 
1524  key_len = unhexify( key_str, "61257134a518a0d57d9d244d45f6498cbc32f2bafc522d79" );
1525  unhexify( src_str, "cfe4d74002696ccf7d87b14a2f9cafc9" );
1526 
1527  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1528  if( 0 == 0 )
1529  {
1530  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1531  hexify( dst_str, output, 16 );
1532 
1533  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1534  }
1535  }
1536  FCT_TEST_END();
1537 
1538 
1539  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_5)
1540  {
1541  unsigned char key_str[100];
1542  unsigned char src_str[100];
1543  unsigned char dst_str[100];
1544  unsigned char output[100];
1545  aes_context ctx;
1546  int key_len;
1547 
1548  memset(key_str, 0x00, 100);
1549  memset(src_str, 0x00, 100);
1550  memset(dst_str, 0x00, 100);
1551  memset(output, 0x00, 100);
1552 
1553  key_len = unhexify( key_str, "b0ab0a6a818baef2d11fa33eac947284fb7d748cfb75e570" );
1554  unhexify( src_str, "d2eafd86f63b109b91f5dbb3a3fb7e13" );
1555 
1556  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1557  if( 0 == 0 )
1558  {
1559  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1560  hexify( dst_str, output, 16 );
1561 
1562  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1563  }
1564  }
1565  FCT_TEST_END();
1566 
1567 
1568  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_6)
1569  {
1570  unsigned char key_str[100];
1571  unsigned char src_str[100];
1572  unsigned char dst_str[100];
1573  unsigned char output[100];
1574  aes_context ctx;
1575  int key_len;
1576 
1577  memset(key_str, 0x00, 100);
1578  memset(src_str, 0x00, 100);
1579  memset(dst_str, 0x00, 100);
1580  memset(output, 0x00, 100);
1581 
1582  key_len = unhexify( key_str, "ee053aa011c8b428cdcc3636313c54d6a03cac01c71579d6" );
1583  unhexify( src_str, "9b9fdd1c5975655f539998b306a324af" );
1584 
1585  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1586  if( 0 == 0 )
1587  {
1588  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1589  hexify( dst_str, output, 16 );
1590 
1591  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1592  }
1593  }
1594  FCT_TEST_END();
1595 
1596 
1597  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_7)
1598  {
1599  unsigned char key_str[100];
1600  unsigned char src_str[100];
1601  unsigned char dst_str[100];
1602  unsigned char output[100];
1603  aes_context ctx;
1604  int key_len;
1605 
1606  memset(key_str, 0x00, 100);
1607  memset(src_str, 0x00, 100);
1608  memset(dst_str, 0x00, 100);
1609  memset(output, 0x00, 100);
1610 
1611  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1612  unhexify( src_str, "275cfc0413d8ccb70513c3859b1d0f72" );
1613 
1614  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1615  if( 0 == 0 )
1616  {
1617  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1618  hexify( dst_str, output, 16 );
1619 
1620  fct_chk( strcmp( (char *) dst_str, "1b077a6af4b7f98229de786d7516b639" ) == 0 );
1621  }
1622  }
1623  FCT_TEST_END();
1624 
1625 
1626  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_8)
1627  {
1628  unsigned char key_str[100];
1629  unsigned char src_str[100];
1630  unsigned char dst_str[100];
1631  unsigned char output[100];
1632  aes_context ctx;
1633  int key_len;
1634 
1635  memset(key_str, 0x00, 100);
1636  memset(src_str, 0x00, 100);
1637  memset(dst_str, 0x00, 100);
1638  memset(output, 0x00, 100);
1639 
1640  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1641  unhexify( src_str, "c9b8135ff1b5adc413dfd053b21bd96d" );
1642 
1643  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1644  if( 0 == 0 )
1645  {
1646  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1647  hexify( dst_str, output, 16 );
1648 
1649  fct_chk( strcmp( (char *) dst_str, "9c2d8842e5f48f57648205d39a239af1" ) == 0 );
1650  }
1651  }
1652  FCT_TEST_END();
1653 
1654 
1655  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_9)
1656  {
1657  unsigned char key_str[100];
1658  unsigned char src_str[100];
1659  unsigned char dst_str[100];
1660  unsigned char output[100];
1661  aes_context ctx;
1662  int key_len;
1663 
1664  memset(key_str, 0x00, 100);
1665  memset(src_str, 0x00, 100);
1666  memset(dst_str, 0x00, 100);
1667  memset(output, 0x00, 100);
1668 
1669  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1670  unhexify( src_str, "4a3650c3371ce2eb35e389a171427440" );
1671 
1672  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1673  if( 0 == 0 )
1674  {
1675  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1676  hexify( dst_str, output, 16 );
1677 
1678  fct_chk( strcmp( (char *) dst_str, "bff52510095f518ecca60af4205444bb" ) == 0 );
1679  }
1680  }
1681  FCT_TEST_END();
1682 
1683 
1684  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_10)
1685  {
1686  unsigned char key_str[100];
1687  unsigned char src_str[100];
1688  unsigned char dst_str[100];
1689  unsigned char output[100];
1690  aes_context ctx;
1691  int key_len;
1692 
1693  memset(key_str, 0x00, 100);
1694  memset(src_str, 0x00, 100);
1695  memset(dst_str, 0x00, 100);
1696  memset(output, 0x00, 100);
1697 
1698  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1699  unhexify( src_str, "b2099795e88cc158fd75ea133d7e7fbe" );
1700 
1701  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1702  if( 0 == 0 )
1703  {
1704  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1705  hexify( dst_str, output, 16 );
1706 
1707  fct_chk( strcmp( (char *) dst_str, "ffffffffffffffffffffc00000000000" ) == 0 );
1708  }
1709  }
1710  FCT_TEST_END();
1711 
1712 
1713  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_11)
1714  {
1715  unsigned char key_str[100];
1716  unsigned char src_str[100];
1717  unsigned char dst_str[100];
1718  unsigned char output[100];
1719  aes_context ctx;
1720  int key_len;
1721 
1722  memset(key_str, 0x00, 100);
1723  memset(src_str, 0x00, 100);
1724  memset(dst_str, 0x00, 100);
1725  memset(output, 0x00, 100);
1726 
1727  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1728  unhexify( src_str, "a6cae46fb6fadfe7a2c302a34242817b" );
1729 
1730  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1731  if( 0 == 0 )
1732  {
1733  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1734  hexify( dst_str, output, 16 );
1735 
1736  fct_chk( strcmp( (char *) dst_str, "ffffffffffffffffffffe00000000000" ) == 0 );
1737  }
1738  }
1739  FCT_TEST_END();
1740 
1741 
1742  FCT_TEST_BGN(aes_192_ecb_decrypt_nist_kat_12)
1743  {
1744  unsigned char key_str[100];
1745  unsigned char src_str[100];
1746  unsigned char dst_str[100];
1747  unsigned char output[100];
1748  aes_context ctx;
1749  int key_len;
1750 
1751  memset(key_str, 0x00, 100);
1752  memset(src_str, 0x00, 100);
1753  memset(dst_str, 0x00, 100);
1754  memset(output, 0x00, 100);
1755 
1756  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1757  unhexify( src_str, "026a7024d6a902e0b3ffccbaa910cc3f" );
1758 
1759  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
1760  if( 0 == 0 )
1761  {
1762  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
1763  hexify( dst_str, output, 16 );
1764 
1765  fct_chk( strcmp( (char *) dst_str, "fffffffffffffffffffff00000000000" ) == 0 );
1766  }
1767  }
1768  FCT_TEST_END();
1769 
1770 
1771  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_1)
1772  {
1773  unsigned char key_str[100];
1774  unsigned char src_str[100];
1775  unsigned char dst_str[100];
1776  unsigned char output[100];
1777  aes_context ctx;
1778  int key_len;
1779 
1780  memset(key_str, 0x00, 100);
1781  memset(src_str, 0x00, 100);
1782  memset(dst_str, 0x00, 100);
1783  memset(output, 0x00, 100);
1784 
1785  key_len = unhexify( key_str, "c1cc358b449909a19436cfbb3f852ef8bcb5ed12ac7058325f56e6099aab1a1c" );
1786  unhexify( src_str, "00000000000000000000000000000000" );
1787 
1788  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1789  if( 0 == 0 )
1790  {
1791  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1792  hexify( dst_str, output, 16 );
1793 
1794  fct_chk( strcmp( (char *) dst_str, "352065272169abf9856843927d0674fd" ) == 0 );
1795  }
1796  }
1797  FCT_TEST_END();
1798 
1799 
1800  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_2)
1801  {
1802  unsigned char key_str[100];
1803  unsigned char src_str[100];
1804  unsigned char dst_str[100];
1805  unsigned char output[100];
1806  aes_context ctx;
1807  int key_len;
1808 
1809  memset(key_str, 0x00, 100);
1810  memset(src_str, 0x00, 100);
1811  memset(dst_str, 0x00, 100);
1812  memset(output, 0x00, 100);
1813 
1814  key_len = unhexify( key_str, "984ca75f4ee8d706f46c2d98c0bf4a45f5b00d791c2dfeb191b5ed8e420fd627" );
1815  unhexify( src_str, "00000000000000000000000000000000" );
1816 
1817  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1818  if( 0 == 0 )
1819  {
1820  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1821  hexify( dst_str, output, 16 );
1822 
1823  fct_chk( strcmp( (char *) dst_str, "4307456a9e67813b452e15fa8fffe398" ) == 0 );
1824  }
1825  }
1826  FCT_TEST_END();
1827 
1828 
1829  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_3)
1830  {
1831  unsigned char key_str[100];
1832  unsigned char src_str[100];
1833  unsigned char dst_str[100];
1834  unsigned char output[100];
1835  aes_context ctx;
1836  int key_len;
1837 
1838  memset(key_str, 0x00, 100);
1839  memset(src_str, 0x00, 100);
1840  memset(dst_str, 0x00, 100);
1841  memset(output, 0x00, 100);
1842 
1843  key_len = unhexify( key_str, "b43d08a447ac8609baadae4ff12918b9f68fc1653f1269222f123981ded7a92f" );
1844  unhexify( src_str, "00000000000000000000000000000000" );
1845 
1846  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1847  if( 0 == 0 )
1848  {
1849  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1850  hexify( dst_str, output, 16 );
1851 
1852  fct_chk( strcmp( (char *) dst_str, "4663446607354989477a5c6f0f007ef4" ) == 0 );
1853  }
1854  }
1855  FCT_TEST_END();
1856 
1857 
1858  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_4)
1859  {
1860  unsigned char key_str[100];
1861  unsigned char src_str[100];
1862  unsigned char dst_str[100];
1863  unsigned char output[100];
1864  aes_context ctx;
1865  int key_len;
1866 
1867  memset(key_str, 0x00, 100);
1868  memset(src_str, 0x00, 100);
1869  memset(dst_str, 0x00, 100);
1870  memset(output, 0x00, 100);
1871 
1872  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1873  unhexify( src_str, "0b24af36193ce4665f2825d7b4749c98" );
1874 
1875  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1876  if( 0 == 0 )
1877  {
1878  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1879  hexify( dst_str, output, 16 );
1880 
1881  fct_chk( strcmp( (char *) dst_str, "a9ff75bd7cf6613d3731c77c3b6d0c04" ) == 0 );
1882  }
1883  }
1884  FCT_TEST_END();
1885 
1886 
1887  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_5)
1888  {
1889  unsigned char key_str[100];
1890  unsigned char src_str[100];
1891  unsigned char dst_str[100];
1892  unsigned char output[100];
1893  aes_context ctx;
1894  int key_len;
1895 
1896  memset(key_str, 0x00, 100);
1897  memset(src_str, 0x00, 100);
1898  memset(dst_str, 0x00, 100);
1899  memset(output, 0x00, 100);
1900 
1901  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1902  unhexify( src_str, "761c1fe41a18acf20d241650611d90f1" );
1903 
1904  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1905  if( 0 == 0 )
1906  {
1907  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1908  hexify( dst_str, output, 16 );
1909 
1910  fct_chk( strcmp( (char *) dst_str, "623a52fcea5d443e48d9181ab32c7421" ) == 0 );
1911  }
1912  }
1913  FCT_TEST_END();
1914 
1915 
1916  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_6)
1917  {
1918  unsigned char key_str[100];
1919  unsigned char src_str[100];
1920  unsigned char dst_str[100];
1921  unsigned char output[100];
1922  aes_context ctx;
1923  int key_len;
1924 
1925  memset(key_str, 0x00, 100);
1926  memset(src_str, 0x00, 100);
1927  memset(dst_str, 0x00, 100);
1928  memset(output, 0x00, 100);
1929 
1930  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1931  unhexify( src_str, "8a560769d605868ad80d819bdba03771" );
1932 
1933  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1934  if( 0 == 0 )
1935  {
1936  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1937  hexify( dst_str, output, 16 );
1938 
1939  fct_chk( strcmp( (char *) dst_str, "38f2c7ae10612415d27ca190d27da8b4" ) == 0 );
1940  }
1941  }
1942  FCT_TEST_END();
1943 
1944 
1945  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_7)
1946  {
1947  unsigned char key_str[100];
1948  unsigned char src_str[100];
1949  unsigned char dst_str[100];
1950  unsigned char output[100];
1951  aes_context ctx;
1952  int key_len;
1953 
1954  memset(key_str, 0x00, 100);
1955  memset(src_str, 0x00, 100);
1956  memset(dst_str, 0x00, 100);
1957  memset(output, 0x00, 100);
1958 
1959  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1960  unhexify( src_str, "ffffff80000000000000000000000000" );
1961 
1962  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1963  if( 0 == 0 )
1964  {
1965  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1966  hexify( dst_str, output, 16 );
1967 
1968  fct_chk( strcmp( (char *) dst_str, "36aff0ef7bf3280772cf4cac80a0d2b2" ) == 0 );
1969  }
1970  }
1971  FCT_TEST_END();
1972 
1973 
1974  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_8)
1975  {
1976  unsigned char key_str[100];
1977  unsigned char src_str[100];
1978  unsigned char dst_str[100];
1979  unsigned char output[100];
1980  aes_context ctx;
1981  int key_len;
1982 
1983  memset(key_str, 0x00, 100);
1984  memset(src_str, 0x00, 100);
1985  memset(dst_str, 0x00, 100);
1986  memset(output, 0x00, 100);
1987 
1988  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1989  unhexify( src_str, "ffffffc0000000000000000000000000" );
1990 
1991  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
1992  if( 0 == 0 )
1993  {
1994  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
1995  hexify( dst_str, output, 16 );
1996 
1997  fct_chk( strcmp( (char *) dst_str, "1f8eedea0f62a1406d58cfc3ecea72cf" ) == 0 );
1998  }
1999  }
2000  FCT_TEST_END();
2001 
2002 
2003  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_9)
2004  {
2005  unsigned char key_str[100];
2006  unsigned char src_str[100];
2007  unsigned char dst_str[100];
2008  unsigned char output[100];
2009  aes_context ctx;
2010  int key_len;
2011 
2012  memset(key_str, 0x00, 100);
2013  memset(src_str, 0x00, 100);
2014  memset(dst_str, 0x00, 100);
2015  memset(output, 0x00, 100);
2016 
2017  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2018  unhexify( src_str, "ffffffe0000000000000000000000000" );
2019 
2020  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
2021  if( 0 == 0 )
2022  {
2023  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
2024  hexify( dst_str, output, 16 );
2025 
2026  fct_chk( strcmp( (char *) dst_str, "abf4154a3375a1d3e6b1d454438f95a6" ) == 0 );
2027  }
2028  }
2029  FCT_TEST_END();
2030 
2031 
2032  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_10)
2033  {
2034  unsigned char key_str[100];
2035  unsigned char src_str[100];
2036  unsigned char dst_str[100];
2037  unsigned char output[100];
2038  aes_context ctx;
2039  int key_len;
2040 
2041  memset(key_str, 0x00, 100);
2042  memset(src_str, 0x00, 100);
2043  memset(dst_str, 0x00, 100);
2044  memset(output, 0x00, 100);
2045 
2046  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffffffffff8000000000000000000000000000" );
2047  unhexify( src_str, "00000000000000000000000000000000" );
2048 
2049  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
2050  if( 0 == 0 )
2051  {
2052  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
2053  hexify( dst_str, output, 16 );
2054 
2055  fct_chk( strcmp( (char *) dst_str, "45d089c36d5c5a4efc689e3b0de10dd5" ) == 0 );
2056  }
2057  }
2058  FCT_TEST_END();
2059 
2060 
2061  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_11)
2062  {
2063  unsigned char key_str[100];
2064  unsigned char src_str[100];
2065  unsigned char dst_str[100];
2066  unsigned char output[100];
2067  aes_context ctx;
2068  int key_len;
2069 
2070  memset(key_str, 0x00, 100);
2071  memset(src_str, 0x00, 100);
2072  memset(dst_str, 0x00, 100);
2073  memset(output, 0x00, 100);
2074 
2075  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffffffffffc000000000000000000000000000" );
2076  unhexify( src_str, "00000000000000000000000000000000" );
2077 
2078  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
2079  if( 0 == 0 )
2080  {
2081  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
2082  hexify( dst_str, output, 16 );
2083 
2084  fct_chk( strcmp( (char *) dst_str, "b4da5df4becb5462e03a0ed00d295629" ) == 0 );
2085  }
2086  }
2087  FCT_TEST_END();
2088 
2089 
2090  FCT_TEST_BGN(aes_256_ecb_encrypt_nist_kat_12)
2091  {
2092  unsigned char key_str[100];
2093  unsigned char src_str[100];
2094  unsigned char dst_str[100];
2095  unsigned char output[100];
2096  aes_context ctx;
2097  int key_len;
2098 
2099  memset(key_str, 0x00, 100);
2100  memset(src_str, 0x00, 100);
2101  memset(dst_str, 0x00, 100);
2102  memset(output, 0x00, 100);
2103 
2104  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffffffffffe000000000000000000000000000" );
2105  unhexify( src_str, "00000000000000000000000000000000" );
2106 
2107  fct_chk( aes_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
2108  if( 0 == 0 )
2109  {
2110  fct_chk( aes_crypt_ecb( &ctx, AES_ENCRYPT, src_str, output ) == 0 );
2111  hexify( dst_str, output, 16 );
2112 
2113  fct_chk( strcmp( (char *) dst_str, "dcf4e129136c1a4b7a0f38935cc34b2b" ) == 0 );
2114  }
2115  }
2116  FCT_TEST_END();
2117 
2118 
2119  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_1)
2120  {
2121  unsigned char key_str[100];
2122  unsigned char src_str[100];
2123  unsigned char dst_str[100];
2124  unsigned char output[100];
2125  aes_context ctx;
2126  int key_len;
2127 
2128  memset(key_str, 0x00, 100);
2129  memset(src_str, 0x00, 100);
2130  memset(dst_str, 0x00, 100);
2131  memset(output, 0x00, 100);
2132 
2133  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffffffffffffffff00000000000000000" );
2134  unhexify( src_str, "edf61ae362e882ddc0167474a7a77f3a" );
2135 
2136  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2137  if( 0 == 0 )
2138  {
2139  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2140  hexify( dst_str, output, 16 );
2141 
2142  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2143  }
2144  }
2145  FCT_TEST_END();
2146 
2147 
2148  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_2)
2149  {
2150  unsigned char key_str[100];
2151  unsigned char src_str[100];
2152  unsigned char dst_str[100];
2153  unsigned char output[100];
2154  aes_context ctx;
2155  int key_len;
2156 
2157  memset(key_str, 0x00, 100);
2158  memset(src_str, 0x00, 100);
2159  memset(dst_str, 0x00, 100);
2160  memset(output, 0x00, 100);
2161 
2162  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffffffffffffffff80000000000000000" );
2163  unhexify( src_str, "6168b00ba7859e0970ecfd757efecf7c" );
2164 
2165  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2166  if( 0 == 0 )
2167  {
2168  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2169  hexify( dst_str, output, 16 );
2170 
2171  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2172  }
2173  }
2174  FCT_TEST_END();
2175 
2176 
2177  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_3)
2178  {
2179  unsigned char key_str[100];
2180  unsigned char src_str[100];
2181  unsigned char dst_str[100];
2182  unsigned char output[100];
2183  aes_context ctx;
2184  int key_len;
2185 
2186  memset(key_str, 0x00, 100);
2187  memset(src_str, 0x00, 100);
2188  memset(dst_str, 0x00, 100);
2189  memset(output, 0x00, 100);
2190 
2191  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffffffffffffffffc0000000000000000" );
2192  unhexify( src_str, "d1415447866230d28bb1ea18a4cdfd02" );
2193 
2194  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2195  if( 0 == 0 )
2196  {
2197  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2198  hexify( dst_str, output, 16 );
2199 
2200  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2201  }
2202  }
2203  FCT_TEST_END();
2204 
2205 
2206  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_4)
2207  {
2208  unsigned char key_str[100];
2209  unsigned char src_str[100];
2210  unsigned char dst_str[100];
2211  unsigned char output[100];
2212  aes_context ctx;
2213  int key_len;
2214 
2215  memset(key_str, 0x00, 100);
2216  memset(src_str, 0x00, 100);
2217  memset(dst_str, 0x00, 100);
2218  memset(output, 0x00, 100);
2219 
2220  key_len = unhexify( key_str, "f8be9ba615c5a952cabbca24f68f8593039624d524c816acda2c9183bd917cb9" );
2221  unhexify( src_str, "a3944b95ca0b52043584ef02151926a8" );
2222 
2223  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2224  if( 0 == 0 )
2225  {
2226  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2227  hexify( dst_str, output, 16 );
2228 
2229  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2230  }
2231  }
2232  FCT_TEST_END();
2233 
2234 
2235  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_5)
2236  {
2237  unsigned char key_str[100];
2238  unsigned char src_str[100];
2239  unsigned char dst_str[100];
2240  unsigned char output[100];
2241  aes_context ctx;
2242  int key_len;
2243 
2244  memset(key_str, 0x00, 100);
2245  memset(src_str, 0x00, 100);
2246  memset(dst_str, 0x00, 100);
2247  memset(output, 0x00, 100);
2248 
2249  key_len = unhexify( key_str, "797f8b3d176dac5b7e34a2d539c4ef367a16f8635f6264737591c5c07bf57a3e" );
2250  unhexify( src_str, "a74289fe73a4c123ca189ea1e1b49ad5" );
2251 
2252  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2253  if( 0 == 0 )
2254  {
2255  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2256  hexify( dst_str, output, 16 );
2257 
2258  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2259  }
2260  }
2261  FCT_TEST_END();
2262 
2263 
2264  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_6)
2265  {
2266  unsigned char key_str[100];
2267  unsigned char src_str[100];
2268  unsigned char dst_str[100];
2269  unsigned char output[100];
2270  aes_context ctx;
2271  int key_len;
2272 
2273  memset(key_str, 0x00, 100);
2274  memset(src_str, 0x00, 100);
2275  memset(dst_str, 0x00, 100);
2276  memset(output, 0x00, 100);
2277 
2278  key_len = unhexify( key_str, "6838d40caf927749c13f0329d331f448e202c73ef52c5f73a37ca635d4c47707" );
2279  unhexify( src_str, "b91d4ea4488644b56cf0812fa7fcf5fc" );
2280 
2281  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2282  if( 0 == 0 )
2283  {
2284  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2285  hexify( dst_str, output, 16 );
2286 
2287  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2288  }
2289  }
2290  FCT_TEST_END();
2291 
2292 
2293  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_7)
2294  {
2295  unsigned char key_str[100];
2296  unsigned char src_str[100];
2297  unsigned char dst_str[100];
2298  unsigned char output[100];
2299  aes_context ctx;
2300  int key_len;
2301 
2302  memset(key_str, 0x00, 100);
2303  memset(src_str, 0x00, 100);
2304  memset(dst_str, 0x00, 100);
2305  memset(output, 0x00, 100);
2306 
2307  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2308  unhexify( src_str, "623a52fcea5d443e48d9181ab32c7421" );
2309 
2310  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2311  if( 0 == 0 )
2312  {
2313  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2314  hexify( dst_str, output, 16 );
2315 
2316  fct_chk( strcmp( (char *) dst_str, "761c1fe41a18acf20d241650611d90f1" ) == 0 );
2317  }
2318  }
2319  FCT_TEST_END();
2320 
2321 
2322  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_8)
2323  {
2324  unsigned char key_str[100];
2325  unsigned char src_str[100];
2326  unsigned char dst_str[100];
2327  unsigned char output[100];
2328  aes_context ctx;
2329  int key_len;
2330 
2331  memset(key_str, 0x00, 100);
2332  memset(src_str, 0x00, 100);
2333  memset(dst_str, 0x00, 100);
2334  memset(output, 0x00, 100);
2335 
2336  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2337  unhexify( src_str, "38f2c7ae10612415d27ca190d27da8b4" );
2338 
2339  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2340  if( 0 == 0 )
2341  {
2342  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2343  hexify( dst_str, output, 16 );
2344 
2345  fct_chk( strcmp( (char *) dst_str, "8a560769d605868ad80d819bdba03771" ) == 0 );
2346  }
2347  }
2348  FCT_TEST_END();
2349 
2350 
2351  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_9)
2352  {
2353  unsigned char key_str[100];
2354  unsigned char src_str[100];
2355  unsigned char dst_str[100];
2356  unsigned char output[100];
2357  aes_context ctx;
2358  int key_len;
2359 
2360  memset(key_str, 0x00, 100);
2361  memset(src_str, 0x00, 100);
2362  memset(dst_str, 0x00, 100);
2363  memset(output, 0x00, 100);
2364 
2365  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2366  unhexify( src_str, "1bc704f1bce135ceb810341b216d7abe" );
2367 
2368  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2369  if( 0 == 0 )
2370  {
2371  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2372  hexify( dst_str, output, 16 );
2373 
2374  fct_chk( strcmp( (char *) dst_str, "91fbef2d15a97816060bee1feaa49afe" ) == 0 );
2375  }
2376  }
2377  FCT_TEST_END();
2378 
2379 
2380  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_10)
2381  {
2382  unsigned char key_str[100];
2383  unsigned char src_str[100];
2384  unsigned char dst_str[100];
2385  unsigned char output[100];
2386  aes_context ctx;
2387  int key_len;
2388 
2389  memset(key_str, 0x00, 100);
2390  memset(src_str, 0x00, 100);
2391  memset(dst_str, 0x00, 100);
2392  memset(output, 0x00, 100);
2393 
2394  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2395  unhexify( src_str, "ddc6bf790c15760d8d9aeb6f9a75fd4e" );
2396 
2397  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2398  if( 0 == 0 )
2399  {
2400  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2401  hexify( dst_str, output, 16 );
2402 
2403  fct_chk( strcmp( (char *) dst_str, "80000000000000000000000000000000" ) == 0 );
2404  }
2405  }
2406  FCT_TEST_END();
2407 
2408 
2409  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_11)
2410  {
2411  unsigned char key_str[100];
2412  unsigned char src_str[100];
2413  unsigned char dst_str[100];
2414  unsigned char output[100];
2415  aes_context ctx;
2416  int key_len;
2417 
2418  memset(key_str, 0x00, 100);
2419  memset(src_str, 0x00, 100);
2420  memset(dst_str, 0x00, 100);
2421  memset(output, 0x00, 100);
2422 
2423  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2424  unhexify( src_str, "0a6bdc6d4c1e6280301fd8e97ddbe601" );
2425 
2426  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2427  if( 0 == 0 )
2428  {
2429  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2430  hexify( dst_str, output, 16 );
2431 
2432  fct_chk( strcmp( (char *) dst_str, "c0000000000000000000000000000000" ) == 0 );
2433  }
2434  }
2435  FCT_TEST_END();
2436 
2437 
2438  FCT_TEST_BGN(aes_256_ecb_decrypt_nist_kat_12)
2439  {
2440  unsigned char key_str[100];
2441  unsigned char src_str[100];
2442  unsigned char dst_str[100];
2443  unsigned char output[100];
2444  aes_context ctx;
2445  int key_len;
2446 
2447  memset(key_str, 0x00, 100);
2448  memset(src_str, 0x00, 100);
2449  memset(dst_str, 0x00, 100);
2450  memset(output, 0x00, 100);
2451 
2452  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2453  unhexify( src_str, "9b80eefb7ebe2d2b16247aa0efc72f5d" );
2454 
2455  fct_chk( aes_setkey_dec( &ctx, key_str, key_len * 8 ) == 0 );
2456  if( 0 == 0 )
2457  {
2458  fct_chk( aes_crypt_ecb( &ctx, AES_DECRYPT, src_str, output ) == 0 );
2459  hexify( dst_str, output, 16 );
2460 
2461  fct_chk( strcmp( (char *) dst_str, "e0000000000000000000000000000000" ) == 0 );
2462  }
2463  }
2464  FCT_TEST_END();
2465 
2466  }
2467  FCT_SUITE_END();
2468 
2469 #endif /* POLARSSL_AES_C */
2470 
2471 }
2472 FCT_END();
2473