PolarSSL v1.2.8
test_suite_aes.cbc.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_cbc_encrypt_nist_kat_1)
235  {
236  unsigned char key_str[100];
237  unsigned char iv_str[100];
238  unsigned char src_str[100];
239  unsigned char dst_str[100];
240  unsigned char output[100];
241  aes_context ctx;
242  int key_len, data_len;
243 
244  memset(key_str, 0x00, 100);
245  memset(iv_str, 0x00, 100);
246  memset(src_str, 0x00, 100);
247  memset(dst_str, 0x00, 100);
248  memset(output, 0x00, 100);
249 
250  key_len = unhexify( key_str, "fffffffffffff8000000000000000000" );
251  unhexify( iv_str, "00000000000000000000000000000000" );
252  data_len = unhexify( src_str, "00000000000000000000000000000000" );
253 
254  aes_setkey_enc( &ctx, key_str, key_len * 8 );
255  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
256  if( 0 == 0 )
257  {
258  hexify( dst_str, output, data_len );
259 
260  fct_chk( strcmp( (char *) dst_str, "8b527a6aebdaec9eaef8eda2cb7783e5" ) == 0 );
261  }
262  }
263  FCT_TEST_END();
264 
265 
266  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_2)
267  {
268  unsigned char key_str[100];
269  unsigned char iv_str[100];
270  unsigned char src_str[100];
271  unsigned char dst_str[100];
272  unsigned char output[100];
273  aes_context ctx;
274  int key_len, data_len;
275 
276  memset(key_str, 0x00, 100);
277  memset(iv_str, 0x00, 100);
278  memset(src_str, 0x00, 100);
279  memset(dst_str, 0x00, 100);
280  memset(output, 0x00, 100);
281 
282  key_len = unhexify( key_str, "fffffffffffffc000000000000000000" );
283  unhexify( iv_str, "00000000000000000000000000000000" );
284  data_len = unhexify( src_str, "00000000000000000000000000000000" );
285 
286  aes_setkey_enc( &ctx, key_str, key_len * 8 );
287  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
288  if( 0 == 0 )
289  {
290  hexify( dst_str, output, data_len );
291 
292  fct_chk( strcmp( (char *) dst_str, "43fdaf53ebbc9880c228617d6a9b548b" ) == 0 );
293  }
294  }
295  FCT_TEST_END();
296 
297 
298  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_3)
299  {
300  unsigned char key_str[100];
301  unsigned char iv_str[100];
302  unsigned char src_str[100];
303  unsigned char dst_str[100];
304  unsigned char output[100];
305  aes_context ctx;
306  int key_len, data_len;
307 
308  memset(key_str, 0x00, 100);
309  memset(iv_str, 0x00, 100);
310  memset(src_str, 0x00, 100);
311  memset(dst_str, 0x00, 100);
312  memset(output, 0x00, 100);
313 
314  key_len = unhexify( key_str, "fffffffffffffe000000000000000000" );
315  unhexify( iv_str, "00000000000000000000000000000000" );
316  data_len = unhexify( src_str, "00000000000000000000000000000000" );
317 
318  aes_setkey_enc( &ctx, key_str, key_len * 8 );
319  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
320  if( 0 == 0 )
321  {
322  hexify( dst_str, output, data_len );
323 
324  fct_chk( strcmp( (char *) dst_str, "53786104b9744b98f052c46f1c850d0b" ) == 0 );
325  }
326  }
327  FCT_TEST_END();
328 
329 
330  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_4)
331  {
332  unsigned char key_str[100];
333  unsigned char iv_str[100];
334  unsigned char src_str[100];
335  unsigned char dst_str[100];
336  unsigned char output[100];
337  aes_context ctx;
338  int key_len, data_len;
339 
340  memset(key_str, 0x00, 100);
341  memset(iv_str, 0x00, 100);
342  memset(src_str, 0x00, 100);
343  memset(dst_str, 0x00, 100);
344  memset(output, 0x00, 100);
345 
346  key_len = unhexify( key_str, "e37b1c6aa2846f6fdb413f238b089f23" );
347  unhexify( iv_str, "00000000000000000000000000000000" );
348  data_len = unhexify( src_str, "00000000000000000000000000000000" );
349 
350  aes_setkey_enc( &ctx, key_str, key_len * 8 );
351  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
352  if( 0 == 0 )
353  {
354  hexify( dst_str, output, data_len );
355 
356  fct_chk( strcmp( (char *) dst_str, "43c9f7e62f5d288bb27aa40ef8fe1ea8" ) == 0 );
357  }
358  }
359  FCT_TEST_END();
360 
361 
362  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_5)
363  {
364  unsigned char key_str[100];
365  unsigned char iv_str[100];
366  unsigned char src_str[100];
367  unsigned char dst_str[100];
368  unsigned char output[100];
369  aes_context ctx;
370  int key_len, data_len;
371 
372  memset(key_str, 0x00, 100);
373  memset(iv_str, 0x00, 100);
374  memset(src_str, 0x00, 100);
375  memset(dst_str, 0x00, 100);
376  memset(output, 0x00, 100);
377 
378  key_len = unhexify( key_str, "6c002b682483e0cabcc731c253be5674" );
379  unhexify( iv_str, "00000000000000000000000000000000" );
380  data_len = unhexify( src_str, "00000000000000000000000000000000" );
381 
382  aes_setkey_enc( &ctx, key_str, key_len * 8 );
383  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
384  if( 0 == 0 )
385  {
386  hexify( dst_str, output, data_len );
387 
388  fct_chk( strcmp( (char *) dst_str, "3580d19cff44f1014a7c966a69059de5" ) == 0 );
389  }
390  }
391  FCT_TEST_END();
392 
393 
394  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_6)
395  {
396  unsigned char key_str[100];
397  unsigned char iv_str[100];
398  unsigned char src_str[100];
399  unsigned char dst_str[100];
400  unsigned char output[100];
401  aes_context ctx;
402  int key_len, data_len;
403 
404  memset(key_str, 0x00, 100);
405  memset(iv_str, 0x00, 100);
406  memset(src_str, 0x00, 100);
407  memset(dst_str, 0x00, 100);
408  memset(output, 0x00, 100);
409 
410  key_len = unhexify( key_str, "143ae8ed6555aba96110ab58893a8ae1" );
411  unhexify( iv_str, "00000000000000000000000000000000" );
412  data_len = unhexify( src_str, "00000000000000000000000000000000" );
413 
414  aes_setkey_enc( &ctx, key_str, key_len * 8 );
415  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
416  if( 0 == 0 )
417  {
418  hexify( dst_str, output, data_len );
419 
420  fct_chk( strcmp( (char *) dst_str, "806da864dd29d48deafbe764f8202aef" ) == 0 );
421  }
422  }
423  FCT_TEST_END();
424 
425 
426  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_7)
427  {
428  unsigned char key_str[100];
429  unsigned char iv_str[100];
430  unsigned char src_str[100];
431  unsigned char dst_str[100];
432  unsigned char output[100];
433  aes_context ctx;
434  int key_len, data_len;
435 
436  memset(key_str, 0x00, 100);
437  memset(iv_str, 0x00, 100);
438  memset(src_str, 0x00, 100);
439  memset(dst_str, 0x00, 100);
440  memset(output, 0x00, 100);
441 
442  key_len = unhexify( key_str, "00000000000000000000000000000000" );
443  unhexify( iv_str, "00000000000000000000000000000000" );
444  data_len = unhexify( src_str, "6a118a874519e64e9963798a503f1d35" );
445 
446  aes_setkey_enc( &ctx, key_str, key_len * 8 );
447  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
448  if( 0 == 0 )
449  {
450  hexify( dst_str, output, data_len );
451 
452  fct_chk( strcmp( (char *) dst_str, "dc43be40be0e53712f7e2bf5ca707209" ) == 0 );
453  }
454  }
455  FCT_TEST_END();
456 
457 
458  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_8)
459  {
460  unsigned char key_str[100];
461  unsigned char iv_str[100];
462  unsigned char src_str[100];
463  unsigned char dst_str[100];
464  unsigned char output[100];
465  aes_context ctx;
466  int key_len, data_len;
467 
468  memset(key_str, 0x00, 100);
469  memset(iv_str, 0x00, 100);
470  memset(src_str, 0x00, 100);
471  memset(dst_str, 0x00, 100);
472  memset(output, 0x00, 100);
473 
474  key_len = unhexify( key_str, "00000000000000000000000000000000" );
475  unhexify( iv_str, "00000000000000000000000000000000" );
476  data_len = unhexify( src_str, "cb9fceec81286ca3e989bd979b0cb284" );
477 
478  aes_setkey_enc( &ctx, key_str, key_len * 8 );
479  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
480  if( 0 == 0 )
481  {
482  hexify( dst_str, output, data_len );
483 
484  fct_chk( strcmp( (char *) dst_str, "92beedab1895a94faa69b632e5cc47ce" ) == 0 );
485  }
486  }
487  FCT_TEST_END();
488 
489 
490  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_9)
491  {
492  unsigned char key_str[100];
493  unsigned char iv_str[100];
494  unsigned char src_str[100];
495  unsigned char dst_str[100];
496  unsigned char output[100];
497  aes_context ctx;
498  int key_len, data_len;
499 
500  memset(key_str, 0x00, 100);
501  memset(iv_str, 0x00, 100);
502  memset(src_str, 0x00, 100);
503  memset(dst_str, 0x00, 100);
504  memset(output, 0x00, 100);
505 
506  key_len = unhexify( key_str, "00000000000000000000000000000000" );
507  unhexify( iv_str, "00000000000000000000000000000000" );
508  data_len = unhexify( src_str, "b26aeb1874e47ca8358ff22378f09144" );
509 
510  aes_setkey_enc( &ctx, key_str, key_len * 8 );
511  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
512  if( 0 == 0 )
513  {
514  hexify( dst_str, output, data_len );
515 
516  fct_chk( strcmp( (char *) dst_str, "459264f4798f6a78bacb89c15ed3d601" ) == 0 );
517  }
518  }
519  FCT_TEST_END();
520 
521 
522  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_10)
523  {
524  unsigned char key_str[100];
525  unsigned char iv_str[100];
526  unsigned char src_str[100];
527  unsigned char dst_str[100];
528  unsigned char output[100];
529  aes_context ctx;
530  int key_len, data_len;
531 
532  memset(key_str, 0x00, 100);
533  memset(iv_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, "00000000000000000000000000000000" );
539  unhexify( iv_str, "00000000000000000000000000000000" );
540  data_len = unhexify( src_str, "ffffffffffffffffffffffc000000000" );
541 
542  aes_setkey_enc( &ctx, key_str, key_len * 8 );
543  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
544  if( 0 == 0 )
545  {
546  hexify( dst_str, output, data_len );
547 
548  fct_chk( strcmp( (char *) dst_str, "90684a2ac55fe1ec2b8ebd5622520b73" ) == 0 );
549  }
550  }
551  FCT_TEST_END();
552 
553 
554  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_11)
555  {
556  unsigned char key_str[100];
557  unsigned char iv_str[100];
558  unsigned char src_str[100];
559  unsigned char dst_str[100];
560  unsigned char output[100];
561  aes_context ctx;
562  int key_len, data_len;
563 
564  memset(key_str, 0x00, 100);
565  memset(iv_str, 0x00, 100);
566  memset(src_str, 0x00, 100);
567  memset(dst_str, 0x00, 100);
568  memset(output, 0x00, 100);
569 
570  key_len = unhexify( key_str, "00000000000000000000000000000000" );
571  unhexify( iv_str, "00000000000000000000000000000000" );
572  data_len = unhexify( src_str, "ffffffffffffffffffffffe000000000" );
573 
574  aes_setkey_enc( &ctx, key_str, key_len * 8 );
575  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
576  if( 0 == 0 )
577  {
578  hexify( dst_str, output, data_len );
579 
580  fct_chk( strcmp( (char *) dst_str, "7472f9a7988607ca79707795991035e6" ) == 0 );
581  }
582  }
583  FCT_TEST_END();
584 
585 
586  FCT_TEST_BGN(aes_128_cbc_encrypt_nist_kat_12)
587  {
588  unsigned char key_str[100];
589  unsigned char iv_str[100];
590  unsigned char src_str[100];
591  unsigned char dst_str[100];
592  unsigned char output[100];
593  aes_context ctx;
594  int key_len, data_len;
595 
596  memset(key_str, 0x00, 100);
597  memset(iv_str, 0x00, 100);
598  memset(src_str, 0x00, 100);
599  memset(dst_str, 0x00, 100);
600  memset(output, 0x00, 100);
601 
602  key_len = unhexify( key_str, "00000000000000000000000000000000" );
603  unhexify( iv_str, "00000000000000000000000000000000" );
604  data_len = unhexify( src_str, "fffffffffffffffffffffff000000000" );
605 
606  aes_setkey_enc( &ctx, key_str, key_len * 8 );
607  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
608  if( 0 == 0 )
609  {
610  hexify( dst_str, output, data_len );
611 
612  fct_chk( strcmp( (char *) dst_str, "56aff089878bf3352f8df172a3ae47d8" ) == 0 );
613  }
614  }
615  FCT_TEST_END();
616 
617 
618  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_1)
619  {
620  unsigned char key_str[100];
621  unsigned char iv_str[100];
622  unsigned char src_str[100];
623  unsigned char dst_str[100];
624  unsigned char output[100];
625  aes_context ctx;
626  int key_len, data_len;
627 
628  memset(key_str, 0x00, 100);
629  memset(iv_str, 0x00, 100);
630  memset(src_str, 0x00, 100);
631  memset(dst_str, 0x00, 100);
632  memset(output, 0x00, 100);
633 
634  key_len = unhexify( key_str, "ffffffffe00000000000000000000000" );
635  unhexify( iv_str, "00000000000000000000000000000000" );
636  data_len = unhexify( src_str, "23f710842b9bb9c32f26648c786807ca" );
637 
638  aes_setkey_dec( &ctx, key_str, key_len * 8 );
639  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
640  if( 0 == 0)
641  {
642  hexify( dst_str, output, data_len );
643 
644  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
645  }
646  }
647  FCT_TEST_END();
648 
649 
650  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_2)
651  {
652  unsigned char key_str[100];
653  unsigned char iv_str[100];
654  unsigned char src_str[100];
655  unsigned char dst_str[100];
656  unsigned char output[100];
657  aes_context ctx;
658  int key_len, data_len;
659 
660  memset(key_str, 0x00, 100);
661  memset(iv_str, 0x00, 100);
662  memset(src_str, 0x00, 100);
663  memset(dst_str, 0x00, 100);
664  memset(output, 0x00, 100);
665 
666  key_len = unhexify( key_str, "fffffffff00000000000000000000000" );
667  unhexify( iv_str, "00000000000000000000000000000000" );
668  data_len = unhexify( src_str, "44a98bf11e163f632c47ec6a49683a89" );
669 
670  aes_setkey_dec( &ctx, key_str, key_len * 8 );
671  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
672  if( 0 == 0)
673  {
674  hexify( dst_str, output, data_len );
675 
676  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
677  }
678  }
679  FCT_TEST_END();
680 
681 
682  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_3)
683  {
684  unsigned char key_str[100];
685  unsigned char iv_str[100];
686  unsigned char src_str[100];
687  unsigned char dst_str[100];
688  unsigned char output[100];
689  aes_context ctx;
690  int key_len, data_len;
691 
692  memset(key_str, 0x00, 100);
693  memset(iv_str, 0x00, 100);
694  memset(src_str, 0x00, 100);
695  memset(dst_str, 0x00, 100);
696  memset(output, 0x00, 100);
697 
698  key_len = unhexify( key_str, "fffffffff80000000000000000000000" );
699  unhexify( iv_str, "00000000000000000000000000000000" );
700  data_len = unhexify( src_str, "0f18aff94274696d9b61848bd50ac5e5" );
701 
702  aes_setkey_dec( &ctx, key_str, key_len * 8 );
703  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
704  if( 0 == 0)
705  {
706  hexify( dst_str, output, data_len );
707 
708  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
709  }
710  }
711  FCT_TEST_END();
712 
713 
714  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_4)
715  {
716  unsigned char key_str[100];
717  unsigned char iv_str[100];
718  unsigned char src_str[100];
719  unsigned char dst_str[100];
720  unsigned char output[100];
721  aes_context ctx;
722  int key_len, data_len;
723 
724  memset(key_str, 0x00, 100);
725  memset(iv_str, 0x00, 100);
726  memset(src_str, 0x00, 100);
727  memset(dst_str, 0x00, 100);
728  memset(output, 0x00, 100);
729 
730  key_len = unhexify( key_str, "e234cdca2606b81f29408d5f6da21206" );
731  unhexify( iv_str, "00000000000000000000000000000000" );
732  data_len = unhexify( src_str, "fff60a4740086b3b9c56195b98d91a7b" );
733 
734  aes_setkey_dec( &ctx, key_str, key_len * 8 );
735  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
736  if( 0 == 0)
737  {
738  hexify( dst_str, output, data_len );
739 
740  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
741  }
742  }
743  FCT_TEST_END();
744 
745 
746  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_5)
747  {
748  unsigned char key_str[100];
749  unsigned char iv_str[100];
750  unsigned char src_str[100];
751  unsigned char dst_str[100];
752  unsigned char output[100];
753  aes_context ctx;
754  int key_len, data_len;
755 
756  memset(key_str, 0x00, 100);
757  memset(iv_str, 0x00, 100);
758  memset(src_str, 0x00, 100);
759  memset(dst_str, 0x00, 100);
760  memset(output, 0x00, 100);
761 
762  key_len = unhexify( key_str, "13237c49074a3da078dc1d828bb78c6f" );
763  unhexify( iv_str, "00000000000000000000000000000000" );
764  data_len = unhexify( src_str, "8146a08e2357f0caa30ca8c94d1a0544" );
765 
766  aes_setkey_dec( &ctx, key_str, key_len * 8 );
767  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
768  if( 0 == 0)
769  {
770  hexify( dst_str, output, data_len );
771 
772  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
773  }
774  }
775  FCT_TEST_END();
776 
777 
778  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_6)
779  {
780  unsigned char key_str[100];
781  unsigned char iv_str[100];
782  unsigned char src_str[100];
783  unsigned char dst_str[100];
784  unsigned char output[100];
785  aes_context ctx;
786  int key_len, data_len;
787 
788  memset(key_str, 0x00, 100);
789  memset(iv_str, 0x00, 100);
790  memset(src_str, 0x00, 100);
791  memset(dst_str, 0x00, 100);
792  memset(output, 0x00, 100);
793 
794  key_len = unhexify( key_str, "3071a2a48fe6cbd04f1a129098e308f8" );
795  unhexify( iv_str, "00000000000000000000000000000000" );
796  data_len = unhexify( src_str, "4b98e06d356deb07ebb824e5713f7be3" );
797 
798  aes_setkey_dec( &ctx, key_str, key_len * 8 );
799  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
800  if( 0 == 0)
801  {
802  hexify( dst_str, output, data_len );
803 
804  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
805  }
806  }
807  FCT_TEST_END();
808 
809 
810  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_7)
811  {
812  unsigned char key_str[100];
813  unsigned char iv_str[100];
814  unsigned char src_str[100];
815  unsigned char dst_str[100];
816  unsigned char output[100];
817  aes_context ctx;
818  int key_len, data_len;
819 
820  memset(key_str, 0x00, 100);
821  memset(iv_str, 0x00, 100);
822  memset(src_str, 0x00, 100);
823  memset(dst_str, 0x00, 100);
824  memset(output, 0x00, 100);
825 
826  key_len = unhexify( key_str, "00000000000000000000000000000000" );
827  unhexify( iv_str, "00000000000000000000000000000000" );
828  data_len = unhexify( src_str, "0336763e966d92595a567cc9ce537f5e" );
829 
830  aes_setkey_dec( &ctx, key_str, key_len * 8 );
831  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
832  if( 0 == 0)
833  {
834  hexify( dst_str, output, data_len );
835 
836  fct_chk( strcmp( (char *) dst_str, "f34481ec3cc627bacd5dc3fb08f273e6" ) == 0 );
837  }
838  }
839  FCT_TEST_END();
840 
841 
842  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_8)
843  {
844  unsigned char key_str[100];
845  unsigned char iv_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, data_len;
851 
852  memset(key_str, 0x00, 100);
853  memset(iv_str, 0x00, 100);
854  memset(src_str, 0x00, 100);
855  memset(dst_str, 0x00, 100);
856  memset(output, 0x00, 100);
857 
858  key_len = unhexify( key_str, "00000000000000000000000000000000" );
859  unhexify( iv_str, "00000000000000000000000000000000" );
860  data_len = unhexify( src_str, "a9a1631bf4996954ebc093957b234589" );
861 
862  aes_setkey_dec( &ctx, key_str, key_len * 8 );
863  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
864  if( 0 == 0)
865  {
866  hexify( dst_str, output, data_len );
867 
868  fct_chk( strcmp( (char *) dst_str, "9798c4640bad75c7c3227db910174e72" ) == 0 );
869  }
870  }
871  FCT_TEST_END();
872 
873 
874  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_9)
875  {
876  unsigned char key_str[100];
877  unsigned char iv_str[100];
878  unsigned char src_str[100];
879  unsigned char dst_str[100];
880  unsigned char output[100];
881  aes_context ctx;
882  int key_len, data_len;
883 
884  memset(key_str, 0x00, 100);
885  memset(iv_str, 0x00, 100);
886  memset(src_str, 0x00, 100);
887  memset(dst_str, 0x00, 100);
888  memset(output, 0x00, 100);
889 
890  key_len = unhexify( key_str, "00000000000000000000000000000000" );
891  unhexify( iv_str, "00000000000000000000000000000000" );
892  data_len = unhexify( src_str, "ff4f8391a6a40ca5b25d23bedd44a597" );
893 
894  aes_setkey_dec( &ctx, key_str, key_len * 8 );
895  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
896  if( 0 == 0)
897  {
898  hexify( dst_str, output, data_len );
899 
900  fct_chk( strcmp( (char *) dst_str, "96ab5c2ff612d9dfaae8c31f30c42168" ) == 0 );
901  }
902  }
903  FCT_TEST_END();
904 
905 
906  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_10)
907  {
908  unsigned char key_str[100];
909  unsigned char iv_str[100];
910  unsigned char src_str[100];
911  unsigned char dst_str[100];
912  unsigned char output[100];
913  aes_context ctx;
914  int key_len, data_len;
915 
916  memset(key_str, 0x00, 100);
917  memset(iv_str, 0x00, 100);
918  memset(src_str, 0x00, 100);
919  memset(dst_str, 0x00, 100);
920  memset(output, 0x00, 100);
921 
922  key_len = unhexify( key_str, "00000000000000000000000000000000" );
923  unhexify( iv_str, "00000000000000000000000000000000" );
924  data_len = unhexify( src_str, "f9b0fda0c4a898f5b9e6f661c4ce4d07" );
925 
926  aes_setkey_dec( &ctx, key_str, key_len * 8 );
927  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
928  if( 0 == 0)
929  {
930  hexify( dst_str, output, data_len );
931 
932  fct_chk( strcmp( (char *) dst_str, "fffffffffffffffffffffffffffffff0" ) == 0 );
933  }
934  }
935  FCT_TEST_END();
936 
937 
938  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_11)
939  {
940  unsigned char key_str[100];
941  unsigned char iv_str[100];
942  unsigned char src_str[100];
943  unsigned char dst_str[100];
944  unsigned char output[100];
945  aes_context ctx;
946  int key_len, data_len;
947 
948  memset(key_str, 0x00, 100);
949  memset(iv_str, 0x00, 100);
950  memset(src_str, 0x00, 100);
951  memset(dst_str, 0x00, 100);
952  memset(output, 0x00, 100);
953 
954  key_len = unhexify( key_str, "00000000000000000000000000000000" );
955  unhexify( iv_str, "00000000000000000000000000000000" );
956  data_len = unhexify( src_str, "8ade895913685c67c5269f8aae42983e" );
957 
958  aes_setkey_dec( &ctx, key_str, key_len * 8 );
959  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
960  if( 0 == 0)
961  {
962  hexify( dst_str, output, data_len );
963 
964  fct_chk( strcmp( (char *) dst_str, "fffffffffffffffffffffffffffffff8" ) == 0 );
965  }
966  }
967  FCT_TEST_END();
968 
969 
970  FCT_TEST_BGN(aes_128_cbc_decrypt_nist_kat_12)
971  {
972  unsigned char key_str[100];
973  unsigned char iv_str[100];
974  unsigned char src_str[100];
975  unsigned char dst_str[100];
976  unsigned char output[100];
977  aes_context ctx;
978  int key_len, data_len;
979 
980  memset(key_str, 0x00, 100);
981  memset(iv_str, 0x00, 100);
982  memset(src_str, 0x00, 100);
983  memset(dst_str, 0x00, 100);
984  memset(output, 0x00, 100);
985 
986  key_len = unhexify( key_str, "00000000000000000000000000000000" );
987  unhexify( iv_str, "00000000000000000000000000000000" );
988  data_len = unhexify( src_str, "39bde67d5c8ed8a8b1c37eb8fa9f5ac0" );
989 
990  aes_setkey_dec( &ctx, key_str, key_len * 8 );
991  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
992  if( 0 == 0)
993  {
994  hexify( dst_str, output, data_len );
995 
996  fct_chk( strcmp( (char *) dst_str, "fffffffffffffffffffffffffffffffc" ) == 0 );
997  }
998  }
999  FCT_TEST_END();
1000 
1001 
1002  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_1)
1003  {
1004  unsigned char key_str[100];
1005  unsigned char iv_str[100];
1006  unsigned char src_str[100];
1007  unsigned char dst_str[100];
1008  unsigned char output[100];
1009  aes_context ctx;
1010  int key_len, data_len;
1011 
1012  memset(key_str, 0x00, 100);
1013  memset(iv_str, 0x00, 100);
1014  memset(src_str, 0x00, 100);
1015  memset(dst_str, 0x00, 100);
1016  memset(output, 0x00, 100);
1017 
1018  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffffffffffffffe00" );
1019  unhexify( iv_str, "00000000000000000000000000000000" );
1020  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1021 
1022  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1023  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1024  if( 0 == 0 )
1025  {
1026  hexify( dst_str, output, data_len );
1027 
1028  fct_chk( strcmp( (char *) dst_str, "ddb505e6cc1384cbaec1df90b80beb20" ) == 0 );
1029  }
1030  }
1031  FCT_TEST_END();
1032 
1033 
1034  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_2)
1035  {
1036  unsigned char key_str[100];
1037  unsigned char iv_str[100];
1038  unsigned char src_str[100];
1039  unsigned char dst_str[100];
1040  unsigned char output[100];
1041  aes_context ctx;
1042  int key_len, data_len;
1043 
1044  memset(key_str, 0x00, 100);
1045  memset(iv_str, 0x00, 100);
1046  memset(src_str, 0x00, 100);
1047  memset(dst_str, 0x00, 100);
1048  memset(output, 0x00, 100);
1049 
1050  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffffffffffffffffffff00" );
1051  unhexify( iv_str, "00000000000000000000000000000000" );
1052  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1053 
1054  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1055  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1056  if( 0 == 0 )
1057  {
1058  hexify( dst_str, output, data_len );
1059 
1060  fct_chk( strcmp( (char *) dst_str, "5674a3bed27bf4bd3622f9f5fe208306" ) == 0 );
1061  }
1062  }
1063  FCT_TEST_END();
1064 
1065 
1066  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_3)
1067  {
1068  unsigned char key_str[100];
1069  unsigned char iv_str[100];
1070  unsigned char src_str[100];
1071  unsigned char dst_str[100];
1072  unsigned char output[100];
1073  aes_context ctx;
1074  int key_len, data_len;
1075 
1076  memset(key_str, 0x00, 100);
1077  memset(iv_str, 0x00, 100);
1078  memset(src_str, 0x00, 100);
1079  memset(dst_str, 0x00, 100);
1080  memset(output, 0x00, 100);
1081 
1082  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffffffffffffffffffff80" );
1083  unhexify( iv_str, "00000000000000000000000000000000" );
1084  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1085 
1086  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1087  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1088  if( 0 == 0 )
1089  {
1090  hexify( dst_str, output, data_len );
1091 
1092  fct_chk( strcmp( (char *) dst_str, "b687f26a89cfbfbb8e5eeac54055315e" ) == 0 );
1093  }
1094  }
1095  FCT_TEST_END();
1096 
1097 
1098  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_4)
1099  {
1100  unsigned char key_str[100];
1101  unsigned char iv_str[100];
1102  unsigned char src_str[100];
1103  unsigned char dst_str[100];
1104  unsigned char output[100];
1105  aes_context ctx;
1106  int key_len, data_len;
1107 
1108  memset(key_str, 0x00, 100);
1109  memset(iv_str, 0x00, 100);
1110  memset(src_str, 0x00, 100);
1111  memset(dst_str, 0x00, 100);
1112  memset(output, 0x00, 100);
1113 
1114  key_len = unhexify( key_str, "25a39dbfd8034f71a81f9ceb55026e4037f8f6aa30ab44ce" );
1115  unhexify( iv_str, "00000000000000000000000000000000" );
1116  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1117 
1118  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1119  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1120  if( 0 == 0 )
1121  {
1122  hexify( dst_str, output, data_len );
1123 
1124  fct_chk( strcmp( (char *) dst_str, "3608c344868e94555d23a120f8a5502d" ) == 0 );
1125  }
1126  }
1127  FCT_TEST_END();
1128 
1129 
1130  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_5)
1131  {
1132  unsigned char key_str[100];
1133  unsigned char iv_str[100];
1134  unsigned char src_str[100];
1135  unsigned char dst_str[100];
1136  unsigned char output[100];
1137  aes_context ctx;
1138  int key_len, data_len;
1139 
1140  memset(key_str, 0x00, 100);
1141  memset(iv_str, 0x00, 100);
1142  memset(src_str, 0x00, 100);
1143  memset(dst_str, 0x00, 100);
1144  memset(output, 0x00, 100);
1145 
1146  key_len = unhexify( key_str, "e08c15411774ec4a908b64eadc6ac4199c7cd453f3aaef53" );
1147  unhexify( iv_str, "00000000000000000000000000000000" );
1148  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1149 
1150  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1151  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1152  if( 0 == 0 )
1153  {
1154  hexify( dst_str, output, data_len );
1155 
1156  fct_chk( strcmp( (char *) dst_str, "77da2021935b840b7f5dcc39132da9e5" ) == 0 );
1157  }
1158  }
1159  FCT_TEST_END();
1160 
1161 
1162  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_6)
1163  {
1164  unsigned char key_str[100];
1165  unsigned char iv_str[100];
1166  unsigned char src_str[100];
1167  unsigned char dst_str[100];
1168  unsigned char output[100];
1169  aes_context ctx;
1170  int key_len, data_len;
1171 
1172  memset(key_str, 0x00, 100);
1173  memset(iv_str, 0x00, 100);
1174  memset(src_str, 0x00, 100);
1175  memset(dst_str, 0x00, 100);
1176  memset(output, 0x00, 100);
1177 
1178  key_len = unhexify( key_str, "3b375a1ff7e8d44409696e6326ec9dec86138e2ae010b980" );
1179  unhexify( iv_str, "00000000000000000000000000000000" );
1180  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1181 
1182  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1183  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1184  if( 0 == 0 )
1185  {
1186  hexify( dst_str, output, data_len );
1187 
1188  fct_chk( strcmp( (char *) dst_str, "3b7c24f825e3bf9873c9f14d39a0e6f4" ) == 0 );
1189  }
1190  }
1191  FCT_TEST_END();
1192 
1193 
1194  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_7)
1195  {
1196  unsigned char key_str[100];
1197  unsigned char iv_str[100];
1198  unsigned char src_str[100];
1199  unsigned char dst_str[100];
1200  unsigned char output[100];
1201  aes_context ctx;
1202  int key_len, data_len;
1203 
1204  memset(key_str, 0x00, 100);
1205  memset(iv_str, 0x00, 100);
1206  memset(src_str, 0x00, 100);
1207  memset(dst_str, 0x00, 100);
1208  memset(output, 0x00, 100);
1209 
1210  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1211  unhexify( iv_str, "00000000000000000000000000000000" );
1212  data_len = unhexify( src_str, "51719783d3185a535bd75adc65071ce1" );
1213 
1214  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1215  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1216  if( 0 == 0 )
1217  {
1218  hexify( dst_str, output, data_len );
1219 
1220  fct_chk( strcmp( (char *) dst_str, "4f354592ff7c8847d2d0870ca9481b7c" ) == 0 );
1221  }
1222  }
1223  FCT_TEST_END();
1224 
1225 
1226  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_8)
1227  {
1228  unsigned char key_str[100];
1229  unsigned char iv_str[100];
1230  unsigned char src_str[100];
1231  unsigned char dst_str[100];
1232  unsigned char output[100];
1233  aes_context ctx;
1234  int key_len, data_len;
1235 
1236  memset(key_str, 0x00, 100);
1237  memset(iv_str, 0x00, 100);
1238  memset(src_str, 0x00, 100);
1239  memset(dst_str, 0x00, 100);
1240  memset(output, 0x00, 100);
1241 
1242  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1243  unhexify( iv_str, "00000000000000000000000000000000" );
1244  data_len = unhexify( src_str, "26aa49dcfe7629a8901a69a9914e6dfd" );
1245 
1246  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1247  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1248  if( 0 == 0 )
1249  {
1250  hexify( dst_str, output, data_len );
1251 
1252  fct_chk( strcmp( (char *) dst_str, "d5e08bf9a182e857cf40b3a36ee248cc" ) == 0 );
1253  }
1254  }
1255  FCT_TEST_END();
1256 
1257 
1258  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_9)
1259  {
1260  unsigned char key_str[100];
1261  unsigned char iv_str[100];
1262  unsigned char src_str[100];
1263  unsigned char dst_str[100];
1264  unsigned char output[100];
1265  aes_context ctx;
1266  int key_len, data_len;
1267 
1268  memset(key_str, 0x00, 100);
1269  memset(iv_str, 0x00, 100);
1270  memset(src_str, 0x00, 100);
1271  memset(dst_str, 0x00, 100);
1272  memset(output, 0x00, 100);
1273 
1274  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1275  unhexify( iv_str, "00000000000000000000000000000000" );
1276  data_len = unhexify( src_str, "941a4773058224e1ef66d10e0a6ee782" );
1277 
1278  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1279  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1280  if( 0 == 0 )
1281  {
1282  hexify( dst_str, output, data_len );
1283 
1284  fct_chk( strcmp( (char *) dst_str, "067cd9d3749207791841562507fa9626" ) == 0 );
1285  }
1286  }
1287  FCT_TEST_END();
1288 
1289 
1290  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_10)
1291  {
1292  unsigned char key_str[100];
1293  unsigned char iv_str[100];
1294  unsigned char src_str[100];
1295  unsigned char dst_str[100];
1296  unsigned char output[100];
1297  aes_context ctx;
1298  int key_len, data_len;
1299 
1300  memset(key_str, 0x00, 100);
1301  memset(iv_str, 0x00, 100);
1302  memset(src_str, 0x00, 100);
1303  memset(dst_str, 0x00, 100);
1304  memset(output, 0x00, 100);
1305 
1306  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1307  unhexify( iv_str, "00000000000000000000000000000000" );
1308  data_len = unhexify( src_str, "ffc00000000000000000000000000000" );
1309 
1310  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1311  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1312  if( 0 == 0 )
1313  {
1314  hexify( dst_str, output, data_len );
1315 
1316  fct_chk( strcmp( (char *) dst_str, "030d7e5b64f380a7e4ea5387b5cd7f49" ) == 0 );
1317  }
1318  }
1319  FCT_TEST_END();
1320 
1321 
1322  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_11)
1323  {
1324  unsigned char key_str[100];
1325  unsigned char iv_str[100];
1326  unsigned char src_str[100];
1327  unsigned char dst_str[100];
1328  unsigned char output[100];
1329  aes_context ctx;
1330  int key_len, data_len;
1331 
1332  memset(key_str, 0x00, 100);
1333  memset(iv_str, 0x00, 100);
1334  memset(src_str, 0x00, 100);
1335  memset(dst_str, 0x00, 100);
1336  memset(output, 0x00, 100);
1337 
1338  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1339  unhexify( iv_str, "00000000000000000000000000000000" );
1340  data_len = unhexify( src_str, "ffe00000000000000000000000000000" );
1341 
1342  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1343  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1344  if( 0 == 0 )
1345  {
1346  hexify( dst_str, output, data_len );
1347 
1348  fct_chk( strcmp( (char *) dst_str, "0dc9a2610037009b698f11bb7e86c83e" ) == 0 );
1349  }
1350  }
1351  FCT_TEST_END();
1352 
1353 
1354  FCT_TEST_BGN(aes_192_cbc_encrypt_nist_kat_12)
1355  {
1356  unsigned char key_str[100];
1357  unsigned char iv_str[100];
1358  unsigned char src_str[100];
1359  unsigned char dst_str[100];
1360  unsigned char output[100];
1361  aes_context ctx;
1362  int key_len, data_len;
1363 
1364  memset(key_str, 0x00, 100);
1365  memset(iv_str, 0x00, 100);
1366  memset(src_str, 0x00, 100);
1367  memset(dst_str, 0x00, 100);
1368  memset(output, 0x00, 100);
1369 
1370  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1371  unhexify( iv_str, "00000000000000000000000000000000" );
1372  data_len = unhexify( src_str, "fff00000000000000000000000000000" );
1373 
1374  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1375  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1376  if( 0 == 0 )
1377  {
1378  hexify( dst_str, output, data_len );
1379 
1380  fct_chk( strcmp( (char *) dst_str, "0046612c766d1840c226364f1fa7ed72" ) == 0 );
1381  }
1382  }
1383  FCT_TEST_END();
1384 
1385 
1386  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_1)
1387  {
1388  unsigned char key_str[100];
1389  unsigned char iv_str[100];
1390  unsigned char src_str[100];
1391  unsigned char dst_str[100];
1392  unsigned char output[100];
1393  aes_context ctx;
1394  int key_len, data_len;
1395 
1396  memset(key_str, 0x00, 100);
1397  memset(iv_str, 0x00, 100);
1398  memset(src_str, 0x00, 100);
1399  memset(dst_str, 0x00, 100);
1400  memset(output, 0x00, 100);
1401 
1402  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1403  unhexify( iv_str, "00000000000000000000000000000000" );
1404  data_len = unhexify( src_str, "902d88d13eae52089abd6143cfe394e9" );
1405 
1406  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1407  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1408  if( 0 == 0)
1409  {
1410  hexify( dst_str, output, data_len );
1411 
1412  fct_chk( strcmp( (char *) dst_str, "ffffffffe00000000000000000000000" ) == 0 );
1413  }
1414  }
1415  FCT_TEST_END();
1416 
1417 
1418  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_2)
1419  {
1420  unsigned char key_str[100];
1421  unsigned char iv_str[100];
1422  unsigned char src_str[100];
1423  unsigned char dst_str[100];
1424  unsigned char output[100];
1425  aes_context ctx;
1426  int key_len, data_len;
1427 
1428  memset(key_str, 0x00, 100);
1429  memset(iv_str, 0x00, 100);
1430  memset(src_str, 0x00, 100);
1431  memset(dst_str, 0x00, 100);
1432  memset(output, 0x00, 100);
1433 
1434  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1435  unhexify( iv_str, "00000000000000000000000000000000" );
1436  data_len = unhexify( src_str, "d49bceb3b823fedd602c305345734bd2" );
1437 
1438  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1439  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1440  if( 0 == 0)
1441  {
1442  hexify( dst_str, output, data_len );
1443 
1444  fct_chk( strcmp( (char *) dst_str, "fffffffff00000000000000000000000" ) == 0 );
1445  }
1446  }
1447  FCT_TEST_END();
1448 
1449 
1450  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_3)
1451  {
1452  unsigned char key_str[100];
1453  unsigned char iv_str[100];
1454  unsigned char src_str[100];
1455  unsigned char dst_str[100];
1456  unsigned char output[100];
1457  aes_context ctx;
1458  int key_len, data_len;
1459 
1460  memset(key_str, 0x00, 100);
1461  memset(iv_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, "000000000000000000000000000000000000000000000000" );
1467  unhexify( iv_str, "00000000000000000000000000000000" );
1468  data_len = unhexify( src_str, "707b1dbb0ffa40ef7d95def421233fae" );
1469 
1470  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1471  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1472  if( 0 == 0)
1473  {
1474  hexify( dst_str, output, data_len );
1475 
1476  fct_chk( strcmp( (char *) dst_str, "fffffffff80000000000000000000000" ) == 0 );
1477  }
1478  }
1479  FCT_TEST_END();
1480 
1481 
1482  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_4)
1483  {
1484  unsigned char key_str[100];
1485  unsigned char iv_str[100];
1486  unsigned char src_str[100];
1487  unsigned char dst_str[100];
1488  unsigned char output[100];
1489  aes_context ctx;
1490  int key_len, data_len;
1491 
1492  memset(key_str, 0x00, 100);
1493  memset(iv_str, 0x00, 100);
1494  memset(src_str, 0x00, 100);
1495  memset(dst_str, 0x00, 100);
1496  memset(output, 0x00, 100);
1497 
1498  key_len = unhexify( key_str, "fffffffffffffffffffc0000000000000000000000000000" );
1499  unhexify( iv_str, "00000000000000000000000000000000" );
1500  data_len = unhexify( src_str, "8dfd999be5d0cfa35732c0ddc88ff5a5" );
1501 
1502  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1503  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1504  if( 0 == 0)
1505  {
1506  hexify( dst_str, output, data_len );
1507 
1508  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1509  }
1510  }
1511  FCT_TEST_END();
1512 
1513 
1514  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_5)
1515  {
1516  unsigned char key_str[100];
1517  unsigned char iv_str[100];
1518  unsigned char src_str[100];
1519  unsigned char dst_str[100];
1520  unsigned char output[100];
1521  aes_context ctx;
1522  int key_len, data_len;
1523 
1524  memset(key_str, 0x00, 100);
1525  memset(iv_str, 0x00, 100);
1526  memset(src_str, 0x00, 100);
1527  memset(dst_str, 0x00, 100);
1528  memset(output, 0x00, 100);
1529 
1530  key_len = unhexify( key_str, "fffffffffffffffffffe0000000000000000000000000000" );
1531  unhexify( iv_str, "00000000000000000000000000000000" );
1532  data_len = unhexify( src_str, "02647c76a300c3173b841487eb2bae9f" );
1533 
1534  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1535  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1536  if( 0 == 0)
1537  {
1538  hexify( dst_str, output, data_len );
1539 
1540  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1541  }
1542  }
1543  FCT_TEST_END();
1544 
1545 
1546  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_6)
1547  {
1548  unsigned char key_str[100];
1549  unsigned char iv_str[100];
1550  unsigned char src_str[100];
1551  unsigned char dst_str[100];
1552  unsigned char output[100];
1553  aes_context ctx;
1554  int key_len, data_len;
1555 
1556  memset(key_str, 0x00, 100);
1557  memset(iv_str, 0x00, 100);
1558  memset(src_str, 0x00, 100);
1559  memset(dst_str, 0x00, 100);
1560  memset(output, 0x00, 100);
1561 
1562  key_len = unhexify( key_str, "ffffffffffffffffffff0000000000000000000000000000" );
1563  unhexify( iv_str, "00000000000000000000000000000000" );
1564  data_len = unhexify( src_str, "172df8b02f04b53adab028b4e01acd87" );
1565 
1566  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1567  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1568  if( 0 == 0)
1569  {
1570  hexify( dst_str, output, data_len );
1571 
1572  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1573  }
1574  }
1575  FCT_TEST_END();
1576 
1577 
1578  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_7)
1579  {
1580  unsigned char key_str[100];
1581  unsigned char iv_str[100];
1582  unsigned char src_str[100];
1583  unsigned char dst_str[100];
1584  unsigned char output[100];
1585  aes_context ctx;
1586  int key_len, data_len;
1587 
1588  memset(key_str, 0x00, 100);
1589  memset(iv_str, 0x00, 100);
1590  memset(src_str, 0x00, 100);
1591  memset(dst_str, 0x00, 100);
1592  memset(output, 0x00, 100);
1593 
1594  key_len = unhexify( key_str, "b3ad5cea1dddc214ca969ac35f37dae1a9a9d1528f89bb35" );
1595  unhexify( iv_str, "00000000000000000000000000000000" );
1596  data_len = unhexify( src_str, "3cf5e1d21a17956d1dffad6a7c41c659" );
1597 
1598  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1599  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1600  if( 0 == 0)
1601  {
1602  hexify( dst_str, output, data_len );
1603 
1604  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1605  }
1606  }
1607  FCT_TEST_END();
1608 
1609 
1610  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_8)
1611  {
1612  unsigned char key_str[100];
1613  unsigned char iv_str[100];
1614  unsigned char src_str[100];
1615  unsigned char dst_str[100];
1616  unsigned char output[100];
1617  aes_context ctx;
1618  int key_len, data_len;
1619 
1620  memset(key_str, 0x00, 100);
1621  memset(iv_str, 0x00, 100);
1622  memset(src_str, 0x00, 100);
1623  memset(dst_str, 0x00, 100);
1624  memset(output, 0x00, 100);
1625 
1626  key_len = unhexify( key_str, "45899367c3132849763073c435a9288a766c8b9ec2308516" );
1627  unhexify( iv_str, "00000000000000000000000000000000" );
1628  data_len = unhexify( src_str, "69fd12e8505f8ded2fdcb197a121b362" );
1629 
1630  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1631  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1632  if( 0 == 0)
1633  {
1634  hexify( dst_str, output, data_len );
1635 
1636  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1637  }
1638  }
1639  FCT_TEST_END();
1640 
1641 
1642  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_9)
1643  {
1644  unsigned char key_str[100];
1645  unsigned char iv_str[100];
1646  unsigned char src_str[100];
1647  unsigned char dst_str[100];
1648  unsigned char output[100];
1649  aes_context ctx;
1650  int key_len, data_len;
1651 
1652  memset(key_str, 0x00, 100);
1653  memset(iv_str, 0x00, 100);
1654  memset(src_str, 0x00, 100);
1655  memset(dst_str, 0x00, 100);
1656  memset(output, 0x00, 100);
1657 
1658  key_len = unhexify( key_str, "ec250e04c3903f602647b85a401a1ae7ca2f02f67fa4253e" );
1659  unhexify( iv_str, "00000000000000000000000000000000" );
1660  data_len = unhexify( src_str, "8aa584e2cc4d17417a97cb9a28ba29c8" );
1661 
1662  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1663  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1664  if( 0 == 0)
1665  {
1666  hexify( dst_str, output, data_len );
1667 
1668  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
1669  }
1670  }
1671  FCT_TEST_END();
1672 
1673 
1674  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_10)
1675  {
1676  unsigned char key_str[100];
1677  unsigned char iv_str[100];
1678  unsigned char src_str[100];
1679  unsigned char dst_str[100];
1680  unsigned char output[100];
1681  aes_context ctx;
1682  int key_len, data_len;
1683 
1684  memset(key_str, 0x00, 100);
1685  memset(iv_str, 0x00, 100);
1686  memset(src_str, 0x00, 100);
1687  memset(dst_str, 0x00, 100);
1688  memset(output, 0x00, 100);
1689 
1690  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1691  unhexify( iv_str, "00000000000000000000000000000000" );
1692  data_len = unhexify( src_str, "c9b8135ff1b5adc413dfd053b21bd96d" );
1693 
1694  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1695  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1696  if( 0 == 0)
1697  {
1698  hexify( dst_str, output, data_len );
1699 
1700  fct_chk( strcmp( (char *) dst_str, "9c2d8842e5f48f57648205d39a239af1" ) == 0 );
1701  }
1702  }
1703  FCT_TEST_END();
1704 
1705 
1706  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_11)
1707  {
1708  unsigned char key_str[100];
1709  unsigned char iv_str[100];
1710  unsigned char src_str[100];
1711  unsigned char dst_str[100];
1712  unsigned char output[100];
1713  aes_context ctx;
1714  int key_len, data_len;
1715 
1716  memset(key_str, 0x00, 100);
1717  memset(iv_str, 0x00, 100);
1718  memset(src_str, 0x00, 100);
1719  memset(dst_str, 0x00, 100);
1720  memset(output, 0x00, 100);
1721 
1722  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1723  unhexify( iv_str, "00000000000000000000000000000000" );
1724  data_len = unhexify( src_str, "4a3650c3371ce2eb35e389a171427440" );
1725 
1726  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1727  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1728  if( 0 == 0)
1729  {
1730  hexify( dst_str, output, data_len );
1731 
1732  fct_chk( strcmp( (char *) dst_str, "bff52510095f518ecca60af4205444bb" ) == 0 );
1733  }
1734  }
1735  FCT_TEST_END();
1736 
1737 
1738  FCT_TEST_BGN(aes_192_cbc_decrypt_nist_kat_12)
1739  {
1740  unsigned char key_str[100];
1741  unsigned char iv_str[100];
1742  unsigned char src_str[100];
1743  unsigned char dst_str[100];
1744  unsigned char output[100];
1745  aes_context ctx;
1746  int key_len, data_len;
1747 
1748  memset(key_str, 0x00, 100);
1749  memset(iv_str, 0x00, 100);
1750  memset(src_str, 0x00, 100);
1751  memset(dst_str, 0x00, 100);
1752  memset(output, 0x00, 100);
1753 
1754  key_len = unhexify( key_str, "000000000000000000000000000000000000000000000000" );
1755  unhexify( iv_str, "00000000000000000000000000000000" );
1756  data_len = unhexify( src_str, "4f354592ff7c8847d2d0870ca9481b7c" );
1757 
1758  aes_setkey_dec( &ctx, key_str, key_len * 8 );
1759  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
1760  if( 0 == 0)
1761  {
1762  hexify( dst_str, output, data_len );
1763 
1764  fct_chk( strcmp( (char *) dst_str, "51719783d3185a535bd75adc65071ce1" ) == 0 );
1765  }
1766  }
1767  FCT_TEST_END();
1768 
1769 
1770  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_1)
1771  {
1772  unsigned char key_str[100];
1773  unsigned char iv_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, data_len;
1779 
1780  memset(key_str, 0x00, 100);
1781  memset(iv_str, 0x00, 100);
1782  memset(src_str, 0x00, 100);
1783  memset(dst_str, 0x00, 100);
1784  memset(output, 0x00, 100);
1785 
1786  key_len = unhexify( key_str, "8000000000000000000000000000000000000000000000000000000000000000" );
1787  unhexify( iv_str, "00000000000000000000000000000000" );
1788  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1789 
1790  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1791  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1792  if( 0 == 0 )
1793  {
1794  hexify( dst_str, output, data_len );
1795 
1796  fct_chk( strcmp( (char *) dst_str, "e35a6dcb19b201a01ebcfa8aa22b5759" ) == 0 );
1797  }
1798  }
1799  FCT_TEST_END();
1800 
1801 
1802  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_2)
1803  {
1804  unsigned char key_str[100];
1805  unsigned char iv_str[100];
1806  unsigned char src_str[100];
1807  unsigned char dst_str[100];
1808  unsigned char output[100];
1809  aes_context ctx;
1810  int key_len, data_len;
1811 
1812  memset(key_str, 0x00, 100);
1813  memset(iv_str, 0x00, 100);
1814  memset(src_str, 0x00, 100);
1815  memset(dst_str, 0x00, 100);
1816  memset(output, 0x00, 100);
1817 
1818  key_len = unhexify( key_str, "c000000000000000000000000000000000000000000000000000000000000000" );
1819  unhexify( iv_str, "00000000000000000000000000000000" );
1820  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1821 
1822  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1823  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1824  if( 0 == 0 )
1825  {
1826  hexify( dst_str, output, data_len );
1827 
1828  fct_chk( strcmp( (char *) dst_str, "b29169cdcf2d83e838125a12ee6aa400" ) == 0 );
1829  }
1830  }
1831  FCT_TEST_END();
1832 
1833 
1834  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_3)
1835  {
1836  unsigned char key_str[100];
1837  unsigned char iv_str[100];
1838  unsigned char src_str[100];
1839  unsigned char dst_str[100];
1840  unsigned char output[100];
1841  aes_context ctx;
1842  int key_len, data_len;
1843 
1844  memset(key_str, 0x00, 100);
1845  memset(iv_str, 0x00, 100);
1846  memset(src_str, 0x00, 100);
1847  memset(dst_str, 0x00, 100);
1848  memset(output, 0x00, 100);
1849 
1850  key_len = unhexify( key_str, "e000000000000000000000000000000000000000000000000000000000000000" );
1851  unhexify( iv_str, "00000000000000000000000000000000" );
1852  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1853 
1854  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1855  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1856  if( 0 == 0 )
1857  {
1858  hexify( dst_str, output, data_len );
1859 
1860  fct_chk( strcmp( (char *) dst_str, "d8f3a72fc3cdf74dfaf6c3e6b97b2fa6" ) == 0 );
1861  }
1862  }
1863  FCT_TEST_END();
1864 
1865 
1866  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_4)
1867  {
1868  unsigned char key_str[100];
1869  unsigned char iv_str[100];
1870  unsigned char src_str[100];
1871  unsigned char dst_str[100];
1872  unsigned char output[100];
1873  aes_context ctx;
1874  int key_len, data_len;
1875 
1876  memset(key_str, 0x00, 100);
1877  memset(iv_str, 0x00, 100);
1878  memset(src_str, 0x00, 100);
1879  memset(dst_str, 0x00, 100);
1880  memset(output, 0x00, 100);
1881 
1882  key_len = unhexify( key_str, "dc0eba1f2232a7879ded34ed8428eeb8769b056bbaf8ad77cb65c3541430b4cf" );
1883  unhexify( iv_str, "00000000000000000000000000000000" );
1884  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1885 
1886  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1887  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1888  if( 0 == 0 )
1889  {
1890  hexify( dst_str, output, data_len );
1891 
1892  fct_chk( strcmp( (char *) dst_str, "fc6aec906323480005c58e7e1ab004ad" ) == 0 );
1893  }
1894  }
1895  FCT_TEST_END();
1896 
1897 
1898  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_5)
1899  {
1900  unsigned char key_str[100];
1901  unsigned char iv_str[100];
1902  unsigned char src_str[100];
1903  unsigned char dst_str[100];
1904  unsigned char output[100];
1905  aes_context ctx;
1906  int key_len, data_len;
1907 
1908  memset(key_str, 0x00, 100);
1909  memset(iv_str, 0x00, 100);
1910  memset(src_str, 0x00, 100);
1911  memset(dst_str, 0x00, 100);
1912  memset(output, 0x00, 100);
1913 
1914  key_len = unhexify( key_str, "f8be9ba615c5a952cabbca24f68f8593039624d524c816acda2c9183bd917cb9" );
1915  unhexify( iv_str, "00000000000000000000000000000000" );
1916  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1917 
1918  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1919  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1920  if( 0 == 0 )
1921  {
1922  hexify( dst_str, output, data_len );
1923 
1924  fct_chk( strcmp( (char *) dst_str, "a3944b95ca0b52043584ef02151926a8" ) == 0 );
1925  }
1926  }
1927  FCT_TEST_END();
1928 
1929 
1930  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_6)
1931  {
1932  unsigned char key_str[100];
1933  unsigned char iv_str[100];
1934  unsigned char src_str[100];
1935  unsigned char dst_str[100];
1936  unsigned char output[100];
1937  aes_context ctx;
1938  int key_len, data_len;
1939 
1940  memset(key_str, 0x00, 100);
1941  memset(iv_str, 0x00, 100);
1942  memset(src_str, 0x00, 100);
1943  memset(dst_str, 0x00, 100);
1944  memset(output, 0x00, 100);
1945 
1946  key_len = unhexify( key_str, "797f8b3d176dac5b7e34a2d539c4ef367a16f8635f6264737591c5c07bf57a3e" );
1947  unhexify( iv_str, "00000000000000000000000000000000" );
1948  data_len = unhexify( src_str, "00000000000000000000000000000000" );
1949 
1950  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1951  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1952  if( 0 == 0 )
1953  {
1954  hexify( dst_str, output, data_len );
1955 
1956  fct_chk( strcmp( (char *) dst_str, "a74289fe73a4c123ca189ea1e1b49ad5" ) == 0 );
1957  }
1958  }
1959  FCT_TEST_END();
1960 
1961 
1962  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_7)
1963  {
1964  unsigned char key_str[100];
1965  unsigned char iv_str[100];
1966  unsigned char src_str[100];
1967  unsigned char dst_str[100];
1968  unsigned char output[100];
1969  aes_context ctx;
1970  int key_len, data_len;
1971 
1972  memset(key_str, 0x00, 100);
1973  memset(iv_str, 0x00, 100);
1974  memset(src_str, 0x00, 100);
1975  memset(dst_str, 0x00, 100);
1976  memset(output, 0x00, 100);
1977 
1978  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1979  unhexify( iv_str, "00000000000000000000000000000000" );
1980  data_len = unhexify( src_str, "761c1fe41a18acf20d241650611d90f1" );
1981 
1982  aes_setkey_enc( &ctx, key_str, key_len * 8 );
1983  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
1984  if( 0 == 0 )
1985  {
1986  hexify( dst_str, output, data_len );
1987 
1988  fct_chk( strcmp( (char *) dst_str, "623a52fcea5d443e48d9181ab32c7421" ) == 0 );
1989  }
1990  }
1991  FCT_TEST_END();
1992 
1993 
1994  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_8)
1995  {
1996  unsigned char key_str[100];
1997  unsigned char iv_str[100];
1998  unsigned char src_str[100];
1999  unsigned char dst_str[100];
2000  unsigned char output[100];
2001  aes_context ctx;
2002  int key_len, data_len;
2003 
2004  memset(key_str, 0x00, 100);
2005  memset(iv_str, 0x00, 100);
2006  memset(src_str, 0x00, 100);
2007  memset(dst_str, 0x00, 100);
2008  memset(output, 0x00, 100);
2009 
2010  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2011  unhexify( iv_str, "00000000000000000000000000000000" );
2012  data_len = unhexify( src_str, "8a560769d605868ad80d819bdba03771" );
2013 
2014  aes_setkey_enc( &ctx, key_str, key_len * 8 );
2015  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
2016  if( 0 == 0 )
2017  {
2018  hexify( dst_str, output, data_len );
2019 
2020  fct_chk( strcmp( (char *) dst_str, "38f2c7ae10612415d27ca190d27da8b4" ) == 0 );
2021  }
2022  }
2023  FCT_TEST_END();
2024 
2025 
2026  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_9)
2027  {
2028  unsigned char key_str[100];
2029  unsigned char iv_str[100];
2030  unsigned char src_str[100];
2031  unsigned char dst_str[100];
2032  unsigned char output[100];
2033  aes_context ctx;
2034  int key_len, data_len;
2035 
2036  memset(key_str, 0x00, 100);
2037  memset(iv_str, 0x00, 100);
2038  memset(src_str, 0x00, 100);
2039  memset(dst_str, 0x00, 100);
2040  memset(output, 0x00, 100);
2041 
2042  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2043  unhexify( iv_str, "00000000000000000000000000000000" );
2044  data_len = unhexify( src_str, "91fbef2d15a97816060bee1feaa49afe" );
2045 
2046  aes_setkey_enc( &ctx, key_str, key_len * 8 );
2047  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
2048  if( 0 == 0 )
2049  {
2050  hexify( dst_str, output, data_len );
2051 
2052  fct_chk( strcmp( (char *) dst_str, "1bc704f1bce135ceb810341b216d7abe" ) == 0 );
2053  }
2054  }
2055  FCT_TEST_END();
2056 
2057 
2058  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_10)
2059  {
2060  unsigned char key_str[100];
2061  unsigned char iv_str[100];
2062  unsigned char src_str[100];
2063  unsigned char dst_str[100];
2064  unsigned char output[100];
2065  aes_context ctx;
2066  int key_len, data_len;
2067 
2068  memset(key_str, 0x00, 100);
2069  memset(iv_str, 0x00, 100);
2070  memset(src_str, 0x00, 100);
2071  memset(dst_str, 0x00, 100);
2072  memset(output, 0x00, 100);
2073 
2074  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2075  unhexify( iv_str, "00000000000000000000000000000000" );
2076  data_len = unhexify( src_str, "ffffffffffffff800000000000000000" );
2077 
2078  aes_setkey_enc( &ctx, key_str, key_len * 8 );
2079  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
2080  if( 0 == 0 )
2081  {
2082  hexify( dst_str, output, data_len );
2083 
2084  fct_chk( strcmp( (char *) dst_str, "0d9ac756eb297695eed4d382eb126d26" ) == 0 );
2085  }
2086  }
2087  FCT_TEST_END();
2088 
2089 
2090  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_11)
2091  {
2092  unsigned char key_str[100];
2093  unsigned char iv_str[100];
2094  unsigned char src_str[100];
2095  unsigned char dst_str[100];
2096  unsigned char output[100];
2097  aes_context ctx;
2098  int key_len, data_len;
2099 
2100  memset(key_str, 0x00, 100);
2101  memset(iv_str, 0x00, 100);
2102  memset(src_str, 0x00, 100);
2103  memset(dst_str, 0x00, 100);
2104  memset(output, 0x00, 100);
2105 
2106  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2107  unhexify( iv_str, "00000000000000000000000000000000" );
2108  data_len = unhexify( src_str, "ffffffffffffffc00000000000000000" );
2109 
2110  aes_setkey_enc( &ctx, key_str, key_len * 8 );
2111  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
2112  if( 0 == 0 )
2113  {
2114  hexify( dst_str, output, data_len );
2115 
2116  fct_chk( strcmp( (char *) dst_str, "56ede9dda3f6f141bff1757fa689c3e1" ) == 0 );
2117  }
2118  }
2119  FCT_TEST_END();
2120 
2121 
2122  FCT_TEST_BGN(aes_256_cbc_encrypt_nist_kat_12)
2123  {
2124  unsigned char key_str[100];
2125  unsigned char iv_str[100];
2126  unsigned char src_str[100];
2127  unsigned char dst_str[100];
2128  unsigned char output[100];
2129  aes_context ctx;
2130  int key_len, data_len;
2131 
2132  memset(key_str, 0x00, 100);
2133  memset(iv_str, 0x00, 100);
2134  memset(src_str, 0x00, 100);
2135  memset(dst_str, 0x00, 100);
2136  memset(output, 0x00, 100);
2137 
2138  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2139  unhexify( iv_str, "00000000000000000000000000000000" );
2140  data_len = unhexify( src_str, "ffffffffffffffe00000000000000000" );
2141 
2142  aes_setkey_enc( &ctx, key_str, key_len * 8 );
2143  fct_chk( aes_crypt_cbc( &ctx, AES_ENCRYPT, data_len, iv_str, src_str, output ) == 0 );
2144  if( 0 == 0 )
2145  {
2146  hexify( dst_str, output, data_len );
2147 
2148  fct_chk( strcmp( (char *) dst_str, "768f520efe0f23e61d3ec8ad9ce91774" ) == 0 );
2149  }
2150  }
2151  FCT_TEST_END();
2152 
2153 
2154  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_1)
2155  {
2156  unsigned char key_str[100];
2157  unsigned char iv_str[100];
2158  unsigned char src_str[100];
2159  unsigned char dst_str[100];
2160  unsigned char output[100];
2161  aes_context ctx;
2162  int key_len, data_len;
2163 
2164  memset(key_str, 0x00, 100);
2165  memset(iv_str, 0x00, 100);
2166  memset(src_str, 0x00, 100);
2167  memset(dst_str, 0x00, 100);
2168  memset(output, 0x00, 100);
2169 
2170  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2171  unhexify( iv_str, "00000000000000000000000000000000" );
2172  data_len = unhexify( src_str, "49af6b372135acef10132e548f217b17" );
2173 
2174  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2175  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2176  if( 0 == 0)
2177  {
2178  hexify( dst_str, output, data_len );
2179 
2180  fct_chk( strcmp( (char *) dst_str, "ff000000000000000000000000000000" ) == 0 );
2181  }
2182  }
2183  FCT_TEST_END();
2184 
2185 
2186  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_2)
2187  {
2188  unsigned char key_str[100];
2189  unsigned char iv_str[100];
2190  unsigned char src_str[100];
2191  unsigned char dst_str[100];
2192  unsigned char output[100];
2193  aes_context ctx;
2194  int key_len, data_len;
2195 
2196  memset(key_str, 0x00, 100);
2197  memset(iv_str, 0x00, 100);
2198  memset(src_str, 0x00, 100);
2199  memset(dst_str, 0x00, 100);
2200  memset(output, 0x00, 100);
2201 
2202  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2203  unhexify( iv_str, "00000000000000000000000000000000" );
2204  data_len = unhexify( src_str, "8bcd40f94ebb63b9f7909676e667f1e7" );
2205 
2206  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2207  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2208  if( 0 == 0)
2209  {
2210  hexify( dst_str, output, data_len );
2211 
2212  fct_chk( strcmp( (char *) dst_str, "ff800000000000000000000000000000" ) == 0 );
2213  }
2214  }
2215  FCT_TEST_END();
2216 
2217 
2218  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_3)
2219  {
2220  unsigned char key_str[100];
2221  unsigned char iv_str[100];
2222  unsigned char src_str[100];
2223  unsigned char dst_str[100];
2224  unsigned char output[100];
2225  aes_context ctx;
2226  int key_len, data_len;
2227 
2228  memset(key_str, 0x00, 100);
2229  memset(iv_str, 0x00, 100);
2230  memset(src_str, 0x00, 100);
2231  memset(dst_str, 0x00, 100);
2232  memset(output, 0x00, 100);
2233 
2234  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2235  unhexify( iv_str, "00000000000000000000000000000000" );
2236  data_len = unhexify( src_str, "fe1cffb83f45dcfb38b29be438dbd3ab" );
2237 
2238  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2239  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2240  if( 0 == 0)
2241  {
2242  hexify( dst_str, output, data_len );
2243 
2244  fct_chk( strcmp( (char *) dst_str, "ffc00000000000000000000000000000" ) == 0 );
2245  }
2246  }
2247  FCT_TEST_END();
2248 
2249 
2250  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_4)
2251  {
2252  unsigned char key_str[100];
2253  unsigned char iv_str[100];
2254  unsigned char src_str[100];
2255  unsigned char dst_str[100];
2256  unsigned char output[100];
2257  aes_context ctx;
2258  int key_len, data_len;
2259 
2260  memset(key_str, 0x00, 100);
2261  memset(iv_str, 0x00, 100);
2262  memset(src_str, 0x00, 100);
2263  memset(dst_str, 0x00, 100);
2264  memset(output, 0x00, 100);
2265 
2266  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc00" );
2267  unhexify( iv_str, "00000000000000000000000000000000" );
2268  data_len = unhexify( src_str, "cca7c3086f5f9511b31233da7cab9160" );
2269 
2270  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2271  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2272  if( 0 == 0)
2273  {
2274  hexify( dst_str, output, data_len );
2275 
2276  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2277  }
2278  }
2279  FCT_TEST_END();
2280 
2281 
2282  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_5)
2283  {
2284  unsigned char key_str[100];
2285  unsigned char iv_str[100];
2286  unsigned char src_str[100];
2287  unsigned char dst_str[100];
2288  unsigned char output[100];
2289  aes_context ctx;
2290  int key_len, data_len;
2291 
2292  memset(key_str, 0x00, 100);
2293  memset(iv_str, 0x00, 100);
2294  memset(src_str, 0x00, 100);
2295  memset(dst_str, 0x00, 100);
2296  memset(output, 0x00, 100);
2297 
2298  key_len = unhexify( key_str, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00" );
2299  unhexify( iv_str, "00000000000000000000000000000000" );
2300  data_len = unhexify( src_str, "5b40ff4ec9be536ba23035fa4f06064c" );
2301 
2302  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2303  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2304  if( 0 == 0)
2305  {
2306  hexify( dst_str, output, data_len );
2307 
2308  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2309  }
2310  }
2311  FCT_TEST_END();
2312 
2313 
2314  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_6)
2315  {
2316  unsigned char key_str[100];
2317  unsigned char iv_str[100];
2318  unsigned char src_str[100];
2319  unsigned char dst_str[100];
2320  unsigned char output[100];
2321  aes_context ctx;
2322  int key_len, data_len;
2323 
2324  memset(key_str, 0x00, 100);
2325  memset(iv_str, 0x00, 100);
2326  memset(src_str, 0x00, 100);
2327  memset(dst_str, 0x00, 100);
2328  memset(output, 0x00, 100);
2329 
2330  key_len = unhexify( key_str, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00" );
2331  unhexify( iv_str, "00000000000000000000000000000000" );
2332  data_len = unhexify( src_str, "60eb5af8416b257149372194e8b88749" );
2333 
2334  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2335  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2336  if( 0 == 0)
2337  {
2338  hexify( dst_str, output, data_len );
2339 
2340  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2341  }
2342  }
2343  FCT_TEST_END();
2344 
2345 
2346  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_7)
2347  {
2348  unsigned char key_str[100];
2349  unsigned char iv_str[100];
2350  unsigned char src_str[100];
2351  unsigned char dst_str[100];
2352  unsigned char output[100];
2353  aes_context ctx;
2354  int key_len, data_len;
2355 
2356  memset(key_str, 0x00, 100);
2357  memset(iv_str, 0x00, 100);
2358  memset(src_str, 0x00, 100);
2359  memset(dst_str, 0x00, 100);
2360  memset(output, 0x00, 100);
2361 
2362  key_len = unhexify( key_str, "90143ae20cd78c5d8ebdd6cb9dc1762427a96c78c639bccc41a61424564eafe1" );
2363  unhexify( iv_str, "00000000000000000000000000000000" );
2364  data_len = unhexify( src_str, "798c7c005dee432b2c8ea5dfa381ecc3" );
2365 
2366  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2367  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2368  if( 0 == 0)
2369  {
2370  hexify( dst_str, output, data_len );
2371 
2372  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2373  }
2374  }
2375  FCT_TEST_END();
2376 
2377 
2378  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_8)
2379  {
2380  unsigned char key_str[100];
2381  unsigned char iv_str[100];
2382  unsigned char src_str[100];
2383  unsigned char dst_str[100];
2384  unsigned char output[100];
2385  aes_context ctx;
2386  int key_len, data_len;
2387 
2388  memset(key_str, 0x00, 100);
2389  memset(iv_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, "b7a5794d52737475d53d5a377200849be0260a67a2b22ced8bbef12882270d07" );
2395  unhexify( iv_str, "00000000000000000000000000000000" );
2396  data_len = unhexify( src_str, "637c31dc2591a07636f646b72daabbe7" );
2397 
2398  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2399  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2400  if( 0 == 0)
2401  {
2402  hexify( dst_str, output, data_len );
2403 
2404  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2405  }
2406  }
2407  FCT_TEST_END();
2408 
2409 
2410  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_9)
2411  {
2412  unsigned char key_str[100];
2413  unsigned char iv_str[100];
2414  unsigned char src_str[100];
2415  unsigned char dst_str[100];
2416  unsigned char output[100];
2417  aes_context ctx;
2418  int key_len, data_len;
2419 
2420  memset(key_str, 0x00, 100);
2421  memset(iv_str, 0x00, 100);
2422  memset(src_str, 0x00, 100);
2423  memset(dst_str, 0x00, 100);
2424  memset(output, 0x00, 100);
2425 
2426  key_len = unhexify( key_str, "fca02f3d5011cfc5c1e23165d413a049d4526a991827424d896fe3435e0bf68e" );
2427  unhexify( iv_str, "00000000000000000000000000000000" );
2428  data_len = unhexify( src_str, "179a49c712154bbffbe6e7a84a18e220" );
2429 
2430  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2431  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2432  if( 0 == 0)
2433  {
2434  hexify( dst_str, output, data_len );
2435 
2436  fct_chk( strcmp( (char *) dst_str, "00000000000000000000000000000000" ) == 0 );
2437  }
2438  }
2439  FCT_TEST_END();
2440 
2441 
2442  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_10)
2443  {
2444  unsigned char key_str[100];
2445  unsigned char iv_str[100];
2446  unsigned char src_str[100];
2447  unsigned char dst_str[100];
2448  unsigned char output[100];
2449  aes_context ctx;
2450  int key_len, data_len;
2451 
2452  memset(key_str, 0x00, 100);
2453  memset(iv_str, 0x00, 100);
2454  memset(src_str, 0x00, 100);
2455  memset(dst_str, 0x00, 100);
2456  memset(output, 0x00, 100);
2457 
2458  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2459  unhexify( iv_str, "00000000000000000000000000000000" );
2460  data_len = unhexify( src_str, "5c9d844ed46f9885085e5d6a4f94c7d7" );
2461 
2462  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2463  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2464  if( 0 == 0)
2465  {
2466  hexify( dst_str, output, data_len );
2467 
2468  fct_chk( strcmp( (char *) dst_str, "014730f80ac625fe84f026c60bfd547d" ) == 0 );
2469  }
2470  }
2471  FCT_TEST_END();
2472 
2473 
2474  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_11)
2475  {
2476  unsigned char key_str[100];
2477  unsigned char iv_str[100];
2478  unsigned char src_str[100];
2479  unsigned char dst_str[100];
2480  unsigned char output[100];
2481  aes_context ctx;
2482  int key_len, data_len;
2483 
2484  memset(key_str, 0x00, 100);
2485  memset(iv_str, 0x00, 100);
2486  memset(src_str, 0x00, 100);
2487  memset(dst_str, 0x00, 100);
2488  memset(output, 0x00, 100);
2489 
2490  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2491  unhexify( iv_str, "00000000000000000000000000000000" );
2492  data_len = unhexify( src_str, "a9ff75bd7cf6613d3731c77c3b6d0c04" );
2493 
2494  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2495  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2496  if( 0 == 0)
2497  {
2498  hexify( dst_str, output, data_len );
2499 
2500  fct_chk( strcmp( (char *) dst_str, "0b24af36193ce4665f2825d7b4749c98" ) == 0 );
2501  }
2502  }
2503  FCT_TEST_END();
2504 
2505 
2506  FCT_TEST_BGN(aes_256_cbc_decrypt_nist_kat_12)
2507  {
2508  unsigned char key_str[100];
2509  unsigned char iv_str[100];
2510  unsigned char src_str[100];
2511  unsigned char dst_str[100];
2512  unsigned char output[100];
2513  aes_context ctx;
2514  int key_len, data_len;
2515 
2516  memset(key_str, 0x00, 100);
2517  memset(iv_str, 0x00, 100);
2518  memset(src_str, 0x00, 100);
2519  memset(dst_str, 0x00, 100);
2520  memset(output, 0x00, 100);
2521 
2522  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2523  unhexify( iv_str, "00000000000000000000000000000000" );
2524  data_len = unhexify( src_str, "623a52fcea5d443e48d9181ab32c7421" );
2525 
2526  aes_setkey_dec( &ctx, key_str, key_len * 8 );
2527  fct_chk( aes_crypt_cbc( &ctx, AES_DECRYPT, data_len, iv_str, src_str, output ) == 0 );
2528  if( 0 == 0)
2529  {
2530  hexify( dst_str, output, data_len );
2531 
2532  fct_chk( strcmp( (char *) dst_str, "761c1fe41a18acf20d241650611d90f1" ) == 0 );
2533  }
2534  }
2535  FCT_TEST_END();
2536 
2537  }
2538  FCT_SUITE_END();
2539 
2540 #endif /* POLARSSL_AES_C */
2541 
2542 }
2543 FCT_END();
2544