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