PolarSSL v1.2.8
test_suite_camellia.c
Go to the documentation of this file.
1 #include "fct.h"
2 #include <polarssl/config.h>
3 
4 #include <polarssl/camellia.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_CAMELLIA_C
229 
230 
231  FCT_SUITE_BGN(test_suite_camellia)
232  {
233 
234  FCT_TEST_BGN(camellia_128_ecb_encrypt_rfc3713_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  camellia_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, "0123456789abcdeffedcba9876543210" );
249  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
250 
251  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
252  if( 0 == 0 )
253  {
254  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
255  hexify( dst_str, output, 16 );
256 
257  fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 );
258  }
259  }
260  FCT_TEST_END();
261 
262 
263  FCT_TEST_BGN(camellia_192_ecb_encrypt_rfc3713_1)
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  camellia_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, "0123456789abcdeffedcba98765432100011223344556677" );
278  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
279 
280  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
281  if( 0 == 0 )
282  {
283  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
284  hexify( dst_str, output, 16 );
285 
286  fct_chk( strcasecmp( (char *) dst_str, "b4993401b3e996f84ee5cee7d79b09b9" ) == 0 );
287  }
288  }
289  FCT_TEST_END();
290 
291 
292  FCT_TEST_BGN(camellia_256_ecb_encrypt_rfc3713_1)
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  camellia_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, "0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff" );
307  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
308 
309  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
310  if( 0 == 0 )
311  {
312  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
313  hexify( dst_str, output, 16 );
314 
315  fct_chk( strcasecmp( (char *) dst_str, "9acc237dff16d76c20ef7c919e3a7509" ) == 0 );
316  }
317  }
318  FCT_TEST_END();
319 
320 
321  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_1)
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  camellia_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, "000102030405060708090A0B0C0D0E0F" );
336  unhexify( src_str, "00112233445566778899AABBCCDDEEFF" );
337 
338  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
339  if( 0 == 0 )
340  {
341  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
342  hexify( dst_str, output, 16 );
343 
344  fct_chk( strcasecmp( (char *) dst_str, "77CF412067AF8270613529149919546F" ) == 0 );
345  }
346  }
347  FCT_TEST_END();
348 
349 
350  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_1)
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  camellia_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, "000102030405060708090A0B0C0D0E0F1011121314151617" );
365  unhexify( src_str, "00112233445566778899AABBCCDDEEFF" );
366 
367  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
368  if( 0 == 0 )
369  {
370  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
371  hexify( dst_str, output, 16 );
372 
373  fct_chk( strcasecmp( (char *) dst_str, "B22F3C36B72D31329EEE8ADDC2906C68" ) == 0 );
374  }
375  }
376  FCT_TEST_END();
377 
378 
379  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_1)
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  camellia_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, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" );
394  unhexify( src_str, "00112233445566778899AABBCCDDEEFF" );
395 
396  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
397  if( 0 == 0 )
398  {
399  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
400  hexify( dst_str, output, 16 );
401 
402  fct_chk( strcasecmp( (char *) dst_str, "2EDF1F3418D53B88841FC8985FB1ECF2" ) == 0 );
403  }
404  }
405  FCT_TEST_END();
406 
407 
408  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_1)
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  camellia_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, "2B7E151628AED2A6ABF7158809CF4F3C" );
423  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
424 
425  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
426  if( 0 == 0 )
427  {
428  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
429  hexify( dst_str, output, 16 );
430 
431  fct_chk( strcasecmp( (char *) dst_str, "432FC5DCD628115B7C388D770B270C96" ) == 0 );
432  }
433  }
434  FCT_TEST_END();
435 
436 
437  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_2)
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  camellia_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, "2B7E151628AED2A6ABF7158809CF4F3C" );
452  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
453 
454  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
455  if( 0 == 0 )
456  {
457  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
458  hexify( dst_str, output, 16 );
459 
460  fct_chk( strcasecmp( (char *) dst_str, "0BE1F14023782A22E8384C5ABB7FAB2B" ) == 0 );
461  }
462  }
463  FCT_TEST_END();
464 
465 
466  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_3)
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  camellia_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, "2B7E151628AED2A6ABF7158809CF4F3C" );
481  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
482 
483  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
484  if( 0 == 0 )
485  {
486  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
487  hexify( dst_str, output, 16 );
488 
489  fct_chk( strcasecmp( (char *) dst_str, "A0A1ABCD1893AB6FE0FE5B65DF5F8636" ) == 0 );
490  }
491  }
492  FCT_TEST_END();
493 
494 
495  FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_4)
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  camellia_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, "2B7E151628AED2A6ABF7158809CF4F3C" );
510  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
511 
512  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
513  if( 0 == 0 )
514  {
515  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
516  hexify( dst_str, output, 16 );
517 
518  fct_chk( strcasecmp( (char *) dst_str, "E61925E0D5DFAA9BB29F815B3076E51A" ) == 0 );
519  }
520  }
521  FCT_TEST_END();
522 
523 
524  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_1)
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  camellia_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, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
539  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
540 
541  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
542  if( 0 == 0 )
543  {
544  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
545  hexify( dst_str, output, 16 );
546 
547  fct_chk( strcasecmp( (char *) dst_str, "CCCC6C4E138B45848514D48D0D3439D3" ) == 0 );
548  }
549  }
550  FCT_TEST_END();
551 
552 
553  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_2)
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  camellia_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, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
568  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
569 
570  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
571  if( 0 == 0 )
572  {
573  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
574  hexify( dst_str, output, 16 );
575 
576  fct_chk( strcasecmp( (char *) dst_str, "5713C62C14B2EC0F8393B6AFD6F5785A" ) == 0 );
577  }
578  }
579  FCT_TEST_END();
580 
581 
582  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_3)
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  camellia_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, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
597  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
598 
599  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
600  if( 0 == 0 )
601  {
602  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
603  hexify( dst_str, output, 16 );
604 
605  fct_chk( strcasecmp( (char *) dst_str, "B40ED2B60EB54D09D030CF511FEEF366" ) == 0 );
606  }
607  }
608  FCT_TEST_END();
609 
610 
611  FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_4)
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  camellia_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, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
626  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
627 
628  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
629  if( 0 == 0 )
630  {
631  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
632  hexify( dst_str, output, 16 );
633 
634  fct_chk( strcasecmp( (char *) dst_str, "909DBD95799096748CB27357E73E1D26" ) == 0 );
635  }
636  }
637  FCT_TEST_END();
638 
639 
640  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_1)
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  camellia_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, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
655  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
656 
657  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
658  if( 0 == 0 )
659  {
660  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
661  hexify( dst_str, output, 16 );
662 
663  fct_chk( strcasecmp( (char *) dst_str, "BEFD219B112FA00098919CD101C9CCFA" ) == 0 );
664  }
665  }
666  FCT_TEST_END();
667 
668 
669  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_2)
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  camellia_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, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
684  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
685 
686  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
687  if( 0 == 0 )
688  {
689  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
690  hexify( dst_str, output, 16 );
691 
692  fct_chk( strcasecmp( (char *) dst_str, "C91D3A8F1AEA08A9386CF4B66C0169EA" ) == 0 );
693  }
694  }
695  FCT_TEST_END();
696 
697 
698  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_3)
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  camellia_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, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
713  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
714 
715  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
716  if( 0 == 0 )
717  {
718  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
719  hexify( dst_str, output, 16 );
720 
721  fct_chk( strcasecmp( (char *) dst_str, "A623D711DC5F25A51BB8A80D56397D28" ) == 0 );
722  }
723  }
724  FCT_TEST_END();
725 
726 
727  FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_4)
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  camellia_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, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
742  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
743 
744  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 );
745  if( 0 == 0 )
746  {
747  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
748  hexify( dst_str, output, 16 );
749 
750  fct_chk( strcasecmp( (char *) dst_str, "7960109FB6DC42947FCFE59EA3C5EB6B" ) == 0 );
751  }
752  }
753  FCT_TEST_END();
754 
755 
756  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_1)
757  {
758  unsigned char key_str[100];
759  unsigned char iv_str[100];
760  unsigned char src_str[100];
761  unsigned char dst_str[100];
762  unsigned char output[100];
763  camellia_context ctx;
764  int key_len, data_len;
765 
766  memset(key_str, 0x00, 100);
767  memset(iv_str, 0x00, 100);
768  memset(src_str, 0x00, 100);
769  memset(dst_str, 0x00, 100);
770  memset(output, 0x00, 100);
771 
772  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
773  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
774  data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
775 
776  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
777  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
778  if( 0 == 0 )
779  {
780  hexify( dst_str, output, data_len );
781 
782  fct_chk( strcasecmp( (char *) dst_str, "1607CF494B36BBF00DAEB0B503C831AB" ) == 0 );
783  }
784  }
785  FCT_TEST_END();
786 
787 
788  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_2)
789  {
790  unsigned char key_str[100];
791  unsigned char iv_str[100];
792  unsigned char src_str[100];
793  unsigned char dst_str[100];
794  unsigned char output[100];
795  camellia_context ctx;
796  int key_len, data_len;
797 
798  memset(key_str, 0x00, 100);
799  memset(iv_str, 0x00, 100);
800  memset(src_str, 0x00, 100);
801  memset(dst_str, 0x00, 100);
802  memset(output, 0x00, 100);
803 
804  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
805  unhexify( iv_str, "1607CF494B36BBF00DAEB0B503C831AB" );
806  data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
807 
808  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
809  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
810  if( 0 == 0 )
811  {
812  hexify( dst_str, output, data_len );
813 
814  fct_chk( strcasecmp( (char *) dst_str, "A2F2CF671629EF7840C5A5DFB5074887" ) == 0 );
815  }
816  }
817  FCT_TEST_END();
818 
819 
820  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_3)
821  {
822  unsigned char key_str[100];
823  unsigned char iv_str[100];
824  unsigned char src_str[100];
825  unsigned char dst_str[100];
826  unsigned char output[100];
827  camellia_context ctx;
828  int key_len, data_len;
829 
830  memset(key_str, 0x00, 100);
831  memset(iv_str, 0x00, 100);
832  memset(src_str, 0x00, 100);
833  memset(dst_str, 0x00, 100);
834  memset(output, 0x00, 100);
835 
836  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
837  unhexify( iv_str, "A2F2CF671629EF7840C5A5DFB5074887" );
838  data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
839 
840  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
841  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
842  if( 0 == 0 )
843  {
844  hexify( dst_str, output, data_len );
845 
846  fct_chk( strcasecmp( (char *) dst_str, "0F06165008CF8B8B5A63586362543E54" ) == 0 );
847  }
848  }
849  FCT_TEST_END();
850 
851 
852  FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_4)
853  {
854  unsigned char key_str[100];
855  unsigned char iv_str[100];
856  unsigned char src_str[100];
857  unsigned char dst_str[100];
858  unsigned char output[100];
859  camellia_context ctx;
860  int key_len, data_len;
861 
862  memset(key_str, 0x00, 100);
863  memset(iv_str, 0x00, 100);
864  memset(src_str, 0x00, 100);
865  memset(dst_str, 0x00, 100);
866  memset(output, 0x00, 100);
867 
868  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
869  unhexify( iv_str, "36A84CDAFD5F9A85ADA0F0A993D6D577" );
870  data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
871 
872  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
873  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
874  if( 0 == 0 )
875  {
876  hexify( dst_str, output, data_len );
877 
878  fct_chk( strcasecmp( (char *) dst_str, "74C64268CDB8B8FAF5B34E8AF3732980" ) == 0 );
879  }
880  }
881  FCT_TEST_END();
882 
883 
884  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_1)
885  {
886  unsigned char key_str[100];
887  unsigned char iv_str[100];
888  unsigned char src_str[100];
889  unsigned char dst_str[100];
890  unsigned char output[100];
891  camellia_context ctx;
892  int key_len, data_len;
893 
894  memset(key_str, 0x00, 100);
895  memset(iv_str, 0x00, 100);
896  memset(src_str, 0x00, 100);
897  memset(dst_str, 0x00, 100);
898  memset(output, 0x00, 100);
899 
900  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
901  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
902  data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
903 
904  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
905  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
906  if( 0 == 0 )
907  {
908  hexify( dst_str, output, data_len );
909 
910  fct_chk( strcasecmp( (char *) dst_str, "2A4830AB5AC4A1A2405955FD2195CF93" ) == 0 );
911  }
912  }
913  FCT_TEST_END();
914 
915 
916  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_2)
917  {
918  unsigned char key_str[100];
919  unsigned char iv_str[100];
920  unsigned char src_str[100];
921  unsigned char dst_str[100];
922  unsigned char output[100];
923  camellia_context ctx;
924  int key_len, data_len;
925 
926  memset(key_str, 0x00, 100);
927  memset(iv_str, 0x00, 100);
928  memset(src_str, 0x00, 100);
929  memset(dst_str, 0x00, 100);
930  memset(output, 0x00, 100);
931 
932  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
933  unhexify( iv_str, "2A4830AB5AC4A1A2405955FD2195CF93" );
934  data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
935 
936  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
937  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
938  if( 0 == 0 )
939  {
940  hexify( dst_str, output, data_len );
941 
942  fct_chk( strcasecmp( (char *) dst_str, "5D5A869BD14CE54264F892A6DD2EC3D5" ) == 0 );
943  }
944  }
945  FCT_TEST_END();
946 
947 
948  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_3)
949  {
950  unsigned char key_str[100];
951  unsigned char iv_str[100];
952  unsigned char src_str[100];
953  unsigned char dst_str[100];
954  unsigned char output[100];
955  camellia_context ctx;
956  int key_len, data_len;
957 
958  memset(key_str, 0x00, 100);
959  memset(iv_str, 0x00, 100);
960  memset(src_str, 0x00, 100);
961  memset(dst_str, 0x00, 100);
962  memset(output, 0x00, 100);
963 
964  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
965  unhexify( iv_str, "5D5A869BD14CE54264F892A6DD2EC3D5" );
966  data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
967 
968  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
969  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
970  if( 0 == 0 )
971  {
972  hexify( dst_str, output, data_len );
973 
974  fct_chk( strcasecmp( (char *) dst_str, "37D359C3349836D884E310ADDF68C449" ) == 0 );
975  }
976  }
977  FCT_TEST_END();
978 
979 
980  FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_4)
981  {
982  unsigned char key_str[100];
983  unsigned char iv_str[100];
984  unsigned char src_str[100];
985  unsigned char dst_str[100];
986  unsigned char output[100];
987  camellia_context ctx;
988  int key_len, data_len;
989 
990  memset(key_str, 0x00, 100);
991  memset(iv_str, 0x00, 100);
992  memset(src_str, 0x00, 100);
993  memset(dst_str, 0x00, 100);
994  memset(output, 0x00, 100);
995 
996  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
997  unhexify( iv_str, "37D359C3349836D884E310ADDF68C449" );
998  data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
999 
1000  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1001  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1002  if( 0 == 0 )
1003  {
1004  hexify( dst_str, output, data_len );
1005 
1006  fct_chk( strcasecmp( (char *) dst_str, "01FAAA930B4AB9916E9668E1428C6B08" ) == 0 );
1007  }
1008  }
1009  FCT_TEST_END();
1010 
1011 
1012  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_1)
1013  {
1014  unsigned char key_str[100];
1015  unsigned char iv_str[100];
1016  unsigned char src_str[100];
1017  unsigned char dst_str[100];
1018  unsigned char output[100];
1019  camellia_context ctx;
1020  int key_len, data_len;
1021 
1022  memset(key_str, 0x00, 100);
1023  memset(iv_str, 0x00, 100);
1024  memset(src_str, 0x00, 100);
1025  memset(dst_str, 0x00, 100);
1026  memset(output, 0x00, 100);
1027 
1028  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1029  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1030  data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1031 
1032  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1033  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1034  if( 0 == 0 )
1035  {
1036  hexify( dst_str, output, data_len );
1037 
1038  fct_chk( strcasecmp( (char *) dst_str, "E6CFA35FC02B134A4D2C0B6737AC3EDA" ) == 0 );
1039  }
1040  }
1041  FCT_TEST_END();
1042 
1043 
1044  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_2)
1045  {
1046  unsigned char key_str[100];
1047  unsigned char iv_str[100];
1048  unsigned char src_str[100];
1049  unsigned char dst_str[100];
1050  unsigned char output[100];
1051  camellia_context ctx;
1052  int key_len, data_len;
1053 
1054  memset(key_str, 0x00, 100);
1055  memset(iv_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, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1061  unhexify( iv_str, "E6CFA35FC02B134A4D2C0B6737AC3EDA" );
1062  data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1063 
1064  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1065  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1066  if( 0 == 0 )
1067  {
1068  hexify( dst_str, output, data_len );
1069 
1070  fct_chk( strcasecmp( (char *) dst_str, "36CBEB73BD504B4070B1B7DE2B21EB50" ) == 0 );
1071  }
1072  }
1073  FCT_TEST_END();
1074 
1075 
1076  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_3)
1077  {
1078  unsigned char key_str[100];
1079  unsigned char iv_str[100];
1080  unsigned char src_str[100];
1081  unsigned char dst_str[100];
1082  unsigned char output[100];
1083  camellia_context ctx;
1084  int key_len, data_len;
1085 
1086  memset(key_str, 0x00, 100);
1087  memset(iv_str, 0x00, 100);
1088  memset(src_str, 0x00, 100);
1089  memset(dst_str, 0x00, 100);
1090  memset(output, 0x00, 100);
1091 
1092  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1093  unhexify( iv_str, "36CBEB73BD504B4070B1B7DE2B21EB50" );
1094  data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1095 
1096  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1097  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1098  if( 0 == 0 )
1099  {
1100  hexify( dst_str, output, data_len );
1101 
1102  fct_chk( strcasecmp( (char *) dst_str, "E31A6055297D96CA3330CDF1B1860A83" ) == 0 );
1103  }
1104  }
1105  FCT_TEST_END();
1106 
1107 
1108  FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_4)
1109  {
1110  unsigned char key_str[100];
1111  unsigned char iv_str[100];
1112  unsigned char src_str[100];
1113  unsigned char dst_str[100];
1114  unsigned char output[100];
1115  camellia_context ctx;
1116  int key_len, data_len;
1117 
1118  memset(key_str, 0x00, 100);
1119  memset(iv_str, 0x00, 100);
1120  memset(src_str, 0x00, 100);
1121  memset(dst_str, 0x00, 100);
1122  memset(output, 0x00, 100);
1123 
1124  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1125  unhexify( iv_str, "E31A6055297D96CA3330CDF1B1860A83" );
1126  data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1127 
1128  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1129  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 );
1130  if( 0 == 0 )
1131  {
1132  hexify( dst_str, output, data_len );
1133 
1134  fct_chk( strcasecmp( (char *) dst_str, "5D563F6D1CCCF236051C0C5C1C58F28F" ) == 0 );
1135  }
1136  }
1137  FCT_TEST_END();
1138 
1139 #ifdef POLARSSL_CIPHER_MODE_CFB
1140 
1141  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_1)
1142  {
1143  unsigned char key_str[100];
1144  unsigned char iv_str[100];
1145  unsigned char src_str[100];
1146  unsigned char dst_str[100];
1147  unsigned char output[100];
1148  camellia_context ctx;
1149  size_t iv_offset = 0;
1150  int key_len;
1151 
1152  memset(key_str, 0x00, 100);
1153  memset(iv_str, 0x00, 100);
1154  memset(src_str, 0x00, 100);
1155  memset(dst_str, 0x00, 100);
1156  memset(output, 0x00, 100);
1157 
1158  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1159  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1160  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1161 
1162  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1163  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1164  hexify( dst_str, output, 16 );
1165 
1166  fct_chk( strcasecmp( (char *) dst_str, "14F7646187817EB586599146B82BD719" ) == 0 );
1167  }
1168  FCT_TEST_END();
1169 #endif /* POLARSSL_CIPHER_MODE_CFB */
1170 
1171 #ifdef POLARSSL_CIPHER_MODE_CFB
1172 
1173  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_2)
1174  {
1175  unsigned char key_str[100];
1176  unsigned char iv_str[100];
1177  unsigned char src_str[100];
1178  unsigned char dst_str[100];
1179  unsigned char output[100];
1180  camellia_context ctx;
1181  size_t iv_offset = 0;
1182  int key_len;
1183 
1184  memset(key_str, 0x00, 100);
1185  memset(iv_str, 0x00, 100);
1186  memset(src_str, 0x00, 100);
1187  memset(dst_str, 0x00, 100);
1188  memset(output, 0x00, 100);
1189 
1190  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1191  unhexify( iv_str, "14F7646187817EB586599146B82BD719" );
1192  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1193 
1194  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1195  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1196  hexify( dst_str, output, 16 );
1197 
1198  fct_chk( strcasecmp( (char *) dst_str, "A53D28BB82DF741103EA4F921A44880B" ) == 0 );
1199  }
1200  FCT_TEST_END();
1201 #endif /* POLARSSL_CIPHER_MODE_CFB */
1202 
1203 #ifdef POLARSSL_CIPHER_MODE_CFB
1204 
1205  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_3)
1206  {
1207  unsigned char key_str[100];
1208  unsigned char iv_str[100];
1209  unsigned char src_str[100];
1210  unsigned char dst_str[100];
1211  unsigned char output[100];
1212  camellia_context ctx;
1213  size_t iv_offset = 0;
1214  int key_len;
1215 
1216  memset(key_str, 0x00, 100);
1217  memset(iv_str, 0x00, 100);
1218  memset(src_str, 0x00, 100);
1219  memset(dst_str, 0x00, 100);
1220  memset(output, 0x00, 100);
1221 
1222  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1223  unhexify( iv_str, "A53D28BB82DF741103EA4F921A44880B" );
1224  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1225 
1226  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1227  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1228  hexify( dst_str, output, 16 );
1229 
1230  fct_chk( strcasecmp( (char *) dst_str, "9C2157A664626D1DEF9EA420FDE69B96" ) == 0 );
1231  }
1232  FCT_TEST_END();
1233 #endif /* POLARSSL_CIPHER_MODE_CFB */
1234 
1235 #ifdef POLARSSL_CIPHER_MODE_CFB
1236 
1237  FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_4)
1238  {
1239  unsigned char key_str[100];
1240  unsigned char iv_str[100];
1241  unsigned char src_str[100];
1242  unsigned char dst_str[100];
1243  unsigned char output[100];
1244  camellia_context ctx;
1245  size_t iv_offset = 0;
1246  int key_len;
1247 
1248  memset(key_str, 0x00, 100);
1249  memset(iv_str, 0x00, 100);
1250  memset(src_str, 0x00, 100);
1251  memset(dst_str, 0x00, 100);
1252  memset(output, 0x00, 100);
1253 
1254  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1255  unhexify( iv_str, "9C2157A664626D1DEF9EA420FDE69B96" );
1256  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1257 
1258  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1259  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1260  hexify( dst_str, output, 16 );
1261 
1262  fct_chk( strcasecmp( (char *) dst_str, "742A25F0542340C7BAEF24CA8482BB09" ) == 0 );
1263  }
1264  FCT_TEST_END();
1265 #endif /* POLARSSL_CIPHER_MODE_CFB */
1266 
1267 #ifdef POLARSSL_CIPHER_MODE_CFB
1268 
1269  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_1)
1270  {
1271  unsigned char key_str[100];
1272  unsigned char iv_str[100];
1273  unsigned char src_str[100];
1274  unsigned char dst_str[100];
1275  unsigned char output[100];
1276  camellia_context ctx;
1277  size_t iv_offset = 0;
1278  int key_len;
1279 
1280  memset(key_str, 0x00, 100);
1281  memset(iv_str, 0x00, 100);
1282  memset(src_str, 0x00, 100);
1283  memset(dst_str, 0x00, 100);
1284  memset(output, 0x00, 100);
1285 
1286  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1287  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1288  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1289 
1290  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1291  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1292  hexify( dst_str, output, 16 );
1293 
1294  fct_chk( strcasecmp( (char *) dst_str, "14F7646187817EB586599146B82BD719" ) == 0 );
1295  }
1296  FCT_TEST_END();
1297 #endif /* POLARSSL_CIPHER_MODE_CFB */
1298 
1299 #ifdef POLARSSL_CIPHER_MODE_CFB
1300 
1301  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_2)
1302  {
1303  unsigned char key_str[100];
1304  unsigned char iv_str[100];
1305  unsigned char src_str[100];
1306  unsigned char dst_str[100];
1307  unsigned char output[100];
1308  camellia_context ctx;
1309  size_t iv_offset = 0;
1310  int key_len;
1311 
1312  memset(key_str, 0x00, 100);
1313  memset(iv_str, 0x00, 100);
1314  memset(src_str, 0x00, 100);
1315  memset(dst_str, 0x00, 100);
1316  memset(output, 0x00, 100);
1317 
1318  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1319  unhexify( iv_str, "14F7646187817EB586599146B82BD719" );
1320  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1321 
1322  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1323  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1324  hexify( dst_str, output, 16 );
1325 
1326  fct_chk( strcasecmp( (char *) dst_str, "A53D28BB82DF741103EA4F921A44880B" ) == 0 );
1327  }
1328  FCT_TEST_END();
1329 #endif /* POLARSSL_CIPHER_MODE_CFB */
1330 
1331 #ifdef POLARSSL_CIPHER_MODE_CFB
1332 
1333  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_3)
1334  {
1335  unsigned char key_str[100];
1336  unsigned char iv_str[100];
1337  unsigned char src_str[100];
1338  unsigned char dst_str[100];
1339  unsigned char output[100];
1340  camellia_context ctx;
1341  size_t iv_offset = 0;
1342  int key_len;
1343 
1344  memset(key_str, 0x00, 100);
1345  memset(iv_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, "2B7E151628AED2A6ABF7158809CF4F3C" );
1351  unhexify( iv_str, "A53D28BB82DF741103EA4F921A44880B" );
1352  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1353 
1354  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1355  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1356  hexify( dst_str, output, 16 );
1357 
1358  fct_chk( strcasecmp( (char *) dst_str, "9C2157A664626D1DEF9EA420FDE69B96" ) == 0 );
1359  }
1360  FCT_TEST_END();
1361 #endif /* POLARSSL_CIPHER_MODE_CFB */
1362 
1363 #ifdef POLARSSL_CIPHER_MODE_CFB
1364 
1365  FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_4)
1366  {
1367  unsigned char key_str[100];
1368  unsigned char iv_str[100];
1369  unsigned char src_str[100];
1370  unsigned char dst_str[100];
1371  unsigned char output[100];
1372  camellia_context ctx;
1373  size_t iv_offset = 0;
1374  int key_len;
1375 
1376  memset(key_str, 0x00, 100);
1377  memset(iv_str, 0x00, 100);
1378  memset(src_str, 0x00, 100);
1379  memset(dst_str, 0x00, 100);
1380  memset(output, 0x00, 100);
1381 
1382  key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" );
1383  unhexify( iv_str, "9C2157A664626D1DEF9EA420FDE69B96" );
1384  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1385 
1386  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1387  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1388  hexify( dst_str, output, 16 );
1389 
1390  fct_chk( strcasecmp( (char *) dst_str, "742A25F0542340C7BAEF24CA8482BB09" ) == 0 );
1391  }
1392  FCT_TEST_END();
1393 #endif /* POLARSSL_CIPHER_MODE_CFB */
1394 
1395 #ifdef POLARSSL_CIPHER_MODE_CFB
1396 
1397  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_1)
1398  {
1399  unsigned char key_str[100];
1400  unsigned char iv_str[100];
1401  unsigned char src_str[100];
1402  unsigned char dst_str[100];
1403  unsigned char output[100];
1404  camellia_context ctx;
1405  size_t iv_offset = 0;
1406  int key_len;
1407 
1408  memset(key_str, 0x00, 100);
1409  memset(iv_str, 0x00, 100);
1410  memset(src_str, 0x00, 100);
1411  memset(dst_str, 0x00, 100);
1412  memset(output, 0x00, 100);
1413 
1414  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1415  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1416  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1417 
1418  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1419  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1420  hexify( dst_str, output, 16 );
1421 
1422  fct_chk( strcasecmp( (char *) dst_str, "C832BB9780677DAA82D9B6860DCD565E" ) == 0 );
1423  }
1424  FCT_TEST_END();
1425 #endif /* POLARSSL_CIPHER_MODE_CFB */
1426 
1427 #ifdef POLARSSL_CIPHER_MODE_CFB
1428 
1429  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_2)
1430  {
1431  unsigned char key_str[100];
1432  unsigned char iv_str[100];
1433  unsigned char src_str[100];
1434  unsigned char dst_str[100];
1435  unsigned char output[100];
1436  camellia_context ctx;
1437  size_t iv_offset = 0;
1438  int key_len;
1439 
1440  memset(key_str, 0x00, 100);
1441  memset(iv_str, 0x00, 100);
1442  memset(src_str, 0x00, 100);
1443  memset(dst_str, 0x00, 100);
1444  memset(output, 0x00, 100);
1445 
1446  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1447  unhexify( iv_str, "C832BB9780677DAA82D9B6860DCD565E" );
1448  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1449 
1450  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1451  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1452  hexify( dst_str, output, 16 );
1453 
1454  fct_chk( strcasecmp( (char *) dst_str, "86F8491627906D780C7A6D46EA331F98" ) == 0 );
1455  }
1456  FCT_TEST_END();
1457 #endif /* POLARSSL_CIPHER_MODE_CFB */
1458 
1459 #ifdef POLARSSL_CIPHER_MODE_CFB
1460 
1461  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_3)
1462  {
1463  unsigned char key_str[100];
1464  unsigned char iv_str[100];
1465  unsigned char src_str[100];
1466  unsigned char dst_str[100];
1467  unsigned char output[100];
1468  camellia_context ctx;
1469  size_t iv_offset = 0;
1470  int key_len;
1471 
1472  memset(key_str, 0x00, 100);
1473  memset(iv_str, 0x00, 100);
1474  memset(src_str, 0x00, 100);
1475  memset(dst_str, 0x00, 100);
1476  memset(output, 0x00, 100);
1477 
1478  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1479  unhexify( iv_str, "86F8491627906D780C7A6D46EA331F98" );
1480  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1481 
1482  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1483  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1484  hexify( dst_str, output, 16 );
1485 
1486  fct_chk( strcasecmp( (char *) dst_str, "69511CCE594CF710CB98BB63D7221F01" ) == 0 );
1487  }
1488  FCT_TEST_END();
1489 #endif /* POLARSSL_CIPHER_MODE_CFB */
1490 
1491 #ifdef POLARSSL_CIPHER_MODE_CFB
1492 
1493  FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_4)
1494  {
1495  unsigned char key_str[100];
1496  unsigned char iv_str[100];
1497  unsigned char src_str[100];
1498  unsigned char dst_str[100];
1499  unsigned char output[100];
1500  camellia_context ctx;
1501  size_t iv_offset = 0;
1502  int key_len;
1503 
1504  memset(key_str, 0x00, 100);
1505  memset(iv_str, 0x00, 100);
1506  memset(src_str, 0x00, 100);
1507  memset(dst_str, 0x00, 100);
1508  memset(output, 0x00, 100);
1509 
1510  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1511  unhexify( iv_str, "69511CCE594CF710CB98BB63D7221F01" );
1512  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1513 
1514  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1515  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1516  hexify( dst_str, output, 16 );
1517 
1518  fct_chk( strcasecmp( (char *) dst_str, "D5B5378A3ABED55803F25565D8907B84" ) == 0 );
1519  }
1520  FCT_TEST_END();
1521 #endif /* POLARSSL_CIPHER_MODE_CFB */
1522 
1523 #ifdef POLARSSL_CIPHER_MODE_CFB
1524 
1525  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_1)
1526  {
1527  unsigned char key_str[100];
1528  unsigned char iv_str[100];
1529  unsigned char src_str[100];
1530  unsigned char dst_str[100];
1531  unsigned char output[100];
1532  camellia_context ctx;
1533  size_t iv_offset = 0;
1534  int key_len;
1535 
1536  memset(key_str, 0x00, 100);
1537  memset(iv_str, 0x00, 100);
1538  memset(src_str, 0x00, 100);
1539  memset(dst_str, 0x00, 100);
1540  memset(output, 0x00, 100);
1541 
1542  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1543  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1544  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1545 
1546  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1547  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1548  hexify( dst_str, output, 16 );
1549 
1550  fct_chk( strcasecmp( (char *) dst_str, "C832BB9780677DAA82D9B6860DCD565E" ) == 0 );
1551  }
1552  FCT_TEST_END();
1553 #endif /* POLARSSL_CIPHER_MODE_CFB */
1554 
1555 #ifdef POLARSSL_CIPHER_MODE_CFB
1556 
1557  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_2)
1558  {
1559  unsigned char key_str[100];
1560  unsigned char iv_str[100];
1561  unsigned char src_str[100];
1562  unsigned char dst_str[100];
1563  unsigned char output[100];
1564  camellia_context ctx;
1565  size_t iv_offset = 0;
1566  int key_len;
1567 
1568  memset(key_str, 0x00, 100);
1569  memset(iv_str, 0x00, 100);
1570  memset(src_str, 0x00, 100);
1571  memset(dst_str, 0x00, 100);
1572  memset(output, 0x00, 100);
1573 
1574  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1575  unhexify( iv_str, "C832BB9780677DAA82D9B6860DCD565E" );
1576  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1577 
1578  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1579  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1580  hexify( dst_str, output, 16 );
1581 
1582  fct_chk( strcasecmp( (char *) dst_str, "86F8491627906D780C7A6D46EA331F98" ) == 0 );
1583  }
1584  FCT_TEST_END();
1585 #endif /* POLARSSL_CIPHER_MODE_CFB */
1586 
1587 #ifdef POLARSSL_CIPHER_MODE_CFB
1588 
1589  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_3)
1590  {
1591  unsigned char key_str[100];
1592  unsigned char iv_str[100];
1593  unsigned char src_str[100];
1594  unsigned char dst_str[100];
1595  unsigned char output[100];
1596  camellia_context ctx;
1597  size_t iv_offset = 0;
1598  int key_len;
1599 
1600  memset(key_str, 0x00, 100);
1601  memset(iv_str, 0x00, 100);
1602  memset(src_str, 0x00, 100);
1603  memset(dst_str, 0x00, 100);
1604  memset(output, 0x00, 100);
1605 
1606  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1607  unhexify( iv_str, "86F8491627906D780C7A6D46EA331F98" );
1608  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1609 
1610  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1611  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1612  hexify( dst_str, output, 16 );
1613 
1614  fct_chk( strcasecmp( (char *) dst_str, "69511CCE594CF710CB98BB63D7221F01" ) == 0 );
1615  }
1616  FCT_TEST_END();
1617 #endif /* POLARSSL_CIPHER_MODE_CFB */
1618 
1619 #ifdef POLARSSL_CIPHER_MODE_CFB
1620 
1621  FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_4)
1622  {
1623  unsigned char key_str[100];
1624  unsigned char iv_str[100];
1625  unsigned char src_str[100];
1626  unsigned char dst_str[100];
1627  unsigned char output[100];
1628  camellia_context ctx;
1629  size_t iv_offset = 0;
1630  int key_len;
1631 
1632  memset(key_str, 0x00, 100);
1633  memset(iv_str, 0x00, 100);
1634  memset(src_str, 0x00, 100);
1635  memset(dst_str, 0x00, 100);
1636  memset(output, 0x00, 100);
1637 
1638  key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" );
1639  unhexify( iv_str, "69511CCE594CF710CB98BB63D7221F01" );
1640  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1641 
1642  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1643  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1644  hexify( dst_str, output, 16 );
1645 
1646  fct_chk( strcasecmp( (char *) dst_str, "D5B5378A3ABED55803F25565D8907B84" ) == 0 );
1647  }
1648  FCT_TEST_END();
1649 #endif /* POLARSSL_CIPHER_MODE_CFB */
1650 
1651 #ifdef POLARSSL_CIPHER_MODE_CFB
1652 
1653  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_1)
1654  {
1655  unsigned char key_str[100];
1656  unsigned char iv_str[100];
1657  unsigned char src_str[100];
1658  unsigned char dst_str[100];
1659  unsigned char output[100];
1660  camellia_context ctx;
1661  size_t iv_offset = 0;
1662  int key_len;
1663 
1664  memset(key_str, 0x00, 100);
1665  memset(iv_str, 0x00, 100);
1666  memset(src_str, 0x00, 100);
1667  memset(dst_str, 0x00, 100);
1668  memset(output, 0x00, 100);
1669 
1670  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1671  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1672  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1673 
1674  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1675  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1676  hexify( dst_str, output, 16 );
1677 
1678  fct_chk( strcasecmp( (char *) dst_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ) == 0 );
1679  }
1680  FCT_TEST_END();
1681 #endif /* POLARSSL_CIPHER_MODE_CFB */
1682 
1683 #ifdef POLARSSL_CIPHER_MODE_CFB
1684 
1685  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_2)
1686  {
1687  unsigned char key_str[100];
1688  unsigned char iv_str[100];
1689  unsigned char src_str[100];
1690  unsigned char dst_str[100];
1691  unsigned char output[100];
1692  camellia_context ctx;
1693  size_t iv_offset = 0;
1694  int key_len;
1695 
1696  memset(key_str, 0x00, 100);
1697  memset(iv_str, 0x00, 100);
1698  memset(src_str, 0x00, 100);
1699  memset(dst_str, 0x00, 100);
1700  memset(output, 0x00, 100);
1701 
1702  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1703  unhexify( iv_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" );
1704  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1705 
1706  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1707  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1708  hexify( dst_str, output, 16 );
1709 
1710  fct_chk( strcasecmp( (char *) dst_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ) == 0 );
1711  }
1712  FCT_TEST_END();
1713 #endif /* POLARSSL_CIPHER_MODE_CFB */
1714 
1715 #ifdef POLARSSL_CIPHER_MODE_CFB
1716 
1717  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_3)
1718  {
1719  unsigned char key_str[100];
1720  unsigned char iv_str[100];
1721  unsigned char src_str[100];
1722  unsigned char dst_str[100];
1723  unsigned char output[100];
1724  camellia_context ctx;
1725  size_t iv_offset = 0;
1726  int key_len;
1727 
1728  memset(key_str, 0x00, 100);
1729  memset(iv_str, 0x00, 100);
1730  memset(src_str, 0x00, 100);
1731  memset(dst_str, 0x00, 100);
1732  memset(output, 0x00, 100);
1733 
1734  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1735  unhexify( iv_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" );
1736  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1737 
1738  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1739  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1740  hexify( dst_str, output, 16 );
1741 
1742  fct_chk( strcasecmp( (char *) dst_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ) == 0 );
1743  }
1744  FCT_TEST_END();
1745 #endif /* POLARSSL_CIPHER_MODE_CFB */
1746 
1747 #ifdef POLARSSL_CIPHER_MODE_CFB
1748 
1749  FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_4)
1750  {
1751  unsigned char key_str[100];
1752  unsigned char iv_str[100];
1753  unsigned char src_str[100];
1754  unsigned char dst_str[100];
1755  unsigned char output[100];
1756  camellia_context ctx;
1757  size_t iv_offset = 0;
1758  int key_len;
1759 
1760  memset(key_str, 0x00, 100);
1761  memset(iv_str, 0x00, 100);
1762  memset(src_str, 0x00, 100);
1763  memset(dst_str, 0x00, 100);
1764  memset(output, 0x00, 100);
1765 
1766  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1767  unhexify( iv_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" );
1768  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1769 
1770  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1771  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1772  hexify( dst_str, output, 16 );
1773 
1774  fct_chk( strcasecmp( (char *) dst_str, "5953ADCE14DB8C7F39F1BD39F359BFFA" ) == 0 );
1775  }
1776  FCT_TEST_END();
1777 #endif /* POLARSSL_CIPHER_MODE_CFB */
1778 
1779 #ifdef POLARSSL_CIPHER_MODE_CFB
1780 
1781  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_1)
1782  {
1783  unsigned char key_str[100];
1784  unsigned char iv_str[100];
1785  unsigned char src_str[100];
1786  unsigned char dst_str[100];
1787  unsigned char output[100];
1788  camellia_context ctx;
1789  size_t iv_offset = 0;
1790  int key_len;
1791 
1792  memset(key_str, 0x00, 100);
1793  memset(iv_str, 0x00, 100);
1794  memset(src_str, 0x00, 100);
1795  memset(dst_str, 0x00, 100);
1796  memset(output, 0x00, 100);
1797 
1798  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1799  unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" );
1800  unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" );
1801 
1802  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1803  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1804  hexify( dst_str, output, 16 );
1805 
1806  fct_chk( strcasecmp( (char *) dst_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ) == 0 );
1807  }
1808  FCT_TEST_END();
1809 #endif /* POLARSSL_CIPHER_MODE_CFB */
1810 
1811 #ifdef POLARSSL_CIPHER_MODE_CFB
1812 
1813  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_2)
1814  {
1815  unsigned char key_str[100];
1816  unsigned char iv_str[100];
1817  unsigned char src_str[100];
1818  unsigned char dst_str[100];
1819  unsigned char output[100];
1820  camellia_context ctx;
1821  size_t iv_offset = 0;
1822  int key_len;
1823 
1824  memset(key_str, 0x00, 100);
1825  memset(iv_str, 0x00, 100);
1826  memset(src_str, 0x00, 100);
1827  memset(dst_str, 0x00, 100);
1828  memset(output, 0x00, 100);
1829 
1830  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1831  unhexify( iv_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" );
1832  unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" );
1833 
1834  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1835  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1836  hexify( dst_str, output, 16 );
1837 
1838  fct_chk( strcasecmp( (char *) dst_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ) == 0 );
1839  }
1840  FCT_TEST_END();
1841 #endif /* POLARSSL_CIPHER_MODE_CFB */
1842 
1843 #ifdef POLARSSL_CIPHER_MODE_CFB
1844 
1845  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_3)
1846  {
1847  unsigned char key_str[100];
1848  unsigned char iv_str[100];
1849  unsigned char src_str[100];
1850  unsigned char dst_str[100];
1851  unsigned char output[100];
1852  camellia_context ctx;
1853  size_t iv_offset = 0;
1854  int key_len;
1855 
1856  memset(key_str, 0x00, 100);
1857  memset(iv_str, 0x00, 100);
1858  memset(src_str, 0x00, 100);
1859  memset(dst_str, 0x00, 100);
1860  memset(output, 0x00, 100);
1861 
1862  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1863  unhexify( iv_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" );
1864  unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" );
1865 
1866  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1867  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1868  hexify( dst_str, output, 16 );
1869 
1870  fct_chk( strcasecmp( (char *) dst_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ) == 0 );
1871  }
1872  FCT_TEST_END();
1873 #endif /* POLARSSL_CIPHER_MODE_CFB */
1874 
1875 #ifdef POLARSSL_CIPHER_MODE_CFB
1876 
1877  FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_4)
1878  {
1879  unsigned char key_str[100];
1880  unsigned char iv_str[100];
1881  unsigned char src_str[100];
1882  unsigned char dst_str[100];
1883  unsigned char output[100];
1884  camellia_context ctx;
1885  size_t iv_offset = 0;
1886  int key_len;
1887 
1888  memset(key_str, 0x00, 100);
1889  memset(iv_str, 0x00, 100);
1890  memset(src_str, 0x00, 100);
1891  memset(dst_str, 0x00, 100);
1892  memset(output, 0x00, 100);
1893 
1894  key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" );
1895  unhexify( iv_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" );
1896  unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" );
1897 
1898  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1899  fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
1900  hexify( dst_str, output, 16 );
1901 
1902  fct_chk( strcasecmp( (char *) dst_str, "5953ADCE14DB8C7F39F1BD39F359BFFA" ) == 0 );
1903  }
1904  FCT_TEST_END();
1905 #endif /* POLARSSL_CIPHER_MODE_CFB */
1906 
1907 
1908  FCT_TEST_BGN(camellia_ecb_encrypt_invalid_key_length)
1909  {
1910  unsigned char key_str[100];
1911  unsigned char src_str[100];
1912  unsigned char dst_str[100];
1913  unsigned char output[100];
1914  camellia_context ctx;
1915  int key_len;
1916 
1917  memset(key_str, 0x00, 100);
1918  memset(src_str, 0x00, 100);
1919  memset(dst_str, 0x00, 100);
1920  memset(output, 0x00, 100);
1921 
1922  key_len = unhexify( key_str, "0123456789abcdeffedcba98765432" );
1923  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
1924 
1925  fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
1927  {
1928  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
1929  hexify( dst_str, output, 16 );
1930 
1931  fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 );
1932  }
1933  }
1934  FCT_TEST_END();
1935 
1936 
1937  FCT_TEST_BGN(camellia_ecb_decrypt_invalid_key_length)
1938  {
1939  unsigned char key_str[100];
1940  unsigned char src_str[100];
1941  unsigned char dst_str[100];
1942  unsigned char output[100];
1943  camellia_context ctx;
1944  int key_len;
1945 
1946  memset(key_str, 0x00, 100);
1947  memset(src_str, 0x00, 100);
1948  memset(dst_str, 0x00, 100);
1949  memset(output, 0x00, 100);
1950 
1951  key_len = unhexify( key_str, "0123456789abcdeffedcba98765432" );
1952  unhexify( src_str, "0123456789abcdeffedcba9876543210" );
1953 
1954  fct_chk( camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
1956  {
1957  fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output ) == 0 );
1958  hexify( dst_str, output, 16 );
1959 
1960  fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 );
1961  }
1962  }
1963  FCT_TEST_END();
1964 
1965 
1966  FCT_TEST_BGN(camellia_256_cbc_encrypt_invalid_input_length)
1967  {
1968  unsigned char key_str[100];
1969  unsigned char iv_str[100];
1970  unsigned char src_str[100];
1971  unsigned char dst_str[100];
1972  unsigned char output[100];
1973  camellia_context ctx;
1974  int key_len, data_len;
1975 
1976  memset(key_str, 0x00, 100);
1977  memset(iv_str, 0x00, 100);
1978  memset(src_str, 0x00, 100);
1979  memset(dst_str, 0x00, 100);
1980  memset(output, 0x00, 100);
1981 
1982  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
1983  unhexify( iv_str, "00000000000000000000000000000000" );
1984  data_len = unhexify( src_str, "ffffffffffffffe000000000000000" );
1985 
1986  camellia_setkey_enc( &ctx, key_str, key_len * 8 );
1987  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH );
1989  {
1990  hexify( dst_str, output, data_len );
1991 
1992  fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 );
1993  }
1994  }
1995  FCT_TEST_END();
1996 
1997 
1998  FCT_TEST_BGN(camellia_256_cbc_decrypt_invalid_input_length)
1999  {
2000  unsigned char key_str[100];
2001  unsigned char iv_str[100];
2002  unsigned char src_str[100];
2003  unsigned char dst_str[100];
2004  unsigned char output[100];
2005  camellia_context ctx;
2006  int key_len, data_len;
2007 
2008  memset(key_str, 0x00, 100);
2009  memset(iv_str, 0x00, 100);
2010  memset(src_str, 0x00, 100);
2011  memset(dst_str, 0x00, 100);
2012  memset(output, 0x00, 100);
2013 
2014  key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" );
2015  unhexify( iv_str, "00000000000000000000000000000000" );
2016  data_len = unhexify( src_str, "623a52fcea5d443e48d9181ab32c74" );
2017 
2018  camellia_setkey_dec( &ctx, key_str, key_len * 8 );
2019  fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH );
2021  {
2022  hexify( dst_str, output, data_len );
2023 
2024  fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 );
2025  }
2026  }
2027  FCT_TEST_END();
2028 
2029 #ifdef POLARSSL_SELF_TEST
2030 
2031  FCT_TEST_BGN(camellia_selftest)
2032  {
2033  fct_chk( camellia_self_test( 0 ) == 0 );
2034  }
2035  FCT_TEST_END();
2036 #endif /* POLARSSL_SELF_TEST */
2037 
2038  }
2039  FCT_SUITE_END();
2040 
2041 #endif /* POLARSSL_CAMELLIA_C */
2042 
2043 }
2044 FCT_END();
2045