PolarSSL v1.1.4
test_suite_des.c
Go to the documentation of this file.
1 #include "fct.h"
2 
3 #include <polarssl/des.h>
4 
5 #include <polarssl/config.h>
6 
7 #ifdef _MSC_VER
8 #include <basetsd.h>
9 typedef UINT32 uint32_t;
10 #else
11 #include <inttypes.h>
12 #endif
13 
14 /*
15  * 32-bit integer manipulation macros (big endian)
16  */
17 #ifndef GET_ULONG_BE
18 #define GET_ULONG_BE(n,b,i) \
19 { \
20  (n) = ( (unsigned long) (b)[(i) ] << 24 ) \
21  | ( (unsigned long) (b)[(i) + 1] << 16 ) \
22  | ( (unsigned long) (b)[(i) + 2] << 8 ) \
23  | ( (unsigned long) (b)[(i) + 3] ); \
24 }
25 #endif
26 
27 #ifndef PUT_ULONG_BE
28 #define PUT_ULONG_BE(n,b,i) \
29 { \
30  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
31  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
32  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
33  (b)[(i) + 3] = (unsigned char) ( (n) ); \
34 }
35 #endif
36 
37 int unhexify(unsigned char *obuf, const char *ibuf)
38 {
39  unsigned char c, c2;
40  int len = strlen(ibuf) / 2;
41  assert(!(strlen(ibuf) %1)); // must be even number of bytes
42 
43  while (*ibuf != 0)
44  {
45  c = *ibuf++;
46  if( c >= '0' && c <= '9' )
47  c -= '0';
48  else if( c >= 'a' && c <= 'f' )
49  c -= 'a' - 10;
50  else if( c >= 'A' && c <= 'F' )
51  c -= 'A' - 10;
52  else
53  assert( 0 );
54 
55  c2 = *ibuf++;
56  if( c2 >= '0' && c2 <= '9' )
57  c2 -= '0';
58  else if( c2 >= 'a' && c2 <= 'f' )
59  c2 -= 'a' - 10;
60  else if( c2 >= 'A' && c2 <= 'F' )
61  c2 -= 'A' - 10;
62  else
63  assert( 0 );
64 
65  *obuf++ = ( c << 4 ) | c2;
66  }
67 
68  return len;
69 }
70 
71 void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
72 {
73  unsigned char l, h;
74 
75  while (len != 0)
76  {
77  h = (*ibuf) / 16;
78  l = (*ibuf) % 16;
79 
80  if( h < 10 )
81  *obuf++ = '0' + h;
82  else
83  *obuf++ = 'a' + h - 10;
84 
85  if( l < 10 )
86  *obuf++ = '0' + l;
87  else
88  *obuf++ = 'a' + l - 10;
89 
90  ++ibuf;
91  len--;
92  }
93 }
94 
104 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
105 {
106  size_t i;
107 
108  if( rng_state != NULL )
109  rng_state = NULL;
110 
111  for( i = 0; i < len; ++i )
112  output[i] = rand();
113 
114  return( 0 );
115 }
116 
122 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
123 {
124  if( rng_state != NULL )
125  rng_state = NULL;
126 
127  memset( output, 0, len );
128 
129  return( 0 );
130 }
131 
132 typedef struct
133 {
134  unsigned char *buf;
135  size_t length;
136 } rnd_buf_info;
137 
149 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
150 {
151  rnd_buf_info *info = (rnd_buf_info *) rng_state;
152  size_t use_len;
153 
154  if( rng_state == NULL )
155  return( rnd_std_rand( NULL, output, len ) );
156 
157  use_len = len;
158  if( len > info->length )
159  use_len = info->length;
160 
161  if( use_len )
162  {
163  memcpy( output, info->buf, use_len );
164  info->buf += use_len;
165  info->length -= use_len;
166  }
167 
168  if( len - use_len > 0 )
169  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
170 
171  return( 0 );
172 }
173 
181 typedef struct
182 {
183  uint32_t key[16];
184  uint32_t v0, v1;
186 
195 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
196 {
197  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
198  uint32_t i, *k, sum, delta=0x9E3779B9;
199  unsigned char result[4];
200 
201  if( rng_state == NULL )
202  return( rnd_std_rand( NULL, output, len ) );
203 
204  k = info->key;
205 
206  while( len > 0 )
207  {
208  size_t use_len = ( len > 4 ) ? 4 : len;
209  sum = 0;
210 
211  for( i = 0; i < 32; i++ )
212  {
213  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
214  sum += delta;
215  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
216  }
217 
218  PUT_ULONG_BE( info->v0, result, 0 );
219  memcpy( output, result, use_len );
220  len -= use_len;
221  }
222 
223  return( 0 );
224 }
225 
226 
228 {
229 #ifdef POLARSSL_DES_C
230 
231 
232  FCT_SUITE_BGN(test_suite_des)
233  {
234 
235  FCT_TEST_BGN(des_encrypt_openssl_test_vector_1)
236  {
237  unsigned char key_str[100];
238  unsigned char src_str[100];
239  unsigned char dst_str[100];
240  unsigned char output[100];
241  des_context ctx;
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  unhexify( key_str, "0000000000000000" );
249  unhexify( src_str, "0000000000000000" );
250 
251  des_setkey_enc( &ctx, key_str );
252  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
253  hexify( dst_str, output, 8 );
254 
255  fct_chk( strcasecmp( (char *) dst_str, "8CA64DE9C1B123A7" ) == 0 );
256  }
257  FCT_TEST_END();
258 
259 
260  FCT_TEST_BGN(des_encrypt_openssl_test_vector_2)
261  {
262  unsigned char key_str[100];
263  unsigned char src_str[100];
264  unsigned char dst_str[100];
265  unsigned char output[100];
266  des_context ctx;
267 
268  memset(key_str, 0x00, 100);
269  memset(src_str, 0x00, 100);
270  memset(dst_str, 0x00, 100);
271  memset(output, 0x00, 100);
272 
273  unhexify( key_str, "FFFFFFFFFFFFFFFF" );
274  unhexify( src_str, "FFFFFFFFFFFFFFFF" );
275 
276  des_setkey_enc( &ctx, key_str );
277  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
278  hexify( dst_str, output, 8 );
279 
280  fct_chk( strcasecmp( (char *) dst_str, "7359B2163E4EDC58" ) == 0 );
281  }
282  FCT_TEST_END();
283 
284 
285  FCT_TEST_BGN(des_encrypt_openssl_test_vector_3)
286  {
287  unsigned char key_str[100];
288  unsigned char src_str[100];
289  unsigned char dst_str[100];
290  unsigned char output[100];
291  des_context ctx;
292 
293  memset(key_str, 0x00, 100);
294  memset(src_str, 0x00, 100);
295  memset(dst_str, 0x00, 100);
296  memset(output, 0x00, 100);
297 
298  unhexify( key_str, "3000000000000000" );
299  unhexify( src_str, "1000000000000001" );
300 
301  des_setkey_enc( &ctx, key_str );
302  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
303  hexify( dst_str, output, 8 );
304 
305  fct_chk( strcasecmp( (char *) dst_str, "958E6E627A05557B" ) == 0 );
306  }
307  FCT_TEST_END();
308 
309 
310  FCT_TEST_BGN(des_encrypt_openssl_test_vector_4)
311  {
312  unsigned char key_str[100];
313  unsigned char src_str[100];
314  unsigned char dst_str[100];
315  unsigned char output[100];
316  des_context ctx;
317 
318  memset(key_str, 0x00, 100);
319  memset(src_str, 0x00, 100);
320  memset(dst_str, 0x00, 100);
321  memset(output, 0x00, 100);
322 
323  unhexify( key_str, "1111111111111111" );
324  unhexify( src_str, "1111111111111111" );
325 
326  des_setkey_enc( &ctx, key_str );
327  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
328  hexify( dst_str, output, 8 );
329 
330  fct_chk( strcasecmp( (char *) dst_str, "F40379AB9E0EC533" ) == 0 );
331  }
332  FCT_TEST_END();
333 
334 
335  FCT_TEST_BGN(des_encrypt_openssl_test_vector_5)
336  {
337  unsigned char key_str[100];
338  unsigned char src_str[100];
339  unsigned char dst_str[100];
340  unsigned char output[100];
341  des_context ctx;
342 
343  memset(key_str, 0x00, 100);
344  memset(src_str, 0x00, 100);
345  memset(dst_str, 0x00, 100);
346  memset(output, 0x00, 100);
347 
348  unhexify( key_str, "0123456789ABCDEF" );
349  unhexify( src_str, "1111111111111111" );
350 
351  des_setkey_enc( &ctx, key_str );
352  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
353  hexify( dst_str, output, 8 );
354 
355  fct_chk( strcasecmp( (char *) dst_str, "17668DFC7292532D" ) == 0 );
356  }
357  FCT_TEST_END();
358 
359 
360  FCT_TEST_BGN(des_encrypt_openssl_test_vector_6)
361  {
362  unsigned char key_str[100];
363  unsigned char src_str[100];
364  unsigned char dst_str[100];
365  unsigned char output[100];
366  des_context ctx;
367 
368  memset(key_str, 0x00, 100);
369  memset(src_str, 0x00, 100);
370  memset(dst_str, 0x00, 100);
371  memset(output, 0x00, 100);
372 
373  unhexify( key_str, "1111111111111111" );
374  unhexify( src_str, "0123456789ABCDEF" );
375 
376  des_setkey_enc( &ctx, key_str );
377  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
378  hexify( dst_str, output, 8 );
379 
380  fct_chk( strcasecmp( (char *) dst_str, "8A5AE1F81AB8F2DD" ) == 0 );
381  }
382  FCT_TEST_END();
383 
384 
385  FCT_TEST_BGN(des_encrypt_openssl_test_vector_7)
386  {
387  unsigned char key_str[100];
388  unsigned char src_str[100];
389  unsigned char dst_str[100];
390  unsigned char output[100];
391  des_context ctx;
392 
393  memset(key_str, 0x00, 100);
394  memset(src_str, 0x00, 100);
395  memset(dst_str, 0x00, 100);
396  memset(output, 0x00, 100);
397 
398  unhexify( key_str, "0000000000000000" );
399  unhexify( src_str, "0000000000000000" );
400 
401  des_setkey_enc( &ctx, key_str );
402  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
403  hexify( dst_str, output, 8 );
404 
405  fct_chk( strcasecmp( (char *) dst_str, "8CA64DE9C1B123A7" ) == 0 );
406  }
407  FCT_TEST_END();
408 
409 
410  FCT_TEST_BGN(des_encrypt_openssl_test_vector_8)
411  {
412  unsigned char key_str[100];
413  unsigned char src_str[100];
414  unsigned char dst_str[100];
415  unsigned char output[100];
416  des_context ctx;
417 
418  memset(key_str, 0x00, 100);
419  memset(src_str, 0x00, 100);
420  memset(dst_str, 0x00, 100);
421  memset(output, 0x00, 100);
422 
423  unhexify( key_str, "FEDCBA9876543210" );
424  unhexify( src_str, "0123456789ABCDEF" );
425 
426  des_setkey_enc( &ctx, key_str );
427  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
428  hexify( dst_str, output, 8 );
429 
430  fct_chk( strcasecmp( (char *) dst_str, "ED39D950FA74BCC4" ) == 0 );
431  }
432  FCT_TEST_END();
433 
434 
435  FCT_TEST_BGN(des_encrypt_openssl_test_vector_9)
436  {
437  unsigned char key_str[100];
438  unsigned char src_str[100];
439  unsigned char dst_str[100];
440  unsigned char output[100];
441  des_context ctx;
442 
443  memset(key_str, 0x00, 100);
444  memset(src_str, 0x00, 100);
445  memset(dst_str, 0x00, 100);
446  memset(output, 0x00, 100);
447 
448  unhexify( key_str, "7CA110454A1A6E57" );
449  unhexify( src_str, "01A1D6D039776742" );
450 
451  des_setkey_enc( &ctx, key_str );
452  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
453  hexify( dst_str, output, 8 );
454 
455  fct_chk( strcasecmp( (char *) dst_str, "690F5B0D9A26939B" ) == 0 );
456  }
457  FCT_TEST_END();
458 
459 
460  FCT_TEST_BGN(des_encrypt_openssl_test_vector_10)
461  {
462  unsigned char key_str[100];
463  unsigned char src_str[100];
464  unsigned char dst_str[100];
465  unsigned char output[100];
466  des_context ctx;
467 
468  memset(key_str, 0x00, 100);
469  memset(src_str, 0x00, 100);
470  memset(dst_str, 0x00, 100);
471  memset(output, 0x00, 100);
472 
473  unhexify( key_str, "0131D9619DC1376E" );
474  unhexify( src_str, "5CD54CA83DEF57DA" );
475 
476  des_setkey_enc( &ctx, key_str );
477  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
478  hexify( dst_str, output, 8 );
479 
480  fct_chk( strcasecmp( (char *) dst_str, "7A389D10354BD271" ) == 0 );
481  }
482  FCT_TEST_END();
483 
484 
485  FCT_TEST_BGN(des_encrypt_openssl_test_vector_11)
486  {
487  unsigned char key_str[100];
488  unsigned char src_str[100];
489  unsigned char dst_str[100];
490  unsigned char output[100];
491  des_context ctx;
492 
493  memset(key_str, 0x00, 100);
494  memset(src_str, 0x00, 100);
495  memset(dst_str, 0x00, 100);
496  memset(output, 0x00, 100);
497 
498  unhexify( key_str, "07A1133E4A0B2686" );
499  unhexify( src_str, "0248D43806F67172" );
500 
501  des_setkey_enc( &ctx, key_str );
502  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
503  hexify( dst_str, output, 8 );
504 
505  fct_chk( strcasecmp( (char *) dst_str, "868EBB51CAB4599A" ) == 0 );
506  }
507  FCT_TEST_END();
508 
509 
510  FCT_TEST_BGN(des_encrypt_openssl_test_vector_12)
511  {
512  unsigned char key_str[100];
513  unsigned char src_str[100];
514  unsigned char dst_str[100];
515  unsigned char output[100];
516  des_context ctx;
517 
518  memset(key_str, 0x00, 100);
519  memset(src_str, 0x00, 100);
520  memset(dst_str, 0x00, 100);
521  memset(output, 0x00, 100);
522 
523  unhexify( key_str, "3849674C2602319E" );
524  unhexify( src_str, "51454B582DDF440A" );
525 
526  des_setkey_enc( &ctx, key_str );
527  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
528  hexify( dst_str, output, 8 );
529 
530  fct_chk( strcasecmp( (char *) dst_str, "7178876E01F19B2A" ) == 0 );
531  }
532  FCT_TEST_END();
533 
534 
535  FCT_TEST_BGN(des_encrypt_openssl_test_vector_13)
536  {
537  unsigned char key_str[100];
538  unsigned char src_str[100];
539  unsigned char dst_str[100];
540  unsigned char output[100];
541  des_context ctx;
542 
543  memset(key_str, 0x00, 100);
544  memset(src_str, 0x00, 100);
545  memset(dst_str, 0x00, 100);
546  memset(output, 0x00, 100);
547 
548  unhexify( key_str, "04B915BA43FEB5B6" );
549  unhexify( src_str, "42FD443059577FA2" );
550 
551  des_setkey_enc( &ctx, key_str );
552  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
553  hexify( dst_str, output, 8 );
554 
555  fct_chk( strcasecmp( (char *) dst_str, "AF37FB421F8C4095" ) == 0 );
556  }
557  FCT_TEST_END();
558 
559 
560  FCT_TEST_BGN(des_encrypt_openssl_test_vector_14)
561  {
562  unsigned char key_str[100];
563  unsigned char src_str[100];
564  unsigned char dst_str[100];
565  unsigned char output[100];
566  des_context ctx;
567 
568  memset(key_str, 0x00, 100);
569  memset(src_str, 0x00, 100);
570  memset(dst_str, 0x00, 100);
571  memset(output, 0x00, 100);
572 
573  unhexify( key_str, "0113B970FD34F2CE" );
574  unhexify( src_str, "059B5E0851CF143A" );
575 
576  des_setkey_enc( &ctx, key_str );
577  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
578  hexify( dst_str, output, 8 );
579 
580  fct_chk( strcasecmp( (char *) dst_str, "86A560F10EC6D85B" ) == 0 );
581  }
582  FCT_TEST_END();
583 
584 
585  FCT_TEST_BGN(des_encrypt_openssl_test_vector_15)
586  {
587  unsigned char key_str[100];
588  unsigned char src_str[100];
589  unsigned char dst_str[100];
590  unsigned char output[100];
591  des_context ctx;
592 
593  memset(key_str, 0x00, 100);
594  memset(src_str, 0x00, 100);
595  memset(dst_str, 0x00, 100);
596  memset(output, 0x00, 100);
597 
598  unhexify( key_str, "0170F175468FB5E6" );
599  unhexify( src_str, "0756D8E0774761D2" );
600 
601  des_setkey_enc( &ctx, key_str );
602  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
603  hexify( dst_str, output, 8 );
604 
605  fct_chk( strcasecmp( (char *) dst_str, "0CD3DA020021DC09" ) == 0 );
606  }
607  FCT_TEST_END();
608 
609 
610  FCT_TEST_BGN(des_encrypt_openssl_test_vector_16)
611  {
612  unsigned char key_str[100];
613  unsigned char src_str[100];
614  unsigned char dst_str[100];
615  unsigned char output[100];
616  des_context ctx;
617 
618  memset(key_str, 0x00, 100);
619  memset(src_str, 0x00, 100);
620  memset(dst_str, 0x00, 100);
621  memset(output, 0x00, 100);
622 
623  unhexify( key_str, "43297FAD38E373FE" );
624  unhexify( src_str, "762514B829BF486A" );
625 
626  des_setkey_enc( &ctx, key_str );
627  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
628  hexify( dst_str, output, 8 );
629 
630  fct_chk( strcasecmp( (char *) dst_str, "EA676B2CB7DB2B7A" ) == 0 );
631  }
632  FCT_TEST_END();
633 
634 
635  FCT_TEST_BGN(des_encrypt_openssl_test_vector_17)
636  {
637  unsigned char key_str[100];
638  unsigned char src_str[100];
639  unsigned char dst_str[100];
640  unsigned char output[100];
641  des_context ctx;
642 
643  memset(key_str, 0x00, 100);
644  memset(src_str, 0x00, 100);
645  memset(dst_str, 0x00, 100);
646  memset(output, 0x00, 100);
647 
648  unhexify( key_str, "07A7137045DA2A16" );
649  unhexify( src_str, "3BDD119049372802" );
650 
651  des_setkey_enc( &ctx, key_str );
652  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
653  hexify( dst_str, output, 8 );
654 
655  fct_chk( strcasecmp( (char *) dst_str, "DFD64A815CAF1A0F" ) == 0 );
656  }
657  FCT_TEST_END();
658 
659 
660  FCT_TEST_BGN(des_encrypt_openssl_test_vector_18)
661  {
662  unsigned char key_str[100];
663  unsigned char src_str[100];
664  unsigned char dst_str[100];
665  unsigned char output[100];
666  des_context ctx;
667 
668  memset(key_str, 0x00, 100);
669  memset(src_str, 0x00, 100);
670  memset(dst_str, 0x00, 100);
671  memset(output, 0x00, 100);
672 
673  unhexify( key_str, "04689104C2FD3B2F" );
674  unhexify( src_str, "26955F6835AF609A" );
675 
676  des_setkey_enc( &ctx, key_str );
677  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
678  hexify( dst_str, output, 8 );
679 
680  fct_chk( strcasecmp( (char *) dst_str, "5C513C9C4886C088" ) == 0 );
681  }
682  FCT_TEST_END();
683 
684 
685  FCT_TEST_BGN(des_encrypt_openssl_test_vector_19)
686  {
687  unsigned char key_str[100];
688  unsigned char src_str[100];
689  unsigned char dst_str[100];
690  unsigned char output[100];
691  des_context ctx;
692 
693  memset(key_str, 0x00, 100);
694  memset(src_str, 0x00, 100);
695  memset(dst_str, 0x00, 100);
696  memset(output, 0x00, 100);
697 
698  unhexify( key_str, "37D06BB516CB7546" );
699  unhexify( src_str, "164D5E404F275232" );
700 
701  des_setkey_enc( &ctx, key_str );
702  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
703  hexify( dst_str, output, 8 );
704 
705  fct_chk( strcasecmp( (char *) dst_str, "0A2AEEAE3FF4AB77" ) == 0 );
706  }
707  FCT_TEST_END();
708 
709 
710  FCT_TEST_BGN(des_encrypt_openssl_test_vector_20)
711  {
712  unsigned char key_str[100];
713  unsigned char src_str[100];
714  unsigned char dst_str[100];
715  unsigned char output[100];
716  des_context ctx;
717 
718  memset(key_str, 0x00, 100);
719  memset(src_str, 0x00, 100);
720  memset(dst_str, 0x00, 100);
721  memset(output, 0x00, 100);
722 
723  unhexify( key_str, "1F08260D1AC2465E" );
724  unhexify( src_str, "6B056E18759F5CCA" );
725 
726  des_setkey_enc( &ctx, key_str );
727  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
728  hexify( dst_str, output, 8 );
729 
730  fct_chk( strcasecmp( (char *) dst_str, "EF1BF03E5DFA575A" ) == 0 );
731  }
732  FCT_TEST_END();
733 
734 
735  FCT_TEST_BGN(des_encrypt_openssl_test_vector_21)
736  {
737  unsigned char key_str[100];
738  unsigned char src_str[100];
739  unsigned char dst_str[100];
740  unsigned char output[100];
741  des_context ctx;
742 
743  memset(key_str, 0x00, 100);
744  memset(src_str, 0x00, 100);
745  memset(dst_str, 0x00, 100);
746  memset(output, 0x00, 100);
747 
748  unhexify( key_str, "584023641ABA6176" );
749  unhexify( src_str, "004BD6EF09176062" );
750 
751  des_setkey_enc( &ctx, key_str );
752  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
753  hexify( dst_str, output, 8 );
754 
755  fct_chk( strcasecmp( (char *) dst_str, "88BF0DB6D70DEE56" ) == 0 );
756  }
757  FCT_TEST_END();
758 
759 
760  FCT_TEST_BGN(des_encrypt_openssl_test_vector_22)
761  {
762  unsigned char key_str[100];
763  unsigned char src_str[100];
764  unsigned char dst_str[100];
765  unsigned char output[100];
766  des_context ctx;
767 
768  memset(key_str, 0x00, 100);
769  memset(src_str, 0x00, 100);
770  memset(dst_str, 0x00, 100);
771  memset(output, 0x00, 100);
772 
773  unhexify( key_str, "025816164629B007" );
774  unhexify( src_str, "480D39006EE762F2" );
775 
776  des_setkey_enc( &ctx, key_str );
777  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
778  hexify( dst_str, output, 8 );
779 
780  fct_chk( strcasecmp( (char *) dst_str, "A1F9915541020B56" ) == 0 );
781  }
782  FCT_TEST_END();
783 
784 
785  FCT_TEST_BGN(des_encrypt_openssl_test_vector_23)
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  des_context ctx;
792 
793  memset(key_str, 0x00, 100);
794  memset(src_str, 0x00, 100);
795  memset(dst_str, 0x00, 100);
796  memset(output, 0x00, 100);
797 
798  unhexify( key_str, "49793EBC79B3258F" );
799  unhexify( src_str, "437540C8698F3CFA" );
800 
801  des_setkey_enc( &ctx, key_str );
802  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
803  hexify( dst_str, output, 8 );
804 
805  fct_chk( strcasecmp( (char *) dst_str, "6FBF1CAFCFFD0556" ) == 0 );
806  }
807  FCT_TEST_END();
808 
809 
810  FCT_TEST_BGN(des_encrypt_openssl_test_vector_24)
811  {
812  unsigned char key_str[100];
813  unsigned char src_str[100];
814  unsigned char dst_str[100];
815  unsigned char output[100];
816  des_context ctx;
817 
818  memset(key_str, 0x00, 100);
819  memset(src_str, 0x00, 100);
820  memset(dst_str, 0x00, 100);
821  memset(output, 0x00, 100);
822 
823  unhexify( key_str, "4FB05E1515AB73A7" );
824  unhexify( src_str, "072D43A077075292" );
825 
826  des_setkey_enc( &ctx, key_str );
827  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
828  hexify( dst_str, output, 8 );
829 
830  fct_chk( strcasecmp( (char *) dst_str, "2F22E49BAB7CA1AC" ) == 0 );
831  }
832  FCT_TEST_END();
833 
834 
835  FCT_TEST_BGN(des_encrypt_openssl_test_vector_25)
836  {
837  unsigned char key_str[100];
838  unsigned char src_str[100];
839  unsigned char dst_str[100];
840  unsigned char output[100];
841  des_context ctx;
842 
843  memset(key_str, 0x00, 100);
844  memset(src_str, 0x00, 100);
845  memset(dst_str, 0x00, 100);
846  memset(output, 0x00, 100);
847 
848  unhexify( key_str, "49E95D6D4CA229BF" );
849  unhexify( src_str, "02FE55778117F12A" );
850 
851  des_setkey_enc( &ctx, key_str );
852  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
853  hexify( dst_str, output, 8 );
854 
855  fct_chk( strcasecmp( (char *) dst_str, "5A6B612CC26CCE4A" ) == 0 );
856  }
857  FCT_TEST_END();
858 
859 
860  FCT_TEST_BGN(des_encrypt_openssl_test_vector_26)
861  {
862  unsigned char key_str[100];
863  unsigned char src_str[100];
864  unsigned char dst_str[100];
865  unsigned char output[100];
866  des_context ctx;
867 
868  memset(key_str, 0x00, 100);
869  memset(src_str, 0x00, 100);
870  memset(dst_str, 0x00, 100);
871  memset(output, 0x00, 100);
872 
873  unhexify( key_str, "018310DC409B26D6" );
874  unhexify( src_str, "1D9D5C5018F728C2" );
875 
876  des_setkey_enc( &ctx, key_str );
877  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
878  hexify( dst_str, output, 8 );
879 
880  fct_chk( strcasecmp( (char *) dst_str, "5F4C038ED12B2E41" ) == 0 );
881  }
882  FCT_TEST_END();
883 
884 
885  FCT_TEST_BGN(des_encrypt_openssl_test_vector_27)
886  {
887  unsigned char key_str[100];
888  unsigned char src_str[100];
889  unsigned char dst_str[100];
890  unsigned char output[100];
891  des_context ctx;
892 
893  memset(key_str, 0x00, 100);
894  memset(src_str, 0x00, 100);
895  memset(dst_str, 0x00, 100);
896  memset(output, 0x00, 100);
897 
898  unhexify( key_str, "1C587F1C13924FEF" );
899  unhexify( src_str, "305532286D6F295A" );
900 
901  des_setkey_enc( &ctx, key_str );
902  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
903  hexify( dst_str, output, 8 );
904 
905  fct_chk( strcasecmp( (char *) dst_str, "63FAC0D034D9F793" ) == 0 );
906  }
907  FCT_TEST_END();
908 
909 
910  FCT_TEST_BGN(des_encrypt_openssl_test_vector_28)
911  {
912  unsigned char key_str[100];
913  unsigned char src_str[100];
914  unsigned char dst_str[100];
915  unsigned char output[100];
916  des_context ctx;
917 
918  memset(key_str, 0x00, 100);
919  memset(src_str, 0x00, 100);
920  memset(dst_str, 0x00, 100);
921  memset(output, 0x00, 100);
922 
923  unhexify( key_str, "0101010101010101" );
924  unhexify( src_str, "0123456789ABCDEF" );
925 
926  des_setkey_enc( &ctx, key_str );
927  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
928  hexify( dst_str, output, 8 );
929 
930  fct_chk( strcasecmp( (char *) dst_str, "617B3A0CE8F07100" ) == 0 );
931  }
932  FCT_TEST_END();
933 
934 
935  FCT_TEST_BGN(des_encrypt_openssl_test_vector_29)
936  {
937  unsigned char key_str[100];
938  unsigned char src_str[100];
939  unsigned char dst_str[100];
940  unsigned char output[100];
941  des_context ctx;
942 
943  memset(key_str, 0x00, 100);
944  memset(src_str, 0x00, 100);
945  memset(dst_str, 0x00, 100);
946  memset(output, 0x00, 100);
947 
948  unhexify( key_str, "1F1F1F1F0E0E0E0E" );
949  unhexify( src_str, "0123456789ABCDEF" );
950 
951  des_setkey_enc( &ctx, key_str );
952  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
953  hexify( dst_str, output, 8 );
954 
955  fct_chk( strcasecmp( (char *) dst_str, "DB958605F8C8C606" ) == 0 );
956  }
957  FCT_TEST_END();
958 
959 
960  FCT_TEST_BGN(des_encrypt_openssl_test_vector_30)
961  {
962  unsigned char key_str[100];
963  unsigned char src_str[100];
964  unsigned char dst_str[100];
965  unsigned char output[100];
966  des_context ctx;
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  unhexify( key_str, "E0FEE0FEF1FEF1FE" );
974  unhexify( src_str, "0123456789ABCDEF" );
975 
976  des_setkey_enc( &ctx, key_str );
977  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
978  hexify( dst_str, output, 8 );
979 
980  fct_chk( strcasecmp( (char *) dst_str, "EDBFD1C66C29CCC7" ) == 0 );
981  }
982  FCT_TEST_END();
983 
984 
985  FCT_TEST_BGN(des_encrypt_openssl_test_vector_31)
986  {
987  unsigned char key_str[100];
988  unsigned char src_str[100];
989  unsigned char dst_str[100];
990  unsigned char output[100];
991  des_context ctx;
992 
993  memset(key_str, 0x00, 100);
994  memset(src_str, 0x00, 100);
995  memset(dst_str, 0x00, 100);
996  memset(output, 0x00, 100);
997 
998  unhexify( key_str, "0000000000000000" );
999  unhexify( src_str, "FFFFFFFFFFFFFFFF" );
1000 
1001  des_setkey_enc( &ctx, key_str );
1002  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1003  hexify( dst_str, output, 8 );
1004 
1005  fct_chk( strcasecmp( (char *) dst_str, "355550B2150E2451" ) == 0 );
1006  }
1007  FCT_TEST_END();
1008 
1009 
1010  FCT_TEST_BGN(des_encrypt_openssl_test_vector_32)
1011  {
1012  unsigned char key_str[100];
1013  unsigned char src_str[100];
1014  unsigned char dst_str[100];
1015  unsigned char output[100];
1016  des_context ctx;
1017 
1018  memset(key_str, 0x00, 100);
1019  memset(src_str, 0x00, 100);
1020  memset(dst_str, 0x00, 100);
1021  memset(output, 0x00, 100);
1022 
1023  unhexify( key_str, "FFFFFFFFFFFFFFFF" );
1024  unhexify( src_str, "0000000000000000" );
1025 
1026  des_setkey_enc( &ctx, key_str );
1027  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1028  hexify( dst_str, output, 8 );
1029 
1030  fct_chk( strcasecmp( (char *) dst_str, "CAAAAF4DEAF1DBAE" ) == 0 );
1031  }
1032  FCT_TEST_END();
1033 
1034 
1035  FCT_TEST_BGN(des_encrypt_openssl_test_vector_33)
1036  {
1037  unsigned char key_str[100];
1038  unsigned char src_str[100];
1039  unsigned char dst_str[100];
1040  unsigned char output[100];
1041  des_context ctx;
1042 
1043  memset(key_str, 0x00, 100);
1044  memset(src_str, 0x00, 100);
1045  memset(dst_str, 0x00, 100);
1046  memset(output, 0x00, 100);
1047 
1048  unhexify( key_str, "0123456789ABCDEF" );
1049  unhexify( src_str, "0000000000000000" );
1050 
1051  des_setkey_enc( &ctx, key_str );
1052  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1053  hexify( dst_str, output, 8 );
1054 
1055  fct_chk( strcasecmp( (char *) dst_str, "D5D44FF720683D0D" ) == 0 );
1056  }
1057  FCT_TEST_END();
1058 
1059 
1060  FCT_TEST_BGN(des_encrypt_openssl_test_vector_34)
1061  {
1062  unsigned char key_str[100];
1063  unsigned char src_str[100];
1064  unsigned char dst_str[100];
1065  unsigned char output[100];
1066  des_context ctx;
1067 
1068  memset(key_str, 0x00, 100);
1069  memset(src_str, 0x00, 100);
1070  memset(dst_str, 0x00, 100);
1071  memset(output, 0x00, 100);
1072 
1073  unhexify( key_str, "FEDCBA9876543210" );
1074  unhexify( src_str, "FFFFFFFFFFFFFFFF" );
1075 
1076  des_setkey_enc( &ctx, key_str );
1077  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1078  hexify( dst_str, output, 8 );
1079 
1080  fct_chk( strcasecmp( (char *) dst_str, "2A2BB008DF97C2F2" ) == 0 );
1081  }
1082  FCT_TEST_END();
1083 
1084 
1085  FCT_TEST_BGN(des_decrypt_openssl_test_vector_1)
1086  {
1087  unsigned char key_str[100];
1088  unsigned char src_str[100];
1089  unsigned char dst_str[100];
1090  unsigned char output[100];
1091  des_context ctx;
1092 
1093  memset(key_str, 0x00, 100);
1094  memset(src_str, 0x00, 100);
1095  memset(dst_str, 0x00, 100);
1096  memset(output, 0x00, 100);
1097 
1098  unhexify( key_str, "0000000000000000" );
1099  unhexify( src_str, "8CA64DE9C1B123A7" );
1100 
1101  des_setkey_dec( &ctx, key_str );
1102  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1103  hexify( dst_str, output, 8 );
1104 
1105  fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 );
1106  }
1107  FCT_TEST_END();
1108 
1109 
1110  FCT_TEST_BGN(des_decrypt_openssl_test_vector_2)
1111  {
1112  unsigned char key_str[100];
1113  unsigned char src_str[100];
1114  unsigned char dst_str[100];
1115  unsigned char output[100];
1116  des_context ctx;
1117 
1118  memset(key_str, 0x00, 100);
1119  memset(src_str, 0x00, 100);
1120  memset(dst_str, 0x00, 100);
1121  memset(output, 0x00, 100);
1122 
1123  unhexify( key_str, "FFFFFFFFFFFFFFFF" );
1124  unhexify( src_str, "7359B2163E4EDC58" );
1125 
1126  des_setkey_dec( &ctx, key_str );
1127  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1128  hexify( dst_str, output, 8 );
1129 
1130  fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 );
1131  }
1132  FCT_TEST_END();
1133 
1134 
1135  FCT_TEST_BGN(des_decrypt_openssl_test_vector_3)
1136  {
1137  unsigned char key_str[100];
1138  unsigned char src_str[100];
1139  unsigned char dst_str[100];
1140  unsigned char output[100];
1141  des_context ctx;
1142 
1143  memset(key_str, 0x00, 100);
1144  memset(src_str, 0x00, 100);
1145  memset(dst_str, 0x00, 100);
1146  memset(output, 0x00, 100);
1147 
1148  unhexify( key_str, "3000000000000000" );
1149  unhexify( src_str, "958E6E627A05557B" );
1150 
1151  des_setkey_dec( &ctx, key_str );
1152  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1153  hexify( dst_str, output, 8 );
1154 
1155  fct_chk( strcasecmp( (char *) dst_str, "1000000000000001" ) == 0 );
1156  }
1157  FCT_TEST_END();
1158 
1159 
1160  FCT_TEST_BGN(des_decrypt_openssl_test_vector_4)
1161  {
1162  unsigned char key_str[100];
1163  unsigned char src_str[100];
1164  unsigned char dst_str[100];
1165  unsigned char output[100];
1166  des_context ctx;
1167 
1168  memset(key_str, 0x00, 100);
1169  memset(src_str, 0x00, 100);
1170  memset(dst_str, 0x00, 100);
1171  memset(output, 0x00, 100);
1172 
1173  unhexify( key_str, "1111111111111111" );
1174  unhexify( src_str, "F40379AB9E0EC533" );
1175 
1176  des_setkey_dec( &ctx, key_str );
1177  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1178  hexify( dst_str, output, 8 );
1179 
1180  fct_chk( strcasecmp( (char *) dst_str, "1111111111111111" ) == 0 );
1181  }
1182  FCT_TEST_END();
1183 
1184 
1185  FCT_TEST_BGN(des_decrypt_openssl_test_vector_5)
1186  {
1187  unsigned char key_str[100];
1188  unsigned char src_str[100];
1189  unsigned char dst_str[100];
1190  unsigned char output[100];
1191  des_context ctx;
1192 
1193  memset(key_str, 0x00, 100);
1194  memset(src_str, 0x00, 100);
1195  memset(dst_str, 0x00, 100);
1196  memset(output, 0x00, 100);
1197 
1198  unhexify( key_str, "0123456789ABCDEF" );
1199  unhexify( src_str, "17668DFC7292532D" );
1200 
1201  des_setkey_dec( &ctx, key_str );
1202  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1203  hexify( dst_str, output, 8 );
1204 
1205  fct_chk( strcasecmp( (char *) dst_str, "1111111111111111" ) == 0 );
1206  }
1207  FCT_TEST_END();
1208 
1209 
1210  FCT_TEST_BGN(des_decrypt_openssl_test_vector_6)
1211  {
1212  unsigned char key_str[100];
1213  unsigned char src_str[100];
1214  unsigned char dst_str[100];
1215  unsigned char output[100];
1216  des_context ctx;
1217 
1218  memset(key_str, 0x00, 100);
1219  memset(src_str, 0x00, 100);
1220  memset(dst_str, 0x00, 100);
1221  memset(output, 0x00, 100);
1222 
1223  unhexify( key_str, "1111111111111111" );
1224  unhexify( src_str, "8A5AE1F81AB8F2DD" );
1225 
1226  des_setkey_dec( &ctx, key_str );
1227  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1228  hexify( dst_str, output, 8 );
1229 
1230  fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 );
1231  }
1232  FCT_TEST_END();
1233 
1234 
1235  FCT_TEST_BGN(des_decrypt_openssl_test_vector_7)
1236  {
1237  unsigned char key_str[100];
1238  unsigned char src_str[100];
1239  unsigned char dst_str[100];
1240  unsigned char output[100];
1241  des_context ctx;
1242 
1243  memset(key_str, 0x00, 100);
1244  memset(src_str, 0x00, 100);
1245  memset(dst_str, 0x00, 100);
1246  memset(output, 0x00, 100);
1247 
1248  unhexify( key_str, "0000000000000000" );
1249  unhexify( src_str, "8CA64DE9C1B123A7" );
1250 
1251  des_setkey_dec( &ctx, key_str );
1252  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1253  hexify( dst_str, output, 8 );
1254 
1255  fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 );
1256  }
1257  FCT_TEST_END();
1258 
1259 
1260  FCT_TEST_BGN(des_decrypt_openssl_test_vector_8)
1261  {
1262  unsigned char key_str[100];
1263  unsigned char src_str[100];
1264  unsigned char dst_str[100];
1265  unsigned char output[100];
1266  des_context ctx;
1267 
1268  memset(key_str, 0x00, 100);
1269  memset(src_str, 0x00, 100);
1270  memset(dst_str, 0x00, 100);
1271  memset(output, 0x00, 100);
1272 
1273  unhexify( key_str, "FEDCBA9876543210" );
1274  unhexify( src_str, "ED39D950FA74BCC4" );
1275 
1276  des_setkey_dec( &ctx, key_str );
1277  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1278  hexify( dst_str, output, 8 );
1279 
1280  fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 );
1281  }
1282  FCT_TEST_END();
1283 
1284 
1285  FCT_TEST_BGN(des_decrypt_openssl_test_vector_9)
1286  {
1287  unsigned char key_str[100];
1288  unsigned char src_str[100];
1289  unsigned char dst_str[100];
1290  unsigned char output[100];
1291  des_context ctx;
1292 
1293  memset(key_str, 0x00, 100);
1294  memset(src_str, 0x00, 100);
1295  memset(dst_str, 0x00, 100);
1296  memset(output, 0x00, 100);
1297 
1298  unhexify( key_str, "7CA110454A1A6E57" );
1299  unhexify( src_str, "690F5B0D9A26939B" );
1300 
1301  des_setkey_dec( &ctx, key_str );
1302  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1303  hexify( dst_str, output, 8 );
1304 
1305  fct_chk( strcasecmp( (char *) dst_str, "01A1D6D039776742" ) == 0 );
1306  }
1307  FCT_TEST_END();
1308 
1309 
1310  FCT_TEST_BGN(des_decrypt_openssl_test_vector_10)
1311  {
1312  unsigned char key_str[100];
1313  unsigned char src_str[100];
1314  unsigned char dst_str[100];
1315  unsigned char output[100];
1316  des_context ctx;
1317 
1318  memset(key_str, 0x00, 100);
1319  memset(src_str, 0x00, 100);
1320  memset(dst_str, 0x00, 100);
1321  memset(output, 0x00, 100);
1322 
1323  unhexify( key_str, "0131D9619DC1376E" );
1324  unhexify( src_str, "7A389D10354BD271" );
1325 
1326  des_setkey_dec( &ctx, key_str );
1327  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1328  hexify( dst_str, output, 8 );
1329 
1330  fct_chk( strcasecmp( (char *) dst_str, "5CD54CA83DEF57DA" ) == 0 );
1331  }
1332  FCT_TEST_END();
1333 
1334 
1335  FCT_TEST_BGN(des_decrypt_openssl_test_vector_11)
1336  {
1337  unsigned char key_str[100];
1338  unsigned char src_str[100];
1339  unsigned char dst_str[100];
1340  unsigned char output[100];
1341  des_context ctx;
1342 
1343  memset(key_str, 0x00, 100);
1344  memset(src_str, 0x00, 100);
1345  memset(dst_str, 0x00, 100);
1346  memset(output, 0x00, 100);
1347 
1348  unhexify( key_str, "07A1133E4A0B2686" );
1349  unhexify( src_str, "868EBB51CAB4599A" );
1350 
1351  des_setkey_dec( &ctx, key_str );
1352  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1353  hexify( dst_str, output, 8 );
1354 
1355  fct_chk( strcasecmp( (char *) dst_str, "0248D43806F67172" ) == 0 );
1356  }
1357  FCT_TEST_END();
1358 
1359 
1360  FCT_TEST_BGN(des_decrypt_openssl_test_vector_12)
1361  {
1362  unsigned char key_str[100];
1363  unsigned char src_str[100];
1364  unsigned char dst_str[100];
1365  unsigned char output[100];
1366  des_context ctx;
1367 
1368  memset(key_str, 0x00, 100);
1369  memset(src_str, 0x00, 100);
1370  memset(dst_str, 0x00, 100);
1371  memset(output, 0x00, 100);
1372 
1373  unhexify( key_str, "3849674C2602319E" );
1374  unhexify( src_str, "7178876E01F19B2A" );
1375 
1376  des_setkey_dec( &ctx, key_str );
1377  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1378  hexify( dst_str, output, 8 );
1379 
1380  fct_chk( strcasecmp( (char *) dst_str, "51454B582DDF440A" ) == 0 );
1381  }
1382  FCT_TEST_END();
1383 
1384 
1385  FCT_TEST_BGN(des_decrypt_openssl_test_vector_13)
1386  {
1387  unsigned char key_str[100];
1388  unsigned char src_str[100];
1389  unsigned char dst_str[100];
1390  unsigned char output[100];
1391  des_context ctx;
1392 
1393  memset(key_str, 0x00, 100);
1394  memset(src_str, 0x00, 100);
1395  memset(dst_str, 0x00, 100);
1396  memset(output, 0x00, 100);
1397 
1398  unhexify( key_str, "04B915BA43FEB5B6" );
1399  unhexify( src_str, "AF37FB421F8C4095" );
1400 
1401  des_setkey_dec( &ctx, key_str );
1402  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1403  hexify( dst_str, output, 8 );
1404 
1405  fct_chk( strcasecmp( (char *) dst_str, "42FD443059577FA2" ) == 0 );
1406  }
1407  FCT_TEST_END();
1408 
1409 
1410  FCT_TEST_BGN(des_decrypt_openssl_test_vector_14)
1411  {
1412  unsigned char key_str[100];
1413  unsigned char src_str[100];
1414  unsigned char dst_str[100];
1415  unsigned char output[100];
1416  des_context ctx;
1417 
1418  memset(key_str, 0x00, 100);
1419  memset(src_str, 0x00, 100);
1420  memset(dst_str, 0x00, 100);
1421  memset(output, 0x00, 100);
1422 
1423  unhexify( key_str, "0113B970FD34F2CE" );
1424  unhexify( src_str, "86A560F10EC6D85B" );
1425 
1426  des_setkey_dec( &ctx, key_str );
1427  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1428  hexify( dst_str, output, 8 );
1429 
1430  fct_chk( strcasecmp( (char *) dst_str, "059B5E0851CF143A" ) == 0 );
1431  }
1432  FCT_TEST_END();
1433 
1434 
1435  FCT_TEST_BGN(des_decrypt_openssl_test_vector_15)
1436  {
1437  unsigned char key_str[100];
1438  unsigned char src_str[100];
1439  unsigned char dst_str[100];
1440  unsigned char output[100];
1441  des_context ctx;
1442 
1443  memset(key_str, 0x00, 100);
1444  memset(src_str, 0x00, 100);
1445  memset(dst_str, 0x00, 100);
1446  memset(output, 0x00, 100);
1447 
1448  unhexify( key_str, "0170F175468FB5E6" );
1449  unhexify( src_str, "0CD3DA020021DC09" );
1450 
1451  des_setkey_dec( &ctx, key_str );
1452  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1453  hexify( dst_str, output, 8 );
1454 
1455  fct_chk( strcasecmp( (char *) dst_str, "0756D8E0774761D2" ) == 0 );
1456  }
1457  FCT_TEST_END();
1458 
1459 
1460  FCT_TEST_BGN(des_decrypt_openssl_test_vector_16)
1461  {
1462  unsigned char key_str[100];
1463  unsigned char src_str[100];
1464  unsigned char dst_str[100];
1465  unsigned char output[100];
1466  des_context ctx;
1467 
1468  memset(key_str, 0x00, 100);
1469  memset(src_str, 0x00, 100);
1470  memset(dst_str, 0x00, 100);
1471  memset(output, 0x00, 100);
1472 
1473  unhexify( key_str, "43297FAD38E373FE" );
1474  unhexify( src_str, "EA676B2CB7DB2B7A" );
1475 
1476  des_setkey_dec( &ctx, key_str );
1477  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1478  hexify( dst_str, output, 8 );
1479 
1480  fct_chk( strcasecmp( (char *) dst_str, "762514B829BF486A" ) == 0 );
1481  }
1482  FCT_TEST_END();
1483 
1484 
1485  FCT_TEST_BGN(des_decrypt_openssl_test_vector_17)
1486  {
1487  unsigned char key_str[100];
1488  unsigned char src_str[100];
1489  unsigned char dst_str[100];
1490  unsigned char output[100];
1491  des_context ctx;
1492 
1493  memset(key_str, 0x00, 100);
1494  memset(src_str, 0x00, 100);
1495  memset(dst_str, 0x00, 100);
1496  memset(output, 0x00, 100);
1497 
1498  unhexify( key_str, "07A7137045DA2A16" );
1499  unhexify( src_str, "DFD64A815CAF1A0F" );
1500 
1501  des_setkey_dec( &ctx, key_str );
1502  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1503  hexify( dst_str, output, 8 );
1504 
1505  fct_chk( strcasecmp( (char *) dst_str, "3BDD119049372802" ) == 0 );
1506  }
1507  FCT_TEST_END();
1508 
1509 
1510  FCT_TEST_BGN(des_decrypt_openssl_test_vector_18)
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  des_context ctx;
1517 
1518  memset(key_str, 0x00, 100);
1519  memset(src_str, 0x00, 100);
1520  memset(dst_str, 0x00, 100);
1521  memset(output, 0x00, 100);
1522 
1523  unhexify( key_str, "04689104C2FD3B2F" );
1524  unhexify( src_str, "5C513C9C4886C088" );
1525 
1526  des_setkey_dec( &ctx, key_str );
1527  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1528  hexify( dst_str, output, 8 );
1529 
1530  fct_chk( strcasecmp( (char *) dst_str, "26955F6835AF609A" ) == 0 );
1531  }
1532  FCT_TEST_END();
1533 
1534 
1535  FCT_TEST_BGN(des_decrypt_openssl_test_vector_19)
1536  {
1537  unsigned char key_str[100];
1538  unsigned char src_str[100];
1539  unsigned char dst_str[100];
1540  unsigned char output[100];
1541  des_context ctx;
1542 
1543  memset(key_str, 0x00, 100);
1544  memset(src_str, 0x00, 100);
1545  memset(dst_str, 0x00, 100);
1546  memset(output, 0x00, 100);
1547 
1548  unhexify( key_str, "37D06BB516CB7546" );
1549  unhexify( src_str, "0A2AEEAE3FF4AB77" );
1550 
1551  des_setkey_dec( &ctx, key_str );
1552  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1553  hexify( dst_str, output, 8 );
1554 
1555  fct_chk( strcasecmp( (char *) dst_str, "164D5E404F275232" ) == 0 );
1556  }
1557  FCT_TEST_END();
1558 
1559 
1560  FCT_TEST_BGN(des_decrypt_openssl_test_vector_20)
1561  {
1562  unsigned char key_str[100];
1563  unsigned char src_str[100];
1564  unsigned char dst_str[100];
1565  unsigned char output[100];
1566  des_context ctx;
1567 
1568  memset(key_str, 0x00, 100);
1569  memset(src_str, 0x00, 100);
1570  memset(dst_str, 0x00, 100);
1571  memset(output, 0x00, 100);
1572 
1573  unhexify( key_str, "1F08260D1AC2465E" );
1574  unhexify( src_str, "EF1BF03E5DFA575A" );
1575 
1576  des_setkey_dec( &ctx, key_str );
1577  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1578  hexify( dst_str, output, 8 );
1579 
1580  fct_chk( strcasecmp( (char *) dst_str, "6B056E18759F5CCA" ) == 0 );
1581  }
1582  FCT_TEST_END();
1583 
1584 
1585  FCT_TEST_BGN(des_decrypt_openssl_test_vector_21)
1586  {
1587  unsigned char key_str[100];
1588  unsigned char src_str[100];
1589  unsigned char dst_str[100];
1590  unsigned char output[100];
1591  des_context ctx;
1592 
1593  memset(key_str, 0x00, 100);
1594  memset(src_str, 0x00, 100);
1595  memset(dst_str, 0x00, 100);
1596  memset(output, 0x00, 100);
1597 
1598  unhexify( key_str, "584023641ABA6176" );
1599  unhexify( src_str, "88BF0DB6D70DEE56" );
1600 
1601  des_setkey_dec( &ctx, key_str );
1602  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1603  hexify( dst_str, output, 8 );
1604 
1605  fct_chk( strcasecmp( (char *) dst_str, "004BD6EF09176062" ) == 0 );
1606  }
1607  FCT_TEST_END();
1608 
1609 
1610  FCT_TEST_BGN(des_decrypt_openssl_test_vector_22)
1611  {
1612  unsigned char key_str[100];
1613  unsigned char src_str[100];
1614  unsigned char dst_str[100];
1615  unsigned char output[100];
1616  des_context ctx;
1617 
1618  memset(key_str, 0x00, 100);
1619  memset(src_str, 0x00, 100);
1620  memset(dst_str, 0x00, 100);
1621  memset(output, 0x00, 100);
1622 
1623  unhexify( key_str, "025816164629B007" );
1624  unhexify( src_str, "A1F9915541020B56" );
1625 
1626  des_setkey_dec( &ctx, key_str );
1627  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1628  hexify( dst_str, output, 8 );
1629 
1630  fct_chk( strcasecmp( (char *) dst_str, "480D39006EE762F2" ) == 0 );
1631  }
1632  FCT_TEST_END();
1633 
1634 
1635  FCT_TEST_BGN(des_decrypt_openssl_test_vector_23)
1636  {
1637  unsigned char key_str[100];
1638  unsigned char src_str[100];
1639  unsigned char dst_str[100];
1640  unsigned char output[100];
1641  des_context ctx;
1642 
1643  memset(key_str, 0x00, 100);
1644  memset(src_str, 0x00, 100);
1645  memset(dst_str, 0x00, 100);
1646  memset(output, 0x00, 100);
1647 
1648  unhexify( key_str, "49793EBC79B3258F" );
1649  unhexify( src_str, "6FBF1CAFCFFD0556" );
1650 
1651  des_setkey_dec( &ctx, key_str );
1652  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1653  hexify( dst_str, output, 8 );
1654 
1655  fct_chk( strcasecmp( (char *) dst_str, "437540C8698F3CFA" ) == 0 );
1656  }
1657  FCT_TEST_END();
1658 
1659 
1660  FCT_TEST_BGN(des_decrypt_openssl_test_vector_24)
1661  {
1662  unsigned char key_str[100];
1663  unsigned char src_str[100];
1664  unsigned char dst_str[100];
1665  unsigned char output[100];
1666  des_context ctx;
1667 
1668  memset(key_str, 0x00, 100);
1669  memset(src_str, 0x00, 100);
1670  memset(dst_str, 0x00, 100);
1671  memset(output, 0x00, 100);
1672 
1673  unhexify( key_str, "4FB05E1515AB73A7" );
1674  unhexify( src_str, "2F22E49BAB7CA1AC" );
1675 
1676  des_setkey_dec( &ctx, key_str );
1677  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1678  hexify( dst_str, output, 8 );
1679 
1680  fct_chk( strcasecmp( (char *) dst_str, "072D43A077075292" ) == 0 );
1681  }
1682  FCT_TEST_END();
1683 
1684 
1685  FCT_TEST_BGN(des_decrypt_openssl_test_vector_25)
1686  {
1687  unsigned char key_str[100];
1688  unsigned char src_str[100];
1689  unsigned char dst_str[100];
1690  unsigned char output[100];
1691  des_context ctx;
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  unhexify( key_str, "49E95D6D4CA229BF" );
1699  unhexify( src_str, "5A6B612CC26CCE4A" );
1700 
1701  des_setkey_dec( &ctx, key_str );
1702  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1703  hexify( dst_str, output, 8 );
1704 
1705  fct_chk( strcasecmp( (char *) dst_str, "02FE55778117F12A" ) == 0 );
1706  }
1707  FCT_TEST_END();
1708 
1709 
1710  FCT_TEST_BGN(des_decrypt_openssl_test_vector_26)
1711  {
1712  unsigned char key_str[100];
1713  unsigned char src_str[100];
1714  unsigned char dst_str[100];
1715  unsigned char output[100];
1716  des_context ctx;
1717 
1718  memset(key_str, 0x00, 100);
1719  memset(src_str, 0x00, 100);
1720  memset(dst_str, 0x00, 100);
1721  memset(output, 0x00, 100);
1722 
1723  unhexify( key_str, "018310DC409B26D6" );
1724  unhexify( src_str, "5F4C038ED12B2E41" );
1725 
1726  des_setkey_dec( &ctx, key_str );
1727  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1728  hexify( dst_str, output, 8 );
1729 
1730  fct_chk( strcasecmp( (char *) dst_str, "1D9D5C5018F728C2" ) == 0 );
1731  }
1732  FCT_TEST_END();
1733 
1734 
1735  FCT_TEST_BGN(des_decrypt_openssl_test_vector_27)
1736  {
1737  unsigned char key_str[100];
1738  unsigned char src_str[100];
1739  unsigned char dst_str[100];
1740  unsigned char output[100];
1741  des_context ctx;
1742 
1743  memset(key_str, 0x00, 100);
1744  memset(src_str, 0x00, 100);
1745  memset(dst_str, 0x00, 100);
1746  memset(output, 0x00, 100);
1747 
1748  unhexify( key_str, "1C587F1C13924FEF" );
1749  unhexify( src_str, "63FAC0D034D9F793" );
1750 
1751  des_setkey_dec( &ctx, key_str );
1752  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1753  hexify( dst_str, output, 8 );
1754 
1755  fct_chk( strcasecmp( (char *) dst_str, "305532286D6F295A" ) == 0 );
1756  }
1757  FCT_TEST_END();
1758 
1759 
1760  FCT_TEST_BGN(des_decrypt_openssl_test_vector_28)
1761  {
1762  unsigned char key_str[100];
1763  unsigned char src_str[100];
1764  unsigned char dst_str[100];
1765  unsigned char output[100];
1766  des_context ctx;
1767 
1768  memset(key_str, 0x00, 100);
1769  memset(src_str, 0x00, 100);
1770  memset(dst_str, 0x00, 100);
1771  memset(output, 0x00, 100);
1772 
1773  unhexify( key_str, "0101010101010101" );
1774  unhexify( src_str, "617B3A0CE8F07100" );
1775 
1776  des_setkey_dec( &ctx, key_str );
1777  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1778  hexify( dst_str, output, 8 );
1779 
1780  fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 );
1781  }
1782  FCT_TEST_END();
1783 
1784 
1785  FCT_TEST_BGN(des_decrypt_openssl_test_vector_29)
1786  {
1787  unsigned char key_str[100];
1788  unsigned char src_str[100];
1789  unsigned char dst_str[100];
1790  unsigned char output[100];
1791  des_context ctx;
1792 
1793  memset(key_str, 0x00, 100);
1794  memset(src_str, 0x00, 100);
1795  memset(dst_str, 0x00, 100);
1796  memset(output, 0x00, 100);
1797 
1798  unhexify( key_str, "1F1F1F1F0E0E0E0E" );
1799  unhexify( src_str, "DB958605F8C8C606" );
1800 
1801  des_setkey_dec( &ctx, key_str );
1802  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1803  hexify( dst_str, output, 8 );
1804 
1805  fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 );
1806  }
1807  FCT_TEST_END();
1808 
1809 
1810  FCT_TEST_BGN(des_decrypt_openssl_test_vector_30)
1811  {
1812  unsigned char key_str[100];
1813  unsigned char src_str[100];
1814  unsigned char dst_str[100];
1815  unsigned char output[100];
1816  des_context ctx;
1817 
1818  memset(key_str, 0x00, 100);
1819  memset(src_str, 0x00, 100);
1820  memset(dst_str, 0x00, 100);
1821  memset(output, 0x00, 100);
1822 
1823  unhexify( key_str, "E0FEE0FEF1FEF1FE" );
1824  unhexify( src_str, "EDBFD1C66C29CCC7" );
1825 
1826  des_setkey_dec( &ctx, key_str );
1827  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1828  hexify( dst_str, output, 8 );
1829 
1830  fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 );
1831  }
1832  FCT_TEST_END();
1833 
1834 
1835  FCT_TEST_BGN(des_decrypt_openssl_test_vector_31)
1836  {
1837  unsigned char key_str[100];
1838  unsigned char src_str[100];
1839  unsigned char dst_str[100];
1840  unsigned char output[100];
1841  des_context ctx;
1842 
1843  memset(key_str, 0x00, 100);
1844  memset(src_str, 0x00, 100);
1845  memset(dst_str, 0x00, 100);
1846  memset(output, 0x00, 100);
1847 
1848  unhexify( key_str, "0000000000000000" );
1849  unhexify( src_str, "355550B2150E2451" );
1850 
1851  des_setkey_dec( &ctx, key_str );
1852  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1853  hexify( dst_str, output, 8 );
1854 
1855  fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 );
1856  }
1857  FCT_TEST_END();
1858 
1859 
1860  FCT_TEST_BGN(des_decrypt_openssl_test_vector_32)
1861  {
1862  unsigned char key_str[100];
1863  unsigned char src_str[100];
1864  unsigned char dst_str[100];
1865  unsigned char output[100];
1866  des_context ctx;
1867 
1868  memset(key_str, 0x00, 100);
1869  memset(src_str, 0x00, 100);
1870  memset(dst_str, 0x00, 100);
1871  memset(output, 0x00, 100);
1872 
1873  unhexify( key_str, "FFFFFFFFFFFFFFFF" );
1874  unhexify( src_str, "CAAAAF4DEAF1DBAE" );
1875 
1876  des_setkey_dec( &ctx, key_str );
1877  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1878  hexify( dst_str, output, 8 );
1879 
1880  fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 );
1881  }
1882  FCT_TEST_END();
1883 
1884 
1885  FCT_TEST_BGN(des_decrypt_openssl_test_vector_33)
1886  {
1887  unsigned char key_str[100];
1888  unsigned char src_str[100];
1889  unsigned char dst_str[100];
1890  unsigned char output[100];
1891  des_context ctx;
1892 
1893  memset(key_str, 0x00, 100);
1894  memset(src_str, 0x00, 100);
1895  memset(dst_str, 0x00, 100);
1896  memset(output, 0x00, 100);
1897 
1898  unhexify( key_str, "0123456789ABCDEF" );
1899  unhexify( src_str, "D5D44FF720683D0D" );
1900 
1901  des_setkey_dec( &ctx, key_str );
1902  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1903  hexify( dst_str, output, 8 );
1904 
1905  fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 );
1906  }
1907  FCT_TEST_END();
1908 
1909 
1910  FCT_TEST_BGN(des_decrypt_openssl_test_vector_34)
1911  {
1912  unsigned char key_str[100];
1913  unsigned char src_str[100];
1914  unsigned char dst_str[100];
1915  unsigned char output[100];
1916  des_context ctx;
1917 
1918  memset(key_str, 0x00, 100);
1919  memset(src_str, 0x00, 100);
1920  memset(dst_str, 0x00, 100);
1921  memset(output, 0x00, 100);
1922 
1923  unhexify( key_str, "FEDCBA9876543210" );
1924  unhexify( src_str, "2A2BB008DF97C2F2" );
1925 
1926  des_setkey_dec( &ctx, key_str );
1927  fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 );
1928  hexify( dst_str, output, 8 );
1929 
1930  fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 );
1931  }
1932  FCT_TEST_END();
1933 
1934 
1935  FCT_TEST_BGN(des_cbc_encrypt_openssl_test_vector_1)
1936  {
1937  unsigned char key_str[100];
1938  unsigned char iv_str[100];
1939  unsigned char src_str[100];
1940  unsigned char dst_str[100];
1941  unsigned char output[100];
1942  des_context ctx;
1943  int src_len;
1944 
1945  memset(key_str, 0x00, 100);
1946  memset(iv_str, 0x00, 100);
1947  memset(src_str, 0x00, 100);
1948  memset(dst_str, 0x00, 100);
1949  memset(output, 0x00, 100);
1950 
1951  unhexify( key_str, "0123456789abcdef" );
1952  unhexify( iv_str, "fedcba9876543210" );
1953  src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520" );
1954 
1955  des_setkey_enc( &ctx, key_str );
1956  fct_chk( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == 0 );
1957  if( 0 == 0 )
1958  {
1959  hexify( dst_str, output, src_len );
1960 
1961  fct_chk( strcasecmp( (char *) dst_str, "ccd173ffab2039f4acd8aefddfd8a1eb468e91157888ba68" ) == 0 );
1962  }
1963  }
1964  FCT_TEST_END();
1965 
1966 
1967  FCT_TEST_BGN(des_cbc_decrypt_openssl_test_vector_1)
1968  {
1969  unsigned char key_str[100];
1970  unsigned char iv_str[100];
1971  unsigned char src_str[100];
1972  unsigned char dst_str[100];
1973  unsigned char output[100];
1974  des_context ctx;
1975  int src_len;
1976 
1977  memset(key_str, 0x00, 100);
1978  memset(iv_str, 0x00, 100);
1979  memset(src_str, 0x00, 100);
1980  memset(dst_str, 0x00, 100);
1981  memset(output, 0x00, 100);
1982 
1983  unhexify( key_str, "0123456789abcdef" );
1984  unhexify( iv_str, "fedcba9876543210" );
1985  src_len = unhexify( src_str, "ccd173ffab2039f4acd8aefddfd8a1eb468e91157888ba68" );
1986 
1987  des_setkey_dec( &ctx, key_str );
1988  fct_chk( des_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == 0 );
1989  if( 0 == 0 )
1990  {
1991  hexify( dst_str, output, src_len );
1992 
1993  fct_chk( strcasecmp( (char *) dst_str, "37363534333231204E6F77206973207468652074696D6520" ) == 0 );
1994  }
1995  }
1996  FCT_TEST_END();
1997 
1998 
1999  FCT_TEST_BGN(3des_ecb_2key_encrypt_openssl_test_vector_1)
2000  {
2001  unsigned char key_str[100];
2002  unsigned char src_str[100];
2003  unsigned char dst_str[100];
2004  unsigned char output[100];
2005  des3_context ctx;
2006 
2007  memset(key_str, 0x00, 100);
2008  memset(src_str, 0x00, 100);
2009  memset(dst_str, 0x00, 100);
2010  memset(output, 0x00, 100);
2011 
2012  unhexify( key_str, "0000000000000000FFFFFFFFFFFFFFFF" );
2013  unhexify( src_str, "0000000000000000" );
2014 
2015  if( 2 == 2 )
2016  des3_set2key_enc( &ctx, key_str );
2017  else if( 2 == 3 )
2018  des3_set3key_enc( &ctx, key_str );
2019  else
2020  fct_chk( 0 );
2021 
2022  fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 );
2023  hexify( dst_str, output, 8 );
2024 
2025  fct_chk( strcasecmp( (char *) dst_str, "9295B59BB384736E" ) == 0 );
2026  }
2027  FCT_TEST_END();
2028 
2029 
2030  FCT_TEST_BGN(3des_ecb_2key_encrypt_openssl_test_vector_2)
2031  {
2032  unsigned char key_str[100];
2033  unsigned char src_str[100];
2034  unsigned char dst_str[100];
2035  unsigned char output[100];
2036  des3_context ctx;
2037 
2038  memset(key_str, 0x00, 100);
2039  memset(src_str, 0x00, 100);
2040  memset(dst_str, 0x00, 100);
2041  memset(output, 0x00, 100);
2042 
2043  unhexify( key_str, "FFFFFFFFFFFFFFFF3000000000000000" );
2044  unhexify( src_str, "FFFFFFFFFFFFFFFF" );
2045 
2046  if( 2 == 2 )
2047  des3_set2key_enc( &ctx, key_str );
2048  else if( 2 == 3 )
2049  des3_set3key_enc( &ctx, key_str );
2050  else
2051  fct_chk( 0 );
2052 
2053  fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 );
2054  hexify( dst_str, output, 8 );
2055 
2056  fct_chk( strcasecmp( (char *) dst_str, "199E9D6DF39AA816" ) == 0 );
2057  }
2058  FCT_TEST_END();
2059 
2060 
2061  FCT_TEST_BGN(3des_ecb_2key_decrypt_openssl_test_vector_1)
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  des3_context ctx;
2068 
2069  memset(key_str, 0x00, 100);
2070  memset(src_str, 0x00, 100);
2071  memset(dst_str, 0x00, 100);
2072  memset(output, 0x00, 100);
2073 
2074  unhexify( key_str, "0000000000000000FFFFFFFFFFFFFFFF" );
2075  unhexify( src_str, "9295B59BB384736E" );
2076 
2077  if( 2 == 2 )
2078  des3_set2key_dec( &ctx, key_str );
2079  else if( 2 == 3 )
2080  des3_set3key_dec( &ctx, key_str );
2081  else
2082  fct_chk( 0 );
2083 
2084  fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 );
2085  hexify( dst_str, output, 8 );
2086 
2087  fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 );
2088  }
2089  FCT_TEST_END();
2090 
2091 
2092  FCT_TEST_BGN(3des_ecb_2key_decrypt_openssl_test_vector_2)
2093  {
2094  unsigned char key_str[100];
2095  unsigned char src_str[100];
2096  unsigned char dst_str[100];
2097  unsigned char output[100];
2098  des3_context ctx;
2099 
2100  memset(key_str, 0x00, 100);
2101  memset(src_str, 0x00, 100);
2102  memset(dst_str, 0x00, 100);
2103  memset(output, 0x00, 100);
2104 
2105  unhexify( key_str, "FFFFFFFFFFFFFFFF3000000000000000" );
2106  unhexify( src_str, "199E9D6DF39AA816" );
2107 
2108  if( 2 == 2 )
2109  des3_set2key_dec( &ctx, key_str );
2110  else if( 2 == 3 )
2111  des3_set3key_dec( &ctx, key_str );
2112  else
2113  fct_chk( 0 );
2114 
2115  fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 );
2116  hexify( dst_str, output, 8 );
2117 
2118  fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 );
2119  }
2120  FCT_TEST_END();
2121 
2122 
2123  FCT_TEST_BGN(3des_cbc_3key_encrypt_openssl_test_vector_1)
2124  {
2125  unsigned char key_str[100];
2126  unsigned char iv_str[100];
2127  unsigned char src_str[100];
2128  unsigned char dst_str[100];
2129  unsigned char output[100];
2130  des3_context ctx;
2131  int src_len;
2132 
2133  memset(key_str, 0x00, 100);
2134  memset(iv_str, 0x00, 100);
2135  memset(src_str, 0x00, 100);
2136  memset(dst_str, 0x00, 100);
2137  memset(output, 0x00, 100);
2138 
2139  unhexify( key_str, "0123456789abcdeff1e0d3c2b5a49786fedcba9876543210" );
2140  unhexify( iv_str, "fedcba9876543210" );
2141  src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520" );
2142 
2143  if( 3 == 2 )
2144  des3_set2key_enc( &ctx, key_str );
2145  else if( 3 == 3 )
2146  des3_set3key_enc( &ctx, key_str );
2147  else
2148  fct_chk( 0 );
2149 
2150  fct_chk( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == 0 );
2151 
2152  if( 0 == 0 )
2153  {
2154  hexify( dst_str, output, src_len );
2155 
2156  fct_chk( strcasecmp( (char *) dst_str, "3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D4" ) == 0 );
2157  }
2158  }
2159  FCT_TEST_END();
2160 
2161 
2162  FCT_TEST_BGN(3des_cbc_3key_decrypt_openssl_test_vector_1)
2163  {
2164  unsigned char key_str[100];
2165  unsigned char iv_str[100];
2166  unsigned char src_str[100];
2167  unsigned char dst_str[100];
2168  unsigned char output[100];
2169  des3_context ctx;
2170  int src_len;
2171 
2172  memset(key_str, 0x00, 100);
2173  memset(iv_str, 0x00, 100);
2174  memset(src_str, 0x00, 100);
2175  memset(dst_str, 0x00, 100);
2176  memset(output, 0x00, 100);
2177 
2178  unhexify( key_str, "0123456789abcdeff1e0d3c2b5a49786fedcba9876543210" );
2179  unhexify( iv_str, "fedcba9876543210" );
2180  src_len = unhexify( src_str, "3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D4" );
2181 
2182  if( 3 == 2 )
2183  des3_set2key_dec( &ctx, key_str );
2184  else if( 3 == 3 )
2185  des3_set3key_dec( &ctx, key_str );
2186  else
2187  fct_chk( 0 );
2188 
2189  fct_chk( des3_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == 0 );
2190 
2191  if( 0 == 0 )
2192  {
2193  hexify( dst_str, output, src_len );
2194 
2195  fct_chk( strcasecmp( (char *) dst_str, "37363534333231204E6F77206973207468652074696D6520" ) == 0 );
2196  }
2197  }
2198  FCT_TEST_END();
2199 
2200 
2201  FCT_TEST_BGN(des_cbc_encrypt_invalid_input_length)
2202  {
2203  unsigned char key_str[100];
2204  unsigned char iv_str[100];
2205  unsigned char src_str[100];
2206  unsigned char dst_str[100];
2207  unsigned char output[100];
2208  des_context ctx;
2209  int src_len;
2210 
2211  memset(key_str, 0x00, 100);
2212  memset(iv_str, 0x00, 100);
2213  memset(src_str, 0x00, 100);
2214  memset(dst_str, 0x00, 100);
2215  memset(output, 0x00, 100);
2216 
2217  unhexify( key_str, "0123456789abcdef" );
2218  unhexify( iv_str, "fedcba9876543210" );
2219  src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D65" );
2220 
2221  des_setkey_enc( &ctx, key_str );
2222  fct_chk( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == POLARSSL_ERR_DES_INVALID_INPUT_LENGTH );
2224  {
2225  hexify( dst_str, output, src_len );
2226 
2227  fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 );
2228  }
2229  }
2230  FCT_TEST_END();
2231 
2232 
2233  FCT_TEST_BGN(3des_cbc_3key_encrypt_invalid_input_length)
2234  {
2235  unsigned char key_str[100];
2236  unsigned char iv_str[100];
2237  unsigned char src_str[100];
2238  unsigned char dst_str[100];
2239  unsigned char output[100];
2240  des3_context ctx;
2241  int src_len;
2242 
2243  memset(key_str, 0x00, 100);
2244  memset(iv_str, 0x00, 100);
2245  memset(src_str, 0x00, 100);
2246  memset(dst_str, 0x00, 100);
2247  memset(output, 0x00, 100);
2248 
2249  unhexify( key_str, "0123456789abcdeff1e0d3c2b5a49786fedcba9876543210" );
2250  unhexify( iv_str, "fedcba9876543210" );
2251  src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D65" );
2252 
2253  if( 3 == 2 )
2254  des3_set2key_enc( &ctx, key_str );
2255  else if( 3 == 3 )
2256  des3_set3key_enc( &ctx, key_str );
2257  else
2258  fct_chk( 0 );
2259 
2260  fct_chk( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == POLARSSL_ERR_DES_INVALID_INPUT_LENGTH );
2261 
2263  {
2264  hexify( dst_str, output, src_len );
2265 
2266  fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 );
2267  }
2268  }
2269  FCT_TEST_END();
2270 
2271 
2272  FCT_TEST_BGN(run_through_parity_bit_tests)
2273  {
2274  int i, j, cnt;
2275  unsigned char key[DES_KEY_SIZE];
2276  unsigned int parity;
2277 
2278  memset( key, 0, DES_KEY_SIZE );
2279  cnt = 0;
2280 
2281  // Iterate through all possible byte values
2282  //
2283  for( i = 0; i < 32; i++ )
2284  {
2285  for( j = 0; j < 8; j++ )
2286  key[j] = cnt++;
2287 
2288  // Set the key parity according to the table
2289  //
2290  des_key_set_parity( key );
2291 
2292  // Check the parity with a function
2293  //
2294  for( j = 0; j < 8; j++ )
2295  {
2296  parity = key[j] ^ ( key[j] >> 4 );
2297  parity = parity ^
2298  ( parity >> 1 ) ^
2299  ( parity >> 2 ) ^
2300  ( parity >> 3 );
2301  parity &= 1;
2302 
2303  if( parity != 1 )
2304  fct_chk( 0 );
2305  }
2306 
2307  // Check the parity with the table
2308  //
2309  fct_chk( des_key_check_key_parity( key ) == 0 );
2310  }
2311  }
2312  FCT_TEST_END();
2313 
2314 #ifdef POLARSSL_SELF_TEST
2315 
2316  FCT_TEST_BGN(des_selftest)
2317  {
2318  fct_chk( des_self_test( 0 ) == 0 );
2319  }
2320  FCT_TEST_END();
2321 #endif /* POLARSSL_SELF_TEST */
2322 
2323  }
2324  FCT_SUITE_END();
2325 
2326 #endif /* POLARSSL_DES_C */
2327 
2328 }
2329 FCT_END();
2330