PolarSSL v1.2.5
test_suite_camellia.c
Go to the documentation of this file.
1 #include "fct.h"
2 
3 #include <polarssl/camellia.h>
4 
5 #include <polarssl/config.h>
6 
7 #ifdef _MSC_VER
8 #include <basetsd.h>
9 typedef UINT32 uint32_t;
10 #else
11 #include <inttypes.h>
12 #endif
13 
14 /*
15  * 32-bit integer manipulation macros (big endian)
16  */
17 #ifndef GET_UINT32_BE
18 #define GET_UINT32_BE(n,b,i) \
19 { \
20  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
21  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
22  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
23  | ( (uint32_t) (b)[(i) + 3] ); \
24 }
25 #endif
26 
27 #ifndef PUT_UINT32_BE
28 #define PUT_UINT32_BE(n,b,i) \
29 { \
30  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
31  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
32  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
33  (b)[(i) + 3] = (unsigned char) ( (n) ); \
34 }
35 #endif
36 
37 int unhexify(unsigned char *obuf, const char *ibuf)
38 {
39  unsigned char c, c2;
40  int len = strlen(ibuf) / 2;
41  assert(!(strlen(ibuf) %1)); // must be even number of bytes
42 
43  while (*ibuf != 0)
44  {
45  c = *ibuf++;
46  if( c >= '0' && c <= '9' )
47  c -= '0';
48  else if( c >= 'a' && c <= 'f' )
49  c -= 'a' - 10;
50  else if( c >= 'A' && c <= 'F' )
51  c -= 'A' - 10;
52  else
53  assert( 0 );
54 
55  c2 = *ibuf++;
56  if( c2 >= '0' && c2 <= '9' )
57  c2 -= '0';
58  else if( c2 >= 'a' && c2 <= 'f' )
59  c2 -= 'a' - 10;
60  else if( c2 >= 'A' && c2 <= 'F' )
61  c2 -= 'A' - 10;
62  else
63  assert( 0 );
64 
65  *obuf++ = ( c << 4 ) | c2;
66  }
67 
68  return len;
69 }
70 
71 void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
72 {
73  unsigned char l, h;
74 
75  while (len != 0)
76  {
77  h = (*ibuf) / 16;
78  l = (*ibuf) % 16;
79 
80  if( h < 10 )
81  *obuf++ = '0' + h;
82  else
83  *obuf++ = 'a' + h - 10;
84 
85  if( l < 10 )
86  *obuf++ = '0' + l;
87  else
88  *obuf++ = 'a' + l - 10;
89 
90  ++ibuf;
91  len--;
92  }
93 }
94 
104 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
105 {
106  size_t i;
107 
108  if( rng_state != NULL )
109  rng_state = NULL;
110 
111  for( i = 0; i < len; ++i )
112  output[i] = rand();
113 
114  return( 0 );
115 }
116 
122 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
123 {
124  if( rng_state != NULL )
125  rng_state = NULL;
126 
127  memset( output, 0, len );
128 
129  return( 0 );
130 }
131 
132 typedef struct
133 {
134  unsigned char *buf;
135  size_t length;
136 } rnd_buf_info;
137 
149 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
150 {
151  rnd_buf_info *info = (rnd_buf_info *) rng_state;
152  size_t use_len;
153 
154  if( rng_state == NULL )
155  return( rnd_std_rand( NULL, output, len ) );
156 
157  use_len = len;
158  if( len > info->length )
159  use_len = info->length;
160 
161  if( use_len )
162  {
163  memcpy( output, info->buf, use_len );
164  info->buf += use_len;
165  info->length -= use_len;
166  }
167 
168  if( len - use_len > 0 )
169  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
170 
171  return( 0 );
172 }
173 
181 typedef struct
182 {
183  uint32_t key[16];
184  uint32_t v0, v1;
186 
195 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
196 {
197  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
198  uint32_t i, *k, sum, delta=0x9E3779B9;
199  unsigned char result[4];
200 
201  if( rng_state == NULL )
202  return( rnd_std_rand( NULL, output, len ) );
203 
204  k = info->key;
205 
206  while( len > 0 )
207  {
208  size_t use_len = ( len > 4 ) ? 4 : len;
209  sum = 0;
210 
211  for( i = 0; i < 32; i++ )
212  {
213  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
214  sum += delta;
215  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
216  }
217 
218  PUT_UINT32_BE( info->v0, result, 0 );
219  memcpy( output, result, use_len );
220  len -= use_len;
221  }
222 
223  return( 0 );
224 }
225 
226 
228 {
229 #ifdef POLARSSL_CAMELLIA_C
230 
231 
232  FCT_SUITE_BGN(test_suite_camellia)
233  {
234 
235  FCT_TEST_BGN(camellia_128_ecb_encrypt_rfc3713_1)
236  {
237  unsigned char key_str[100];
238  unsigned char src_str[100];
239  unsigned char dst_str[100];
240  unsigned char output[100];
241  camellia_context ctx;
242  int key_len;
243 
244  memset(key_str, 0x00, 100);
245  memset(src_str, 0x00, 100);
246  memset(dst_str, 0x00, 100);
247  memset(output, 0x00, 100);
248 
249  key_len = unhexify( key_str, "0123456789abcdeffedcba9876543210" );
250  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
251 
252  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
253  if( 0 == 0 )
254  {
255  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
256  hexify( dst_str, output, 16 );
257 
258  fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 );
259  }
260  }
261  FCT_TEST_END();
262 
263 
264  FCT_TEST_BGN(camellia_192_ecb_encrypt_rfc3713_1)
265  {
266  unsigned char key_str[100];
267  unsigned char src_str[100];
268  unsigned char dst_str[100];
269  unsigned char output[100];
270  camellia_context ctx;
271  int key_len;
272 
273  memset(key_str, 0x00, 100);
274  memset(src_str, 0x00, 100);
275  memset(dst_str, 0x00, 100);
276  memset(output, 0x00, 100);
277 
278  key_len = unhexify( key_str, "0123456789abcdeffedcba98765432100011223344556677" );
279  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
280 
281  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
282  if( 0 == 0 )
283  {
284  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
285  hexify( dst_str, output, 16 );
286 
287  fct_chk( strcasecmp( (char *) dst_str, "b4993401b3e996f84ee5cee7d79b09b9" ) == 0 );
288  }
289  }
290  FCT_TEST_END();
291 
292 
293  FCT_TEST_BGN(camellia_256_ecb_encrypt_rfc3713_1)
294  {
295  unsigned char key_str[100];
296  unsigned char src_str[100];
297  unsigned char dst_str[100];
298  unsigned char output[100];
299  camellia_context ctx;
300  int key_len;
301 
302  memset(key_str, 0x00, 100);
303  memset(src_str, 0x00, 100);
304  memset(dst_str, 0x00, 100);
305  memset(output, 0x00, 100);
306 
307  key_len = unhexify( key_str, "0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff" );
308  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
309 
310  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
311  if( 0 == 0 )
312  {
313  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
314  hexify( dst_str, output, 16 );
315 
316  fct_chk( strcasecmp( (char *) dst_str, "9acc237dff16d76c20ef7c919e3a7509" ) == 0 );
317  }
318  }
319  FCT_TEST_END();
320 
321 
322  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_1)
323  {
324  unsigned char key_str[100];
325  unsigned char src_str[100];
326  unsigned char dst_str[100];
327  unsigned char output[100];
328  camellia_context ctx;
329  int key_len;
330 
331  memset(key_str, 0x00, 100);
332  memset(src_str, 0x00, 100);
333  memset(dst_str, 0x00, 100);
334  memset(output, 0x00, 100);
335 
336  key_len = unhexify( key_str, "000102030405060708090A0B0C0D0E0F" );
337  unhexify( src_str, "00112233445566778899AABBCCDDEEFF" );
338 
339  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
340  if( 0 == 0 )
341  {
342  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
343  hexify( dst_str, output, 16 );
344 
345  fct_chk( strcasecmp( (char *) dst_str, "77CF412067AF8270613529149919546F" ) == 0 );
346  }
347  }
348  FCT_TEST_END();
349 
350 
351  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_1)
352  {
353  unsigned char key_str[100];
354  unsigned char src_str[100];
355  unsigned char dst_str[100];
356  unsigned char output[100];
357  camellia_context ctx;
358  int key_len;
359 
360  memset(key_str, 0x00, 100);
361  memset(src_str, 0x00, 100);
362  memset(dst_str, 0x00, 100);
363  memset(output, 0x00, 100);
364 
365  key_len = unhexify( key_str, "000102030405060708090A0B0C0D0E0F1011121314151617" );
366  unhexify( src_str, "00112233445566778899AABBCCDDEEFF" );
367 
368  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
369  if( 0 == 0 )
370  {
371  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
372  hexify( dst_str, output, 16 );
373 
374  fct_chk( strcasecmp( (char *) dst_str, "B22F3C36B72D31329EEE8ADDC2906C68" ) == 0 );
375  }
376  }
377  FCT_TEST_END();
378 
379 
380  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_1)
381  {
382  unsigned char key_str[100];
383  unsigned char src_str[100];
384  unsigned char dst_str[100];
385  unsigned char output[100];
386  camellia_context ctx;
387  int key_len;
388 
389  memset(key_str, 0x00, 100);
390  memset(src_str, 0x00, 100);
391  memset(dst_str, 0x00, 100);
392  memset(output, 0x00, 100);
393 
394  key_len = unhexify( key_str, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" );
395  unhexify( src_str, "00112233445566778899AABBCCDDEEFF" );
396 
397  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
398  if( 0 == 0 )
399  {
400  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
401  hexify( dst_str, output, 16 );
402 
403  fct_chk( strcasecmp( (char *) dst_str, "2EDF1F3418D53B88841FC8985FB1ECF2" ) == 0 );
404  }
405  }
406  FCT_TEST_END();
407 
408 
409  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_1)
410  {
411  unsigned char key_str[100];
412  unsigned char src_str[100];
413  unsigned char dst_str[100];
414  unsigned char output[100];
415  camellia_context ctx;
416  int key_len;
417 
418  memset(key_str, 0x00, 100);
419  memset(src_str, 0x00, 100);
420  memset(dst_str, 0x00, 100);
421  memset(output, 0x00, 100);
422 
423  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
424  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
425 
426  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
427  if( 0 == 0 )
428  {
429  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
430  hexify( dst_str, output, 16 );
431 
432  fct_chk( strcasecmp( (char *) dst_str, "432FC5DCD628115B7C388D770B270C96" ) == 0 );
433  }
434  }
435  FCT_TEST_END();
436 
437 
438  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_2)
439  {
440  unsigned char key_str[100];
441  unsigned char src_str[100];
442  unsigned char dst_str[100];
443  unsigned char output[100];
444  camellia_context ctx;
445  int key_len;
446 
447  memset(key_str, 0x00, 100);
448  memset(src_str, 0x00, 100);
449  memset(dst_str, 0x00, 100);
450  memset(output, 0x00, 100);
451 
452  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
453  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
454 
455  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
456  if( 0 == 0 )
457  {
458  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
459  hexify( dst_str, output, 16 );
460 
461  fct_chk( strcasecmp( (char *) dst_str, "0BE1F14023782A22E8384C5ABB7FAB2B" ) == 0 );
462  }
463  }
464  FCT_TEST_END();
465 
466 
467  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_3)
468  {
469  unsigned char key_str[100];
470  unsigned char src_str[100];
471  unsigned char dst_str[100];
472  unsigned char output[100];
473  camellia_context ctx;
474  int key_len;
475 
476  memset(key_str, 0x00, 100);
477  memset(src_str, 0x00, 100);
478  memset(dst_str, 0x00, 100);
479  memset(output, 0x00, 100);
480 
481  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
482  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
483 
484  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
485  if( 0 == 0 )
486  {
487  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
488  hexify( dst_str, output, 16 );
489 
490  fct_chk( strcasecmp( (char *) dst_str, "A0A1ABCD1893AB6FE0FE5B65DF5F8636" ) == 0 );
491  }
492  }
493  FCT_TEST_END();
494 
495 
496  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_4)
497  {
498  unsigned char key_str[100];
499  unsigned char src_str[100];
500  unsigned char dst_str[100];
501  unsigned char output[100];
502  camellia_context ctx;
503  int key_len;
504 
505  memset(key_str, 0x00, 100);
506  memset(src_str, 0x00, 100);
507  memset(dst_str, 0x00, 100);
508  memset(output, 0x00, 100);
509 
510  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
511  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
512 
513  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
514  if( 0 == 0 )
515  {
516  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
517  hexify( dst_str, output, 16 );
518 
519  fct_chk( strcasecmp( (char *) dst_str, "E61925E0D5DFAA9BB29F815B3076E51A" ) == 0 );
520  }
521  }
522  FCT_TEST_END();
523 
524 
525  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_1)
526  {
527  unsigned char key_str[100];
528  unsigned char src_str[100];
529  unsigned char dst_str[100];
530  unsigned char output[100];
531  camellia_context ctx;
532  int key_len;
533 
534  memset(key_str, 0x00, 100);
535  memset(src_str, 0x00, 100);
536  memset(dst_str, 0x00, 100);
537  memset(output, 0x00, 100);
538 
539  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
540  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
541 
542  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
543  if( 0 == 0 )
544  {
545  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
546  hexify( dst_str, output, 16 );
547 
548  fct_chk( strcasecmp( (char *) dst_str, "CCCC6C4E138B45848514D48D0D3439D3" ) == 0 );
549  }
550  }
551  FCT_TEST_END();
552 
553 
554  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_2)
555  {
556  unsigned char key_str[100];
557  unsigned char src_str[100];
558  unsigned char dst_str[100];
559  unsigned char output[100];
560  camellia_context ctx;
561  int key_len;
562 
563  memset(key_str, 0x00, 100);
564  memset(src_str, 0x00, 100);
565  memset(dst_str, 0x00, 100);
566  memset(output, 0x00, 100);
567 
568  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
569  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
570 
571  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
572  if( 0 == 0 )
573  {
574  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
575  hexify( dst_str, output, 16 );
576 
577  fct_chk( strcasecmp( (char *) dst_str, "5713C62C14B2EC0F8393B6AFD6F5785A" ) == 0 );
578  }
579  }
580  FCT_TEST_END();
581 
582 
583  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_3)
584  {
585  unsigned char key_str[100];
586  unsigned char src_str[100];
587  unsigned char dst_str[100];
588  unsigned char output[100];
589  camellia_context ctx;
590  int key_len;
591 
592  memset(key_str, 0x00, 100);
593  memset(src_str, 0x00, 100);
594  memset(dst_str, 0x00, 100);
595  memset(output, 0x00, 100);
596 
597  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
598  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
599 
600  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
601  if( 0 == 0 )
602  {
603  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
604  hexify( dst_str, output, 16 );
605 
606  fct_chk( strcasecmp( (char *) dst_str, "B40ED2B60EB54D09D030CF511FEEF366" ) == 0 );
607  }
608  }
609  FCT_TEST_END();
610 
611 
612  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_4)
613  {
614  unsigned char key_str[100];
615  unsigned char src_str[100];
616  unsigned char dst_str[100];
617  unsigned char output[100];
618  camellia_context ctx;
619  int key_len;
620 
621  memset(key_str, 0x00, 100);
622  memset(src_str, 0x00, 100);
623  memset(dst_str, 0x00, 100);
624  memset(output, 0x00, 100);
625 
626  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
627  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
628 
629  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
630  if( 0 == 0 )
631  {
632  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
633  hexify( dst_str, output, 16 );
634 
635  fct_chk( strcasecmp( (char *) dst_str, "909DBD95799096748CB27357E73E1D26" ) == 0 );
636  }
637  }
638  FCT_TEST_END();
639 
640 
641  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_1)
642  {
643  unsigned char key_str[100];
644  unsigned char src_str[100];
645  unsigned char dst_str[100];
646  unsigned char output[100];
647  camellia_context ctx;
648  int key_len;
649 
650  memset(key_str, 0x00, 100);
651  memset(src_str, 0x00, 100);
652  memset(dst_str, 0x00, 100);
653  memset(output, 0x00, 100);
654 
655  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
656  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
657 
658  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
659  if( 0 == 0 )
660  {
661  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
662  hexify( dst_str, output, 16 );
663 
664  fct_chk( strcasecmp( (char *) dst_str, "BEFD219B112FA00098919CD101C9CCFA" ) == 0 );
665  }
666  }
667  FCT_TEST_END();
668 
669 
670  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_2)
671  {
672  unsigned char key_str[100];
673  unsigned char src_str[100];
674  unsigned char dst_str[100];
675  unsigned char output[100];
676  camellia_context ctx;
677  int key_len;
678 
679  memset(key_str, 0x00, 100);
680  memset(src_str, 0x00, 100);
681  memset(dst_str, 0x00, 100);
682  memset(output, 0x00, 100);
683 
684  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
685  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
686 
687  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
688  if( 0 == 0 )
689  {
690  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
691  hexify( dst_str, output, 16 );
692 
693  fct_chk( strcasecmp( (char *) dst_str, "C91D3A8F1AEA08A9386CF4B66C0169EA" ) == 0 );
694  }
695  }
696  FCT_TEST_END();
697 
698 
699  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_3)
700  {
701  unsigned char key_str[100];
702  unsigned char src_str[100];
703  unsigned char dst_str[100];
704  unsigned char output[100];
705  camellia_context ctx;
706  int key_len;
707 
708  memset(key_str, 0x00, 100);
709  memset(src_str, 0x00, 100);
710  memset(dst_str, 0x00, 100);
711  memset(output, 0x00, 100);
712 
713  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
714  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
715 
716  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
717  if( 0 == 0 )
718  {
719  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
720  hexify( dst_str, output, 16 );
721 
722  fct_chk( strcasecmp( (char *) dst_str, "A623D711DC5F25A51BB8A80D56397D28" ) == 0 );
723  }
724  }
725  FCT_TEST_END();
726 
727 
728  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_4)
729  {
730  unsigned char key_str[100];
731  unsigned char src_str[100];
732  unsigned char dst_str[100];
733  unsigned char output[100];
734  camellia_context ctx;
735  int key_len;
736 
737  memset(key_str, 0x00, 100);
738  memset(src_str, 0x00, 100);
739  memset(dst_str, 0x00, 100);
740  memset(output, 0x00, 100);
741 
742  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
743  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
744 
745  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
746  if( 0 == 0 )
747  {
748  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
749  hexify( dst_str, output, 16 );
750 
751  fct_chk( strcasecmp( (char *) dst_str, "7960109FB6DC42947FCFE59EA3C5EB6B" ) == 0 );
752  }
753  }
754  FCT_TEST_END();
755 
756 
757  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_1)
758  {
759  unsigned char key_str[100];
760  unsigned char iv_str[100];
761  unsigned char src_str[100];
762  unsigned char dst_str[100];
763  unsigned char output[100];
764  camellia_context ctx;
765  int key_len, data_len;
766 
767  memset(key_str, 0x00, 100);
768  memset(iv_str, 0x00, 100);
769  memset(src_str, 0x00, 100);
770  memset(dst_str, 0x00, 100);
771  memset(output, 0x00, 100);
772 
773  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
774  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
775  data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
776 
777  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
778  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
779  if( 0 == 0 )
780  {
781  hexify( dst_str, output, data_len );
782 
783  fct_chk( strcasecmp( (char *) dst_str, "1607CF494B36BBF00DAEB0B503C831AB" ) == 0 );
784  }
785  }
786  FCT_TEST_END();
787 
788 
789  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_2)
790  {
791  unsigned char key_str[100];
792  unsigned char iv_str[100];
793  unsigned char src_str[100];
794  unsigned char dst_str[100];
795  unsigned char output[100];
796  camellia_context ctx;
797  int key_len, data_len;
798 
799  memset(key_str, 0x00, 100);
800  memset(iv_str, 0x00, 100);
801  memset(src_str, 0x00, 100);
802  memset(dst_str, 0x00, 100);
803  memset(output, 0x00, 100);
804 
805  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
806  unhexify( iv_str, "1607CF494B36BBF00DAEB0B503C831AB" );
807  data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
808 
809  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
810  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
811  if( 0 == 0 )
812  {
813  hexify( dst_str, output, data_len );
814 
815  fct_chk( strcasecmp( (char *) dst_str, "A2F2CF671629EF7840C5A5DFB5074887" ) == 0 );
816  }
817  }
818  FCT_TEST_END();
819 
820 
821  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_3)
822  {
823  unsigned char key_str[100];
824  unsigned char iv_str[100];
825  unsigned char src_str[100];
826  unsigned char dst_str[100];
827  unsigned char output[100];
828  camellia_context ctx;
829  int key_len, data_len;
830 
831  memset(key_str, 0x00, 100);
832  memset(iv_str, 0x00, 100);
833  memset(src_str, 0x00, 100);
834  memset(dst_str, 0x00, 100);
835  memset(output, 0x00, 100);
836 
837  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
838  unhexify( iv_str, "A2F2CF671629EF7840C5A5DFB5074887" );
839  data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
840 
841  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
842  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
843  if( 0 == 0 )
844  {
845  hexify( dst_str, output, data_len );
846 
847  fct_chk( strcasecmp( (char *) dst_str, "0F06165008CF8B8B5A63586362543E54" ) == 0 );
848  }
849  }
850  FCT_TEST_END();
851 
852 
853  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_4)
854  {
855  unsigned char key_str[100];
856  unsigned char iv_str[100];
857  unsigned char src_str[100];
858  unsigned char dst_str[100];
859  unsigned char output[100];
860  camellia_context ctx;
861  int key_len, data_len;
862 
863  memset(key_str, 0x00, 100);
864  memset(iv_str, 0x00, 100);
865  memset(src_str, 0x00, 100);
866  memset(dst_str, 0x00, 100);
867  memset(output, 0x00, 100);
868 
869  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
870  unhexify( iv_str, "36A84CDAFD5F9A85ADA0F0A993D6D577" );
871  data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
872 
873  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
874  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
875  if( 0 == 0 )
876  {
877  hexify( dst_str, output, data_len );
878 
879  fct_chk( strcasecmp( (char *) dst_str, "74C64268CDB8B8FAF5B34E8AF3732980" ) == 0 );
880  }
881  }
882  FCT_TEST_END();
883 
884 
885  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_1)
886  {
887  unsigned char key_str[100];
888  unsigned char iv_str[100];
889  unsigned char src_str[100];
890  unsigned char dst_str[100];
891  unsigned char output[100];
892  camellia_context ctx;
893  int key_len, data_len;
894 
895  memset(key_str, 0x00, 100);
896  memset(iv_str, 0x00, 100);
897  memset(src_str, 0x00, 100);
898  memset(dst_str, 0x00, 100);
899  memset(output, 0x00, 100);
900 
901  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
902  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
903  data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
904 
905  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
906  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
907  if( 0 == 0 )
908  {
909  hexify( dst_str, output, data_len );
910 
911  fct_chk( strcasecmp( (char *) dst_str, "2A4830AB5AC4A1A2405955FD2195CF93" ) == 0 );
912  }
913  }
914  FCT_TEST_END();
915 
916 
917  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_2)
918  {
919  unsigned char key_str[100];
920  unsigned char iv_str[100];
921  unsigned char src_str[100];
922  unsigned char dst_str[100];
923  unsigned char output[100];
924  camellia_context ctx;
925  int key_len, data_len;
926 
927  memset(key_str, 0x00, 100);
928  memset(iv_str, 0x00, 100);
929  memset(src_str, 0x00, 100);
930  memset(dst_str, 0x00, 100);
931  memset(output, 0x00, 100);
932 
933  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
934  unhexify( iv_str, "2A4830AB5AC4A1A2405955FD2195CF93" );
935  data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
936 
937  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
938  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
939  if( 0 == 0 )
940  {
941  hexify( dst_str, output, data_len );
942 
943  fct_chk( strcasecmp( (char *) dst_str, "5D5A869BD14CE54264F892A6DD2EC3D5" ) == 0 );
944  }
945  }
946  FCT_TEST_END();
947 
948 
949  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_3)
950  {
951  unsigned char key_str[100];
952  unsigned char iv_str[100];
953  unsigned char src_str[100];
954  unsigned char dst_str[100];
955  unsigned char output[100];
956  camellia_context ctx;
957  int key_len, data_len;
958 
959  memset(key_str, 0x00, 100);
960  memset(iv_str, 0x00, 100);
961  memset(src_str, 0x00, 100);
962  memset(dst_str, 0x00, 100);
963  memset(output, 0x00, 100);
964 
965  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
966  unhexify( iv_str, "5D5A869BD14CE54264F892A6DD2EC3D5" );
967  data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
968 
969  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
970  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
971  if( 0 == 0 )
972  {
973  hexify( dst_str, output, data_len );
974 
975  fct_chk( strcasecmp( (char *) dst_str, "37D359C3349836D884E310ADDF68C449" ) == 0 );
976  }
977  }
978  FCT_TEST_END();
979 
980 
981  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_4)
982  {
983  unsigned char key_str[100];
984  unsigned char iv_str[100];
985  unsigned char src_str[100];
986  unsigned char dst_str[100];
987  unsigned char output[100];
988  camellia_context ctx;
989  int key_len, data_len;
990 
991  memset(key_str, 0x00, 100);
992  memset(iv_str, 0x00, 100);
993  memset(src_str, 0x00, 100);
994  memset(dst_str, 0x00, 100);
995  memset(output, 0x00, 100);
996 
997  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
998  unhexify( iv_str, "37D359C3349836D884E310ADDF68C449" );
999  data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1000 
1001  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1002  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1003  if( 0 == 0 )
1004  {
1005  hexify( dst_str, output, data_len );
1006 
1007  fct_chk( strcasecmp( (char *) dst_str, "01FAAA930B4AB9916E9668E1428C6B08" ) == 0 );
1008  }
1009  }
1010  FCT_TEST_END();
1011 
1012 
1013  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_1)
1014  {
1015  unsigned char key_str[100];
1016  unsigned char iv_str[100];
1017  unsigned char src_str[100];
1018  unsigned char dst_str[100];
1019  unsigned char output[100];
1020  camellia_context ctx;
1021  int key_len, data_len;
1022 
1023  memset(key_str, 0x00, 100);
1024  memset(iv_str, 0x00, 100);
1025  memset(src_str, 0x00, 100);
1026  memset(dst_str, 0x00, 100);
1027  memset(output, 0x00, 100);
1028 
1029  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1030  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1031  data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1032 
1033  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1034  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1035  if( 0 == 0 )
1036  {
1037  hexify( dst_str, output, data_len );
1038 
1039  fct_chk( strcasecmp( (char *) dst_str, "E6CFA35FC02B134A4D2C0B6737AC3EDA" ) == 0 );
1040  }
1041  }
1042  FCT_TEST_END();
1043 
1044 
1045  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_2)
1046  {
1047  unsigned char key_str[100];
1048  unsigned char iv_str[100];
1049  unsigned char src_str[100];
1050  unsigned char dst_str[100];
1051  unsigned char output[100];
1052  camellia_context ctx;
1053  int key_len, data_len;
1054 
1055  memset(key_str, 0x00, 100);
1056  memset(iv_str, 0x00, 100);
1057  memset(src_str, 0x00, 100);
1058  memset(dst_str, 0x00, 100);
1059  memset(output, 0x00, 100);
1060 
1061  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1062  unhexify( iv_str, "E6CFA35FC02B134A4D2C0B6737AC3EDA" );
1063  data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1064 
1065  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1066  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1067  if( 0 == 0 )
1068  {
1069  hexify( dst_str, output, data_len );
1070 
1071  fct_chk( strcasecmp( (char *) dst_str, "36CBEB73BD504B4070B1B7DE2B21EB50" ) == 0 );
1072  }
1073  }
1074  FCT_TEST_END();
1075 
1076 
1077  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_3)
1078  {
1079  unsigned char key_str[100];
1080  unsigned char iv_str[100];
1081  unsigned char src_str[100];
1082  unsigned char dst_str[100];
1083  unsigned char output[100];
1084  camellia_context ctx;
1085  int key_len, data_len;
1086 
1087  memset(key_str, 0x00, 100);
1088  memset(iv_str, 0x00, 100);
1089  memset(src_str, 0x00, 100);
1090  memset(dst_str, 0x00, 100);
1091  memset(output, 0x00, 100);
1092 
1093  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1094  unhexify( iv_str, "36CBEB73BD504B4070B1B7DE2B21EB50" );
1095  data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1096 
1097  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1098  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1099  if( 0 == 0 )
1100  {
1101  hexify( dst_str, output, data_len );
1102 
1103  fct_chk( strcasecmp( (char *) dst_str, "E31A6055297D96CA3330CDF1B1860A83" ) == 0 );
1104  }
1105  }
1106  FCT_TEST_END();
1107 
1108 
1109  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_4)
1110  {
1111  unsigned char key_str[100];
1112  unsigned char iv_str[100];
1113  unsigned char src_str[100];
1114  unsigned char dst_str[100];
1115  unsigned char output[100];
1116  camellia_context ctx;
1117  int key_len, data_len;
1118 
1119  memset(key_str, 0x00, 100);
1120  memset(iv_str, 0x00, 100);
1121  memset(src_str, 0x00, 100);
1122  memset(dst_str, 0x00, 100);
1123  memset(output, 0x00, 100);
1124 
1125  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1126  unhexify( iv_str, "E31A6055297D96CA3330CDF1B1860A83" );
1127  data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1128 
1129  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1130  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1131  if( 0 == 0 )
1132  {
1133  hexify( dst_str, output, data_len );
1134 
1135  fct_chk( strcasecmp( (char *) dst_str, "5D563F6D1CCCF236051C0C5C1C58F28F" ) == 0 );
1136  }
1137  }
1138  FCT_TEST_END();
1139 
1140 #ifdef POLARSSL_CIPHER_MODE_CFB
1141 
1142  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_1)
1143  {
1144  unsigned char key_str[100];
1145  unsigned char iv_str[100];
1146  unsigned char src_str[100];
1147  unsigned char dst_str[100];
1148  unsigned char output[100];
1149  camellia_context ctx;
1150  size_t iv_offset = 0;
1151  int key_len;
1152 
1153  memset(key_str, 0x00, 100);
1154  memset(iv_str, 0x00, 100);
1155  memset(src_str, 0x00, 100);
1156  memset(dst_str, 0x00, 100);
1157  memset(output, 0x00, 100);
1158 
1159  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1160  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1161  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1162 
1163  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1164  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1165  hexify( dst_str, output, 16 );
1166 
1167  fct_chk( strcasecmp( (char *) dst_str, "14F7646187817EB586599146B82BD719" ) == 0 );
1168  }
1169  FCT_TEST_END();
1170 #endif /* POLARSSL_CIPHER_MODE_CFB */
1171 
1172 #ifdef POLARSSL_CIPHER_MODE_CFB
1173 
1174  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_2)
1175  {
1176  unsigned char key_str[100];
1177  unsigned char iv_str[100];
1178  unsigned char src_str[100];
1179  unsigned char dst_str[100];
1180  unsigned char output[100];
1181  camellia_context ctx;
1182  size_t iv_offset = 0;
1183  int key_len;
1184 
1185  memset(key_str, 0x00, 100);
1186  memset(iv_str, 0x00, 100);
1187  memset(src_str, 0x00, 100);
1188  memset(dst_str, 0x00, 100);
1189  memset(output, 0x00, 100);
1190 
1191  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1192  unhexify( iv_str, "14F7646187817EB586599146B82BD719" );
1193  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1194 
1195  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1196  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1197  hexify( dst_str, output, 16 );
1198 
1199  fct_chk( strcasecmp( (char *) dst_str, "A53D28BB82DF741103EA4F921A44880B" ) == 0 );
1200  }
1201  FCT_TEST_END();
1202 #endif /* POLARSSL_CIPHER_MODE_CFB */
1203 
1204 #ifdef POLARSSL_CIPHER_MODE_CFB
1205 
1206  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_3)
1207  {
1208  unsigned char key_str[100];
1209  unsigned char iv_str[100];
1210  unsigned char src_str[100];
1211  unsigned char dst_str[100];
1212  unsigned char output[100];
1213  camellia_context ctx;
1214  size_t iv_offset = 0;
1215  int key_len;
1216 
1217  memset(key_str, 0x00, 100);
1218  memset(iv_str, 0x00, 100);
1219  memset(src_str, 0x00, 100);
1220  memset(dst_str, 0x00, 100);
1221  memset(output, 0x00, 100);
1222 
1223  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1224  unhexify( iv_str, "A53D28BB82DF741103EA4F921A44880B" );
1225  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1226 
1227  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1228  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1229  hexify( dst_str, output, 16 );
1230 
1231  fct_chk( strcasecmp( (char *) dst_str, "9C2157A664626D1DEF9EA420FDE69B96" ) == 0 );
1232  }
1233  FCT_TEST_END();
1234 #endif /* POLARSSL_CIPHER_MODE_CFB */
1235 
1236 #ifdef POLARSSL_CIPHER_MODE_CFB
1237 
1238  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_4)
1239  {
1240  unsigned char key_str[100];
1241  unsigned char iv_str[100];
1242  unsigned char src_str[100];
1243  unsigned char dst_str[100];
1244  unsigned char output[100];
1245  camellia_context ctx;
1246  size_t iv_offset = 0;
1247  int key_len;
1248 
1249  memset(key_str, 0x00, 100);
1250  memset(iv_str, 0x00, 100);
1251  memset(src_str, 0x00, 100);
1252  memset(dst_str, 0x00, 100);
1253  memset(output, 0x00, 100);
1254 
1255  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1256  unhexify( iv_str, "9C2157A664626D1DEF9EA420FDE69B96" );
1257  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1258 
1259  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1260  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1261  hexify( dst_str, output, 16 );
1262 
1263  fct_chk( strcasecmp( (char *) dst_str, "742A25F0542340C7BAEF24CA8482BB09" ) == 0 );
1264  }
1265  FCT_TEST_END();
1266 #endif /* POLARSSL_CIPHER_MODE_CFB */
1267 
1268 #ifdef POLARSSL_CIPHER_MODE_CFB
1269 
1270  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_1)
1271  {
1272  unsigned char key_str[100];
1273  unsigned char iv_str[100];
1274  unsigned char src_str[100];
1275  unsigned char dst_str[100];
1276  unsigned char output[100];
1277  camellia_context ctx;
1278  size_t iv_offset = 0;
1279  int key_len;
1280 
1281  memset(key_str, 0x00, 100);
1282  memset(iv_str, 0x00, 100);
1283  memset(src_str, 0x00, 100);
1284  memset(dst_str, 0x00, 100);
1285  memset(output, 0x00, 100);
1286 
1287  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1288  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1289  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1290 
1291  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1292  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1293  hexify( dst_str, output, 16 );
1294 
1295  fct_chk( strcasecmp( (char *) dst_str, "14F7646187817EB586599146B82BD719" ) == 0 );
1296  }
1297  FCT_TEST_END();
1298 #endif /* POLARSSL_CIPHER_MODE_CFB */
1299 
1300 #ifdef POLARSSL_CIPHER_MODE_CFB
1301 
1302  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_2)
1303  {
1304  unsigned char key_str[100];
1305  unsigned char iv_str[100];
1306  unsigned char src_str[100];
1307  unsigned char dst_str[100];
1308  unsigned char output[100];
1309  camellia_context ctx;
1310  size_t iv_offset = 0;
1311  int key_len;
1312 
1313  memset(key_str, 0x00, 100);
1314  memset(iv_str, 0x00, 100);
1315  memset(src_str, 0x00, 100);
1316  memset(dst_str, 0x00, 100);
1317  memset(output, 0x00, 100);
1318 
1319  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1320  unhexify( iv_str, "14F7646187817EB586599146B82BD719" );
1321  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1322 
1323  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1324  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1325  hexify( dst_str, output, 16 );
1326 
1327  fct_chk( strcasecmp( (char *) dst_str, "A53D28BB82DF741103EA4F921A44880B" ) == 0 );
1328  }
1329  FCT_TEST_END();
1330 #endif /* POLARSSL_CIPHER_MODE_CFB */
1331 
1332 #ifdef POLARSSL_CIPHER_MODE_CFB
1333 
1334  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_3)
1335  {
1336  unsigned char key_str[100];
1337  unsigned char iv_str[100];
1338  unsigned char src_str[100];
1339  unsigned char dst_str[100];
1340  unsigned char output[100];
1341  camellia_context ctx;
1342  size_t iv_offset = 0;
1343  int key_len;
1344 
1345  memset(key_str, 0x00, 100);
1346  memset(iv_str, 0x00, 100);
1347  memset(src_str, 0x00, 100);
1348  memset(dst_str, 0x00, 100);
1349  memset(output, 0x00, 100);
1350 
1351  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1352  unhexify( iv_str, "A53D28BB82DF741103EA4F921A44880B" );
1353  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1354 
1355  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1356  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1357  hexify( dst_str, output, 16 );
1358 
1359  fct_chk( strcasecmp( (char *) dst_str, "9C2157A664626D1DEF9EA420FDE69B96" ) == 0 );
1360  }
1361  FCT_TEST_END();
1362 #endif /* POLARSSL_CIPHER_MODE_CFB */
1363 
1364 #ifdef POLARSSL_CIPHER_MODE_CFB
1365 
1366  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_4)
1367  {
1368  unsigned char key_str[100];
1369  unsigned char iv_str[100];
1370  unsigned char src_str[100];
1371  unsigned char dst_str[100];
1372  unsigned char output[100];
1373  camellia_context ctx;
1374  size_t iv_offset = 0;
1375  int key_len;
1376 
1377  memset(key_str, 0x00, 100);
1378  memset(iv_str, 0x00, 100);
1379  memset(src_str, 0x00, 100);
1380  memset(dst_str, 0x00, 100);
1381  memset(output, 0x00, 100);
1382 
1383  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1384  unhexify( iv_str, "9C2157A664626D1DEF9EA420FDE69B96" );
1385  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1386 
1387  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1388  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1389  hexify( dst_str, output, 16 );
1390 
1391  fct_chk( strcasecmp( (char *) dst_str, "742A25F0542340C7BAEF24CA8482BB09" ) == 0 );
1392  }
1393  FCT_TEST_END();
1394 #endif /* POLARSSL_CIPHER_MODE_CFB */
1395 
1396 #ifdef POLARSSL_CIPHER_MODE_CFB
1397 
1398  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_1)
1399  {
1400  unsigned char key_str[100];
1401  unsigned char iv_str[100];
1402  unsigned char src_str[100];
1403  unsigned char dst_str[100];
1404  unsigned char output[100];
1405  camellia_context ctx;
1406  size_t iv_offset = 0;
1407  int key_len;
1408 
1409  memset(key_str, 0x00, 100);
1410  memset(iv_str, 0x00, 100);
1411  memset(src_str, 0x00, 100);
1412  memset(dst_str, 0x00, 100);
1413  memset(output, 0x00, 100);
1414 
1415  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1416  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1417  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1418 
1419  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1420  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1421  hexify( dst_str, output, 16 );
1422 
1423  fct_chk( strcasecmp( (char *) dst_str, "C832BB9780677DAA82D9B6860DCD565E" ) == 0 );
1424  }
1425  FCT_TEST_END();
1426 #endif /* POLARSSL_CIPHER_MODE_CFB */
1427 
1428 #ifdef POLARSSL_CIPHER_MODE_CFB
1429 
1430  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_2)
1431  {
1432  unsigned char key_str[100];
1433  unsigned char iv_str[100];
1434  unsigned char src_str[100];
1435  unsigned char dst_str[100];
1436  unsigned char output[100];
1437  camellia_context ctx;
1438  size_t iv_offset = 0;
1439  int key_len;
1440 
1441  memset(key_str, 0x00, 100);
1442  memset(iv_str, 0x00, 100);
1443  memset(src_str, 0x00, 100);
1444  memset(dst_str, 0x00, 100);
1445  memset(output, 0x00, 100);
1446 
1447  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1448  unhexify( iv_str, "C832BB9780677DAA82D9B6860DCD565E" );
1449  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1450 
1451  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1452  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1453  hexify( dst_str, output, 16 );
1454 
1455  fct_chk( strcasecmp( (char *) dst_str, "86F8491627906D780C7A6D46EA331F98" ) == 0 );
1456  }
1457  FCT_TEST_END();
1458 #endif /* POLARSSL_CIPHER_MODE_CFB */
1459 
1460 #ifdef POLARSSL_CIPHER_MODE_CFB
1461 
1462  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_3)
1463  {
1464  unsigned char key_str[100];
1465  unsigned char iv_str[100];
1466  unsigned char src_str[100];
1467  unsigned char dst_str[100];
1468  unsigned char output[100];
1469  camellia_context ctx;
1470  size_t iv_offset = 0;
1471  int key_len;
1472 
1473  memset(key_str, 0x00, 100);
1474  memset(iv_str, 0x00, 100);
1475  memset(src_str, 0x00, 100);
1476  memset(dst_str, 0x00, 100);
1477  memset(output, 0x00, 100);
1478 
1479  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1480  unhexify( iv_str, "86F8491627906D780C7A6D46EA331F98" );
1481  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1482 
1483  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1484  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1485  hexify( dst_str, output, 16 );
1486 
1487  fct_chk( strcasecmp( (char *) dst_str, "69511CCE594CF710CB98BB63D7221F01" ) == 0 );
1488  }
1489  FCT_TEST_END();
1490 #endif /* POLARSSL_CIPHER_MODE_CFB */
1491 
1492 #ifdef POLARSSL_CIPHER_MODE_CFB
1493 
1494  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_4)
1495  {
1496  unsigned char key_str[100];
1497  unsigned char iv_str[100];
1498  unsigned char src_str[100];
1499  unsigned char dst_str[100];
1500  unsigned char output[100];
1501  camellia_context ctx;
1502  size_t iv_offset = 0;
1503  int key_len;
1504 
1505  memset(key_str, 0x00, 100);
1506  memset(iv_str, 0x00, 100);
1507  memset(src_str, 0x00, 100);
1508  memset(dst_str, 0x00, 100);
1509  memset(output, 0x00, 100);
1510 
1511  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1512  unhexify( iv_str, "69511CCE594CF710CB98BB63D7221F01" );
1513  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1514 
1515  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1516  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1517  hexify( dst_str, output, 16 );
1518 
1519  fct_chk( strcasecmp( (char *) dst_str, "D5B5378A3ABED55803F25565D8907B84" ) == 0 );
1520  }
1521  FCT_TEST_END();
1522 #endif /* POLARSSL_CIPHER_MODE_CFB */
1523 
1524 #ifdef POLARSSL_CIPHER_MODE_CFB
1525 
1526  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_1)
1527  {
1528  unsigned char key_str[100];
1529  unsigned char iv_str[100];
1530  unsigned char src_str[100];
1531  unsigned char dst_str[100];
1532  unsigned char output[100];
1533  camellia_context ctx;
1534  size_t iv_offset = 0;
1535  int key_len;
1536 
1537  memset(key_str, 0x00, 100);
1538  memset(iv_str, 0x00, 100);
1539  memset(src_str, 0x00, 100);
1540  memset(dst_str, 0x00, 100);
1541  memset(output, 0x00, 100);
1542 
1543  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1544  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1545  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1546 
1547  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1548  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1549  hexify( dst_str, output, 16 );
1550 
1551  fct_chk( strcasecmp( (char *) dst_str, "C832BB9780677DAA82D9B6860DCD565E" ) == 0 );
1552  }
1553  FCT_TEST_END();
1554 #endif /* POLARSSL_CIPHER_MODE_CFB */
1555 
1556 #ifdef POLARSSL_CIPHER_MODE_CFB
1557 
1558  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_2)
1559  {
1560  unsigned char key_str[100];
1561  unsigned char iv_str[100];
1562  unsigned char src_str[100];
1563  unsigned char dst_str[100];
1564  unsigned char output[100];
1565  camellia_context ctx;
1566  size_t iv_offset = 0;
1567  int key_len;
1568 
1569  memset(key_str, 0x00, 100);
1570  memset(iv_str, 0x00, 100);
1571  memset(src_str, 0x00, 100);
1572  memset(dst_str, 0x00, 100);
1573  memset(output, 0x00, 100);
1574 
1575  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1576  unhexify( iv_str, "C832BB9780677DAA82D9B6860DCD565E" );
1577  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1578 
1579  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1580  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1581  hexify( dst_str, output, 16 );
1582 
1583  fct_chk( strcasecmp( (char *) dst_str, "86F8491627906D780C7A6D46EA331F98" ) == 0 );
1584  }
1585  FCT_TEST_END();
1586 #endif /* POLARSSL_CIPHER_MODE_CFB */
1587 
1588 #ifdef POLARSSL_CIPHER_MODE_CFB
1589 
1590  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_3)
1591  {
1592  unsigned char key_str[100];
1593  unsigned char iv_str[100];
1594  unsigned char src_str[100];
1595  unsigned char dst_str[100];
1596  unsigned char output[100];
1597  camellia_context ctx;
1598  size_t iv_offset = 0;
1599  int key_len;
1600 
1601  memset(key_str, 0x00, 100);
1602  memset(iv_str, 0x00, 100);
1603  memset(src_str, 0x00, 100);
1604  memset(dst_str, 0x00, 100);
1605  memset(output, 0x00, 100);
1606 
1607  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1608  unhexify( iv_str, "86F8491627906D780C7A6D46EA331F98" );
1609  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1610 
1611  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1612  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1613  hexify( dst_str, output, 16 );
1614 
1615  fct_chk( strcasecmp( (char *) dst_str, "69511CCE594CF710CB98BB63D7221F01" ) == 0 );
1616  }
1617  FCT_TEST_END();
1618 #endif /* POLARSSL_CIPHER_MODE_CFB */
1619 
1620 #ifdef POLARSSL_CIPHER_MODE_CFB
1621 
1622  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_4)
1623  {
1624  unsigned char key_str[100];
1625  unsigned char iv_str[100];
1626  unsigned char src_str[100];
1627  unsigned char dst_str[100];
1628  unsigned char output[100];
1629  camellia_context ctx;
1630  size_t iv_offset = 0;
1631  int key_len;
1632 
1633  memset(key_str, 0x00, 100);
1634  memset(iv_str, 0x00, 100);
1635  memset(src_str, 0x00, 100);
1636  memset(dst_str, 0x00, 100);
1637  memset(output, 0x00, 100);
1638 
1639  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1640  unhexify( iv_str, "69511CCE594CF710CB98BB63D7221F01" );
1641  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1642 
1643  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1644  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1645  hexify( dst_str, output, 16 );
1646 
1647  fct_chk( strcasecmp( (char *) dst_str, "D5B5378A3ABED55803F25565D8907B84" ) == 0 );
1648  }
1649  FCT_TEST_END();
1650 #endif /* POLARSSL_CIPHER_MODE_CFB */
1651 
1652 #ifdef POLARSSL_CIPHER_MODE_CFB
1653 
1654  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_1)
1655  {
1656  unsigned char key_str[100];
1657  unsigned char iv_str[100];
1658  unsigned char src_str[100];
1659  unsigned char dst_str[100];
1660  unsigned char output[100];
1661  camellia_context ctx;
1662  size_t iv_offset = 0;
1663  int key_len;
1664 
1665  memset(key_str, 0x00, 100);
1666  memset(iv_str, 0x00, 100);
1667  memset(src_str, 0x00, 100);
1668  memset(dst_str, 0x00, 100);
1669  memset(output, 0x00, 100);
1670 
1671  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1672  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1673  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1674 
1675  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1676  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1677  hexify( dst_str, output, 16 );
1678 
1679  fct_chk( strcasecmp( (char *) dst_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ) == 0 );
1680  }
1681  FCT_TEST_END();
1682 #endif /* POLARSSL_CIPHER_MODE_CFB */
1683 
1684 #ifdef POLARSSL_CIPHER_MODE_CFB
1685 
1686  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_2)
1687  {
1688  unsigned char key_str[100];
1689  unsigned char iv_str[100];
1690  unsigned char src_str[100];
1691  unsigned char dst_str[100];
1692  unsigned char output[100];
1693  camellia_context ctx;
1694  size_t iv_offset = 0;
1695  int key_len;
1696 
1697  memset(key_str, 0x00, 100);
1698  memset(iv_str, 0x00, 100);
1699  memset(src_str, 0x00, 100);
1700  memset(dst_str, 0x00, 100);
1701  memset(output, 0x00, 100);
1702 
1703  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1704  unhexify( iv_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" );
1705  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1706 
1707  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1708  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1709  hexify( dst_str, output, 16 );
1710 
1711  fct_chk( strcasecmp( (char *) dst_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ) == 0 );
1712  }
1713  FCT_TEST_END();
1714 #endif /* POLARSSL_CIPHER_MODE_CFB */
1715 
1716 #ifdef POLARSSL_CIPHER_MODE_CFB
1717 
1718  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_3)
1719  {
1720  unsigned char key_str[100];
1721  unsigned char iv_str[100];
1722  unsigned char src_str[100];
1723  unsigned char dst_str[100];
1724  unsigned char output[100];
1725  camellia_context ctx;
1726  size_t iv_offset = 0;
1727  int key_len;
1728 
1729  memset(key_str, 0x00, 100);
1730  memset(iv_str, 0x00, 100);
1731  memset(src_str, 0x00, 100);
1732  memset(dst_str, 0x00, 100);
1733  memset(output, 0x00, 100);
1734 
1735  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1736  unhexify( iv_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" );
1737  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1738 
1739  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1740  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1741  hexify( dst_str, output, 16 );
1742 
1743  fct_chk( strcasecmp( (char *) dst_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ) == 0 );
1744  }
1745  FCT_TEST_END();
1746 #endif /* POLARSSL_CIPHER_MODE_CFB */
1747 
1748 #ifdef POLARSSL_CIPHER_MODE_CFB
1749 
1750  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_4)
1751  {
1752  unsigned char key_str[100];
1753  unsigned char iv_str[100];
1754  unsigned char src_str[100];
1755  unsigned char dst_str[100];
1756  unsigned char output[100];
1757  camellia_context ctx;
1758  size_t iv_offset = 0;
1759  int key_len;
1760 
1761  memset(key_str, 0x00, 100);
1762  memset(iv_str, 0x00, 100);
1763  memset(src_str, 0x00, 100);
1764  memset(dst_str, 0x00, 100);
1765  memset(output, 0x00, 100);
1766 
1767  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1768  unhexify( iv_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" );
1769  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1770 
1771  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1772  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1773  hexify( dst_str, output, 16 );
1774 
1775  fct_chk( strcasecmp( (char *) dst_str, "5953ADCE14DB8C7F39F1BD39F359BFFA" ) == 0 );
1776  }
1777  FCT_TEST_END();
1778 #endif /* POLARSSL_CIPHER_MODE_CFB */
1779 
1780 #ifdef POLARSSL_CIPHER_MODE_CFB
1781 
1782  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_1)
1783  {
1784  unsigned char key_str[100];
1785  unsigned char iv_str[100];
1786  unsigned char src_str[100];
1787  unsigned char dst_str[100];
1788  unsigned char output[100];
1789  camellia_context ctx;
1790  size_t iv_offset = 0;
1791  int key_len;
1792 
1793  memset(key_str, 0x00, 100);
1794  memset(iv_str, 0x00, 100);
1795  memset(src_str, 0x00, 100);
1796  memset(dst_str, 0x00, 100);
1797  memset(output, 0x00, 100);
1798 
1799  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1800  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1801  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1802 
1803  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1804  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1805  hexify( dst_str, output, 16 );
1806 
1807  fct_chk( strcasecmp( (char *) dst_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ) == 0 );
1808  }
1809  FCT_TEST_END();
1810 #endif /* POLARSSL_CIPHER_MODE_CFB */
1811 
1812 #ifdef POLARSSL_CIPHER_MODE_CFB
1813 
1814  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_2)
1815  {
1816  unsigned char key_str[100];
1817  unsigned char iv_str[100];
1818  unsigned char src_str[100];
1819  unsigned char dst_str[100];
1820  unsigned char output[100];
1821  camellia_context ctx;
1822  size_t iv_offset = 0;
1823  int key_len;
1824 
1825  memset(key_str, 0x00, 100);
1826  memset(iv_str, 0x00, 100);
1827  memset(src_str, 0x00, 100);
1828  memset(dst_str, 0x00, 100);
1829  memset(output, 0x00, 100);
1830 
1831  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1832  unhexify( iv_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" );
1833  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1834 
1835  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1836  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1837  hexify( dst_str, output, 16 );
1838 
1839  fct_chk( strcasecmp( (char *) dst_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ) == 0 );
1840  }
1841  FCT_TEST_END();
1842 #endif /* POLARSSL_CIPHER_MODE_CFB */
1843 
1844 #ifdef POLARSSL_CIPHER_MODE_CFB
1845 
1846  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_3)
1847  {
1848  unsigned char key_str[100];
1849  unsigned char iv_str[100];
1850  unsigned char src_str[100];
1851  unsigned char dst_str[100];
1852  unsigned char output[100];
1853  camellia_context ctx;
1854  size_t iv_offset = 0;
1855  int key_len;
1856 
1857  memset(key_str, 0x00, 100);
1858  memset(iv_str, 0x00, 100);
1859  memset(src_str, 0x00, 100);
1860  memset(dst_str, 0x00, 100);
1861  memset(output, 0x00, 100);
1862 
1863  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1864  unhexify( iv_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" );
1865  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1866 
1867  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1868  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1869  hexify( dst_str, output, 16 );
1870 
1871  fct_chk( strcasecmp( (char *) dst_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ) == 0 );
1872  }
1873  FCT_TEST_END();
1874 #endif /* POLARSSL_CIPHER_MODE_CFB */
1875 
1876 #ifdef POLARSSL_CIPHER_MODE_CFB
1877 
1878  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_4)
1879  {
1880  unsigned char key_str[100];
1881  unsigned char iv_str[100];
1882  unsigned char src_str[100];
1883  unsigned char dst_str[100];
1884  unsigned char output[100];
1885  camellia_context ctx;
1886  size_t iv_offset = 0;
1887  int key_len;
1888 
1889  memset(key_str, 0x00, 100);
1890  memset(iv_str, 0x00, 100);
1891  memset(src_str, 0x00, 100);
1892  memset(dst_str, 0x00, 100);
1893  memset(output, 0x00, 100);
1894 
1895  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1896  unhexify( iv_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" );
1897  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1898 
1899  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1900  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1901  hexify( dst_str, output, 16 );
1902 
1903  fct_chk( strcasecmp( (char *) dst_str, "5953ADCE14DB8C7F39F1BD39F359BFFA" ) == 0 );
1904  }
1905  FCT_TEST_END();
1906 #endif /* POLARSSL_CIPHER_MODE_CFB */
1907 
1908 
1909  FCT_TEST_BGN(camellia_ecb_encrypt_invalid_key_length)
1910  {
1911  unsigned char key_str[100];
1912  unsigned char src_str[100];
1913  unsigned char dst_str[100];
1914  unsigned char output[100];
1915  camellia_context ctx;
1916  int key_len;
1917 
1918  memset(key_str, 0x00, 100);
1919  memset(src_str, 0x00, 100);
1920  memset(dst_str, 0x00, 100);
1921  memset(output, 0x00, 100);
1922 
1923  key_len = unhexify( key_str, "0123456789abcdeffedcba98765432" );
1924  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
1925 
1926  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
1928  {
1929  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
1930  hexify( dst_str, output, 16 );
1931 
1932  fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 );
1933  }
1934  }
1935  FCT_TEST_END();
1936 
1937 
1938  FCT_TEST_BGN(camellia_ecb_decrypt_invalid_key_length)
1939  {
1940  unsigned char key_str[100];
1941  unsigned char src_str[100];
1942  unsigned char dst_str[100];
1943  unsigned char output[100];
1944  camellia_context ctx;
1945  int key_len;
1946 
1947  memset(key_str, 0x00, 100);
1948  memset(src_str, 0x00, 100);
1949  memset(dst_str, 0x00, 100);
1950  memset(output, 0x00, 100);
1951 
1952  key_len = unhexify( key_str, "0123456789abcdeffedcba98765432" );
1953  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
1954 
1955  fct_chk( camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
1957  {
1958  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output ) == 0 );
1959  hexify( dst_str, output, 16 );
1960 
1961  fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 );
1962  }
1963  }
1964  FCT_TEST_END();
1965 
1966 
1967  FCT_TEST_BGN(camellia_256_cbc_encrypt_invalid_input_length)
1968  {
1969  unsigned char key_str[100];
1970  unsigned char iv_str[100];
1971  unsigned char src_str[100];
1972  unsigned char dst_str[100];
1973  unsigned char output[100];
1974  camellia_context ctx;
1975  int key_len, data_len;
1976 
1977  memset(key_str, 0x00, 100);
1978  memset(iv_str, 0x00, 100);
1979  memset(src_str, 0x00, 100);
1980  memset(dst_str, 0x00, 100);
1981  memset(output, 0x00, 100);
1982 
1983  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1984  unhexify( iv_str, "00000000000000000000000000000000" );
1985  data_len = unhexify( src_str, "ffffffffffffffe000000000000000" );
1986 
1987  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1988  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH );
1990  {
1991  hexify( dst_str, output, data_len );
1992 
1993  fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 );
1994  }
1995  }
1996  FCT_TEST_END();
1997 
1998 
1999  FCT_TEST_BGN(camellia_256_cbc_decrypt_invalid_input_length)
2000  {
2001  unsigned char key_str[100];
2002  unsigned char iv_str[100];
2003  unsigned char src_str[100];
2004  unsigned char dst_str[100];
2005  unsigned char output[100];
2006  camellia_context ctx;
2007  int key_len, data_len;
2008 
2009  memset(key_str, 0x00, 100);
2010  memset(iv_str, 0x00, 100);
2011  memset(src_str, 0x00, 100);
2012  memset(dst_str, 0x00, 100);
2013  memset(output, 0x00, 100);
2014 
2015  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2016  unhexify( iv_str, "00000000000000000000000000000000" );
2017  data_len = unhexify( src_str, "623a52fcea5d443e48d9181ab32c74" );
2018 
2019  camellia_setkey_dec( &ctx, key_str, key_len * 8 );
2020  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH );
2022  {
2023  hexify( dst_str, output, data_len );
2024 
2025  fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 );
2026  }
2027  }
2028  FCT_TEST_END();
2029 
2030 #ifdef POLARSSL_SELF_TEST
2031 
2032  FCT_TEST_BGN(camellia_selftest)
2033  {
2034  fct_chk( camellia_self_test( 0 ) == 0 );
2035  }
2036  FCT_TEST_END();
2037 #endif /* POLARSSL_SELF_TEST */
2038 
2039  }
2040  FCT_SUITE_END();
2041 
2042 #endif /* POLARSSL_CAMELLIA_C */
2043 
2044 }
2045 FCT_END();
2046