PolarSSL v1.2.8
test_suite_blowfish.c
Go to the documentation of this file.
1 #include "fct.h"
2 #include <polarssl/config.h>
3 
4 #include "polarssl/blowfish.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_BLOWFISH_C
229 
230 
231  FCT_SUITE_BGN(test_suite_blowfish)
232  {
233 
234  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_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  blowfish_context ctx;
241  int key_len;
242 
243  memset(key_str, 0x00, 100);
244  memset(src_str, 0x00, 100);
245  memset(dst_str, 0x00, 100);
246  memset(output, 0x00, 100);
247 
248  key_len = unhexify( key_str, "0000000000000000" );
249  unhexify( src_str, "0000000000000000" );
250 
251  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
252  if( 0 == 0 )
253  {
254  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
255  hexify( dst_str, output, 8 );
256 
257  fct_chk( strcmp( (char *) dst_str, "4ef997456198dd78" ) == 0 );
258  }
259  }
260  FCT_TEST_END();
261 
262 
263  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_2)
264  {
265  unsigned char key_str[100];
266  unsigned char src_str[100];
267  unsigned char dst_str[100];
268  unsigned char output[100];
269  blowfish_context ctx;
270  int key_len;
271 
272  memset(key_str, 0x00, 100);
273  memset(src_str, 0x00, 100);
274  memset(dst_str, 0x00, 100);
275  memset(output, 0x00, 100);
276 
277  key_len = unhexify( key_str, "ffffffffffffffff" );
278  unhexify( src_str, "ffffffffffffffff" );
279 
280  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
281  if( 0 == 0 )
282  {
283  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
284  hexify( dst_str, output, 8 );
285 
286  fct_chk( strcmp( (char *) dst_str, "51866fd5b85ecb8a" ) == 0 );
287  }
288  }
289  FCT_TEST_END();
290 
291 
292  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_3)
293  {
294  unsigned char key_str[100];
295  unsigned char src_str[100];
296  unsigned char dst_str[100];
297  unsigned char output[100];
298  blowfish_context ctx;
299  int key_len;
300 
301  memset(key_str, 0x00, 100);
302  memset(src_str, 0x00, 100);
303  memset(dst_str, 0x00, 100);
304  memset(output, 0x00, 100);
305 
306  key_len = unhexify( key_str, "3000000000000000" );
307  unhexify( src_str, "1000000000000001" );
308 
309  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
310  if( 0 == 0 )
311  {
312  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
313  hexify( dst_str, output, 8 );
314 
315  fct_chk( strcmp( (char *) dst_str, "7d856f9a613063f2" ) == 0 );
316  }
317  }
318  FCT_TEST_END();
319 
320 
321  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_4)
322  {
323  unsigned char key_str[100];
324  unsigned char src_str[100];
325  unsigned char dst_str[100];
326  unsigned char output[100];
327  blowfish_context ctx;
328  int key_len;
329 
330  memset(key_str, 0x00, 100);
331  memset(src_str, 0x00, 100);
332  memset(dst_str, 0x00, 100);
333  memset(output, 0x00, 100);
334 
335  key_len = unhexify( key_str, "1111111111111111" );
336  unhexify( src_str, "1111111111111111" );
337 
338  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
339  if( 0 == 0 )
340  {
341  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
342  hexify( dst_str, output, 8 );
343 
344  fct_chk( strcmp( (char *) dst_str, "2466dd878b963c9d" ) == 0 );
345  }
346  }
347  FCT_TEST_END();
348 
349 
350  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_5)
351  {
352  unsigned char key_str[100];
353  unsigned char src_str[100];
354  unsigned char dst_str[100];
355  unsigned char output[100];
356  blowfish_context ctx;
357  int key_len;
358 
359  memset(key_str, 0x00, 100);
360  memset(src_str, 0x00, 100);
361  memset(dst_str, 0x00, 100);
362  memset(output, 0x00, 100);
363 
364  key_len = unhexify( key_str, "0123456789abcdef" );
365  unhexify( src_str, "1111111111111111" );
366 
367  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
368  if( 0 == 0 )
369  {
370  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
371  hexify( dst_str, output, 8 );
372 
373  fct_chk( strcmp( (char *) dst_str, "61f9c3802281b096" ) == 0 );
374  }
375  }
376  FCT_TEST_END();
377 
378 
379  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_6)
380  {
381  unsigned char key_str[100];
382  unsigned char src_str[100];
383  unsigned char dst_str[100];
384  unsigned char output[100];
385  blowfish_context ctx;
386  int key_len;
387 
388  memset(key_str, 0x00, 100);
389  memset(src_str, 0x00, 100);
390  memset(dst_str, 0x00, 100);
391  memset(output, 0x00, 100);
392 
393  key_len = unhexify( key_str, "1111111111111111" );
394  unhexify( src_str, "0123456789abcdef" );
395 
396  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
397  if( 0 == 0 )
398  {
399  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
400  hexify( dst_str, output, 8 );
401 
402  fct_chk( strcmp( (char *) dst_str, "7d0cc630afda1ec7" ) == 0 );
403  }
404  }
405  FCT_TEST_END();
406 
407 
408  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_7)
409  {
410  unsigned char key_str[100];
411  unsigned char src_str[100];
412  unsigned char dst_str[100];
413  unsigned char output[100];
414  blowfish_context ctx;
415  int key_len;
416 
417  memset(key_str, 0x00, 100);
418  memset(src_str, 0x00, 100);
419  memset(dst_str, 0x00, 100);
420  memset(output, 0x00, 100);
421 
422  key_len = unhexify( key_str, "0000000000000000" );
423  unhexify( src_str, "0000000000000000" );
424 
425  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
426  if( 0 == 0 )
427  {
428  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
429  hexify( dst_str, output, 8 );
430 
431  fct_chk( strcmp( (char *) dst_str, "4ef997456198dd78" ) == 0 );
432  }
433  }
434  FCT_TEST_END();
435 
436 
437  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_8)
438  {
439  unsigned char key_str[100];
440  unsigned char src_str[100];
441  unsigned char dst_str[100];
442  unsigned char output[100];
443  blowfish_context ctx;
444  int key_len;
445 
446  memset(key_str, 0x00, 100);
447  memset(src_str, 0x00, 100);
448  memset(dst_str, 0x00, 100);
449  memset(output, 0x00, 100);
450 
451  key_len = unhexify( key_str, "fedcba9876543210" );
452  unhexify( src_str, "0123456789abcdef" );
453 
454  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
455  if( 0 == 0 )
456  {
457  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
458  hexify( dst_str, output, 8 );
459 
460  fct_chk( strcmp( (char *) dst_str, "0aceab0fc6a0a28d" ) == 0 );
461  }
462  }
463  FCT_TEST_END();
464 
465 
466  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_9)
467  {
468  unsigned char key_str[100];
469  unsigned char src_str[100];
470  unsigned char dst_str[100];
471  unsigned char output[100];
472  blowfish_context ctx;
473  int key_len;
474 
475  memset(key_str, 0x00, 100);
476  memset(src_str, 0x00, 100);
477  memset(dst_str, 0x00, 100);
478  memset(output, 0x00, 100);
479 
480  key_len = unhexify( key_str, "7ca110454a1a6e57" );
481  unhexify( src_str, "01a1d6d039776742" );
482 
483  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
484  if( 0 == 0 )
485  {
486  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
487  hexify( dst_str, output, 8 );
488 
489  fct_chk( strcmp( (char *) dst_str, "59c68245eb05282b" ) == 0 );
490  }
491  }
492  FCT_TEST_END();
493 
494 
495  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_10)
496  {
497  unsigned char key_str[100];
498  unsigned char src_str[100];
499  unsigned char dst_str[100];
500  unsigned char output[100];
501  blowfish_context ctx;
502  int key_len;
503 
504  memset(key_str, 0x00, 100);
505  memset(src_str, 0x00, 100);
506  memset(dst_str, 0x00, 100);
507  memset(output, 0x00, 100);
508 
509  key_len = unhexify( key_str, "0131d9619dc1376e" );
510  unhexify( src_str, "5cd54ca83def57da" );
511 
512  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
513  if( 0 == 0 )
514  {
515  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
516  hexify( dst_str, output, 8 );
517 
518  fct_chk( strcmp( (char *) dst_str, "b1b8cc0b250f09a0" ) == 0 );
519  }
520  }
521  FCT_TEST_END();
522 
523 
524  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_11)
525  {
526  unsigned char key_str[100];
527  unsigned char src_str[100];
528  unsigned char dst_str[100];
529  unsigned char output[100];
530  blowfish_context ctx;
531  int key_len;
532 
533  memset(key_str, 0x00, 100);
534  memset(src_str, 0x00, 100);
535  memset(dst_str, 0x00, 100);
536  memset(output, 0x00, 100);
537 
538  key_len = unhexify( key_str, "07a1133e4a0b2686" );
539  unhexify( src_str, "0248d43806f67172" );
540 
541  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
542  if( 0 == 0 )
543  {
544  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
545  hexify( dst_str, output, 8 );
546 
547  fct_chk( strcmp( (char *) dst_str, "1730e5778bea1da4" ) == 0 );
548  }
549  }
550  FCT_TEST_END();
551 
552 
553  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_12)
554  {
555  unsigned char key_str[100];
556  unsigned char src_str[100];
557  unsigned char dst_str[100];
558  unsigned char output[100];
559  blowfish_context ctx;
560  int key_len;
561 
562  memset(key_str, 0x00, 100);
563  memset(src_str, 0x00, 100);
564  memset(dst_str, 0x00, 100);
565  memset(output, 0x00, 100);
566 
567  key_len = unhexify( key_str, "3849674c2602319e" );
568  unhexify( src_str, "51454b582ddf440a" );
569 
570  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
571  if( 0 == 0 )
572  {
573  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
574  hexify( dst_str, output, 8 );
575 
576  fct_chk( strcmp( (char *) dst_str, "a25e7856cf2651eb" ) == 0 );
577  }
578  }
579  FCT_TEST_END();
580 
581 
582  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_13)
583  {
584  unsigned char key_str[100];
585  unsigned char src_str[100];
586  unsigned char dst_str[100];
587  unsigned char output[100];
588  blowfish_context ctx;
589  int key_len;
590 
591  memset(key_str, 0x00, 100);
592  memset(src_str, 0x00, 100);
593  memset(dst_str, 0x00, 100);
594  memset(output, 0x00, 100);
595 
596  key_len = unhexify( key_str, "04b915ba43feb5b6" );
597  unhexify( src_str, "42fd443059577fa2" );
598 
599  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
600  if( 0 == 0 )
601  {
602  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
603  hexify( dst_str, output, 8 );
604 
605  fct_chk( strcmp( (char *) dst_str, "353882b109ce8f1a" ) == 0 );
606  }
607  }
608  FCT_TEST_END();
609 
610 
611  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_14)
612  {
613  unsigned char key_str[100];
614  unsigned char src_str[100];
615  unsigned char dst_str[100];
616  unsigned char output[100];
617  blowfish_context ctx;
618  int key_len;
619 
620  memset(key_str, 0x00, 100);
621  memset(src_str, 0x00, 100);
622  memset(dst_str, 0x00, 100);
623  memset(output, 0x00, 100);
624 
625  key_len = unhexify( key_str, "0113b970fd34f2ce" );
626  unhexify( src_str, "059b5e0851cf143a" );
627 
628  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
629  if( 0 == 0 )
630  {
631  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
632  hexify( dst_str, output, 8 );
633 
634  fct_chk( strcmp( (char *) dst_str, "48f4d0884c379918" ) == 0 );
635  }
636  }
637  FCT_TEST_END();
638 
639 
640  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_15)
641  {
642  unsigned char key_str[100];
643  unsigned char src_str[100];
644  unsigned char dst_str[100];
645  unsigned char output[100];
646  blowfish_context ctx;
647  int key_len;
648 
649  memset(key_str, 0x00, 100);
650  memset(src_str, 0x00, 100);
651  memset(dst_str, 0x00, 100);
652  memset(output, 0x00, 100);
653 
654  key_len = unhexify( key_str, "0170f175468fb5e6" );
655  unhexify( src_str, "0756d8e0774761d2" );
656 
657  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
658  if( 0 == 0 )
659  {
660  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
661  hexify( dst_str, output, 8 );
662 
663  fct_chk( strcmp( (char *) dst_str, "432193b78951fc98" ) == 0 );
664  }
665  }
666  FCT_TEST_END();
667 
668 
669  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_16)
670  {
671  unsigned char key_str[100];
672  unsigned char src_str[100];
673  unsigned char dst_str[100];
674  unsigned char output[100];
675  blowfish_context ctx;
676  int key_len;
677 
678  memset(key_str, 0x00, 100);
679  memset(src_str, 0x00, 100);
680  memset(dst_str, 0x00, 100);
681  memset(output, 0x00, 100);
682 
683  key_len = unhexify( key_str, "43297fad38e373fe" );
684  unhexify( src_str, "762514b829bf486a" );
685 
686  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
687  if( 0 == 0 )
688  {
689  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
690  hexify( dst_str, output, 8 );
691 
692  fct_chk( strcmp( (char *) dst_str, "13f04154d69d1ae5" ) == 0 );
693  }
694  }
695  FCT_TEST_END();
696 
697 
698  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_17)
699  {
700  unsigned char key_str[100];
701  unsigned char src_str[100];
702  unsigned char dst_str[100];
703  unsigned char output[100];
704  blowfish_context ctx;
705  int key_len;
706 
707  memset(key_str, 0x00, 100);
708  memset(src_str, 0x00, 100);
709  memset(dst_str, 0x00, 100);
710  memset(output, 0x00, 100);
711 
712  key_len = unhexify( key_str, "07a7137045da2a16" );
713  unhexify( src_str, "3bdd119049372802" );
714 
715  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
716  if( 0 == 0 )
717  {
718  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
719  hexify( dst_str, output, 8 );
720 
721  fct_chk( strcmp( (char *) dst_str, "2eedda93ffd39c79" ) == 0 );
722  }
723  }
724  FCT_TEST_END();
725 
726 
727  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_18)
728  {
729  unsigned char key_str[100];
730  unsigned char src_str[100];
731  unsigned char dst_str[100];
732  unsigned char output[100];
733  blowfish_context ctx;
734  int key_len;
735 
736  memset(key_str, 0x00, 100);
737  memset(src_str, 0x00, 100);
738  memset(dst_str, 0x00, 100);
739  memset(output, 0x00, 100);
740 
741  key_len = unhexify( key_str, "04689104c2fd3b2f" );
742  unhexify( src_str, "26955f6835af609a" );
743 
744  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
745  if( 0 == 0 )
746  {
747  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
748  hexify( dst_str, output, 8 );
749 
750  fct_chk( strcmp( (char *) dst_str, "d887e0393c2da6e3" ) == 0 );
751  }
752  }
753  FCT_TEST_END();
754 
755 
756  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_19)
757  {
758  unsigned char key_str[100];
759  unsigned char src_str[100];
760  unsigned char dst_str[100];
761  unsigned char output[100];
762  blowfish_context ctx;
763  int key_len;
764 
765  memset(key_str, 0x00, 100);
766  memset(src_str, 0x00, 100);
767  memset(dst_str, 0x00, 100);
768  memset(output, 0x00, 100);
769 
770  key_len = unhexify( key_str, "37d06bb516cb7546" );
771  unhexify( src_str, "164d5e404f275232" );
772 
773  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
774  if( 0 == 0 )
775  {
776  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
777  hexify( dst_str, output, 8 );
778 
779  fct_chk( strcmp( (char *) dst_str, "5f99d04f5b163969" ) == 0 );
780  }
781  }
782  FCT_TEST_END();
783 
784 
785  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_20)
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  blowfish_context ctx;
792  int key_len;
793 
794  memset(key_str, 0x00, 100);
795  memset(src_str, 0x00, 100);
796  memset(dst_str, 0x00, 100);
797  memset(output, 0x00, 100);
798 
799  key_len = unhexify( key_str, "1f08260d1ac2465e" );
800  unhexify( src_str, "6b056e18759f5cca" );
801 
802  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
803  if( 0 == 0 )
804  {
805  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
806  hexify( dst_str, output, 8 );
807 
808  fct_chk( strcmp( (char *) dst_str, "4a057a3b24d3977b" ) == 0 );
809  }
810  }
811  FCT_TEST_END();
812 
813 
814  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_21)
815  {
816  unsigned char key_str[100];
817  unsigned char src_str[100];
818  unsigned char dst_str[100];
819  unsigned char output[100];
820  blowfish_context ctx;
821  int key_len;
822 
823  memset(key_str, 0x00, 100);
824  memset(src_str, 0x00, 100);
825  memset(dst_str, 0x00, 100);
826  memset(output, 0x00, 100);
827 
828  key_len = unhexify( key_str, "584023641aba6176" );
829  unhexify( src_str, "004bd6ef09176062" );
830 
831  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
832  if( 0 == 0 )
833  {
834  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
835  hexify( dst_str, output, 8 );
836 
837  fct_chk( strcmp( (char *) dst_str, "452031c1e4fada8e" ) == 0 );
838  }
839  }
840  FCT_TEST_END();
841 
842 
843  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_22)
844  {
845  unsigned char key_str[100];
846  unsigned char src_str[100];
847  unsigned char dst_str[100];
848  unsigned char output[100];
849  blowfish_context ctx;
850  int key_len;
851 
852  memset(key_str, 0x00, 100);
853  memset(src_str, 0x00, 100);
854  memset(dst_str, 0x00, 100);
855  memset(output, 0x00, 100);
856 
857  key_len = unhexify( key_str, "025816164629b007" );
858  unhexify( src_str, "480d39006ee762f2" );
859 
860  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
861  if( 0 == 0 )
862  {
863  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
864  hexify( dst_str, output, 8 );
865 
866  fct_chk( strcmp( (char *) dst_str, "7555ae39f59b87bd" ) == 0 );
867  }
868  }
869  FCT_TEST_END();
870 
871 
872  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_23)
873  {
874  unsigned char key_str[100];
875  unsigned char src_str[100];
876  unsigned char dst_str[100];
877  unsigned char output[100];
878  blowfish_context ctx;
879  int key_len;
880 
881  memset(key_str, 0x00, 100);
882  memset(src_str, 0x00, 100);
883  memset(dst_str, 0x00, 100);
884  memset(output, 0x00, 100);
885 
886  key_len = unhexify( key_str, "49793ebc79b3258f" );
887  unhexify( src_str, "437540c8698f3cfa" );
888 
889  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
890  if( 0 == 0 )
891  {
892  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
893  hexify( dst_str, output, 8 );
894 
895  fct_chk( strcmp( (char *) dst_str, "53c55f9cb49fc019" ) == 0 );
896  }
897  }
898  FCT_TEST_END();
899 
900 
901  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_24)
902  {
903  unsigned char key_str[100];
904  unsigned char src_str[100];
905  unsigned char dst_str[100];
906  unsigned char output[100];
907  blowfish_context ctx;
908  int key_len;
909 
910  memset(key_str, 0x00, 100);
911  memset(src_str, 0x00, 100);
912  memset(dst_str, 0x00, 100);
913  memset(output, 0x00, 100);
914 
915  key_len = unhexify( key_str, "4fb05e1515ab73a7" );
916  unhexify( src_str, "072d43a077075292" );
917 
918  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
919  if( 0 == 0 )
920  {
921  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
922  hexify( dst_str, output, 8 );
923 
924  fct_chk( strcmp( (char *) dst_str, "7a8e7bfa937e89a3" ) == 0 );
925  }
926  }
927  FCT_TEST_END();
928 
929 
930  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_25)
931  {
932  unsigned char key_str[100];
933  unsigned char src_str[100];
934  unsigned char dst_str[100];
935  unsigned char output[100];
936  blowfish_context ctx;
937  int key_len;
938 
939  memset(key_str, 0x00, 100);
940  memset(src_str, 0x00, 100);
941  memset(dst_str, 0x00, 100);
942  memset(output, 0x00, 100);
943 
944  key_len = unhexify( key_str, "49e95d6d4ca229bf" );
945  unhexify( src_str, "02fe55778117f12a" );
946 
947  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
948  if( 0 == 0 )
949  {
950  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
951  hexify( dst_str, output, 8 );
952 
953  fct_chk( strcmp( (char *) dst_str, "cf9c5d7a4986adb5" ) == 0 );
954  }
955  }
956  FCT_TEST_END();
957 
958 
959  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_26)
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  blowfish_context ctx;
966  int key_len;
967 
968  memset(key_str, 0x00, 100);
969  memset(src_str, 0x00, 100);
970  memset(dst_str, 0x00, 100);
971  memset(output, 0x00, 100);
972 
973  key_len = unhexify( key_str, "018310dc409b26d6" );
974  unhexify( src_str, "1d9d5c5018f728c2" );
975 
976  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
977  if( 0 == 0 )
978  {
979  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
980  hexify( dst_str, output, 8 );
981 
982  fct_chk( strcmp( (char *) dst_str, "d1abb290658bc778" ) == 0 );
983  }
984  }
985  FCT_TEST_END();
986 
987 
988  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_27)
989  {
990  unsigned char key_str[100];
991  unsigned char src_str[100];
992  unsigned char dst_str[100];
993  unsigned char output[100];
994  blowfish_context ctx;
995  int key_len;
996 
997  memset(key_str, 0x00, 100);
998  memset(src_str, 0x00, 100);
999  memset(dst_str, 0x00, 100);
1000  memset(output, 0x00, 100);
1001 
1002  key_len = unhexify( key_str, "1c587f1c13924fef" );
1003  unhexify( src_str, "305532286d6f295a" );
1004 
1005  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1006  if( 0 == 0 )
1007  {
1008  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1009  hexify( dst_str, output, 8 );
1010 
1011  fct_chk( strcmp( (char *) dst_str, "55cb3774d13ef201" ) == 0 );
1012  }
1013  }
1014  FCT_TEST_END();
1015 
1016 
1017  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_28)
1018  {
1019  unsigned char key_str[100];
1020  unsigned char src_str[100];
1021  unsigned char dst_str[100];
1022  unsigned char output[100];
1023  blowfish_context ctx;
1024  int key_len;
1025 
1026  memset(key_str, 0x00, 100);
1027  memset(src_str, 0x00, 100);
1028  memset(dst_str, 0x00, 100);
1029  memset(output, 0x00, 100);
1030 
1031  key_len = unhexify( key_str, "0101010101010101" );
1032  unhexify( src_str, "0123456789abcdef" );
1033 
1034  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1035  if( 0 == 0 )
1036  {
1037  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1038  hexify( dst_str, output, 8 );
1039 
1040  fct_chk( strcmp( (char *) dst_str, "fa34ec4847b268b2" ) == 0 );
1041  }
1042  }
1043  FCT_TEST_END();
1044 
1045 
1046  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_29)
1047  {
1048  unsigned char key_str[100];
1049  unsigned char src_str[100];
1050  unsigned char dst_str[100];
1051  unsigned char output[100];
1052  blowfish_context ctx;
1053  int key_len;
1054 
1055  memset(key_str, 0x00, 100);
1056  memset(src_str, 0x00, 100);
1057  memset(dst_str, 0x00, 100);
1058  memset(output, 0x00, 100);
1059 
1060  key_len = unhexify( key_str, "1f1f1f1f0e0e0e0e" );
1061  unhexify( src_str, "0123456789abcdef" );
1062 
1063  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1064  if( 0 == 0 )
1065  {
1066  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1067  hexify( dst_str, output, 8 );
1068 
1069  fct_chk( strcmp( (char *) dst_str, "a790795108ea3cae" ) == 0 );
1070  }
1071  }
1072  FCT_TEST_END();
1073 
1074 
1075  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_30)
1076  {
1077  unsigned char key_str[100];
1078  unsigned char src_str[100];
1079  unsigned char dst_str[100];
1080  unsigned char output[100];
1081  blowfish_context ctx;
1082  int key_len;
1083 
1084  memset(key_str, 0x00, 100);
1085  memset(src_str, 0x00, 100);
1086  memset(dst_str, 0x00, 100);
1087  memset(output, 0x00, 100);
1088 
1089  key_len = unhexify( key_str, "e0fee0fef1fef1fe" );
1090  unhexify( src_str, "0123456789abcdef" );
1091 
1092  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1093  if( 0 == 0 )
1094  {
1095  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1096  hexify( dst_str, output, 8 );
1097 
1098  fct_chk( strcmp( (char *) dst_str, "c39e072d9fac631d" ) == 0 );
1099  }
1100  }
1101  FCT_TEST_END();
1102 
1103 
1104  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_31)
1105  {
1106  unsigned char key_str[100];
1107  unsigned char src_str[100];
1108  unsigned char dst_str[100];
1109  unsigned char output[100];
1110  blowfish_context ctx;
1111  int key_len;
1112 
1113  memset(key_str, 0x00, 100);
1114  memset(src_str, 0x00, 100);
1115  memset(dst_str, 0x00, 100);
1116  memset(output, 0x00, 100);
1117 
1118  key_len = unhexify( key_str, "0000000000000000" );
1119  unhexify( src_str, "ffffffffffffffff" );
1120 
1121  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1122  if( 0 == 0 )
1123  {
1124  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1125  hexify( dst_str, output, 8 );
1126 
1127  fct_chk( strcmp( (char *) dst_str, "014933e0cdaff6e4" ) == 0 );
1128  }
1129  }
1130  FCT_TEST_END();
1131 
1132 
1133  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_32)
1134  {
1135  unsigned char key_str[100];
1136  unsigned char src_str[100];
1137  unsigned char dst_str[100];
1138  unsigned char output[100];
1139  blowfish_context ctx;
1140  int key_len;
1141 
1142  memset(key_str, 0x00, 100);
1143  memset(src_str, 0x00, 100);
1144  memset(dst_str, 0x00, 100);
1145  memset(output, 0x00, 100);
1146 
1147  key_len = unhexify( key_str, "ffffffffffffffff" );
1148  unhexify( src_str, "0000000000000000" );
1149 
1150  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1151  if( 0 == 0 )
1152  {
1153  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1154  hexify( dst_str, output, 8 );
1155 
1156  fct_chk( strcmp( (char *) dst_str, "f21e9a77b71c49bc" ) == 0 );
1157  }
1158  }
1159  FCT_TEST_END();
1160 
1161 
1162  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_33)
1163  {
1164  unsigned char key_str[100];
1165  unsigned char src_str[100];
1166  unsigned char dst_str[100];
1167  unsigned char output[100];
1168  blowfish_context ctx;
1169  int key_len;
1170 
1171  memset(key_str, 0x00, 100);
1172  memset(src_str, 0x00, 100);
1173  memset(dst_str, 0x00, 100);
1174  memset(output, 0x00, 100);
1175 
1176  key_len = unhexify( key_str, "0123456789abcdef" );
1177  unhexify( src_str, "0000000000000000" );
1178 
1179  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1180  if( 0 == 0 )
1181  {
1182  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1183  hexify( dst_str, output, 8 );
1184 
1185  fct_chk( strcmp( (char *) dst_str, "245946885754369a" ) == 0 );
1186  }
1187  }
1188  FCT_TEST_END();
1189 
1190 
1191  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_34)
1192  {
1193  unsigned char key_str[100];
1194  unsigned char src_str[100];
1195  unsigned char dst_str[100];
1196  unsigned char output[100];
1197  blowfish_context ctx;
1198  int key_len;
1199 
1200  memset(key_str, 0x00, 100);
1201  memset(src_str, 0x00, 100);
1202  memset(dst_str, 0x00, 100);
1203  memset(output, 0x00, 100);
1204 
1205  key_len = unhexify( key_str, "fedcba9876543210" );
1206  unhexify( src_str, "ffffffffffffffff" );
1207 
1208  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1209  if( 0 == 0 )
1210  {
1211  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1212  hexify( dst_str, output, 8 );
1213 
1214  fct_chk( strcmp( (char *) dst_str, "6b5c5a9c5d9e0a5a" ) == 0 );
1215  }
1216  }
1217  FCT_TEST_END();
1218 
1219 
1220  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_1)
1221  {
1222  unsigned char key_str[100];
1223  unsigned char src_str[100];
1224  unsigned char dst_str[100];
1225  unsigned char output[100];
1226  blowfish_context ctx;
1227  int key_len;
1228 
1229  memset(key_str, 0x00, 100);
1230  memset(src_str, 0x00, 100);
1231  memset(dst_str, 0x00, 100);
1232  memset(output, 0x00, 100);
1233 
1234  key_len = unhexify( key_str, "0000000000000000" );
1235  unhexify( src_str, "4ef997456198dd78" );
1236 
1237  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1238  if( 0 == 0 )
1239  {
1240  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1241  hexify( dst_str, output, 8 );
1242 
1243  fct_chk( strcmp( (char *) dst_str, "0000000000000000" ) == 0 );
1244  }
1245  }
1246  FCT_TEST_END();
1247 
1248 
1249  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_2)
1250  {
1251  unsigned char key_str[100];
1252  unsigned char src_str[100];
1253  unsigned char dst_str[100];
1254  unsigned char output[100];
1255  blowfish_context ctx;
1256  int key_len;
1257 
1258  memset(key_str, 0x00, 100);
1259  memset(src_str, 0x00, 100);
1260  memset(dst_str, 0x00, 100);
1261  memset(output, 0x00, 100);
1262 
1263  key_len = unhexify( key_str, "ffffffffffffffff" );
1264  unhexify( src_str, "51866fd5b85ecb8a" );
1265 
1266  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1267  if( 0 == 0 )
1268  {
1269  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1270  hexify( dst_str, output, 8 );
1271 
1272  fct_chk( strcmp( (char *) dst_str, "ffffffffffffffff" ) == 0 );
1273  }
1274  }
1275  FCT_TEST_END();
1276 
1277 
1278  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_3)
1279  {
1280  unsigned char key_str[100];
1281  unsigned char src_str[100];
1282  unsigned char dst_str[100];
1283  unsigned char output[100];
1284  blowfish_context ctx;
1285  int key_len;
1286 
1287  memset(key_str, 0x00, 100);
1288  memset(src_str, 0x00, 100);
1289  memset(dst_str, 0x00, 100);
1290  memset(output, 0x00, 100);
1291 
1292  key_len = unhexify( key_str, "3000000000000000" );
1293  unhexify( src_str, "7d856f9a613063f2" );
1294 
1295  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1296  if( 0 == 0 )
1297  {
1298  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1299  hexify( dst_str, output, 8 );
1300 
1301  fct_chk( strcmp( (char *) dst_str, "1000000000000001" ) == 0 );
1302  }
1303  }
1304  FCT_TEST_END();
1305 
1306 
1307  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_4)
1308  {
1309  unsigned char key_str[100];
1310  unsigned char src_str[100];
1311  unsigned char dst_str[100];
1312  unsigned char output[100];
1313  blowfish_context ctx;
1314  int key_len;
1315 
1316  memset(key_str, 0x00, 100);
1317  memset(src_str, 0x00, 100);
1318  memset(dst_str, 0x00, 100);
1319  memset(output, 0x00, 100);
1320 
1321  key_len = unhexify( key_str, "1111111111111111" );
1322  unhexify( src_str, "2466dd878b963c9d" );
1323 
1324  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1325  if( 0 == 0 )
1326  {
1327  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1328  hexify( dst_str, output, 8 );
1329 
1330  fct_chk( strcmp( (char *) dst_str, "1111111111111111" ) == 0 );
1331  }
1332  }
1333  FCT_TEST_END();
1334 
1335 
1336  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_5)
1337  {
1338  unsigned char key_str[100];
1339  unsigned char src_str[100];
1340  unsigned char dst_str[100];
1341  unsigned char output[100];
1342  blowfish_context ctx;
1343  int key_len;
1344 
1345  memset(key_str, 0x00, 100);
1346  memset(src_str, 0x00, 100);
1347  memset(dst_str, 0x00, 100);
1348  memset(output, 0x00, 100);
1349 
1350  key_len = unhexify( key_str, "0123456789abcdef" );
1351  unhexify( src_str, "61f9c3802281b096" );
1352 
1353  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1354  if( 0 == 0 )
1355  {
1356  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1357  hexify( dst_str, output, 8 );
1358 
1359  fct_chk( strcmp( (char *) dst_str, "1111111111111111" ) == 0 );
1360  }
1361  }
1362  FCT_TEST_END();
1363 
1364 
1365  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_6)
1366  {
1367  unsigned char key_str[100];
1368  unsigned char src_str[100];
1369  unsigned char dst_str[100];
1370  unsigned char output[100];
1371  blowfish_context ctx;
1372  int key_len;
1373 
1374  memset(key_str, 0x00, 100);
1375  memset(src_str, 0x00, 100);
1376  memset(dst_str, 0x00, 100);
1377  memset(output, 0x00, 100);
1378 
1379  key_len = unhexify( key_str, "1111111111111111" );
1380  unhexify( src_str, "7d0cc630afda1ec7" );
1381 
1382  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1383  if( 0 == 0 )
1384  {
1385  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1386  hexify( dst_str, output, 8 );
1387 
1388  fct_chk( strcmp( (char *) dst_str, "0123456789abcdef" ) == 0 );
1389  }
1390  }
1391  FCT_TEST_END();
1392 
1393 
1394  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_7)
1395  {
1396  unsigned char key_str[100];
1397  unsigned char src_str[100];
1398  unsigned char dst_str[100];
1399  unsigned char output[100];
1400  blowfish_context ctx;
1401  int key_len;
1402 
1403  memset(key_str, 0x00, 100);
1404  memset(src_str, 0x00, 100);
1405  memset(dst_str, 0x00, 100);
1406  memset(output, 0x00, 100);
1407 
1408  key_len = unhexify( key_str, "0000000000000000" );
1409  unhexify( src_str, "4ef997456198dd78" );
1410 
1411  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1412  if( 0 == 0 )
1413  {
1414  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1415  hexify( dst_str, output, 8 );
1416 
1417  fct_chk( strcmp( (char *) dst_str, "0000000000000000" ) == 0 );
1418  }
1419  }
1420  FCT_TEST_END();
1421 
1422 
1423  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_8)
1424  {
1425  unsigned char key_str[100];
1426  unsigned char src_str[100];
1427  unsigned char dst_str[100];
1428  unsigned char output[100];
1429  blowfish_context ctx;
1430  int key_len;
1431 
1432  memset(key_str, 0x00, 100);
1433  memset(src_str, 0x00, 100);
1434  memset(dst_str, 0x00, 100);
1435  memset(output, 0x00, 100);
1436 
1437  key_len = unhexify( key_str, "fedcba9876543210" );
1438  unhexify( src_str, "0aceab0fc6a0a28d" );
1439 
1440  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1441  if( 0 == 0 )
1442  {
1443  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1444  hexify( dst_str, output, 8 );
1445 
1446  fct_chk( strcmp( (char *) dst_str, "0123456789abcdef" ) == 0 );
1447  }
1448  }
1449  FCT_TEST_END();
1450 
1451 
1452  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_9)
1453  {
1454  unsigned char key_str[100];
1455  unsigned char src_str[100];
1456  unsigned char dst_str[100];
1457  unsigned char output[100];
1458  blowfish_context ctx;
1459  int key_len;
1460 
1461  memset(key_str, 0x00, 100);
1462  memset(src_str, 0x00, 100);
1463  memset(dst_str, 0x00, 100);
1464  memset(output, 0x00, 100);
1465 
1466  key_len = unhexify( key_str, "7ca110454a1a6e57" );
1467  unhexify( src_str, "59c68245eb05282b" );
1468 
1469  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1470  if( 0 == 0 )
1471  {
1472  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1473  hexify( dst_str, output, 8 );
1474 
1475  fct_chk( strcmp( (char *) dst_str, "01a1d6d039776742" ) == 0 );
1476  }
1477  }
1478  FCT_TEST_END();
1479 
1480 
1481  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_10)
1482  {
1483  unsigned char key_str[100];
1484  unsigned char src_str[100];
1485  unsigned char dst_str[100];
1486  unsigned char output[100];
1487  blowfish_context ctx;
1488  int key_len;
1489 
1490  memset(key_str, 0x00, 100);
1491  memset(src_str, 0x00, 100);
1492  memset(dst_str, 0x00, 100);
1493  memset(output, 0x00, 100);
1494 
1495  key_len = unhexify( key_str, "0131d9619dc1376e" );
1496  unhexify( src_str, "b1b8cc0b250f09a0" );
1497 
1498  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1499  if( 0 == 0 )
1500  {
1501  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1502  hexify( dst_str, output, 8 );
1503 
1504  fct_chk( strcmp( (char *) dst_str, "5cd54ca83def57da" ) == 0 );
1505  }
1506  }
1507  FCT_TEST_END();
1508 
1509 
1510  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_11)
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  blowfish_context ctx;
1517  int key_len;
1518 
1519  memset(key_str, 0x00, 100);
1520  memset(src_str, 0x00, 100);
1521  memset(dst_str, 0x00, 100);
1522  memset(output, 0x00, 100);
1523 
1524  key_len = unhexify( key_str, "07a1133e4a0b2686" );
1525  unhexify( src_str, "1730e5778bea1da4" );
1526 
1527  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1528  if( 0 == 0 )
1529  {
1530  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1531  hexify( dst_str, output, 8 );
1532 
1533  fct_chk( strcmp( (char *) dst_str, "0248d43806f67172" ) == 0 );
1534  }
1535  }
1536  FCT_TEST_END();
1537 
1538 
1539  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_12)
1540  {
1541  unsigned char key_str[100];
1542  unsigned char src_str[100];
1543  unsigned char dst_str[100];
1544  unsigned char output[100];
1545  blowfish_context ctx;
1546  int key_len;
1547 
1548  memset(key_str, 0x00, 100);
1549  memset(src_str, 0x00, 100);
1550  memset(dst_str, 0x00, 100);
1551  memset(output, 0x00, 100);
1552 
1553  key_len = unhexify( key_str, "3849674c2602319e" );
1554  unhexify( src_str, "a25e7856cf2651eb" );
1555 
1556  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1557  if( 0 == 0 )
1558  {
1559  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1560  hexify( dst_str, output, 8 );
1561 
1562  fct_chk( strcmp( (char *) dst_str, "51454b582ddf440a" ) == 0 );
1563  }
1564  }
1565  FCT_TEST_END();
1566 
1567 
1568  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_13)
1569  {
1570  unsigned char key_str[100];
1571  unsigned char src_str[100];
1572  unsigned char dst_str[100];
1573  unsigned char output[100];
1574  blowfish_context ctx;
1575  int key_len;
1576 
1577  memset(key_str, 0x00, 100);
1578  memset(src_str, 0x00, 100);
1579  memset(dst_str, 0x00, 100);
1580  memset(output, 0x00, 100);
1581 
1582  key_len = unhexify( key_str, "04b915ba43feb5b6" );
1583  unhexify( src_str, "353882b109ce8f1a" );
1584 
1585  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1586  if( 0 == 0 )
1587  {
1588  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1589  hexify( dst_str, output, 8 );
1590 
1591  fct_chk( strcmp( (char *) dst_str, "42fd443059577fa2" ) == 0 );
1592  }
1593  }
1594  FCT_TEST_END();
1595 
1596 
1597  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_14)
1598  {
1599  unsigned char key_str[100];
1600  unsigned char src_str[100];
1601  unsigned char dst_str[100];
1602  unsigned char output[100];
1603  blowfish_context ctx;
1604  int key_len;
1605 
1606  memset(key_str, 0x00, 100);
1607  memset(src_str, 0x00, 100);
1608  memset(dst_str, 0x00, 100);
1609  memset(output, 0x00, 100);
1610 
1611  key_len = unhexify( key_str, "0113b970fd34f2ce" );
1612  unhexify( src_str, "48f4d0884c379918" );
1613 
1614  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1615  if( 0 == 0 )
1616  {
1617  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1618  hexify( dst_str, output, 8 );
1619 
1620  fct_chk( strcmp( (char *) dst_str, "059b5e0851cf143a" ) == 0 );
1621  }
1622  }
1623  FCT_TEST_END();
1624 
1625 
1626  FCT_TEST_BGN(blowfish_ecb_encrypt_ssleay_reference_15)
1627  {
1628  unsigned char key_str[100];
1629  unsigned char src_str[100];
1630  unsigned char dst_str[100];
1631  unsigned char output[100];
1632  blowfish_context ctx;
1633  int key_len;
1634 
1635  memset(key_str, 0x00, 100);
1636  memset(src_str, 0x00, 100);
1637  memset(dst_str, 0x00, 100);
1638  memset(output, 0x00, 100);
1639 
1640  key_len = unhexify( key_str, "0170f175468fb5e6" );
1641  unhexify( src_str, "0756d8e0774761d2" );
1642 
1643  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1644  if( 0 == 0 )
1645  {
1646  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
1647  hexify( dst_str, output, 8 );
1648 
1649  fct_chk( strcmp( (char *) dst_str, "432193b78951fc98" ) == 0 );
1650  }
1651  }
1652  FCT_TEST_END();
1653 
1654 
1655  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_16)
1656  {
1657  unsigned char key_str[100];
1658  unsigned char src_str[100];
1659  unsigned char dst_str[100];
1660  unsigned char output[100];
1661  blowfish_context ctx;
1662  int key_len;
1663 
1664  memset(key_str, 0x00, 100);
1665  memset(src_str, 0x00, 100);
1666  memset(dst_str, 0x00, 100);
1667  memset(output, 0x00, 100);
1668 
1669  key_len = unhexify( key_str, "43297fad38e373fe" );
1670  unhexify( src_str, "13f04154d69d1ae5" );
1671 
1672  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1673  if( 0 == 0 )
1674  {
1675  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1676  hexify( dst_str, output, 8 );
1677 
1678  fct_chk( strcmp( (char *) dst_str, "762514b829bf486a" ) == 0 );
1679  }
1680  }
1681  FCT_TEST_END();
1682 
1683 
1684  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_17)
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  blowfish_context ctx;
1691  int key_len;
1692 
1693  memset(key_str, 0x00, 100);
1694  memset(src_str, 0x00, 100);
1695  memset(dst_str, 0x00, 100);
1696  memset(output, 0x00, 100);
1697 
1698  key_len = unhexify( key_str, "07a7137045da2a16" );
1699  unhexify( src_str, "2eedda93ffd39c79" );
1700 
1701  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1702  if( 0 == 0 )
1703  {
1704  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1705  hexify( dst_str, output, 8 );
1706 
1707  fct_chk( strcmp( (char *) dst_str, "3bdd119049372802" ) == 0 );
1708  }
1709  }
1710  FCT_TEST_END();
1711 
1712 
1713  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_18)
1714  {
1715  unsigned char key_str[100];
1716  unsigned char src_str[100];
1717  unsigned char dst_str[100];
1718  unsigned char output[100];
1719  blowfish_context ctx;
1720  int key_len;
1721 
1722  memset(key_str, 0x00, 100);
1723  memset(src_str, 0x00, 100);
1724  memset(dst_str, 0x00, 100);
1725  memset(output, 0x00, 100);
1726 
1727  key_len = unhexify( key_str, "04689104c2fd3b2f" );
1728  unhexify( src_str, "d887e0393c2da6e3" );
1729 
1730  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1731  if( 0 == 0 )
1732  {
1733  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1734  hexify( dst_str, output, 8 );
1735 
1736  fct_chk( strcmp( (char *) dst_str, "26955f6835af609a" ) == 0 );
1737  }
1738  }
1739  FCT_TEST_END();
1740 
1741 
1742  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_19)
1743  {
1744  unsigned char key_str[100];
1745  unsigned char src_str[100];
1746  unsigned char dst_str[100];
1747  unsigned char output[100];
1748  blowfish_context ctx;
1749  int key_len;
1750 
1751  memset(key_str, 0x00, 100);
1752  memset(src_str, 0x00, 100);
1753  memset(dst_str, 0x00, 100);
1754  memset(output, 0x00, 100);
1755 
1756  key_len = unhexify( key_str, "37d06bb516cb7546" );
1757  unhexify( src_str, "5f99d04f5b163969" );
1758 
1759  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1760  if( 0 == 0 )
1761  {
1762  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1763  hexify( dst_str, output, 8 );
1764 
1765  fct_chk( strcmp( (char *) dst_str, "164d5e404f275232" ) == 0 );
1766  }
1767  }
1768  FCT_TEST_END();
1769 
1770 
1771  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_20)
1772  {
1773  unsigned char key_str[100];
1774  unsigned char src_str[100];
1775  unsigned char dst_str[100];
1776  unsigned char output[100];
1777  blowfish_context ctx;
1778  int key_len;
1779 
1780  memset(key_str, 0x00, 100);
1781  memset(src_str, 0x00, 100);
1782  memset(dst_str, 0x00, 100);
1783  memset(output, 0x00, 100);
1784 
1785  key_len = unhexify( key_str, "1f08260d1ac2465e" );
1786  unhexify( src_str, "4a057a3b24d3977b" );
1787 
1788  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1789  if( 0 == 0 )
1790  {
1791  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1792  hexify( dst_str, output, 8 );
1793 
1794  fct_chk( strcmp( (char *) dst_str, "6b056e18759f5cca" ) == 0 );
1795  }
1796  }
1797  FCT_TEST_END();
1798 
1799 
1800  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_21)
1801  {
1802  unsigned char key_str[100];
1803  unsigned char src_str[100];
1804  unsigned char dst_str[100];
1805  unsigned char output[100];
1806  blowfish_context ctx;
1807  int key_len;
1808 
1809  memset(key_str, 0x00, 100);
1810  memset(src_str, 0x00, 100);
1811  memset(dst_str, 0x00, 100);
1812  memset(output, 0x00, 100);
1813 
1814  key_len = unhexify( key_str, "584023641aba6176" );
1815  unhexify( src_str, "452031c1e4fada8e" );
1816 
1817  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1818  if( 0 == 0 )
1819  {
1820  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1821  hexify( dst_str, output, 8 );
1822 
1823  fct_chk( strcmp( (char *) dst_str, "004bd6ef09176062" ) == 0 );
1824  }
1825  }
1826  FCT_TEST_END();
1827 
1828 
1829  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_22)
1830  {
1831  unsigned char key_str[100];
1832  unsigned char src_str[100];
1833  unsigned char dst_str[100];
1834  unsigned char output[100];
1835  blowfish_context ctx;
1836  int key_len;
1837 
1838  memset(key_str, 0x00, 100);
1839  memset(src_str, 0x00, 100);
1840  memset(dst_str, 0x00, 100);
1841  memset(output, 0x00, 100);
1842 
1843  key_len = unhexify( key_str, "025816164629b007" );
1844  unhexify( src_str, "7555ae39f59b87bd" );
1845 
1846  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1847  if( 0 == 0 )
1848  {
1849  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1850  hexify( dst_str, output, 8 );
1851 
1852  fct_chk( strcmp( (char *) dst_str, "480d39006ee762f2" ) == 0 );
1853  }
1854  }
1855  FCT_TEST_END();
1856 
1857 
1858  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_23)
1859  {
1860  unsigned char key_str[100];
1861  unsigned char src_str[100];
1862  unsigned char dst_str[100];
1863  unsigned char output[100];
1864  blowfish_context ctx;
1865  int key_len;
1866 
1867  memset(key_str, 0x00, 100);
1868  memset(src_str, 0x00, 100);
1869  memset(dst_str, 0x00, 100);
1870  memset(output, 0x00, 100);
1871 
1872  key_len = unhexify( key_str, "49793ebc79b3258f" );
1873  unhexify( src_str, "53c55f9cb49fc019" );
1874 
1875  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1876  if( 0 == 0 )
1877  {
1878  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1879  hexify( dst_str, output, 8 );
1880 
1881  fct_chk( strcmp( (char *) dst_str, "437540c8698f3cfa" ) == 0 );
1882  }
1883  }
1884  FCT_TEST_END();
1885 
1886 
1887  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_24)
1888  {
1889  unsigned char key_str[100];
1890  unsigned char src_str[100];
1891  unsigned char dst_str[100];
1892  unsigned char output[100];
1893  blowfish_context ctx;
1894  int key_len;
1895 
1896  memset(key_str, 0x00, 100);
1897  memset(src_str, 0x00, 100);
1898  memset(dst_str, 0x00, 100);
1899  memset(output, 0x00, 100);
1900 
1901  key_len = unhexify( key_str, "4fb05e1515ab73a7" );
1902  unhexify( src_str, "7a8e7bfa937e89a3" );
1903 
1904  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1905  if( 0 == 0 )
1906  {
1907  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1908  hexify( dst_str, output, 8 );
1909 
1910  fct_chk( strcmp( (char *) dst_str, "072d43a077075292" ) == 0 );
1911  }
1912  }
1913  FCT_TEST_END();
1914 
1915 
1916  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_25)
1917  {
1918  unsigned char key_str[100];
1919  unsigned char src_str[100];
1920  unsigned char dst_str[100];
1921  unsigned char output[100];
1922  blowfish_context ctx;
1923  int key_len;
1924 
1925  memset(key_str, 0x00, 100);
1926  memset(src_str, 0x00, 100);
1927  memset(dst_str, 0x00, 100);
1928  memset(output, 0x00, 100);
1929 
1930  key_len = unhexify( key_str, "49e95d6d4ca229bf" );
1931  unhexify( src_str, "cf9c5d7a4986adb5" );
1932 
1933  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1934  if( 0 == 0 )
1935  {
1936  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1937  hexify( dst_str, output, 8 );
1938 
1939  fct_chk( strcmp( (char *) dst_str, "02fe55778117f12a" ) == 0 );
1940  }
1941  }
1942  FCT_TEST_END();
1943 
1944 
1945  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_26)
1946  {
1947  unsigned char key_str[100];
1948  unsigned char src_str[100];
1949  unsigned char dst_str[100];
1950  unsigned char output[100];
1951  blowfish_context ctx;
1952  int key_len;
1953 
1954  memset(key_str, 0x00, 100);
1955  memset(src_str, 0x00, 100);
1956  memset(dst_str, 0x00, 100);
1957  memset(output, 0x00, 100);
1958 
1959  key_len = unhexify( key_str, "018310dc409b26d6" );
1960  unhexify( src_str, "d1abb290658bc778" );
1961 
1962  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1963  if( 0 == 0 )
1964  {
1965  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1966  hexify( dst_str, output, 8 );
1967 
1968  fct_chk( strcmp( (char *) dst_str, "1d9d5c5018f728c2" ) == 0 );
1969  }
1970  }
1971  FCT_TEST_END();
1972 
1973 
1974  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_27)
1975  {
1976  unsigned char key_str[100];
1977  unsigned char src_str[100];
1978  unsigned char dst_str[100];
1979  unsigned char output[100];
1980  blowfish_context ctx;
1981  int key_len;
1982 
1983  memset(key_str, 0x00, 100);
1984  memset(src_str, 0x00, 100);
1985  memset(dst_str, 0x00, 100);
1986  memset(output, 0x00, 100);
1987 
1988  key_len = unhexify( key_str, "1c587f1c13924fef" );
1989  unhexify( src_str, "55cb3774d13ef201" );
1990 
1991  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
1992  if( 0 == 0 )
1993  {
1994  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
1995  hexify( dst_str, output, 8 );
1996 
1997  fct_chk( strcmp( (char *) dst_str, "305532286d6f295a" ) == 0 );
1998  }
1999  }
2000  FCT_TEST_END();
2001 
2002 
2003  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_28)
2004  {
2005  unsigned char key_str[100];
2006  unsigned char src_str[100];
2007  unsigned char dst_str[100];
2008  unsigned char output[100];
2009  blowfish_context ctx;
2010  int key_len;
2011 
2012  memset(key_str, 0x00, 100);
2013  memset(src_str, 0x00, 100);
2014  memset(dst_str, 0x00, 100);
2015  memset(output, 0x00, 100);
2016 
2017  key_len = unhexify( key_str, "0101010101010101" );
2018  unhexify( src_str, "fa34ec4847b268b2" );
2019 
2020  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2021  if( 0 == 0 )
2022  {
2023  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2024  hexify( dst_str, output, 8 );
2025 
2026  fct_chk( strcmp( (char *) dst_str, "0123456789abcdef" ) == 0 );
2027  }
2028  }
2029  FCT_TEST_END();
2030 
2031 
2032  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_29)
2033  {
2034  unsigned char key_str[100];
2035  unsigned char src_str[100];
2036  unsigned char dst_str[100];
2037  unsigned char output[100];
2038  blowfish_context ctx;
2039  int key_len;
2040 
2041  memset(key_str, 0x00, 100);
2042  memset(src_str, 0x00, 100);
2043  memset(dst_str, 0x00, 100);
2044  memset(output, 0x00, 100);
2045 
2046  key_len = unhexify( key_str, "1f1f1f1f0e0e0e0e" );
2047  unhexify( src_str, "a790795108ea3cae" );
2048 
2049  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2050  if( 0 == 0 )
2051  {
2052  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2053  hexify( dst_str, output, 8 );
2054 
2055  fct_chk( strcmp( (char *) dst_str, "0123456789abcdef" ) == 0 );
2056  }
2057  }
2058  FCT_TEST_END();
2059 
2060 
2061  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_30)
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  blowfish_context ctx;
2068  int key_len;
2069 
2070  memset(key_str, 0x00, 100);
2071  memset(src_str, 0x00, 100);
2072  memset(dst_str, 0x00, 100);
2073  memset(output, 0x00, 100);
2074 
2075  key_len = unhexify( key_str, "e0fee0fef1fef1fe" );
2076  unhexify( src_str, "c39e072d9fac631d" );
2077 
2078  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2079  if( 0 == 0 )
2080  {
2081  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2082  hexify( dst_str, output, 8 );
2083 
2084  fct_chk( strcmp( (char *) dst_str, "0123456789abcdef" ) == 0 );
2085  }
2086  }
2087  FCT_TEST_END();
2088 
2089 
2090  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_31)
2091  {
2092  unsigned char key_str[100];
2093  unsigned char src_str[100];
2094  unsigned char dst_str[100];
2095  unsigned char output[100];
2096  blowfish_context ctx;
2097  int key_len;
2098 
2099  memset(key_str, 0x00, 100);
2100  memset(src_str, 0x00, 100);
2101  memset(dst_str, 0x00, 100);
2102  memset(output, 0x00, 100);
2103 
2104  key_len = unhexify( key_str, "0000000000000000" );
2105  unhexify( src_str, "014933e0cdaff6e4" );
2106 
2107  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2108  if( 0 == 0 )
2109  {
2110  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2111  hexify( dst_str, output, 8 );
2112 
2113  fct_chk( strcmp( (char *) dst_str, "ffffffffffffffff" ) == 0 );
2114  }
2115  }
2116  FCT_TEST_END();
2117 
2118 
2119  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_32)
2120  {
2121  unsigned char key_str[100];
2122  unsigned char src_str[100];
2123  unsigned char dst_str[100];
2124  unsigned char output[100];
2125  blowfish_context ctx;
2126  int key_len;
2127 
2128  memset(key_str, 0x00, 100);
2129  memset(src_str, 0x00, 100);
2130  memset(dst_str, 0x00, 100);
2131  memset(output, 0x00, 100);
2132 
2133  key_len = unhexify( key_str, "ffffffffffffffff" );
2134  unhexify( src_str, "f21e9a77b71c49bc" );
2135 
2136  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2137  if( 0 == 0 )
2138  {
2139  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2140  hexify( dst_str, output, 8 );
2141 
2142  fct_chk( strcmp( (char *) dst_str, "0000000000000000" ) == 0 );
2143  }
2144  }
2145  FCT_TEST_END();
2146 
2147 
2148  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_33)
2149  {
2150  unsigned char key_str[100];
2151  unsigned char src_str[100];
2152  unsigned char dst_str[100];
2153  unsigned char output[100];
2154  blowfish_context ctx;
2155  int key_len;
2156 
2157  memset(key_str, 0x00, 100);
2158  memset(src_str, 0x00, 100);
2159  memset(dst_str, 0x00, 100);
2160  memset(output, 0x00, 100);
2161 
2162  key_len = unhexify( key_str, "0123456789abcdef" );
2163  unhexify( src_str, "245946885754369a" );
2164 
2165  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2166  if( 0 == 0 )
2167  {
2168  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2169  hexify( dst_str, output, 8 );
2170 
2171  fct_chk( strcmp( (char *) dst_str, "0000000000000000" ) == 0 );
2172  }
2173  }
2174  FCT_TEST_END();
2175 
2176 
2177  FCT_TEST_BGN(blowfish_ecb_decrypt_ssleay_reference_34)
2178  {
2179  unsigned char key_str[100];
2180  unsigned char src_str[100];
2181  unsigned char dst_str[100];
2182  unsigned char output[100];
2183  blowfish_context ctx;
2184  int key_len;
2185 
2186  memset(key_str, 0x00, 100);
2187  memset(src_str, 0x00, 100);
2188  memset(dst_str, 0x00, 100);
2189  memset(output, 0x00, 100);
2190 
2191  key_len = unhexify( key_str, "fedcba9876543210" );
2192  unhexify( src_str, "6b5c5a9c5d9e0a5a" );
2193 
2194  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2195  if( 0 == 0 )
2196  {
2197  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 );
2198  hexify( dst_str, output, 8 );
2199 
2200  fct_chk( strcmp( (char *) dst_str, "ffffffffffffffff" ) == 0 );
2201  }
2202  }
2203  FCT_TEST_END();
2204 
2205 
2206  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_1)
2207  {
2208  unsigned char key_str[100];
2209  unsigned char src_str[100];
2210  unsigned char dst_str[100];
2211  unsigned char output[100];
2212  blowfish_context ctx;
2213  int key_len;
2214 
2215  memset(key_str, 0x00, 100);
2216  memset(src_str, 0x00, 100);
2217  memset(dst_str, 0x00, 100);
2218  memset(output, 0x00, 100);
2219 
2220  key_len = unhexify( key_str, "f0" );
2221  unhexify( src_str, "fedcba9876543210" );
2222 
2223  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH );
2225  {
2226  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2227  hexify( dst_str, output, 8 );
2228 
2229  fct_chk( strcmp( (char *) dst_str, "" ) == 0 );
2230  }
2231  }
2232  FCT_TEST_END();
2233 
2234 
2235  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_2)
2236  {
2237  unsigned char key_str[100];
2238  unsigned char src_str[100];
2239  unsigned char dst_str[100];
2240  unsigned char output[100];
2241  blowfish_context ctx;
2242  int key_len;
2243 
2244  memset(key_str, 0x00, 100);
2245  memset(src_str, 0x00, 100);
2246  memset(dst_str, 0x00, 100);
2247  memset(output, 0x00, 100);
2248 
2249  key_len = unhexify( key_str, "f0e1" );
2250  unhexify( src_str, "fedcba9876543210" );
2251 
2252  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH );
2254  {
2255  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2256  hexify( dst_str, output, 8 );
2257 
2258  fct_chk( strcmp( (char *) dst_str, "" ) == 0 );
2259  }
2260  }
2261  FCT_TEST_END();
2262 
2263 
2264  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_3)
2265  {
2266  unsigned char key_str[100];
2267  unsigned char src_str[100];
2268  unsigned char dst_str[100];
2269  unsigned char output[100];
2270  blowfish_context ctx;
2271  int key_len;
2272 
2273  memset(key_str, 0x00, 100);
2274  memset(src_str, 0x00, 100);
2275  memset(dst_str, 0x00, 100);
2276  memset(output, 0x00, 100);
2277 
2278  key_len = unhexify( key_str, "f0e1d2" );
2279  unhexify( src_str, "fedcba9876543210" );
2280 
2281  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH );
2283  {
2284  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2285  hexify( dst_str, output, 8 );
2286 
2287  fct_chk( strcmp( (char *) dst_str, "" ) == 0 );
2288  }
2289  }
2290  FCT_TEST_END();
2291 
2292 
2293  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_4)
2294  {
2295  unsigned char key_str[100];
2296  unsigned char src_str[100];
2297  unsigned char dst_str[100];
2298  unsigned char output[100];
2299  blowfish_context ctx;
2300  int key_len;
2301 
2302  memset(key_str, 0x00, 100);
2303  memset(src_str, 0x00, 100);
2304  memset(dst_str, 0x00, 100);
2305  memset(output, 0x00, 100);
2306 
2307  key_len = unhexify( key_str, "f0e1d2c3" );
2308  unhexify( src_str, "fedcba9876543210" );
2309 
2310  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2311  if( 0 == 0 )
2312  {
2313  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2314  hexify( dst_str, output, 8 );
2315 
2316  fct_chk( strcmp( (char *) dst_str, "be1e639408640f05" ) == 0 );
2317  }
2318  }
2319  FCT_TEST_END();
2320 
2321 
2322  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_5)
2323  {
2324  unsigned char key_str[100];
2325  unsigned char src_str[100];
2326  unsigned char dst_str[100];
2327  unsigned char output[100];
2328  blowfish_context ctx;
2329  int key_len;
2330 
2331  memset(key_str, 0x00, 100);
2332  memset(src_str, 0x00, 100);
2333  memset(dst_str, 0x00, 100);
2334  memset(output, 0x00, 100);
2335 
2336  key_len = unhexify( key_str, "f0e1d2c3b4" );
2337  unhexify( src_str, "fedcba9876543210" );
2338 
2339  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2340  if( 0 == 0 )
2341  {
2342  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2343  hexify( dst_str, output, 8 );
2344 
2345  fct_chk( strcmp( (char *) dst_str, "b39e44481bdb1e6e" ) == 0 );
2346  }
2347  }
2348  FCT_TEST_END();
2349 
2350 
2351  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_6)
2352  {
2353  unsigned char key_str[100];
2354  unsigned char src_str[100];
2355  unsigned char dst_str[100];
2356  unsigned char output[100];
2357  blowfish_context ctx;
2358  int key_len;
2359 
2360  memset(key_str, 0x00, 100);
2361  memset(src_str, 0x00, 100);
2362  memset(dst_str, 0x00, 100);
2363  memset(output, 0x00, 100);
2364 
2365  key_len = unhexify( key_str, "f0e1d2c3b4a5" );
2366  unhexify( src_str, "fedcba9876543210" );
2367 
2368  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2369  if( 0 == 0 )
2370  {
2371  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2372  hexify( dst_str, output, 8 );
2373 
2374  fct_chk( strcmp( (char *) dst_str, "9457aa83b1928c0d" ) == 0 );
2375  }
2376  }
2377  FCT_TEST_END();
2378 
2379 
2380  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_7)
2381  {
2382  unsigned char key_str[100];
2383  unsigned char src_str[100];
2384  unsigned char dst_str[100];
2385  unsigned char output[100];
2386  blowfish_context ctx;
2387  int key_len;
2388 
2389  memset(key_str, 0x00, 100);
2390  memset(src_str, 0x00, 100);
2391  memset(dst_str, 0x00, 100);
2392  memset(output, 0x00, 100);
2393 
2394  key_len = unhexify( key_str, "f0e1d2c3b4a596" );
2395  unhexify( src_str, "fedcba9876543210" );
2396 
2397  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2398  if( 0 == 0 )
2399  {
2400  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2401  hexify( dst_str, output, 8 );
2402 
2403  fct_chk( strcmp( (char *) dst_str, "8bb77032f960629d" ) == 0 );
2404  }
2405  }
2406  FCT_TEST_END();
2407 
2408 
2409  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_8)
2410  {
2411  unsigned char key_str[100];
2412  unsigned char src_str[100];
2413  unsigned char dst_str[100];
2414  unsigned char output[100];
2415  blowfish_context ctx;
2416  int key_len;
2417 
2418  memset(key_str, 0x00, 100);
2419  memset(src_str, 0x00, 100);
2420  memset(dst_str, 0x00, 100);
2421  memset(output, 0x00, 100);
2422 
2423  key_len = unhexify( key_str, "f0e1d2c3b4a59687" );
2424  unhexify( src_str, "fedcba9876543210" );
2425 
2426  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2427  if( 0 == 0 )
2428  {
2429  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2430  hexify( dst_str, output, 8 );
2431 
2432  fct_chk( strcmp( (char *) dst_str, "e87a244e2cc85e82" ) == 0 );
2433  }
2434  }
2435  FCT_TEST_END();
2436 
2437 
2438  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_9)
2439  {
2440  unsigned char key_str[100];
2441  unsigned char src_str[100];
2442  unsigned char dst_str[100];
2443  unsigned char output[100];
2444  blowfish_context ctx;
2445  int key_len;
2446 
2447  memset(key_str, 0x00, 100);
2448  memset(src_str, 0x00, 100);
2449  memset(dst_str, 0x00, 100);
2450  memset(output, 0x00, 100);
2451 
2452  key_len = unhexify( key_str, "f0e1d2c3b4a5968778" );
2453  unhexify( src_str, "fedcba9876543210" );
2454 
2455  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2456  if( 0 == 0 )
2457  {
2458  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2459  hexify( dst_str, output, 8 );
2460 
2461  fct_chk( strcmp( (char *) dst_str, "15750e7a4f4ec577" ) == 0 );
2462  }
2463  }
2464  FCT_TEST_END();
2465 
2466 
2467  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_10)
2468  {
2469  unsigned char key_str[100];
2470  unsigned char src_str[100];
2471  unsigned char dst_str[100];
2472  unsigned char output[100];
2473  blowfish_context ctx;
2474  int key_len;
2475 
2476  memset(key_str, 0x00, 100);
2477  memset(src_str, 0x00, 100);
2478  memset(dst_str, 0x00, 100);
2479  memset(output, 0x00, 100);
2480 
2481  key_len = unhexify( key_str, "f0e1d2c3b4a596877869" );
2482  unhexify( src_str, "fedcba9876543210" );
2483 
2484  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2485  if( 0 == 0 )
2486  {
2487  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2488  hexify( dst_str, output, 8 );
2489 
2490  fct_chk( strcmp( (char *) dst_str, "122ba70b3ab64ae0" ) == 0 );
2491  }
2492  }
2493  FCT_TEST_END();
2494 
2495 
2496  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_11)
2497  {
2498  unsigned char key_str[100];
2499  unsigned char src_str[100];
2500  unsigned char dst_str[100];
2501  unsigned char output[100];
2502  blowfish_context ctx;
2503  int key_len;
2504 
2505  memset(key_str, 0x00, 100);
2506  memset(src_str, 0x00, 100);
2507  memset(dst_str, 0x00, 100);
2508  memset(output, 0x00, 100);
2509 
2510  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a" );
2511  unhexify( src_str, "fedcba9876543210" );
2512 
2513  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2514  if( 0 == 0 )
2515  {
2516  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2517  hexify( dst_str, output, 8 );
2518 
2519  fct_chk( strcmp( (char *) dst_str, "3a833c9affc537f6" ) == 0 );
2520  }
2521  }
2522  FCT_TEST_END();
2523 
2524 
2525  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_12)
2526  {
2527  unsigned char key_str[100];
2528  unsigned char src_str[100];
2529  unsigned char dst_str[100];
2530  unsigned char output[100];
2531  blowfish_context ctx;
2532  int key_len;
2533 
2534  memset(key_str, 0x00, 100);
2535  memset(src_str, 0x00, 100);
2536  memset(dst_str, 0x00, 100);
2537  memset(output, 0x00, 100);
2538 
2539  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b" );
2540  unhexify( src_str, "fedcba9876543210" );
2541 
2542  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2543  if( 0 == 0 )
2544  {
2545  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2546  hexify( dst_str, output, 8 );
2547 
2548  fct_chk( strcmp( (char *) dst_str, "9409da87a90f6bf2" ) == 0 );
2549  }
2550  }
2551  FCT_TEST_END();
2552 
2553 
2554  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_13)
2555  {
2556  unsigned char key_str[100];
2557  unsigned char src_str[100];
2558  unsigned char dst_str[100];
2559  unsigned char output[100];
2560  blowfish_context ctx;
2561  int key_len;
2562 
2563  memset(key_str, 0x00, 100);
2564  memset(src_str, 0x00, 100);
2565  memset(dst_str, 0x00, 100);
2566  memset(output, 0x00, 100);
2567 
2568  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c" );
2569  unhexify( src_str, "fedcba9876543210" );
2570 
2571  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2572  if( 0 == 0 )
2573  {
2574  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2575  hexify( dst_str, output, 8 );
2576 
2577  fct_chk( strcmp( (char *) dst_str, "884f80625060b8b4" ) == 0 );
2578  }
2579  }
2580  FCT_TEST_END();
2581 
2582 
2583  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_14)
2584  {
2585  unsigned char key_str[100];
2586  unsigned char src_str[100];
2587  unsigned char dst_str[100];
2588  unsigned char output[100];
2589  blowfish_context ctx;
2590  int key_len;
2591 
2592  memset(key_str, 0x00, 100);
2593  memset(src_str, 0x00, 100);
2594  memset(dst_str, 0x00, 100);
2595  memset(output, 0x00, 100);
2596 
2597  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d" );
2598  unhexify( src_str, "fedcba9876543210" );
2599 
2600  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2601  if( 0 == 0 )
2602  {
2603  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2604  hexify( dst_str, output, 8 );
2605 
2606  fct_chk( strcmp( (char *) dst_str, "1f85031c19e11968" ) == 0 );
2607  }
2608  }
2609  FCT_TEST_END();
2610 
2611 
2612  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_15)
2613  {
2614  unsigned char key_str[100];
2615  unsigned char src_str[100];
2616  unsigned char dst_str[100];
2617  unsigned char output[100];
2618  blowfish_context ctx;
2619  int key_len;
2620 
2621  memset(key_str, 0x00, 100);
2622  memset(src_str, 0x00, 100);
2623  memset(dst_str, 0x00, 100);
2624  memset(output, 0x00, 100);
2625 
2626  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e" );
2627  unhexify( src_str, "fedcba9876543210" );
2628 
2629  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2630  if( 0 == 0 )
2631  {
2632  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2633  hexify( dst_str, output, 8 );
2634 
2635  fct_chk( strcmp( (char *) dst_str, "79d9373a714ca34f" ) == 0 );
2636  }
2637  }
2638  FCT_TEST_END();
2639 
2640 
2641  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_16)
2642  {
2643  unsigned char key_str[100];
2644  unsigned char src_str[100];
2645  unsigned char dst_str[100];
2646  unsigned char output[100];
2647  blowfish_context ctx;
2648  int key_len;
2649 
2650  memset(key_str, 0x00, 100);
2651  memset(src_str, 0x00, 100);
2652  memset(dst_str, 0x00, 100);
2653  memset(output, 0x00, 100);
2654 
2655  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f" );
2656  unhexify( src_str, "fedcba9876543210" );
2657 
2658  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2659  if( 0 == 0 )
2660  {
2661  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2662  hexify( dst_str, output, 8 );
2663 
2664  fct_chk( strcmp( (char *) dst_str, "93142887ee3be15c" ) == 0 );
2665  }
2666  }
2667  FCT_TEST_END();
2668 
2669 
2670  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_17)
2671  {
2672  unsigned char key_str[100];
2673  unsigned char src_str[100];
2674  unsigned char dst_str[100];
2675  unsigned char output[100];
2676  blowfish_context ctx;
2677  int key_len;
2678 
2679  memset(key_str, 0x00, 100);
2680  memset(src_str, 0x00, 100);
2681  memset(dst_str, 0x00, 100);
2682  memset(output, 0x00, 100);
2683 
2684  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f00" );
2685  unhexify( src_str, "fedcba9876543210" );
2686 
2687  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2688  if( 0 == 0 )
2689  {
2690  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2691  hexify( dst_str, output, 8 );
2692 
2693  fct_chk( strcmp( (char *) dst_str, "03429e838ce2d14b" ) == 0 );
2694  }
2695  }
2696  FCT_TEST_END();
2697 
2698 
2699  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_18)
2700  {
2701  unsigned char key_str[100];
2702  unsigned char src_str[100];
2703  unsigned char dst_str[100];
2704  unsigned char output[100];
2705  blowfish_context ctx;
2706  int key_len;
2707 
2708  memset(key_str, 0x00, 100);
2709  memset(src_str, 0x00, 100);
2710  memset(dst_str, 0x00, 100);
2711  memset(output, 0x00, 100);
2712 
2713  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f0011" );
2714  unhexify( src_str, "fedcba9876543210" );
2715 
2716  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2717  if( 0 == 0 )
2718  {
2719  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2720  hexify( dst_str, output, 8 );
2721 
2722  fct_chk( strcmp( (char *) dst_str, "a4299e27469ff67b" ) == 0 );
2723  }
2724  }
2725  FCT_TEST_END();
2726 
2727 
2728  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_19)
2729  {
2730  unsigned char key_str[100];
2731  unsigned char src_str[100];
2732  unsigned char dst_str[100];
2733  unsigned char output[100];
2734  blowfish_context ctx;
2735  int key_len;
2736 
2737  memset(key_str, 0x00, 100);
2738  memset(src_str, 0x00, 100);
2739  memset(dst_str, 0x00, 100);
2740  memset(output, 0x00, 100);
2741 
2742  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f001122" );
2743  unhexify( src_str, "fedcba9876543210" );
2744 
2745  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2746  if( 0 == 0 )
2747  {
2748  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2749  hexify( dst_str, output, 8 );
2750 
2751  fct_chk( strcmp( (char *) dst_str, "afd5aed1c1bc96a8" ) == 0 );
2752  }
2753  }
2754  FCT_TEST_END();
2755 
2756 
2757  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_20)
2758  {
2759  unsigned char key_str[100];
2760  unsigned char src_str[100];
2761  unsigned char dst_str[100];
2762  unsigned char output[100];
2763  blowfish_context ctx;
2764  int key_len;
2765 
2766  memset(key_str, 0x00, 100);
2767  memset(src_str, 0x00, 100);
2768  memset(dst_str, 0x00, 100);
2769  memset(output, 0x00, 100);
2770 
2771  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f00112233" );
2772  unhexify( src_str, "fedcba9876543210" );
2773 
2774  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2775  if( 0 == 0 )
2776  {
2777  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2778  hexify( dst_str, output, 8 );
2779 
2780  fct_chk( strcmp( (char *) dst_str, "10851c0e3858da9f" ) == 0 );
2781  }
2782  }
2783  FCT_TEST_END();
2784 
2785 
2786  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_21)
2787  {
2788  unsigned char key_str[100];
2789  unsigned char src_str[100];
2790  unsigned char dst_str[100];
2791  unsigned char output[100];
2792  blowfish_context ctx;
2793  int key_len;
2794 
2795  memset(key_str, 0x00, 100);
2796  memset(src_str, 0x00, 100);
2797  memset(dst_str, 0x00, 100);
2798  memset(output, 0x00, 100);
2799 
2800  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344" );
2801  unhexify( src_str, "fedcba9876543210" );
2802 
2803  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2804  if( 0 == 0 )
2805  {
2806  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2807  hexify( dst_str, output, 8 );
2808 
2809  fct_chk( strcmp( (char *) dst_str, "e6f51ed79b9db21f" ) == 0 );
2810  }
2811  }
2812  FCT_TEST_END();
2813 
2814 
2815  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_22)
2816  {
2817  unsigned char key_str[100];
2818  unsigned char src_str[100];
2819  unsigned char dst_str[100];
2820  unsigned char output[100];
2821  blowfish_context ctx;
2822  int key_len;
2823 
2824  memset(key_str, 0x00, 100);
2825  memset(src_str, 0x00, 100);
2826  memset(dst_str, 0x00, 100);
2827  memset(output, 0x00, 100);
2828 
2829  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455" );
2830  unhexify( src_str, "fedcba9876543210" );
2831 
2832  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2833  if( 0 == 0 )
2834  {
2835  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2836  hexify( dst_str, output, 8 );
2837 
2838  fct_chk( strcmp( (char *) dst_str, "64a6e14afd36b46f" ) == 0 );
2839  }
2840  }
2841  FCT_TEST_END();
2842 
2843 
2844  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_23)
2845  {
2846  unsigned char key_str[100];
2847  unsigned char src_str[100];
2848  unsigned char dst_str[100];
2849  unsigned char output[100];
2850  blowfish_context ctx;
2851  int key_len;
2852 
2853  memset(key_str, 0x00, 100);
2854  memset(src_str, 0x00, 100);
2855  memset(dst_str, 0x00, 100);
2856  memset(output, 0x00, 100);
2857 
2858  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566" );
2859  unhexify( src_str, "fedcba9876543210" );
2860 
2861  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2862  if( 0 == 0 )
2863  {
2864  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2865  hexify( dst_str, output, 8 );
2866 
2867  fct_chk( strcmp( (char *) dst_str, "80c7d7d45a5479ad" ) == 0 );
2868  }
2869  }
2870  FCT_TEST_END();
2871 
2872 
2873  FCT_TEST_BGN(blowfish_setkey_setkey_ssleay_reference_24)
2874  {
2875  unsigned char key_str[100];
2876  unsigned char src_str[100];
2877  unsigned char dst_str[100];
2878  unsigned char output[100];
2879  blowfish_context ctx;
2880  int key_len;
2881 
2882  memset(key_str, 0x00, 100);
2883  memset(src_str, 0x00, 100);
2884  memset(dst_str, 0x00, 100);
2885  memset(output, 0x00, 100);
2886 
2887  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344556677" );
2888  unhexify( src_str, "fedcba9876543210" );
2889 
2890  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2891  if( 0 == 0 )
2892  {
2893  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2894  hexify( dst_str, output, 8 );
2895 
2896  fct_chk( strcmp( (char *) dst_str, "05044b62fa52d080" ) == 0 );
2897  }
2898  }
2899  FCT_TEST_END();
2900 
2901 
2902  FCT_TEST_BGN(blowfish_setkey_setkey_440_bits)
2903  {
2904  unsigned char key_str[100];
2905  unsigned char src_str[100];
2906  unsigned char dst_str[100];
2907  unsigned char output[100];
2908  blowfish_context ctx;
2909  int key_len;
2910 
2911  memset(key_str, 0x00, 100);
2912  memset(src_str, 0x00, 100);
2913  memset(dst_str, 0x00, 100);
2914  memset(output, 0x00, 100);
2915 
2916  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566778899aabbccddeeff0123456789abcdef0102030405060708090a0b0c0d0e0f" );
2917  unhexify( src_str, "fedcba9876543210" );
2918 
2919  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2920  if( 0 == 0 )
2921  {
2922  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2923  hexify( dst_str, output, 8 );
2924 
2925  fct_chk( strcmp( (char *) dst_str, "9a2ab8f1b00c73d2" ) == 0 );
2926  }
2927  }
2928  FCT_TEST_END();
2929 
2930 
2931  FCT_TEST_BGN(blowfish_setkey_setkey_448_bits)
2932  {
2933  unsigned char key_str[100];
2934  unsigned char src_str[100];
2935  unsigned char dst_str[100];
2936  unsigned char output[100];
2937  blowfish_context ctx;
2938  int key_len;
2939 
2940  memset(key_str, 0x00, 100);
2941  memset(src_str, 0x00, 100);
2942  memset(dst_str, 0x00, 100);
2943  memset(output, 0x00, 100);
2944 
2945  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566778899aabbccddeeff0123456789abcdef0102030405060708090a0b0c0d0e0fff" );
2946  unhexify( src_str, "fedcba9876543210" );
2947 
2948  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == 0 );
2949  if( 0 == 0 )
2950  {
2951  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2952  hexify( dst_str, output, 8 );
2953 
2954  fct_chk( strcmp( (char *) dst_str, "2fb3ab7f0ee91b69" ) == 0 );
2955  }
2956  }
2957  FCT_TEST_END();
2958 
2959 
2960  FCT_TEST_BGN(blowfish_setkey_setkey_456_bits)
2961  {
2962  unsigned char key_str[100];
2963  unsigned char src_str[100];
2964  unsigned char dst_str[100];
2965  unsigned char output[100];
2966  blowfish_context ctx;
2967  int key_len;
2968 
2969  memset(key_str, 0x00, 100);
2970  memset(src_str, 0x00, 100);
2971  memset(dst_str, 0x00, 100);
2972  memset(output, 0x00, 100);
2973 
2974  key_len = unhexify( key_str, "f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566778899aabbccddeeff0123456789abcdef0102030405060708090a0b0c0d0e0fffff" );
2975  unhexify( src_str, "fedcba9876543210" );
2976 
2977  fct_chk( blowfish_setkey( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH );
2979  {
2980  fct_chk( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 );
2981  hexify( dst_str, output, 8 );
2982 
2983  fct_chk( strcmp( (char *) dst_str, "" ) == 0 );
2984  }
2985  }
2986  FCT_TEST_END();
2987 
2988 
2989  FCT_TEST_BGN(blowfish_cbc_encrypt)
2990  {
2991  unsigned char key_str[100];
2992  unsigned char iv_str[100];
2993  unsigned char src_str[100];
2994  unsigned char dst_str[100];
2995  unsigned char output[100];
2996  blowfish_context ctx;
2997  int key_len, data_len;
2998 
2999  memset(key_str, 0x00, 100);
3000  memset(iv_str, 0x00, 100);
3001  memset(src_str, 0x00, 100);
3002  memset(dst_str, 0x00, 100);
3003  memset(output, 0x00, 100);
3004 
3005  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3006  unhexify( iv_str, "FEDCBA9876543210" );
3007  data_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520666F722000000000" );
3008 
3009  blowfish_setkey( &ctx, key_str, key_len * 8 );
3010 
3011  fct_chk( blowfish_crypt_cbc( &ctx, BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == 0 );
3012  if( 0 == 0 )
3013  {
3014  hexify( dst_str, output, data_len );
3015 
3016  fct_chk( strcmp( (char *) dst_str, "6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc" ) == 0 );
3017  }
3018  }
3019  FCT_TEST_END();
3020 
3021 
3022  FCT_TEST_BGN(blowfish_cbc_decrypt)
3023  {
3024  unsigned char key_str[100];
3025  unsigned char iv_str[100];
3026  unsigned char src_str[100];
3027  unsigned char dst_str[100];
3028  unsigned char output[100];
3029  blowfish_context ctx;
3030  int key_len, data_len;
3031 
3032  memset(key_str, 0x00, 100);
3033  memset(iv_str, 0x00, 100);
3034  memset(src_str, 0x00, 100);
3035  memset(dst_str, 0x00, 100);
3036  memset(output, 0x00, 100);
3037 
3038  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3039  unhexify( iv_str, "FEDCBA9876543210" );
3040  data_len = unhexify( src_str, "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC" );
3041 
3042  blowfish_setkey( &ctx, key_str, key_len * 8 );
3043  fct_chk( blowfish_crypt_cbc( &ctx, BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == 0 );
3044  if( 0 == 0)
3045  {
3046  hexify( dst_str, output, data_len );
3047 
3048  fct_chk( strcmp( (char *) dst_str, "37363534333231204e6f77206973207468652074696d6520666f722000000000" ) == 0 );
3049  }
3050  }
3051  FCT_TEST_END();
3052 
3053 
3054  FCT_TEST_BGN(blowfish_cbc_encrypt)
3055  {
3056  unsigned char key_str[100];
3057  unsigned char iv_str[100];
3058  unsigned char src_str[100];
3059  unsigned char dst_str[100];
3060  unsigned char output[100];
3061  blowfish_context ctx;
3062  int key_len, data_len;
3063 
3064  memset(key_str, 0x00, 100);
3065  memset(iv_str, 0x00, 100);
3066  memset(src_str, 0x00, 100);
3067  memset(dst_str, 0x00, 100);
3068  memset(output, 0x00, 100);
3069 
3070  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3071  unhexify( iv_str, "FEDCBA9876543210" );
3072  data_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520666F7220000000" );
3073 
3074  blowfish_setkey( &ctx, key_str, key_len * 8 );
3075 
3076  fct_chk( blowfish_crypt_cbc( &ctx, BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH );
3078  {
3079  hexify( dst_str, output, data_len );
3080 
3081  fct_chk( strcmp( (char *) dst_str, "" ) == 0 );
3082  }
3083  }
3084  FCT_TEST_END();
3085 
3086 
3087  FCT_TEST_BGN(blowfish_cbc_decrypt)
3088  {
3089  unsigned char key_str[100];
3090  unsigned char iv_str[100];
3091  unsigned char src_str[100];
3092  unsigned char dst_str[100];
3093  unsigned char output[100];
3094  blowfish_context ctx;
3095  int key_len, data_len;
3096 
3097  memset(key_str, 0x00, 100);
3098  memset(iv_str, 0x00, 100);
3099  memset(src_str, 0x00, 100);
3100  memset(dst_str, 0x00, 100);
3101  memset(output, 0x00, 100);
3102 
3103  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3104  unhexify( iv_str, "FEDCBA9876543210" );
3105  data_len = unhexify( src_str, "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC00" );
3106 
3107  blowfish_setkey( &ctx, key_str, key_len * 8 );
3108  fct_chk( blowfish_crypt_cbc( &ctx, BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH );
3110  {
3111  hexify( dst_str, output, data_len );
3112 
3113  fct_chk( strcmp( (char *) dst_str, "" ) == 0 );
3114  }
3115  }
3116  FCT_TEST_END();
3117 
3118 
3119  FCT_TEST_BGN(blowfish_cfb_encrypt)
3120  {
3121  unsigned char key_str[100];
3122  unsigned char iv_str[100];
3123  unsigned char src_str[100];
3124  unsigned char dst_str[100];
3125  unsigned char output[100];
3126  blowfish_context ctx;
3127  size_t iv_offset = 0;
3128  int key_len, src_len;
3129 
3130  memset(key_str, 0x00, 100);
3131  memset(iv_str, 0x00, 100);
3132  memset(src_str, 0x00, 100);
3133  memset(dst_str, 0x00, 100);
3134  memset(output, 0x00, 100);
3135 
3136  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3137  unhexify( iv_str, "FEDCBA9876543210" );
3138  src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520666F722000" );
3139 
3140  blowfish_setkey( &ctx, key_str, key_len * 8 );
3141  fct_chk( blowfish_crypt_cfb64( &ctx, BLOWFISH_ENCRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 );
3142  hexify( dst_str, output, src_len );
3143 
3144  fct_chk( strcmp( (char *) dst_str, "e73214a2822139caf26ecf6d2eb9e76e3da3de04d1517200519d57a6c3" ) == 0 );
3145  }
3146  FCT_TEST_END();
3147 
3148 
3149  FCT_TEST_BGN(blowfish_cfb_decrypt)
3150  {
3151  unsigned char key_str[100];
3152  unsigned char iv_str[100];
3153  unsigned char src_str[100];
3154  unsigned char dst_str[100];
3155  unsigned char output[100];
3156  blowfish_context ctx;
3157  size_t iv_offset = 0;
3158  int key_len, src_len;
3159 
3160  memset(key_str, 0x00, 100);
3161  memset(iv_str, 0x00, 100);
3162  memset(src_str, 0x00, 100);
3163  memset(dst_str, 0x00, 100);
3164  memset(output, 0x00, 100);
3165 
3166  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3167  unhexify( iv_str, "FEDCBA9876543210" );
3168  src_len = unhexify( src_str, "E73214A2822139CAF26ECF6D2EB9E76E3DA3DE04D1517200519D57A6C3" );
3169 
3170  blowfish_setkey( &ctx, key_str, key_len * 8 );
3171  fct_chk( blowfish_crypt_cfb64( &ctx, BLOWFISH_DECRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 );
3172  hexify( dst_str, output, src_len );
3173 
3174  fct_chk( strcmp( (char *) dst_str, "37363534333231204e6f77206973207468652074696d6520666f722000" ) == 0 );
3175  }
3176  FCT_TEST_END();
3177 
3178 
3179  FCT_TEST_BGN(blowfish_ctr_encrypt)
3180  {
3181  unsigned char key_str[100];
3182  unsigned char iv_str[100];
3183  unsigned char stream_str[100];
3184  unsigned char src_str[100];
3185  unsigned char dst_str[100];
3186  unsigned char output[100];
3187  blowfish_context ctx;
3188  size_t iv_offset = 0;
3189  int key_len, src_len;
3190 
3191  memset(key_str, 0x00, 100);
3192  memset(iv_str, 0x00, 100);
3193  memset(stream_str, 0x00, 100);
3194  memset(src_str, 0x00, 100);
3195  memset(dst_str, 0x00, 100);
3196  memset(output, 0x00, 100);
3197 
3198  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3199  unhexify( iv_str, "FEDCBA9876543210" );
3200  src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520666F722000" );
3201 
3202  blowfish_setkey( &ctx, key_str, key_len * 8 );
3203  fct_chk( blowfish_crypt_ctr( &ctx, src_len, &iv_offset, iv_str, stream_str, src_str, output ) == 0 );
3204  hexify( dst_str, output, src_len );
3205 
3206  fct_chk( strcmp( (char *) dst_str, "e73214a2822139ca60254740dd8c5b8acf5e9569c4affeb944b8fc020e" ) == 0 );
3207  }
3208  FCT_TEST_END();
3209 
3210 
3211  FCT_TEST_BGN(blowfish_ctr_decrypt)
3212  {
3213  unsigned char key_str[100];
3214  unsigned char iv_str[100];
3215  unsigned char stream_str[100];
3216  unsigned char src_str[100];
3217  unsigned char dst_str[100];
3218  unsigned char output[100];
3219  blowfish_context ctx;
3220  size_t iv_offset = 0;
3221  int key_len, src_len;
3222 
3223  memset(key_str, 0x00, 100);
3224  memset(iv_str, 0x00, 100);
3225  memset(stream_str, 0x00, 100);
3226  memset(src_str, 0x00, 100);
3227  memset(dst_str, 0x00, 100);
3228  memset(output, 0x00, 100);
3229 
3230  key_len = unhexify( key_str, "0123456789ABCDEFF0E1D2C3B4A59687" );
3231  unhexify( iv_str, "FEDCBA9876543210" );
3232  src_len = unhexify( src_str, "e73214a2822139ca60254740dd8c5b8acf5e9569c4affeb944b8fc020e" );
3233 
3234  blowfish_setkey( &ctx, key_str, key_len * 8 );
3235  fct_chk( blowfish_crypt_ctr( &ctx, src_len, &iv_offset, iv_str, stream_str, src_str, output ) == 0 );
3236  hexify( dst_str, output, src_len );
3237 
3238  fct_chk( strcmp( (char *) dst_str, "37363534333231204e6f77206973207468652074696d6520666f722000" ) == 0 );
3239  }
3240  FCT_TEST_END();
3241 
3242  }
3243  FCT_SUITE_END();
3244 
3245 #endif /* POLARSSL_BLOWFISH_C */
3246 
3247 }
3248 FCT_END();
3249