PolarSSL v1.2.5
test_suite_cipher.camellia.c
Go to the documentation of this file.
1 #include "fct.h"
2 
3 #include <polarssl/cipher.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_CIPHER_C
230 
231 
232  FCT_SUITE_BGN(test_suite_cipher)
233  {
234 #ifdef POLARSSL_SELF_TEST
235 
236  FCT_TEST_BGN(cipher_selftest)
237  {
238  fct_chk( cipher_self_test( 0 ) == 0 );
239  }
240  FCT_TEST_END();
241 #endif /* POLARSSL_SELF_TEST */
242 
243 
244  FCT_TEST_BGN(decrypt_empty_buffer)
245  unsigned char key[32];
246  unsigned char iv[16];
247 
248  cipher_context_t ctx_dec;
249  const cipher_info_t *cipher_info;
250 
251  unsigned char encbuf[64];
252  unsigned char decbuf[64];
253 
254  size_t outlen = 0;
255 
256  memset( key, 0, 32 );
257  memset( iv , 0, 16 );
258 
259  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
260 
261  memset( encbuf, 0, 64 );
262  memset( decbuf, 0, 64 );
263 
264  /* Initialise enc and dec contexts */
266  fct_chk( NULL != cipher_info);
267 
268  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
269 
270  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
271 
272  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
273 
274  /* decode 0-byte string */
275  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, 0, decbuf, &outlen ) );
276  fct_chk( 0 == outlen );
277  fct_chk( POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
278  fct_chk( 0 == outlen );
279 
280  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
281  FCT_TEST_END();
282 
283 #ifdef POLARSSL_CAMELLIA_C
284 
285  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes)
286  size_t length = 0;
287  unsigned char key[32];
288  unsigned char iv[16];
289 
290  const cipher_info_t *cipher_info;
291  cipher_context_t ctx_dec;
292  cipher_context_t ctx_enc;
293 
294  unsigned char inbuf[64];
295  unsigned char encbuf[64];
296  unsigned char decbuf[64];
297 
298  size_t outlen = 0;
299  size_t enclen = 0;
300 
301  memset( key, 0, 32 );
302  memset( iv , 0, 16 );
303 
304  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
305  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
306 
307  memset( inbuf, 5, 64 );
308  memset( encbuf, 0, 64 );
309  memset( decbuf, 0, 64 );
310 
311  /* Check and get info structures */
313  fct_chk( NULL != cipher_info );
314  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
315 
316  /* Initialise enc and dec contexts */
317  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
318  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
319 
320  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
321  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
322 
323  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
324  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
325 
326  if( POLARSSL_MODE_CBC == cipher_info->mode )
327  {
328  enclen = cipher_get_block_size( &ctx_enc )
329  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
330  }
331  else
332  {
333  enclen = length;
334  }
335 
336  /* encode length number of bytes from inbuf */
337  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
338  if( POLARSSL_MODE_CBC == cipher_info->mode )
339  {
340  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
341  }
342  else
343  {
344  fct_chk( outlen == enclen );
345  }
346 
347  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
348  if( POLARSSL_MODE_CBC == cipher_info->mode )
349  {
350  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
351  }
352  else
353  {
354  fct_chk( outlen == 0 );
355  }
356 
357 
358  /* decode the previously encoded string */
359  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
360  if( POLARSSL_MODE_CBC == cipher_info->mode )
361  {
362  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
363  }
364  else
365  {
366  fct_chk( enclen == outlen );
367  }
368 
369  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
370  if( POLARSSL_MODE_CBC == cipher_info->mode )
371  {
372  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
373  }
374  else
375  {
376  fct_chk( outlen == 0 );
377  }
378 
379 
380  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
381 
382  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
383  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
384  FCT_TEST_END();
385 #endif /* POLARSSL_CAMELLIA_C */
386 
387 #ifdef POLARSSL_CAMELLIA_C
388 
389  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_byte)
390  size_t length = 1;
391  unsigned char key[32];
392  unsigned char iv[16];
393 
394  const cipher_info_t *cipher_info;
395  cipher_context_t ctx_dec;
396  cipher_context_t ctx_enc;
397 
398  unsigned char inbuf[64];
399  unsigned char encbuf[64];
400  unsigned char decbuf[64];
401 
402  size_t outlen = 0;
403  size_t enclen = 0;
404 
405  memset( key, 0, 32 );
406  memset( iv , 0, 16 );
407 
408  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
409  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
410 
411  memset( inbuf, 5, 64 );
412  memset( encbuf, 0, 64 );
413  memset( decbuf, 0, 64 );
414 
415  /* Check and get info structures */
417  fct_chk( NULL != cipher_info );
418  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
419 
420  /* Initialise enc and dec contexts */
421  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
422  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
423 
424  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
425  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
426 
427  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
428  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
429 
430  if( POLARSSL_MODE_CBC == cipher_info->mode )
431  {
432  enclen = cipher_get_block_size( &ctx_enc )
433  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
434  }
435  else
436  {
437  enclen = length;
438  }
439 
440  /* encode length number of bytes from inbuf */
441  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
442  if( POLARSSL_MODE_CBC == cipher_info->mode )
443  {
444  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
445  }
446  else
447  {
448  fct_chk( outlen == enclen );
449  }
450 
451  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
452  if( POLARSSL_MODE_CBC == cipher_info->mode )
453  {
454  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
455  }
456  else
457  {
458  fct_chk( outlen == 0 );
459  }
460 
461 
462  /* decode the previously encoded string */
463  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
464  if( POLARSSL_MODE_CBC == cipher_info->mode )
465  {
466  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
467  }
468  else
469  {
470  fct_chk( enclen == outlen );
471  }
472 
473  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
474  if( POLARSSL_MODE_CBC == cipher_info->mode )
475  {
476  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
477  }
478  else
479  {
480  fct_chk( outlen == 0 );
481  }
482 
483 
484  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
485 
486  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
487  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
488  FCT_TEST_END();
489 #endif /* POLARSSL_CAMELLIA_C */
490 
491 #ifdef POLARSSL_CAMELLIA_C
492 
493  FCT_TEST_BGN(camellia_encrypt_and_decrypt_2_bytes)
494  size_t length = 2;
495  unsigned char key[32];
496  unsigned char iv[16];
497 
498  const cipher_info_t *cipher_info;
499  cipher_context_t ctx_dec;
500  cipher_context_t ctx_enc;
501 
502  unsigned char inbuf[64];
503  unsigned char encbuf[64];
504  unsigned char decbuf[64];
505 
506  size_t outlen = 0;
507  size_t enclen = 0;
508 
509  memset( key, 0, 32 );
510  memset( iv , 0, 16 );
511 
512  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
513  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
514 
515  memset( inbuf, 5, 64 );
516  memset( encbuf, 0, 64 );
517  memset( decbuf, 0, 64 );
518 
519  /* Check and get info structures */
521  fct_chk( NULL != cipher_info );
522  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
523 
524  /* Initialise enc and dec contexts */
525  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
526  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
527 
528  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
529  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
530 
531  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
532  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
533 
534  if( POLARSSL_MODE_CBC == cipher_info->mode )
535  {
536  enclen = cipher_get_block_size( &ctx_enc )
537  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
538  }
539  else
540  {
541  enclen = length;
542  }
543 
544  /* encode length number of bytes from inbuf */
545  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
546  if( POLARSSL_MODE_CBC == cipher_info->mode )
547  {
548  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
549  }
550  else
551  {
552  fct_chk( outlen == enclen );
553  }
554 
555  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
556  if( POLARSSL_MODE_CBC == cipher_info->mode )
557  {
558  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
559  }
560  else
561  {
562  fct_chk( outlen == 0 );
563  }
564 
565 
566  /* decode the previously encoded string */
567  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
568  if( POLARSSL_MODE_CBC == cipher_info->mode )
569  {
570  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
571  }
572  else
573  {
574  fct_chk( enclen == outlen );
575  }
576 
577  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
578  if( POLARSSL_MODE_CBC == cipher_info->mode )
579  {
580  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
581  }
582  else
583  {
584  fct_chk( outlen == 0 );
585  }
586 
587 
588  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
589 
590  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
591  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
592  FCT_TEST_END();
593 #endif /* POLARSSL_CAMELLIA_C */
594 
595 #ifdef POLARSSL_CAMELLIA_C
596 
597  FCT_TEST_BGN(camellia_encrypt_and_decrypt_7_bytes)
598  size_t length = 7;
599  unsigned char key[32];
600  unsigned char iv[16];
601 
602  const cipher_info_t *cipher_info;
603  cipher_context_t ctx_dec;
604  cipher_context_t ctx_enc;
605 
606  unsigned char inbuf[64];
607  unsigned char encbuf[64];
608  unsigned char decbuf[64];
609 
610  size_t outlen = 0;
611  size_t enclen = 0;
612 
613  memset( key, 0, 32 );
614  memset( iv , 0, 16 );
615 
616  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
617  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
618 
619  memset( inbuf, 5, 64 );
620  memset( encbuf, 0, 64 );
621  memset( decbuf, 0, 64 );
622 
623  /* Check and get info structures */
625  fct_chk( NULL != cipher_info );
626  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
627 
628  /* Initialise enc and dec contexts */
629  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
630  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
631 
632  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
633  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
634 
635  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
636  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
637 
638  if( POLARSSL_MODE_CBC == cipher_info->mode )
639  {
640  enclen = cipher_get_block_size( &ctx_enc )
641  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
642  }
643  else
644  {
645  enclen = length;
646  }
647 
648  /* encode length number of bytes from inbuf */
649  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
650  if( POLARSSL_MODE_CBC == cipher_info->mode )
651  {
652  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
653  }
654  else
655  {
656  fct_chk( outlen == enclen );
657  }
658 
659  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
660  if( POLARSSL_MODE_CBC == cipher_info->mode )
661  {
662  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
663  }
664  else
665  {
666  fct_chk( outlen == 0 );
667  }
668 
669 
670  /* decode the previously encoded string */
671  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
672  if( POLARSSL_MODE_CBC == cipher_info->mode )
673  {
674  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
675  }
676  else
677  {
678  fct_chk( enclen == outlen );
679  }
680 
681  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
682  if( POLARSSL_MODE_CBC == cipher_info->mode )
683  {
684  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
685  }
686  else
687  {
688  fct_chk( outlen == 0 );
689  }
690 
691 
692  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
693 
694  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
695  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
696  FCT_TEST_END();
697 #endif /* POLARSSL_CAMELLIA_C */
698 
699 #ifdef POLARSSL_CAMELLIA_C
700 
701  FCT_TEST_BGN(camellia_encrypt_and_decrypt_8_bytes)
702  size_t length = 8;
703  unsigned char key[32];
704  unsigned char iv[16];
705 
706  const cipher_info_t *cipher_info;
707  cipher_context_t ctx_dec;
708  cipher_context_t ctx_enc;
709 
710  unsigned char inbuf[64];
711  unsigned char encbuf[64];
712  unsigned char decbuf[64];
713 
714  size_t outlen = 0;
715  size_t enclen = 0;
716 
717  memset( key, 0, 32 );
718  memset( iv , 0, 16 );
719 
720  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
721  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
722 
723  memset( inbuf, 5, 64 );
724  memset( encbuf, 0, 64 );
725  memset( decbuf, 0, 64 );
726 
727  /* Check and get info structures */
729  fct_chk( NULL != cipher_info );
730  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
731 
732  /* Initialise enc and dec contexts */
733  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
734  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
735 
736  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
737  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
738 
739  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
740  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
741 
742  if( POLARSSL_MODE_CBC == cipher_info->mode )
743  {
744  enclen = cipher_get_block_size( &ctx_enc )
745  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
746  }
747  else
748  {
749  enclen = length;
750  }
751 
752  /* encode length number of bytes from inbuf */
753  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
754  if( POLARSSL_MODE_CBC == cipher_info->mode )
755  {
756  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
757  }
758  else
759  {
760  fct_chk( outlen == enclen );
761  }
762 
763  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
764  if( POLARSSL_MODE_CBC == cipher_info->mode )
765  {
766  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
767  }
768  else
769  {
770  fct_chk( outlen == 0 );
771  }
772 
773 
774  /* decode the previously encoded string */
775  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
776  if( POLARSSL_MODE_CBC == cipher_info->mode )
777  {
778  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
779  }
780  else
781  {
782  fct_chk( enclen == outlen );
783  }
784 
785  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
786  if( POLARSSL_MODE_CBC == cipher_info->mode )
787  {
788  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
789  }
790  else
791  {
792  fct_chk( outlen == 0 );
793  }
794 
795 
796  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
797 
798  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
799  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
800  FCT_TEST_END();
801 #endif /* POLARSSL_CAMELLIA_C */
802 
803 #ifdef POLARSSL_CAMELLIA_C
804 
805  FCT_TEST_BGN(camellia_encrypt_and_decrypt_9_bytes)
806  size_t length = 9;
807  unsigned char key[32];
808  unsigned char iv[16];
809 
810  const cipher_info_t *cipher_info;
811  cipher_context_t ctx_dec;
812  cipher_context_t ctx_enc;
813 
814  unsigned char inbuf[64];
815  unsigned char encbuf[64];
816  unsigned char decbuf[64];
817 
818  size_t outlen = 0;
819  size_t enclen = 0;
820 
821  memset( key, 0, 32 );
822  memset( iv , 0, 16 );
823 
824  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
825  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
826 
827  memset( inbuf, 5, 64 );
828  memset( encbuf, 0, 64 );
829  memset( decbuf, 0, 64 );
830 
831  /* Check and get info structures */
833  fct_chk( NULL != cipher_info );
834  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
835 
836  /* Initialise enc and dec contexts */
837  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
838  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
839 
840  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
841  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
842 
843  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
844  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
845 
846  if( POLARSSL_MODE_CBC == cipher_info->mode )
847  {
848  enclen = cipher_get_block_size( &ctx_enc )
849  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
850  }
851  else
852  {
853  enclen = length;
854  }
855 
856  /* encode length number of bytes from inbuf */
857  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
858  if( POLARSSL_MODE_CBC == cipher_info->mode )
859  {
860  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
861  }
862  else
863  {
864  fct_chk( outlen == enclen );
865  }
866 
867  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
868  if( POLARSSL_MODE_CBC == cipher_info->mode )
869  {
870  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
871  }
872  else
873  {
874  fct_chk( outlen == 0 );
875  }
876 
877 
878  /* decode the previously encoded string */
879  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
880  if( POLARSSL_MODE_CBC == cipher_info->mode )
881  {
882  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
883  }
884  else
885  {
886  fct_chk( enclen == outlen );
887  }
888 
889  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
890  if( POLARSSL_MODE_CBC == cipher_info->mode )
891  {
892  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
893  }
894  else
895  {
896  fct_chk( outlen == 0 );
897  }
898 
899 
900  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
901 
902  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
903  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
904  FCT_TEST_END();
905 #endif /* POLARSSL_CAMELLIA_C */
906 
907 #ifdef POLARSSL_CAMELLIA_C
908 
909  FCT_TEST_BGN(camellia_encrypt_and_decrypt_15_bytes)
910  size_t length = 15;
911  unsigned char key[32];
912  unsigned char iv[16];
913 
914  const cipher_info_t *cipher_info;
915  cipher_context_t ctx_dec;
916  cipher_context_t ctx_enc;
917 
918  unsigned char inbuf[64];
919  unsigned char encbuf[64];
920  unsigned char decbuf[64];
921 
922  size_t outlen = 0;
923  size_t enclen = 0;
924 
925  memset( key, 0, 32 );
926  memset( iv , 0, 16 );
927 
928  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
929  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
930 
931  memset( inbuf, 5, 64 );
932  memset( encbuf, 0, 64 );
933  memset( decbuf, 0, 64 );
934 
935  /* Check and get info structures */
937  fct_chk( NULL != cipher_info );
938  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
939 
940  /* Initialise enc and dec contexts */
941  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
942  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
943 
944  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
945  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
946 
947  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
948  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
949 
950  if( POLARSSL_MODE_CBC == cipher_info->mode )
951  {
952  enclen = cipher_get_block_size( &ctx_enc )
953  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
954  }
955  else
956  {
957  enclen = length;
958  }
959 
960  /* encode length number of bytes from inbuf */
961  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
962  if( POLARSSL_MODE_CBC == cipher_info->mode )
963  {
964  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
965  }
966  else
967  {
968  fct_chk( outlen == enclen );
969  }
970 
971  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
972  if( POLARSSL_MODE_CBC == cipher_info->mode )
973  {
974  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
975  }
976  else
977  {
978  fct_chk( outlen == 0 );
979  }
980 
981 
982  /* decode the previously encoded string */
983  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
984  if( POLARSSL_MODE_CBC == cipher_info->mode )
985  {
986  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
987  }
988  else
989  {
990  fct_chk( enclen == outlen );
991  }
992 
993  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
994  if( POLARSSL_MODE_CBC == cipher_info->mode )
995  {
996  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
997  }
998  else
999  {
1000  fct_chk( outlen == 0 );
1001  }
1002 
1003 
1004  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1005 
1006  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1007  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1008  FCT_TEST_END();
1009 #endif /* POLARSSL_CAMELLIA_C */
1010 
1011 #ifdef POLARSSL_CAMELLIA_C
1012 
1013  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes)
1014  size_t length = 16;
1015  unsigned char key[32];
1016  unsigned char iv[16];
1017 
1018  const cipher_info_t *cipher_info;
1019  cipher_context_t ctx_dec;
1020  cipher_context_t ctx_enc;
1021 
1022  unsigned char inbuf[64];
1023  unsigned char encbuf[64];
1024  unsigned char decbuf[64];
1025 
1026  size_t outlen = 0;
1027  size_t enclen = 0;
1028 
1029  memset( key, 0, 32 );
1030  memset( iv , 0, 16 );
1031 
1032  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1033  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1034 
1035  memset( inbuf, 5, 64 );
1036  memset( encbuf, 0, 64 );
1037  memset( decbuf, 0, 64 );
1038 
1039  /* Check and get info structures */
1041  fct_chk( NULL != cipher_info );
1042  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1043 
1044  /* Initialise enc and dec contexts */
1045  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1046  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1047 
1048  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1049  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1050 
1051  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1052  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1053 
1054  if( POLARSSL_MODE_CBC == cipher_info->mode )
1055  {
1056  enclen = cipher_get_block_size( &ctx_enc )
1057  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1058  }
1059  else
1060  {
1061  enclen = length;
1062  }
1063 
1064  /* encode length number of bytes from inbuf */
1065  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1066  if( POLARSSL_MODE_CBC == cipher_info->mode )
1067  {
1068  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1069  }
1070  else
1071  {
1072  fct_chk( outlen == enclen );
1073  }
1074 
1075  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1076  if( POLARSSL_MODE_CBC == cipher_info->mode )
1077  {
1078  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1079  }
1080  else
1081  {
1082  fct_chk( outlen == 0 );
1083  }
1084 
1085 
1086  /* decode the previously encoded string */
1087  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1088  if( POLARSSL_MODE_CBC == cipher_info->mode )
1089  {
1090  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1091  }
1092  else
1093  {
1094  fct_chk( enclen == outlen );
1095  }
1096 
1097  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1098  if( POLARSSL_MODE_CBC == cipher_info->mode )
1099  {
1100  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1101  }
1102  else
1103  {
1104  fct_chk( outlen == 0 );
1105  }
1106 
1107 
1108  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1109 
1110  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1111  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1112  FCT_TEST_END();
1113 #endif /* POLARSSL_CAMELLIA_C */
1114 
1115 #ifdef POLARSSL_CAMELLIA_C
1116 
1117  FCT_TEST_BGN(camellia_encrypt_and_decrypt_17_bytes)
1118  size_t length = 17;
1119  unsigned char key[32];
1120  unsigned char iv[16];
1121 
1122  const cipher_info_t *cipher_info;
1123  cipher_context_t ctx_dec;
1124  cipher_context_t ctx_enc;
1125 
1126  unsigned char inbuf[64];
1127  unsigned char encbuf[64];
1128  unsigned char decbuf[64];
1129 
1130  size_t outlen = 0;
1131  size_t enclen = 0;
1132 
1133  memset( key, 0, 32 );
1134  memset( iv , 0, 16 );
1135 
1136  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1137  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1138 
1139  memset( inbuf, 5, 64 );
1140  memset( encbuf, 0, 64 );
1141  memset( decbuf, 0, 64 );
1142 
1143  /* Check and get info structures */
1145  fct_chk( NULL != cipher_info );
1146  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1147 
1148  /* Initialise enc and dec contexts */
1149  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1150  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1151 
1152  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1153  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1154 
1155  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1156  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1157 
1158  if( POLARSSL_MODE_CBC == cipher_info->mode )
1159  {
1160  enclen = cipher_get_block_size( &ctx_enc )
1161  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1162  }
1163  else
1164  {
1165  enclen = length;
1166  }
1167 
1168  /* encode length number of bytes from inbuf */
1169  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1170  if( POLARSSL_MODE_CBC == cipher_info->mode )
1171  {
1172  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1173  }
1174  else
1175  {
1176  fct_chk( outlen == enclen );
1177  }
1178 
1179  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1180  if( POLARSSL_MODE_CBC == cipher_info->mode )
1181  {
1182  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1183  }
1184  else
1185  {
1186  fct_chk( outlen == 0 );
1187  }
1188 
1189 
1190  /* decode the previously encoded string */
1191  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1192  if( POLARSSL_MODE_CBC == cipher_info->mode )
1193  {
1194  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1195  }
1196  else
1197  {
1198  fct_chk( enclen == outlen );
1199  }
1200 
1201  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1202  if( POLARSSL_MODE_CBC == cipher_info->mode )
1203  {
1204  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1205  }
1206  else
1207  {
1208  fct_chk( outlen == 0 );
1209  }
1210 
1211 
1212  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1213 
1214  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1215  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1216  FCT_TEST_END();
1217 #endif /* POLARSSL_CAMELLIA_C */
1218 
1219 #ifdef POLARSSL_CAMELLIA_C
1220 
1221  FCT_TEST_BGN(camellia_encrypt_and_decrypt_31_bytes)
1222  size_t length = 31;
1223  unsigned char key[32];
1224  unsigned char iv[16];
1225 
1226  const cipher_info_t *cipher_info;
1227  cipher_context_t ctx_dec;
1228  cipher_context_t ctx_enc;
1229 
1230  unsigned char inbuf[64];
1231  unsigned char encbuf[64];
1232  unsigned char decbuf[64];
1233 
1234  size_t outlen = 0;
1235  size_t enclen = 0;
1236 
1237  memset( key, 0, 32 );
1238  memset( iv , 0, 16 );
1239 
1240  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1241  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1242 
1243  memset( inbuf, 5, 64 );
1244  memset( encbuf, 0, 64 );
1245  memset( decbuf, 0, 64 );
1246 
1247  /* Check and get info structures */
1249  fct_chk( NULL != cipher_info );
1250  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1251 
1252  /* Initialise enc and dec contexts */
1253  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1254  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1255 
1256  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1257  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1258 
1259  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1260  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1261 
1262  if( POLARSSL_MODE_CBC == cipher_info->mode )
1263  {
1264  enclen = cipher_get_block_size( &ctx_enc )
1265  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1266  }
1267  else
1268  {
1269  enclen = length;
1270  }
1271 
1272  /* encode length number of bytes from inbuf */
1273  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1274  if( POLARSSL_MODE_CBC == cipher_info->mode )
1275  {
1276  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1277  }
1278  else
1279  {
1280  fct_chk( outlen == enclen );
1281  }
1282 
1283  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1284  if( POLARSSL_MODE_CBC == cipher_info->mode )
1285  {
1286  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1287  }
1288  else
1289  {
1290  fct_chk( outlen == 0 );
1291  }
1292 
1293 
1294  /* decode the previously encoded string */
1295  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1296  if( POLARSSL_MODE_CBC == cipher_info->mode )
1297  {
1298  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1299  }
1300  else
1301  {
1302  fct_chk( enclen == outlen );
1303  }
1304 
1305  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1306  if( POLARSSL_MODE_CBC == cipher_info->mode )
1307  {
1308  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1309  }
1310  else
1311  {
1312  fct_chk( outlen == 0 );
1313  }
1314 
1315 
1316  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1317 
1318  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1319  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1320  FCT_TEST_END();
1321 #endif /* POLARSSL_CAMELLIA_C */
1322 
1323 #ifdef POLARSSL_CAMELLIA_C
1324 
1325  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
1326  size_t length = 32;
1327  unsigned char key[32];
1328  unsigned char iv[16];
1329 
1330  const cipher_info_t *cipher_info;
1331  cipher_context_t ctx_dec;
1332  cipher_context_t ctx_enc;
1333 
1334  unsigned char inbuf[64];
1335  unsigned char encbuf[64];
1336  unsigned char decbuf[64];
1337 
1338  size_t outlen = 0;
1339  size_t enclen = 0;
1340 
1341  memset( key, 0, 32 );
1342  memset( iv , 0, 16 );
1343 
1344  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1345  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1346 
1347  memset( inbuf, 5, 64 );
1348  memset( encbuf, 0, 64 );
1349  memset( decbuf, 0, 64 );
1350 
1351  /* Check and get info structures */
1353  fct_chk( NULL != cipher_info );
1354  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1355 
1356  /* Initialise enc and dec contexts */
1357  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1358  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1359 
1360  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1361  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1362 
1363  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1364  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1365 
1366  if( POLARSSL_MODE_CBC == cipher_info->mode )
1367  {
1368  enclen = cipher_get_block_size( &ctx_enc )
1369  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1370  }
1371  else
1372  {
1373  enclen = length;
1374  }
1375 
1376  /* encode length number of bytes from inbuf */
1377  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1378  if( POLARSSL_MODE_CBC == cipher_info->mode )
1379  {
1380  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1381  }
1382  else
1383  {
1384  fct_chk( outlen == enclen );
1385  }
1386 
1387  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1388  if( POLARSSL_MODE_CBC == cipher_info->mode )
1389  {
1390  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1391  }
1392  else
1393  {
1394  fct_chk( outlen == 0 );
1395  }
1396 
1397 
1398  /* decode the previously encoded string */
1399  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1400  if( POLARSSL_MODE_CBC == cipher_info->mode )
1401  {
1402  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1403  }
1404  else
1405  {
1406  fct_chk( enclen == outlen );
1407  }
1408 
1409  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1410  if( POLARSSL_MODE_CBC == cipher_info->mode )
1411  {
1412  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1413  }
1414  else
1415  {
1416  fct_chk( outlen == 0 );
1417  }
1418 
1419 
1420  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1421 
1422  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1423  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1424  FCT_TEST_END();
1425 #endif /* POLARSSL_CAMELLIA_C */
1426 
1427 #ifdef POLARSSL_CAMELLIA_C
1428 
1429  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
1430  size_t length = 33;
1431  unsigned char key[32];
1432  unsigned char iv[16];
1433 
1434  const cipher_info_t *cipher_info;
1435  cipher_context_t ctx_dec;
1436  cipher_context_t ctx_enc;
1437 
1438  unsigned char inbuf[64];
1439  unsigned char encbuf[64];
1440  unsigned char decbuf[64];
1441 
1442  size_t outlen = 0;
1443  size_t enclen = 0;
1444 
1445  memset( key, 0, 32 );
1446  memset( iv , 0, 16 );
1447 
1448  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1449  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1450 
1451  memset( inbuf, 5, 64 );
1452  memset( encbuf, 0, 64 );
1453  memset( decbuf, 0, 64 );
1454 
1455  /* Check and get info structures */
1457  fct_chk( NULL != cipher_info );
1458  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1459 
1460  /* Initialise enc and dec contexts */
1461  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1462  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1463 
1464  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1465  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1466 
1467  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1468  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1469 
1470  if( POLARSSL_MODE_CBC == cipher_info->mode )
1471  {
1472  enclen = cipher_get_block_size( &ctx_enc )
1473  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1474  }
1475  else
1476  {
1477  enclen = length;
1478  }
1479 
1480  /* encode length number of bytes from inbuf */
1481  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1482  if( POLARSSL_MODE_CBC == cipher_info->mode )
1483  {
1484  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1485  }
1486  else
1487  {
1488  fct_chk( outlen == enclen );
1489  }
1490 
1491  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1492  if( POLARSSL_MODE_CBC == cipher_info->mode )
1493  {
1494  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1495  }
1496  else
1497  {
1498  fct_chk( outlen == 0 );
1499  }
1500 
1501 
1502  /* decode the previously encoded string */
1503  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1504  if( POLARSSL_MODE_CBC == cipher_info->mode )
1505  {
1506  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1507  }
1508  else
1509  {
1510  fct_chk( enclen == outlen );
1511  }
1512 
1513  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1514  if( POLARSSL_MODE_CBC == cipher_info->mode )
1515  {
1516  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1517  }
1518  else
1519  {
1520  fct_chk( outlen == 0 );
1521  }
1522 
1523 
1524  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1525 
1526  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1527  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1528  FCT_TEST_END();
1529 #endif /* POLARSSL_CAMELLIA_C */
1530 
1531 #ifdef POLARSSL_CAMELLIA_C
1532 
1533  FCT_TEST_BGN(camellia_encrypt_and_decrypt_47_bytes)
1534  size_t length = 47;
1535  unsigned char key[32];
1536  unsigned char iv[16];
1537 
1538  const cipher_info_t *cipher_info;
1539  cipher_context_t ctx_dec;
1540  cipher_context_t ctx_enc;
1541 
1542  unsigned char inbuf[64];
1543  unsigned char encbuf[64];
1544  unsigned char decbuf[64];
1545 
1546  size_t outlen = 0;
1547  size_t enclen = 0;
1548 
1549  memset( key, 0, 32 );
1550  memset( iv , 0, 16 );
1551 
1552  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1553  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1554 
1555  memset( inbuf, 5, 64 );
1556  memset( encbuf, 0, 64 );
1557  memset( decbuf, 0, 64 );
1558 
1559  /* Check and get info structures */
1561  fct_chk( NULL != cipher_info );
1562  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1563 
1564  /* Initialise enc and dec contexts */
1565  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1566  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1567 
1568  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1569  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1570 
1571  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1572  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1573 
1574  if( POLARSSL_MODE_CBC == cipher_info->mode )
1575  {
1576  enclen = cipher_get_block_size( &ctx_enc )
1577  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1578  }
1579  else
1580  {
1581  enclen = length;
1582  }
1583 
1584  /* encode length number of bytes from inbuf */
1585  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1586  if( POLARSSL_MODE_CBC == cipher_info->mode )
1587  {
1588  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1589  }
1590  else
1591  {
1592  fct_chk( outlen == enclen );
1593  }
1594 
1595  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1596  if( POLARSSL_MODE_CBC == cipher_info->mode )
1597  {
1598  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1599  }
1600  else
1601  {
1602  fct_chk( outlen == 0 );
1603  }
1604 
1605 
1606  /* decode the previously encoded string */
1607  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1608  if( POLARSSL_MODE_CBC == cipher_info->mode )
1609  {
1610  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1611  }
1612  else
1613  {
1614  fct_chk( enclen == outlen );
1615  }
1616 
1617  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1618  if( POLARSSL_MODE_CBC == cipher_info->mode )
1619  {
1620  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1621  }
1622  else
1623  {
1624  fct_chk( outlen == 0 );
1625  }
1626 
1627 
1628  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1629 
1630  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1631  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1632  FCT_TEST_END();
1633 #endif /* POLARSSL_CAMELLIA_C */
1634 
1635 #ifdef POLARSSL_CAMELLIA_C
1636 
1637  FCT_TEST_BGN(camellia_encrypt_and_decrypt_48_bytes)
1638  size_t length = 48;
1639  unsigned char key[32];
1640  unsigned char iv[16];
1641 
1642  const cipher_info_t *cipher_info;
1643  cipher_context_t ctx_dec;
1644  cipher_context_t ctx_enc;
1645 
1646  unsigned char inbuf[64];
1647  unsigned char encbuf[64];
1648  unsigned char decbuf[64];
1649 
1650  size_t outlen = 0;
1651  size_t enclen = 0;
1652 
1653  memset( key, 0, 32 );
1654  memset( iv , 0, 16 );
1655 
1656  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1657  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1658 
1659  memset( inbuf, 5, 64 );
1660  memset( encbuf, 0, 64 );
1661  memset( decbuf, 0, 64 );
1662 
1663  /* Check and get info structures */
1665  fct_chk( NULL != cipher_info );
1666  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1667 
1668  /* Initialise enc and dec contexts */
1669  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1670  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1671 
1672  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1673  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1674 
1675  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1676  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1677 
1678  if( POLARSSL_MODE_CBC == cipher_info->mode )
1679  {
1680  enclen = cipher_get_block_size( &ctx_enc )
1681  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1682  }
1683  else
1684  {
1685  enclen = length;
1686  }
1687 
1688  /* encode length number of bytes from inbuf */
1689  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1690  if( POLARSSL_MODE_CBC == cipher_info->mode )
1691  {
1692  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1693  }
1694  else
1695  {
1696  fct_chk( outlen == enclen );
1697  }
1698 
1699  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1700  if( POLARSSL_MODE_CBC == cipher_info->mode )
1701  {
1702  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1703  }
1704  else
1705  {
1706  fct_chk( outlen == 0 );
1707  }
1708 
1709 
1710  /* decode the previously encoded string */
1711  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1712  if( POLARSSL_MODE_CBC == cipher_info->mode )
1713  {
1714  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1715  }
1716  else
1717  {
1718  fct_chk( enclen == outlen );
1719  }
1720 
1721  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1722  if( POLARSSL_MODE_CBC == cipher_info->mode )
1723  {
1724  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1725  }
1726  else
1727  {
1728  fct_chk( outlen == 0 );
1729  }
1730 
1731 
1732  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1733 
1734  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1735  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1736  FCT_TEST_END();
1737 #endif /* POLARSSL_CAMELLIA_C */
1738 
1739 #ifdef POLARSSL_CAMELLIA_C
1740 
1741  FCT_TEST_BGN(camellia_encrypt_and_decrypt_49_bytes)
1742  size_t length = 49;
1743  unsigned char key[32];
1744  unsigned char iv[16];
1745 
1746  const cipher_info_t *cipher_info;
1747  cipher_context_t ctx_dec;
1748  cipher_context_t ctx_enc;
1749 
1750  unsigned char inbuf[64];
1751  unsigned char encbuf[64];
1752  unsigned char decbuf[64];
1753 
1754  size_t outlen = 0;
1755  size_t enclen = 0;
1756 
1757  memset( key, 0, 32 );
1758  memset( iv , 0, 16 );
1759 
1760  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1761  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1762 
1763  memset( inbuf, 5, 64 );
1764  memset( encbuf, 0, 64 );
1765  memset( decbuf, 0, 64 );
1766 
1767  /* Check and get info structures */
1769  fct_chk( NULL != cipher_info );
1770  fct_chk( cipher_info_from_string( "CAMELLIA-128-CBC" ) == cipher_info );
1771 
1772  /* Initialise enc and dec contexts */
1773  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1774  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1775 
1776  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1777  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1778 
1779  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1780  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1781 
1782  if( POLARSSL_MODE_CBC == cipher_info->mode )
1783  {
1784  enclen = cipher_get_block_size( &ctx_enc )
1785  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1786  }
1787  else
1788  {
1789  enclen = length;
1790  }
1791 
1792  /* encode length number of bytes from inbuf */
1793  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1794  if( POLARSSL_MODE_CBC == cipher_info->mode )
1795  {
1796  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1797  }
1798  else
1799  {
1800  fct_chk( outlen == enclen );
1801  }
1802 
1803  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1804  if( POLARSSL_MODE_CBC == cipher_info->mode )
1805  {
1806  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1807  }
1808  else
1809  {
1810  fct_chk( outlen == 0 );
1811  }
1812 
1813 
1814  /* decode the previously encoded string */
1815  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1816  if( POLARSSL_MODE_CBC == cipher_info->mode )
1817  {
1818  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1819  }
1820  else
1821  {
1822  fct_chk( enclen == outlen );
1823  }
1824 
1825  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1826  if( POLARSSL_MODE_CBC == cipher_info->mode )
1827  {
1828  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1829  }
1830  else
1831  {
1832  fct_chk( outlen == 0 );
1833  }
1834 
1835 
1836  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1837 
1838  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1839  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1840  FCT_TEST_END();
1841 #endif /* POLARSSL_CAMELLIA_C */
1842 
1843 #ifdef POLARSSL_CAMELLIA_C
1844 
1845  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes_in_multiple_parts)
1846  size_t first_length = 0;
1847  size_t second_length = 0;
1848  size_t length = first_length + second_length;
1849  unsigned char key[32];
1850  unsigned char iv[16];
1851 
1852  cipher_context_t ctx_dec;
1853  cipher_context_t ctx_enc;
1854  const cipher_info_t *cipher_info;
1855 
1856  unsigned char inbuf[64];
1857  unsigned char encbuf[64];
1858  unsigned char decbuf[64];
1859 
1860  size_t outlen = 0;
1861  size_t totaloutlen = 0;
1862  size_t enclen = 0;
1863 
1864  memset( key, 0, 32 );
1865  memset( iv , 0, 16 );
1866 
1867  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1868  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1869 
1870  memset( inbuf, 5, 64 );
1871  memset( encbuf, 0, 64 );
1872  memset( decbuf, 0, 64 );
1873 
1874  /* Initialise enc and dec contexts */
1876  fct_chk( NULL != cipher_info);
1877 
1878  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1879  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1880 
1881  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1882  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1883 
1884  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1885  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1886 
1887  if( POLARSSL_MODE_CBC == cipher_info->mode )
1888  {
1889  enclen = cipher_get_block_size(&ctx_enc )
1890  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1891  }
1892  else
1893  {
1894  enclen = length;
1895  }
1896 
1897  /* encode length number of bytes from inbuf */
1898  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
1899  totaloutlen = outlen;
1900  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
1901  totaloutlen += outlen;
1902  if( POLARSSL_MODE_CBC == cipher_info->mode )
1903  {
1904  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
1905  }
1906  else
1907  {
1908  fct_chk( totaloutlen == enclen );
1909  }
1910  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
1911  totaloutlen += outlen;
1912  if( POLARSSL_MODE_CBC == cipher_info->mode )
1913  {
1914  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
1915  }
1916  else
1917  {
1918  fct_chk( outlen == 0 );
1919  }
1920 
1921  /* decode the previously encoded string */
1922  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1923  if( POLARSSL_MODE_CBC == cipher_info->mode )
1924  {
1925  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
1926  }
1927  else
1928  {
1929  fct_chk( enclen == outlen );
1930  }
1931  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1932  if( POLARSSL_MODE_CBC == cipher_info->mode )
1933  {
1934  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
1935  }
1936  else
1937  {
1938  fct_chk( outlen == 0 );
1939  }
1940 
1941 
1942  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1943 
1944  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
1945  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
1946  FCT_TEST_END();
1947 #endif /* POLARSSL_CAMELLIA_C */
1948 
1949 #ifdef POLARSSL_CAMELLIA_C
1950 
1951  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
1952  size_t first_length = 1;
1953  size_t second_length = 0;
1954  size_t length = first_length + second_length;
1955  unsigned char key[32];
1956  unsigned char iv[16];
1957 
1958  cipher_context_t ctx_dec;
1959  cipher_context_t ctx_enc;
1960  const cipher_info_t *cipher_info;
1961 
1962  unsigned char inbuf[64];
1963  unsigned char encbuf[64];
1964  unsigned char decbuf[64];
1965 
1966  size_t outlen = 0;
1967  size_t totaloutlen = 0;
1968  size_t enclen = 0;
1969 
1970  memset( key, 0, 32 );
1971  memset( iv , 0, 16 );
1972 
1973  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
1974  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
1975 
1976  memset( inbuf, 5, 64 );
1977  memset( encbuf, 0, 64 );
1978  memset( decbuf, 0, 64 );
1979 
1980  /* Initialise enc and dec contexts */
1982  fct_chk( NULL != cipher_info);
1983 
1984  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
1985  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
1986 
1987  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
1988  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
1989 
1990  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
1991  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
1992 
1993  if( POLARSSL_MODE_CBC == cipher_info->mode )
1994  {
1995  enclen = cipher_get_block_size(&ctx_enc )
1996  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
1997  }
1998  else
1999  {
2000  enclen = length;
2001  }
2002 
2003  /* encode length number of bytes from inbuf */
2004  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2005  totaloutlen = outlen;
2006  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2007  totaloutlen += outlen;
2008  if( POLARSSL_MODE_CBC == cipher_info->mode )
2009  {
2010  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2011  }
2012  else
2013  {
2014  fct_chk( totaloutlen == enclen );
2015  }
2016  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2017  totaloutlen += outlen;
2018  if( POLARSSL_MODE_CBC == cipher_info->mode )
2019  {
2020  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2021  }
2022  else
2023  {
2024  fct_chk( outlen == 0 );
2025  }
2026 
2027  /* decode the previously encoded string */
2028  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2029  if( POLARSSL_MODE_CBC == cipher_info->mode )
2030  {
2031  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2032  }
2033  else
2034  {
2035  fct_chk( enclen == outlen );
2036  }
2037  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2038  if( POLARSSL_MODE_CBC == cipher_info->mode )
2039  {
2040  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2041  }
2042  else
2043  {
2044  fct_chk( outlen == 0 );
2045  }
2046 
2047 
2048  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2049 
2050  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2051  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2052  FCT_TEST_END();
2053 #endif /* POLARSSL_CAMELLIA_C */
2054 
2055 #ifdef POLARSSL_CAMELLIA_C
2056 
2057  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
2058  size_t first_length = 0;
2059  size_t second_length = 1;
2060  size_t length = first_length + second_length;
2061  unsigned char key[32];
2062  unsigned char iv[16];
2063 
2064  cipher_context_t ctx_dec;
2065  cipher_context_t ctx_enc;
2066  const cipher_info_t *cipher_info;
2067 
2068  unsigned char inbuf[64];
2069  unsigned char encbuf[64];
2070  unsigned char decbuf[64];
2071 
2072  size_t outlen = 0;
2073  size_t totaloutlen = 0;
2074  size_t enclen = 0;
2075 
2076  memset( key, 0, 32 );
2077  memset( iv , 0, 16 );
2078 
2079  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2080  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2081 
2082  memset( inbuf, 5, 64 );
2083  memset( encbuf, 0, 64 );
2084  memset( decbuf, 0, 64 );
2085 
2086  /* Initialise enc and dec contexts */
2088  fct_chk( NULL != cipher_info);
2089 
2090  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2091  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2092 
2093  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2094  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2095 
2096  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2097  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2098 
2099  if( POLARSSL_MODE_CBC == cipher_info->mode )
2100  {
2101  enclen = cipher_get_block_size(&ctx_enc )
2102  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2103  }
2104  else
2105  {
2106  enclen = length;
2107  }
2108 
2109  /* encode length number of bytes from inbuf */
2110  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2111  totaloutlen = outlen;
2112  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2113  totaloutlen += outlen;
2114  if( POLARSSL_MODE_CBC == cipher_info->mode )
2115  {
2116  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2117  }
2118  else
2119  {
2120  fct_chk( totaloutlen == enclen );
2121  }
2122  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2123  totaloutlen += outlen;
2124  if( POLARSSL_MODE_CBC == cipher_info->mode )
2125  {
2126  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2127  }
2128  else
2129  {
2130  fct_chk( outlen == 0 );
2131  }
2132 
2133  /* decode the previously encoded string */
2134  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2135  if( POLARSSL_MODE_CBC == cipher_info->mode )
2136  {
2137  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2138  }
2139  else
2140  {
2141  fct_chk( enclen == outlen );
2142  }
2143  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2144  if( POLARSSL_MODE_CBC == cipher_info->mode )
2145  {
2146  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2147  }
2148  else
2149  {
2150  fct_chk( outlen == 0 );
2151  }
2152 
2153 
2154  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2155 
2156  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2157  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2158  FCT_TEST_END();
2159 #endif /* POLARSSL_CAMELLIA_C */
2160 
2161 #ifdef POLARSSL_CAMELLIA_C
2162 
2163  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
2164  size_t first_length = 16;
2165  size_t second_length = 0;
2166  size_t length = first_length + second_length;
2167  unsigned char key[32];
2168  unsigned char iv[16];
2169 
2170  cipher_context_t ctx_dec;
2171  cipher_context_t ctx_enc;
2172  const cipher_info_t *cipher_info;
2173 
2174  unsigned char inbuf[64];
2175  unsigned char encbuf[64];
2176  unsigned char decbuf[64];
2177 
2178  size_t outlen = 0;
2179  size_t totaloutlen = 0;
2180  size_t enclen = 0;
2181 
2182  memset( key, 0, 32 );
2183  memset( iv , 0, 16 );
2184 
2185  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2186  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2187 
2188  memset( inbuf, 5, 64 );
2189  memset( encbuf, 0, 64 );
2190  memset( decbuf, 0, 64 );
2191 
2192  /* Initialise enc and dec contexts */
2194  fct_chk( NULL != cipher_info);
2195 
2196  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2197  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2198 
2199  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2200  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2201 
2202  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2203  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2204 
2205  if( POLARSSL_MODE_CBC == cipher_info->mode )
2206  {
2207  enclen = cipher_get_block_size(&ctx_enc )
2208  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2209  }
2210  else
2211  {
2212  enclen = length;
2213  }
2214 
2215  /* encode length number of bytes from inbuf */
2216  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2217  totaloutlen = outlen;
2218  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2219  totaloutlen += outlen;
2220  if( POLARSSL_MODE_CBC == cipher_info->mode )
2221  {
2222  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2223  }
2224  else
2225  {
2226  fct_chk( totaloutlen == enclen );
2227  }
2228  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2229  totaloutlen += outlen;
2230  if( POLARSSL_MODE_CBC == cipher_info->mode )
2231  {
2232  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2233  }
2234  else
2235  {
2236  fct_chk( outlen == 0 );
2237  }
2238 
2239  /* decode the previously encoded string */
2240  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2241  if( POLARSSL_MODE_CBC == cipher_info->mode )
2242  {
2243  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2244  }
2245  else
2246  {
2247  fct_chk( enclen == outlen );
2248  }
2249  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2250  if( POLARSSL_MODE_CBC == cipher_info->mode )
2251  {
2252  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2253  }
2254  else
2255  {
2256  fct_chk( outlen == 0 );
2257  }
2258 
2259 
2260  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2261 
2262  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2263  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2264  FCT_TEST_END();
2265 #endif /* POLARSSL_CAMELLIA_C */
2266 
2267 #ifdef POLARSSL_CAMELLIA_C
2268 
2269  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
2270  size_t first_length = 0;
2271  size_t second_length = 16;
2272  size_t length = first_length + second_length;
2273  unsigned char key[32];
2274  unsigned char iv[16];
2275 
2276  cipher_context_t ctx_dec;
2277  cipher_context_t ctx_enc;
2278  const cipher_info_t *cipher_info;
2279 
2280  unsigned char inbuf[64];
2281  unsigned char encbuf[64];
2282  unsigned char decbuf[64];
2283 
2284  size_t outlen = 0;
2285  size_t totaloutlen = 0;
2286  size_t enclen = 0;
2287 
2288  memset( key, 0, 32 );
2289  memset( iv , 0, 16 );
2290 
2291  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2292  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2293 
2294  memset( inbuf, 5, 64 );
2295  memset( encbuf, 0, 64 );
2296  memset( decbuf, 0, 64 );
2297 
2298  /* Initialise enc and dec contexts */
2300  fct_chk( NULL != cipher_info);
2301 
2302  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2303  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2304 
2305  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2306  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2307 
2308  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2309  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2310 
2311  if( POLARSSL_MODE_CBC == cipher_info->mode )
2312  {
2313  enclen = cipher_get_block_size(&ctx_enc )
2314  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2315  }
2316  else
2317  {
2318  enclen = length;
2319  }
2320 
2321  /* encode length number of bytes from inbuf */
2322  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2323  totaloutlen = outlen;
2324  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2325  totaloutlen += outlen;
2326  if( POLARSSL_MODE_CBC == cipher_info->mode )
2327  {
2328  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2329  }
2330  else
2331  {
2332  fct_chk( totaloutlen == enclen );
2333  }
2334  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2335  totaloutlen += outlen;
2336  if( POLARSSL_MODE_CBC == cipher_info->mode )
2337  {
2338  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2339  }
2340  else
2341  {
2342  fct_chk( outlen == 0 );
2343  }
2344 
2345  /* decode the previously encoded string */
2346  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2347  if( POLARSSL_MODE_CBC == cipher_info->mode )
2348  {
2349  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2350  }
2351  else
2352  {
2353  fct_chk( enclen == outlen );
2354  }
2355  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2356  if( POLARSSL_MODE_CBC == cipher_info->mode )
2357  {
2358  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2359  }
2360  else
2361  {
2362  fct_chk( outlen == 0 );
2363  }
2364 
2365 
2366  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2367 
2368  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2369  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2370  FCT_TEST_END();
2371 #endif /* POLARSSL_CAMELLIA_C */
2372 
2373 #ifdef POLARSSL_CAMELLIA_C
2374 
2375  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
2376  size_t first_length = 1;
2377  size_t second_length = 15;
2378  size_t length = first_length + second_length;
2379  unsigned char key[32];
2380  unsigned char iv[16];
2381 
2382  cipher_context_t ctx_dec;
2383  cipher_context_t ctx_enc;
2384  const cipher_info_t *cipher_info;
2385 
2386  unsigned char inbuf[64];
2387  unsigned char encbuf[64];
2388  unsigned char decbuf[64];
2389 
2390  size_t outlen = 0;
2391  size_t totaloutlen = 0;
2392  size_t enclen = 0;
2393 
2394  memset( key, 0, 32 );
2395  memset( iv , 0, 16 );
2396 
2397  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2398  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2399 
2400  memset( inbuf, 5, 64 );
2401  memset( encbuf, 0, 64 );
2402  memset( decbuf, 0, 64 );
2403 
2404  /* Initialise enc and dec contexts */
2406  fct_chk( NULL != cipher_info);
2407 
2408  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2409  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2410 
2411  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2412  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2413 
2414  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2415  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2416 
2417  if( POLARSSL_MODE_CBC == cipher_info->mode )
2418  {
2419  enclen = cipher_get_block_size(&ctx_enc )
2420  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2421  }
2422  else
2423  {
2424  enclen = length;
2425  }
2426 
2427  /* encode length number of bytes from inbuf */
2428  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2429  totaloutlen = outlen;
2430  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2431  totaloutlen += outlen;
2432  if( POLARSSL_MODE_CBC == cipher_info->mode )
2433  {
2434  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2435  }
2436  else
2437  {
2438  fct_chk( totaloutlen == enclen );
2439  }
2440  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2441  totaloutlen += outlen;
2442  if( POLARSSL_MODE_CBC == cipher_info->mode )
2443  {
2444  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2445  }
2446  else
2447  {
2448  fct_chk( outlen == 0 );
2449  }
2450 
2451  /* decode the previously encoded string */
2452  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2453  if( POLARSSL_MODE_CBC == cipher_info->mode )
2454  {
2455  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2456  }
2457  else
2458  {
2459  fct_chk( enclen == outlen );
2460  }
2461  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2462  if( POLARSSL_MODE_CBC == cipher_info->mode )
2463  {
2464  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2465  }
2466  else
2467  {
2468  fct_chk( outlen == 0 );
2469  }
2470 
2471 
2472  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2473 
2474  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2475  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2476  FCT_TEST_END();
2477 #endif /* POLARSSL_CAMELLIA_C */
2478 
2479 #ifdef POLARSSL_CAMELLIA_C
2480 
2481  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
2482  size_t first_length = 15;
2483  size_t second_length = 1;
2484  size_t length = first_length + second_length;
2485  unsigned char key[32];
2486  unsigned char iv[16];
2487 
2488  cipher_context_t ctx_dec;
2489  cipher_context_t ctx_enc;
2490  const cipher_info_t *cipher_info;
2491 
2492  unsigned char inbuf[64];
2493  unsigned char encbuf[64];
2494  unsigned char decbuf[64];
2495 
2496  size_t outlen = 0;
2497  size_t totaloutlen = 0;
2498  size_t enclen = 0;
2499 
2500  memset( key, 0, 32 );
2501  memset( iv , 0, 16 );
2502 
2503  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2504  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2505 
2506  memset( inbuf, 5, 64 );
2507  memset( encbuf, 0, 64 );
2508  memset( decbuf, 0, 64 );
2509 
2510  /* Initialise enc and dec contexts */
2512  fct_chk( NULL != cipher_info);
2513 
2514  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2515  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2516 
2517  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2518  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2519 
2520  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2521  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2522 
2523  if( POLARSSL_MODE_CBC == cipher_info->mode )
2524  {
2525  enclen = cipher_get_block_size(&ctx_enc )
2526  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2527  }
2528  else
2529  {
2530  enclen = length;
2531  }
2532 
2533  /* encode length number of bytes from inbuf */
2534  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2535  totaloutlen = outlen;
2536  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2537  totaloutlen += outlen;
2538  if( POLARSSL_MODE_CBC == cipher_info->mode )
2539  {
2540  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2541  }
2542  else
2543  {
2544  fct_chk( totaloutlen == enclen );
2545  }
2546  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2547  totaloutlen += outlen;
2548  if( POLARSSL_MODE_CBC == cipher_info->mode )
2549  {
2550  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2551  }
2552  else
2553  {
2554  fct_chk( outlen == 0 );
2555  }
2556 
2557  /* decode the previously encoded string */
2558  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2559  if( POLARSSL_MODE_CBC == cipher_info->mode )
2560  {
2561  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2562  }
2563  else
2564  {
2565  fct_chk( enclen == outlen );
2566  }
2567  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2568  if( POLARSSL_MODE_CBC == cipher_info->mode )
2569  {
2570  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2571  }
2572  else
2573  {
2574  fct_chk( outlen == 0 );
2575  }
2576 
2577 
2578  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2579 
2580  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2581  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2582  FCT_TEST_END();
2583 #endif /* POLARSSL_CAMELLIA_C */
2584 
2585 #ifdef POLARSSL_CAMELLIA_C
2586 
2587  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2588  size_t first_length = 15;
2589  size_t second_length = 7;
2590  size_t length = first_length + second_length;
2591  unsigned char key[32];
2592  unsigned char iv[16];
2593 
2594  cipher_context_t ctx_dec;
2595  cipher_context_t ctx_enc;
2596  const cipher_info_t *cipher_info;
2597 
2598  unsigned char inbuf[64];
2599  unsigned char encbuf[64];
2600  unsigned char decbuf[64];
2601 
2602  size_t outlen = 0;
2603  size_t totaloutlen = 0;
2604  size_t enclen = 0;
2605 
2606  memset( key, 0, 32 );
2607  memset( iv , 0, 16 );
2608 
2609  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2610  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2611 
2612  memset( inbuf, 5, 64 );
2613  memset( encbuf, 0, 64 );
2614  memset( decbuf, 0, 64 );
2615 
2616  /* Initialise enc and dec contexts */
2618  fct_chk( NULL != cipher_info);
2619 
2620  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2621  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2622 
2623  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2624  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2625 
2626  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2627  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2628 
2629  if( POLARSSL_MODE_CBC == cipher_info->mode )
2630  {
2631  enclen = cipher_get_block_size(&ctx_enc )
2632  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2633  }
2634  else
2635  {
2636  enclen = length;
2637  }
2638 
2639  /* encode length number of bytes from inbuf */
2640  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2641  totaloutlen = outlen;
2642  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2643  totaloutlen += outlen;
2644  if( POLARSSL_MODE_CBC == cipher_info->mode )
2645  {
2646  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2647  }
2648  else
2649  {
2650  fct_chk( totaloutlen == enclen );
2651  }
2652  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2653  totaloutlen += outlen;
2654  if( POLARSSL_MODE_CBC == cipher_info->mode )
2655  {
2656  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2657  }
2658  else
2659  {
2660  fct_chk( outlen == 0 );
2661  }
2662 
2663  /* decode the previously encoded string */
2664  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2665  if( POLARSSL_MODE_CBC == cipher_info->mode )
2666  {
2667  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2668  }
2669  else
2670  {
2671  fct_chk( enclen == outlen );
2672  }
2673  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2674  if( POLARSSL_MODE_CBC == cipher_info->mode )
2675  {
2676  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2677  }
2678  else
2679  {
2680  fct_chk( outlen == 0 );
2681  }
2682 
2683 
2684  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2685 
2686  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2687  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2688  FCT_TEST_END();
2689 #endif /* POLARSSL_CAMELLIA_C */
2690 
2691 #ifdef POLARSSL_CAMELLIA_C
2692 
2693  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2694  size_t first_length = 16;
2695  size_t second_length = 6;
2696  size_t length = first_length + second_length;
2697  unsigned char key[32];
2698  unsigned char iv[16];
2699 
2700  cipher_context_t ctx_dec;
2701  cipher_context_t ctx_enc;
2702  const cipher_info_t *cipher_info;
2703 
2704  unsigned char inbuf[64];
2705  unsigned char encbuf[64];
2706  unsigned char decbuf[64];
2707 
2708  size_t outlen = 0;
2709  size_t totaloutlen = 0;
2710  size_t enclen = 0;
2711 
2712  memset( key, 0, 32 );
2713  memset( iv , 0, 16 );
2714 
2715  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2716  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2717 
2718  memset( inbuf, 5, 64 );
2719  memset( encbuf, 0, 64 );
2720  memset( decbuf, 0, 64 );
2721 
2722  /* Initialise enc and dec contexts */
2724  fct_chk( NULL != cipher_info);
2725 
2726  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2727  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2728 
2729  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2730  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2731 
2732  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2733  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2734 
2735  if( POLARSSL_MODE_CBC == cipher_info->mode )
2736  {
2737  enclen = cipher_get_block_size(&ctx_enc )
2738  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2739  }
2740  else
2741  {
2742  enclen = length;
2743  }
2744 
2745  /* encode length number of bytes from inbuf */
2746  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2747  totaloutlen = outlen;
2748  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2749  totaloutlen += outlen;
2750  if( POLARSSL_MODE_CBC == cipher_info->mode )
2751  {
2752  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2753  }
2754  else
2755  {
2756  fct_chk( totaloutlen == enclen );
2757  }
2758  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2759  totaloutlen += outlen;
2760  if( POLARSSL_MODE_CBC == cipher_info->mode )
2761  {
2762  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2763  }
2764  else
2765  {
2766  fct_chk( outlen == 0 );
2767  }
2768 
2769  /* decode the previously encoded string */
2770  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2771  if( POLARSSL_MODE_CBC == cipher_info->mode )
2772  {
2773  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2774  }
2775  else
2776  {
2777  fct_chk( enclen == outlen );
2778  }
2779  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2780  if( POLARSSL_MODE_CBC == cipher_info->mode )
2781  {
2782  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2783  }
2784  else
2785  {
2786  fct_chk( outlen == 0 );
2787  }
2788 
2789 
2790  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2791 
2792  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2793  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2794  FCT_TEST_END();
2795 #endif /* POLARSSL_CAMELLIA_C */
2796 
2797 #ifdef POLARSSL_CAMELLIA_C
2798 
2799  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2800  size_t first_length = 17;
2801  size_t second_length = 6;
2802  size_t length = first_length + second_length;
2803  unsigned char key[32];
2804  unsigned char iv[16];
2805 
2806  cipher_context_t ctx_dec;
2807  cipher_context_t ctx_enc;
2808  const cipher_info_t *cipher_info;
2809 
2810  unsigned char inbuf[64];
2811  unsigned char encbuf[64];
2812  unsigned char decbuf[64];
2813 
2814  size_t outlen = 0;
2815  size_t totaloutlen = 0;
2816  size_t enclen = 0;
2817 
2818  memset( key, 0, 32 );
2819  memset( iv , 0, 16 );
2820 
2821  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2822  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2823 
2824  memset( inbuf, 5, 64 );
2825  memset( encbuf, 0, 64 );
2826  memset( decbuf, 0, 64 );
2827 
2828  /* Initialise enc and dec contexts */
2830  fct_chk( NULL != cipher_info);
2831 
2832  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2833  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2834 
2835  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2836  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2837 
2838  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2839  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2840 
2841  if( POLARSSL_MODE_CBC == cipher_info->mode )
2842  {
2843  enclen = cipher_get_block_size(&ctx_enc )
2844  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2845  }
2846  else
2847  {
2848  enclen = length;
2849  }
2850 
2851  /* encode length number of bytes from inbuf */
2852  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2853  totaloutlen = outlen;
2854  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2855  totaloutlen += outlen;
2856  if( POLARSSL_MODE_CBC == cipher_info->mode )
2857  {
2858  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2859  }
2860  else
2861  {
2862  fct_chk( totaloutlen == enclen );
2863  }
2864  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2865  totaloutlen += outlen;
2866  if( POLARSSL_MODE_CBC == cipher_info->mode )
2867  {
2868  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2869  }
2870  else
2871  {
2872  fct_chk( outlen == 0 );
2873  }
2874 
2875  /* decode the previously encoded string */
2876  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2877  if( POLARSSL_MODE_CBC == cipher_info->mode )
2878  {
2879  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2880  }
2881  else
2882  {
2883  fct_chk( enclen == outlen );
2884  }
2885  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2886  if( POLARSSL_MODE_CBC == cipher_info->mode )
2887  {
2888  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2889  }
2890  else
2891  {
2892  fct_chk( outlen == 0 );
2893  }
2894 
2895 
2896  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2897 
2898  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
2899  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
2900  FCT_TEST_END();
2901 #endif /* POLARSSL_CAMELLIA_C */
2902 
2903 #ifdef POLARSSL_CAMELLIA_C
2904 
2905  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
2906  size_t first_length = 16;
2907  size_t second_length = 16;
2908  size_t length = first_length + second_length;
2909  unsigned char key[32];
2910  unsigned char iv[16];
2911 
2912  cipher_context_t ctx_dec;
2913  cipher_context_t ctx_enc;
2914  const cipher_info_t *cipher_info;
2915 
2916  unsigned char inbuf[64];
2917  unsigned char encbuf[64];
2918  unsigned char decbuf[64];
2919 
2920  size_t outlen = 0;
2921  size_t totaloutlen = 0;
2922  size_t enclen = 0;
2923 
2924  memset( key, 0, 32 );
2925  memset( iv , 0, 16 );
2926 
2927  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
2928  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
2929 
2930  memset( inbuf, 5, 64 );
2931  memset( encbuf, 0, 64 );
2932  memset( decbuf, 0, 64 );
2933 
2934  /* Initialise enc and dec contexts */
2936  fct_chk( NULL != cipher_info);
2937 
2938  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
2939  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
2940 
2941  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
2942  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
2943 
2944  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
2945  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
2946 
2947  if( POLARSSL_MODE_CBC == cipher_info->mode )
2948  {
2949  enclen = cipher_get_block_size(&ctx_enc )
2950  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
2951  }
2952  else
2953  {
2954  enclen = length;
2955  }
2956 
2957  /* encode length number of bytes from inbuf */
2958  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2959  totaloutlen = outlen;
2960  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2961  totaloutlen += outlen;
2962  if( POLARSSL_MODE_CBC == cipher_info->mode )
2963  {
2964  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
2965  }
2966  else
2967  {
2968  fct_chk( totaloutlen == enclen );
2969  }
2970  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2971  totaloutlen += outlen;
2972  if( POLARSSL_MODE_CBC == cipher_info->mode )
2973  {
2974  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
2975  }
2976  else
2977  {
2978  fct_chk( outlen == 0 );
2979  }
2980 
2981  /* decode the previously encoded string */
2982  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2983  if( POLARSSL_MODE_CBC == cipher_info->mode )
2984  {
2985  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
2986  }
2987  else
2988  {
2989  fct_chk( enclen == outlen );
2990  }
2991  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2992  if( POLARSSL_MODE_CBC == cipher_info->mode )
2993  {
2994  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
2995  }
2996  else
2997  {
2998  fct_chk( outlen == 0 );
2999  }
3000 
3001 
3002  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3003 
3004  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3005  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3006  FCT_TEST_END();
3007 #endif /* POLARSSL_CAMELLIA_C */
3008 
3009 #ifdef POLARSSL_CAMELLIA_C
3010 #ifdef POLARSSL_CIPHER_MODE_CFB
3011 
3012  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes)
3013  size_t length = 0;
3014  unsigned char key[32];
3015  unsigned char iv[16];
3016 
3017  const cipher_info_t *cipher_info;
3018  cipher_context_t ctx_dec;
3019  cipher_context_t ctx_enc;
3020 
3021  unsigned char inbuf[64];
3022  unsigned char encbuf[64];
3023  unsigned char decbuf[64];
3024 
3025  size_t outlen = 0;
3026  size_t enclen = 0;
3027 
3028  memset( key, 0, 32 );
3029  memset( iv , 0, 16 );
3030 
3031  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3032  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3033 
3034  memset( inbuf, 5, 64 );
3035  memset( encbuf, 0, 64 );
3036  memset( decbuf, 0, 64 );
3037 
3038  /* Check and get info structures */
3040  fct_chk( NULL != cipher_info );
3041  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3042 
3043  /* Initialise enc and dec contexts */
3044  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3045  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3046 
3047  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3048  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3049 
3050  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3051  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3052 
3053  if( POLARSSL_MODE_CBC == cipher_info->mode )
3054  {
3055  enclen = cipher_get_block_size( &ctx_enc )
3056  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3057  }
3058  else
3059  {
3060  enclen = length;
3061  }
3062 
3063  /* encode length number of bytes from inbuf */
3064  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3065  if( POLARSSL_MODE_CBC == cipher_info->mode )
3066  {
3067  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3068  }
3069  else
3070  {
3071  fct_chk( outlen == enclen );
3072  }
3073 
3074  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3075  if( POLARSSL_MODE_CBC == cipher_info->mode )
3076  {
3077  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3078  }
3079  else
3080  {
3081  fct_chk( outlen == 0 );
3082  }
3083 
3084 
3085  /* decode the previously encoded string */
3086  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3087  if( POLARSSL_MODE_CBC == cipher_info->mode )
3088  {
3089  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3090  }
3091  else
3092  {
3093  fct_chk( enclen == outlen );
3094  }
3095 
3096  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3097  if( POLARSSL_MODE_CBC == cipher_info->mode )
3098  {
3099  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3100  }
3101  else
3102  {
3103  fct_chk( outlen == 0 );
3104  }
3105 
3106 
3107  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3108 
3109  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3110  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3111  FCT_TEST_END();
3112 #endif /* POLARSSL_CAMELLIA_C */
3113 #endif /* POLARSSL_CIPHER_MODE_CFB */
3114 
3115 #ifdef POLARSSL_CAMELLIA_C
3116 #ifdef POLARSSL_CIPHER_MODE_CFB
3117 
3118  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_byte)
3119  size_t length = 1;
3120  unsigned char key[32];
3121  unsigned char iv[16];
3122 
3123  const cipher_info_t *cipher_info;
3124  cipher_context_t ctx_dec;
3125  cipher_context_t ctx_enc;
3126 
3127  unsigned char inbuf[64];
3128  unsigned char encbuf[64];
3129  unsigned char decbuf[64];
3130 
3131  size_t outlen = 0;
3132  size_t enclen = 0;
3133 
3134  memset( key, 0, 32 );
3135  memset( iv , 0, 16 );
3136 
3137  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3138  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3139 
3140  memset( inbuf, 5, 64 );
3141  memset( encbuf, 0, 64 );
3142  memset( decbuf, 0, 64 );
3143 
3144  /* Check and get info structures */
3146  fct_chk( NULL != cipher_info );
3147  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3148 
3149  /* Initialise enc and dec contexts */
3150  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3151  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3152 
3153  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3154  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3155 
3156  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3157  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3158 
3159  if( POLARSSL_MODE_CBC == cipher_info->mode )
3160  {
3161  enclen = cipher_get_block_size( &ctx_enc )
3162  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3163  }
3164  else
3165  {
3166  enclen = length;
3167  }
3168 
3169  /* encode length number of bytes from inbuf */
3170  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3171  if( POLARSSL_MODE_CBC == cipher_info->mode )
3172  {
3173  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3174  }
3175  else
3176  {
3177  fct_chk( outlen == enclen );
3178  }
3179 
3180  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3181  if( POLARSSL_MODE_CBC == cipher_info->mode )
3182  {
3183  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3184  }
3185  else
3186  {
3187  fct_chk( outlen == 0 );
3188  }
3189 
3190 
3191  /* decode the previously encoded string */
3192  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3193  if( POLARSSL_MODE_CBC == cipher_info->mode )
3194  {
3195  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3196  }
3197  else
3198  {
3199  fct_chk( enclen == outlen );
3200  }
3201 
3202  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3203  if( POLARSSL_MODE_CBC == cipher_info->mode )
3204  {
3205  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3206  }
3207  else
3208  {
3209  fct_chk( outlen == 0 );
3210  }
3211 
3212 
3213  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3214 
3215  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3216  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3217  FCT_TEST_END();
3218 #endif /* POLARSSL_CAMELLIA_C */
3219 #endif /* POLARSSL_CIPHER_MODE_CFB */
3220 
3221 #ifdef POLARSSL_CAMELLIA_C
3222 #ifdef POLARSSL_CIPHER_MODE_CFB
3223 
3224  FCT_TEST_BGN(camellia_encrypt_and_decrypt_2_bytes)
3225  size_t length = 2;
3226  unsigned char key[32];
3227  unsigned char iv[16];
3228 
3229  const cipher_info_t *cipher_info;
3230  cipher_context_t ctx_dec;
3231  cipher_context_t ctx_enc;
3232 
3233  unsigned char inbuf[64];
3234  unsigned char encbuf[64];
3235  unsigned char decbuf[64];
3236 
3237  size_t outlen = 0;
3238  size_t enclen = 0;
3239 
3240  memset( key, 0, 32 );
3241  memset( iv , 0, 16 );
3242 
3243  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3244  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3245 
3246  memset( inbuf, 5, 64 );
3247  memset( encbuf, 0, 64 );
3248  memset( decbuf, 0, 64 );
3249 
3250  /* Check and get info structures */
3252  fct_chk( NULL != cipher_info );
3253  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3254 
3255  /* Initialise enc and dec contexts */
3256  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3257  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3258 
3259  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3260  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3261 
3262  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3263  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3264 
3265  if( POLARSSL_MODE_CBC == cipher_info->mode )
3266  {
3267  enclen = cipher_get_block_size( &ctx_enc )
3268  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3269  }
3270  else
3271  {
3272  enclen = length;
3273  }
3274 
3275  /* encode length number of bytes from inbuf */
3276  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3277  if( POLARSSL_MODE_CBC == cipher_info->mode )
3278  {
3279  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3280  }
3281  else
3282  {
3283  fct_chk( outlen == enclen );
3284  }
3285 
3286  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3287  if( POLARSSL_MODE_CBC == cipher_info->mode )
3288  {
3289  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3290  }
3291  else
3292  {
3293  fct_chk( outlen == 0 );
3294  }
3295 
3296 
3297  /* decode the previously encoded string */
3298  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3299  if( POLARSSL_MODE_CBC == cipher_info->mode )
3300  {
3301  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3302  }
3303  else
3304  {
3305  fct_chk( enclen == outlen );
3306  }
3307 
3308  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3309  if( POLARSSL_MODE_CBC == cipher_info->mode )
3310  {
3311  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3312  }
3313  else
3314  {
3315  fct_chk( outlen == 0 );
3316  }
3317 
3318 
3319  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3320 
3321  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3322  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3323  FCT_TEST_END();
3324 #endif /* POLARSSL_CAMELLIA_C */
3325 #endif /* POLARSSL_CIPHER_MODE_CFB */
3326 
3327 #ifdef POLARSSL_CAMELLIA_C
3328 #ifdef POLARSSL_CIPHER_MODE_CFB
3329 
3330  FCT_TEST_BGN(camellia_encrypt_and_decrypt_7_bytes)
3331  size_t length = 7;
3332  unsigned char key[32];
3333  unsigned char iv[16];
3334 
3335  const cipher_info_t *cipher_info;
3336  cipher_context_t ctx_dec;
3337  cipher_context_t ctx_enc;
3338 
3339  unsigned char inbuf[64];
3340  unsigned char encbuf[64];
3341  unsigned char decbuf[64];
3342 
3343  size_t outlen = 0;
3344  size_t enclen = 0;
3345 
3346  memset( key, 0, 32 );
3347  memset( iv , 0, 16 );
3348 
3349  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3350  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3351 
3352  memset( inbuf, 5, 64 );
3353  memset( encbuf, 0, 64 );
3354  memset( decbuf, 0, 64 );
3355 
3356  /* Check and get info structures */
3358  fct_chk( NULL != cipher_info );
3359  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3360 
3361  /* Initialise enc and dec contexts */
3362  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3363  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3364 
3365  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3366  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3367 
3368  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3369  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3370 
3371  if( POLARSSL_MODE_CBC == cipher_info->mode )
3372  {
3373  enclen = cipher_get_block_size( &ctx_enc )
3374  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3375  }
3376  else
3377  {
3378  enclen = length;
3379  }
3380 
3381  /* encode length number of bytes from inbuf */
3382  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3383  if( POLARSSL_MODE_CBC == cipher_info->mode )
3384  {
3385  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3386  }
3387  else
3388  {
3389  fct_chk( outlen == enclen );
3390  }
3391 
3392  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3393  if( POLARSSL_MODE_CBC == cipher_info->mode )
3394  {
3395  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3396  }
3397  else
3398  {
3399  fct_chk( outlen == 0 );
3400  }
3401 
3402 
3403  /* decode the previously encoded string */
3404  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3405  if( POLARSSL_MODE_CBC == cipher_info->mode )
3406  {
3407  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3408  }
3409  else
3410  {
3411  fct_chk( enclen == outlen );
3412  }
3413 
3414  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3415  if( POLARSSL_MODE_CBC == cipher_info->mode )
3416  {
3417  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3418  }
3419  else
3420  {
3421  fct_chk( outlen == 0 );
3422  }
3423 
3424 
3425  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3426 
3427  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3428  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3429  FCT_TEST_END();
3430 #endif /* POLARSSL_CAMELLIA_C */
3431 #endif /* POLARSSL_CIPHER_MODE_CFB */
3432 
3433 #ifdef POLARSSL_CAMELLIA_C
3434 #ifdef POLARSSL_CIPHER_MODE_CFB
3435 
3436  FCT_TEST_BGN(camellia_encrypt_and_decrypt_8_bytes)
3437  size_t length = 8;
3438  unsigned char key[32];
3439  unsigned char iv[16];
3440 
3441  const cipher_info_t *cipher_info;
3442  cipher_context_t ctx_dec;
3443  cipher_context_t ctx_enc;
3444 
3445  unsigned char inbuf[64];
3446  unsigned char encbuf[64];
3447  unsigned char decbuf[64];
3448 
3449  size_t outlen = 0;
3450  size_t enclen = 0;
3451 
3452  memset( key, 0, 32 );
3453  memset( iv , 0, 16 );
3454 
3455  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3456  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3457 
3458  memset( inbuf, 5, 64 );
3459  memset( encbuf, 0, 64 );
3460  memset( decbuf, 0, 64 );
3461 
3462  /* Check and get info structures */
3464  fct_chk( NULL != cipher_info );
3465  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3466 
3467  /* Initialise enc and dec contexts */
3468  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3469  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3470 
3471  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3472  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3473 
3474  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3475  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3476 
3477  if( POLARSSL_MODE_CBC == cipher_info->mode )
3478  {
3479  enclen = cipher_get_block_size( &ctx_enc )
3480  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3481  }
3482  else
3483  {
3484  enclen = length;
3485  }
3486 
3487  /* encode length number of bytes from inbuf */
3488  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3489  if( POLARSSL_MODE_CBC == cipher_info->mode )
3490  {
3491  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3492  }
3493  else
3494  {
3495  fct_chk( outlen == enclen );
3496  }
3497 
3498  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3499  if( POLARSSL_MODE_CBC == cipher_info->mode )
3500  {
3501  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3502  }
3503  else
3504  {
3505  fct_chk( outlen == 0 );
3506  }
3507 
3508 
3509  /* decode the previously encoded string */
3510  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3511  if( POLARSSL_MODE_CBC == cipher_info->mode )
3512  {
3513  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3514  }
3515  else
3516  {
3517  fct_chk( enclen == outlen );
3518  }
3519 
3520  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3521  if( POLARSSL_MODE_CBC == cipher_info->mode )
3522  {
3523  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3524  }
3525  else
3526  {
3527  fct_chk( outlen == 0 );
3528  }
3529 
3530 
3531  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3532 
3533  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3534  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3535  FCT_TEST_END();
3536 #endif /* POLARSSL_CAMELLIA_C */
3537 #endif /* POLARSSL_CIPHER_MODE_CFB */
3538 
3539 #ifdef POLARSSL_CAMELLIA_C
3540 #ifdef POLARSSL_CIPHER_MODE_CFB
3541 
3542  FCT_TEST_BGN(camellia_encrypt_and_decrypt_9_bytes)
3543  size_t length = 9;
3544  unsigned char key[32];
3545  unsigned char iv[16];
3546 
3547  const cipher_info_t *cipher_info;
3548  cipher_context_t ctx_dec;
3549  cipher_context_t ctx_enc;
3550 
3551  unsigned char inbuf[64];
3552  unsigned char encbuf[64];
3553  unsigned char decbuf[64];
3554 
3555  size_t outlen = 0;
3556  size_t enclen = 0;
3557 
3558  memset( key, 0, 32 );
3559  memset( iv , 0, 16 );
3560 
3561  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3562  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3563 
3564  memset( inbuf, 5, 64 );
3565  memset( encbuf, 0, 64 );
3566  memset( decbuf, 0, 64 );
3567 
3568  /* Check and get info structures */
3570  fct_chk( NULL != cipher_info );
3571  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3572 
3573  /* Initialise enc and dec contexts */
3574  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3575  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3576 
3577  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3578  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3579 
3580  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3581  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3582 
3583  if( POLARSSL_MODE_CBC == cipher_info->mode )
3584  {
3585  enclen = cipher_get_block_size( &ctx_enc )
3586  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3587  }
3588  else
3589  {
3590  enclen = length;
3591  }
3592 
3593  /* encode length number of bytes from inbuf */
3594  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3595  if( POLARSSL_MODE_CBC == cipher_info->mode )
3596  {
3597  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3598  }
3599  else
3600  {
3601  fct_chk( outlen == enclen );
3602  }
3603 
3604  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3605  if( POLARSSL_MODE_CBC == cipher_info->mode )
3606  {
3607  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3608  }
3609  else
3610  {
3611  fct_chk( outlen == 0 );
3612  }
3613 
3614 
3615  /* decode the previously encoded string */
3616  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3617  if( POLARSSL_MODE_CBC == cipher_info->mode )
3618  {
3619  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3620  }
3621  else
3622  {
3623  fct_chk( enclen == outlen );
3624  }
3625 
3626  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3627  if( POLARSSL_MODE_CBC == cipher_info->mode )
3628  {
3629  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3630  }
3631  else
3632  {
3633  fct_chk( outlen == 0 );
3634  }
3635 
3636 
3637  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3638 
3639  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3640  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3641  FCT_TEST_END();
3642 #endif /* POLARSSL_CAMELLIA_C */
3643 #endif /* POLARSSL_CIPHER_MODE_CFB */
3644 
3645 #ifdef POLARSSL_CAMELLIA_C
3646 #ifdef POLARSSL_CIPHER_MODE_CFB
3647 
3648  FCT_TEST_BGN(camellia_encrypt_and_decrypt_15_bytes)
3649  size_t length = 15;
3650  unsigned char key[32];
3651  unsigned char iv[16];
3652 
3653  const cipher_info_t *cipher_info;
3654  cipher_context_t ctx_dec;
3655  cipher_context_t ctx_enc;
3656 
3657  unsigned char inbuf[64];
3658  unsigned char encbuf[64];
3659  unsigned char decbuf[64];
3660 
3661  size_t outlen = 0;
3662  size_t enclen = 0;
3663 
3664  memset( key, 0, 32 );
3665  memset( iv , 0, 16 );
3666 
3667  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3668  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3669 
3670  memset( inbuf, 5, 64 );
3671  memset( encbuf, 0, 64 );
3672  memset( decbuf, 0, 64 );
3673 
3674  /* Check and get info structures */
3676  fct_chk( NULL != cipher_info );
3677  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3678 
3679  /* Initialise enc and dec contexts */
3680  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3681  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3682 
3683  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3684  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3685 
3686  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3687  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3688 
3689  if( POLARSSL_MODE_CBC == cipher_info->mode )
3690  {
3691  enclen = cipher_get_block_size( &ctx_enc )
3692  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3693  }
3694  else
3695  {
3696  enclen = length;
3697  }
3698 
3699  /* encode length number of bytes from inbuf */
3700  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3701  if( POLARSSL_MODE_CBC == cipher_info->mode )
3702  {
3703  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3704  }
3705  else
3706  {
3707  fct_chk( outlen == enclen );
3708  }
3709 
3710  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3711  if( POLARSSL_MODE_CBC == cipher_info->mode )
3712  {
3713  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3714  }
3715  else
3716  {
3717  fct_chk( outlen == 0 );
3718  }
3719 
3720 
3721  /* decode the previously encoded string */
3722  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3723  if( POLARSSL_MODE_CBC == cipher_info->mode )
3724  {
3725  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3726  }
3727  else
3728  {
3729  fct_chk( enclen == outlen );
3730  }
3731 
3732  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3733  if( POLARSSL_MODE_CBC == cipher_info->mode )
3734  {
3735  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3736  }
3737  else
3738  {
3739  fct_chk( outlen == 0 );
3740  }
3741 
3742 
3743  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3744 
3745  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3746  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3747  FCT_TEST_END();
3748 #endif /* POLARSSL_CAMELLIA_C */
3749 #endif /* POLARSSL_CIPHER_MODE_CFB */
3750 
3751 #ifdef POLARSSL_CAMELLIA_C
3752 #ifdef POLARSSL_CIPHER_MODE_CFB
3753 
3754  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes)
3755  size_t length = 16;
3756  unsigned char key[32];
3757  unsigned char iv[16];
3758 
3759  const cipher_info_t *cipher_info;
3760  cipher_context_t ctx_dec;
3761  cipher_context_t ctx_enc;
3762 
3763  unsigned char inbuf[64];
3764  unsigned char encbuf[64];
3765  unsigned char decbuf[64];
3766 
3767  size_t outlen = 0;
3768  size_t enclen = 0;
3769 
3770  memset( key, 0, 32 );
3771  memset( iv , 0, 16 );
3772 
3773  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3774  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3775 
3776  memset( inbuf, 5, 64 );
3777  memset( encbuf, 0, 64 );
3778  memset( decbuf, 0, 64 );
3779 
3780  /* Check and get info structures */
3782  fct_chk( NULL != cipher_info );
3783  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3784 
3785  /* Initialise enc and dec contexts */
3786  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3787  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3788 
3789  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3790  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3791 
3792  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3793  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3794 
3795  if( POLARSSL_MODE_CBC == cipher_info->mode )
3796  {
3797  enclen = cipher_get_block_size( &ctx_enc )
3798  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3799  }
3800  else
3801  {
3802  enclen = length;
3803  }
3804 
3805  /* encode length number of bytes from inbuf */
3806  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3807  if( POLARSSL_MODE_CBC == cipher_info->mode )
3808  {
3809  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3810  }
3811  else
3812  {
3813  fct_chk( outlen == enclen );
3814  }
3815 
3816  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3817  if( POLARSSL_MODE_CBC == cipher_info->mode )
3818  {
3819  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3820  }
3821  else
3822  {
3823  fct_chk( outlen == 0 );
3824  }
3825 
3826 
3827  /* decode the previously encoded string */
3828  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3829  if( POLARSSL_MODE_CBC == cipher_info->mode )
3830  {
3831  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3832  }
3833  else
3834  {
3835  fct_chk( enclen == outlen );
3836  }
3837 
3838  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3839  if( POLARSSL_MODE_CBC == cipher_info->mode )
3840  {
3841  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3842  }
3843  else
3844  {
3845  fct_chk( outlen == 0 );
3846  }
3847 
3848 
3849  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3850 
3851  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3852  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3853  FCT_TEST_END();
3854 #endif /* POLARSSL_CAMELLIA_C */
3855 #endif /* POLARSSL_CIPHER_MODE_CFB */
3856 
3857 #ifdef POLARSSL_CAMELLIA_C
3858 #ifdef POLARSSL_CIPHER_MODE_CFB
3859 
3860  FCT_TEST_BGN(camellia_encrypt_and_decrypt_17_bytes)
3861  size_t length = 17;
3862  unsigned char key[32];
3863  unsigned char iv[16];
3864 
3865  const cipher_info_t *cipher_info;
3866  cipher_context_t ctx_dec;
3867  cipher_context_t ctx_enc;
3868 
3869  unsigned char inbuf[64];
3870  unsigned char encbuf[64];
3871  unsigned char decbuf[64];
3872 
3873  size_t outlen = 0;
3874  size_t enclen = 0;
3875 
3876  memset( key, 0, 32 );
3877  memset( iv , 0, 16 );
3878 
3879  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3880  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3881 
3882  memset( inbuf, 5, 64 );
3883  memset( encbuf, 0, 64 );
3884  memset( decbuf, 0, 64 );
3885 
3886  /* Check and get info structures */
3888  fct_chk( NULL != cipher_info );
3889  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3890 
3891  /* Initialise enc and dec contexts */
3892  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3893  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
3894 
3895  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
3896  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
3897 
3898  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
3899  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
3900 
3901  if( POLARSSL_MODE_CBC == cipher_info->mode )
3902  {
3903  enclen = cipher_get_block_size( &ctx_enc )
3904  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
3905  }
3906  else
3907  {
3908  enclen = length;
3909  }
3910 
3911  /* encode length number of bytes from inbuf */
3912  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
3913  if( POLARSSL_MODE_CBC == cipher_info->mode )
3914  {
3915  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
3916  }
3917  else
3918  {
3919  fct_chk( outlen == enclen );
3920  }
3921 
3922  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
3923  if( POLARSSL_MODE_CBC == cipher_info->mode )
3924  {
3925  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
3926  }
3927  else
3928  {
3929  fct_chk( outlen == 0 );
3930  }
3931 
3932 
3933  /* decode the previously encoded string */
3934  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
3935  if( POLARSSL_MODE_CBC == cipher_info->mode )
3936  {
3937  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
3938  }
3939  else
3940  {
3941  fct_chk( enclen == outlen );
3942  }
3943 
3944  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
3945  if( POLARSSL_MODE_CBC == cipher_info->mode )
3946  {
3947  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
3948  }
3949  else
3950  {
3951  fct_chk( outlen == 0 );
3952  }
3953 
3954 
3955  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
3956 
3957  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
3958  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
3959  FCT_TEST_END();
3960 #endif /* POLARSSL_CAMELLIA_C */
3961 #endif /* POLARSSL_CIPHER_MODE_CFB */
3962 
3963 #ifdef POLARSSL_CAMELLIA_C
3964 #ifdef POLARSSL_CIPHER_MODE_CFB
3965 
3966  FCT_TEST_BGN(camellia_encrypt_and_decrypt_31_bytes)
3967  size_t length = 31;
3968  unsigned char key[32];
3969  unsigned char iv[16];
3970 
3971  const cipher_info_t *cipher_info;
3972  cipher_context_t ctx_dec;
3973  cipher_context_t ctx_enc;
3974 
3975  unsigned char inbuf[64];
3976  unsigned char encbuf[64];
3977  unsigned char decbuf[64];
3978 
3979  size_t outlen = 0;
3980  size_t enclen = 0;
3981 
3982  memset( key, 0, 32 );
3983  memset( iv , 0, 16 );
3984 
3985  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
3986  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
3987 
3988  memset( inbuf, 5, 64 );
3989  memset( encbuf, 0, 64 );
3990  memset( decbuf, 0, 64 );
3991 
3992  /* Check and get info structures */
3994  fct_chk( NULL != cipher_info );
3995  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
3996 
3997  /* Initialise enc and dec contexts */
3998  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
3999  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4000 
4001  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4002  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4003 
4004  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4005  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4006 
4007  if( POLARSSL_MODE_CBC == cipher_info->mode )
4008  {
4009  enclen = cipher_get_block_size( &ctx_enc )
4010  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4011  }
4012  else
4013  {
4014  enclen = length;
4015  }
4016 
4017  /* encode length number of bytes from inbuf */
4018  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
4019  if( POLARSSL_MODE_CBC == cipher_info->mode )
4020  {
4021  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4022  }
4023  else
4024  {
4025  fct_chk( outlen == enclen );
4026  }
4027 
4028  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
4029  if( POLARSSL_MODE_CBC == cipher_info->mode )
4030  {
4031  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4032  }
4033  else
4034  {
4035  fct_chk( outlen == 0 );
4036  }
4037 
4038 
4039  /* decode the previously encoded string */
4040  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4041  if( POLARSSL_MODE_CBC == cipher_info->mode )
4042  {
4043  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4044  }
4045  else
4046  {
4047  fct_chk( enclen == outlen );
4048  }
4049 
4050  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4051  if( POLARSSL_MODE_CBC == cipher_info->mode )
4052  {
4053  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4054  }
4055  else
4056  {
4057  fct_chk( outlen == 0 );
4058  }
4059 
4060 
4061  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4062 
4063  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4064  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4065  FCT_TEST_END();
4066 #endif /* POLARSSL_CAMELLIA_C */
4067 #endif /* POLARSSL_CIPHER_MODE_CFB */
4068 
4069 #ifdef POLARSSL_CAMELLIA_C
4070 #ifdef POLARSSL_CIPHER_MODE_CFB
4071 
4072  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
4073  size_t length = 32;
4074  unsigned char key[32];
4075  unsigned char iv[16];
4076 
4077  const cipher_info_t *cipher_info;
4078  cipher_context_t ctx_dec;
4079  cipher_context_t ctx_enc;
4080 
4081  unsigned char inbuf[64];
4082  unsigned char encbuf[64];
4083  unsigned char decbuf[64];
4084 
4085  size_t outlen = 0;
4086  size_t enclen = 0;
4087 
4088  memset( key, 0, 32 );
4089  memset( iv , 0, 16 );
4090 
4091  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4092  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4093 
4094  memset( inbuf, 5, 64 );
4095  memset( encbuf, 0, 64 );
4096  memset( decbuf, 0, 64 );
4097 
4098  /* Check and get info structures */
4100  fct_chk( NULL != cipher_info );
4101  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
4102 
4103  /* Initialise enc and dec contexts */
4104  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4105  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4106 
4107  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4108  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4109 
4110  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4111  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4112 
4113  if( POLARSSL_MODE_CBC == cipher_info->mode )
4114  {
4115  enclen = cipher_get_block_size( &ctx_enc )
4116  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4117  }
4118  else
4119  {
4120  enclen = length;
4121  }
4122 
4123  /* encode length number of bytes from inbuf */
4124  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
4125  if( POLARSSL_MODE_CBC == cipher_info->mode )
4126  {
4127  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4128  }
4129  else
4130  {
4131  fct_chk( outlen == enclen );
4132  }
4133 
4134  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
4135  if( POLARSSL_MODE_CBC == cipher_info->mode )
4136  {
4137  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4138  }
4139  else
4140  {
4141  fct_chk( outlen == 0 );
4142  }
4143 
4144 
4145  /* decode the previously encoded string */
4146  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4147  if( POLARSSL_MODE_CBC == cipher_info->mode )
4148  {
4149  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4150  }
4151  else
4152  {
4153  fct_chk( enclen == outlen );
4154  }
4155 
4156  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4157  if( POLARSSL_MODE_CBC == cipher_info->mode )
4158  {
4159  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4160  }
4161  else
4162  {
4163  fct_chk( outlen == 0 );
4164  }
4165 
4166 
4167  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4168 
4169  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4170  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4171  FCT_TEST_END();
4172 #endif /* POLARSSL_CAMELLIA_C */
4173 #endif /* POLARSSL_CIPHER_MODE_CFB */
4174 
4175 #ifdef POLARSSL_CAMELLIA_C
4176 #ifdef POLARSSL_CIPHER_MODE_CFB
4177 
4178  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
4179  size_t length = 33;
4180  unsigned char key[32];
4181  unsigned char iv[16];
4182 
4183  const cipher_info_t *cipher_info;
4184  cipher_context_t ctx_dec;
4185  cipher_context_t ctx_enc;
4186 
4187  unsigned char inbuf[64];
4188  unsigned char encbuf[64];
4189  unsigned char decbuf[64];
4190 
4191  size_t outlen = 0;
4192  size_t enclen = 0;
4193 
4194  memset( key, 0, 32 );
4195  memset( iv , 0, 16 );
4196 
4197  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4198  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4199 
4200  memset( inbuf, 5, 64 );
4201  memset( encbuf, 0, 64 );
4202  memset( decbuf, 0, 64 );
4203 
4204  /* Check and get info structures */
4206  fct_chk( NULL != cipher_info );
4207  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
4208 
4209  /* Initialise enc and dec contexts */
4210  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4211  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4212 
4213  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4214  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4215 
4216  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4217  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4218 
4219  if( POLARSSL_MODE_CBC == cipher_info->mode )
4220  {
4221  enclen = cipher_get_block_size( &ctx_enc )
4222  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4223  }
4224  else
4225  {
4226  enclen = length;
4227  }
4228 
4229  /* encode length number of bytes from inbuf */
4230  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
4231  if( POLARSSL_MODE_CBC == cipher_info->mode )
4232  {
4233  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4234  }
4235  else
4236  {
4237  fct_chk( outlen == enclen );
4238  }
4239 
4240  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
4241  if( POLARSSL_MODE_CBC == cipher_info->mode )
4242  {
4243  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4244  }
4245  else
4246  {
4247  fct_chk( outlen == 0 );
4248  }
4249 
4250 
4251  /* decode the previously encoded string */
4252  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4253  if( POLARSSL_MODE_CBC == cipher_info->mode )
4254  {
4255  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4256  }
4257  else
4258  {
4259  fct_chk( enclen == outlen );
4260  }
4261 
4262  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4263  if( POLARSSL_MODE_CBC == cipher_info->mode )
4264  {
4265  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4266  }
4267  else
4268  {
4269  fct_chk( outlen == 0 );
4270  }
4271 
4272 
4273  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4274 
4275  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4276  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4277  FCT_TEST_END();
4278 #endif /* POLARSSL_CAMELLIA_C */
4279 #endif /* POLARSSL_CIPHER_MODE_CFB */
4280 
4281 #ifdef POLARSSL_CAMELLIA_C
4282 #ifdef POLARSSL_CIPHER_MODE_CFB
4283 
4284  FCT_TEST_BGN(camellia_encrypt_and_decrypt_47_bytes)
4285  size_t length = 47;
4286  unsigned char key[32];
4287  unsigned char iv[16];
4288 
4289  const cipher_info_t *cipher_info;
4290  cipher_context_t ctx_dec;
4291  cipher_context_t ctx_enc;
4292 
4293  unsigned char inbuf[64];
4294  unsigned char encbuf[64];
4295  unsigned char decbuf[64];
4296 
4297  size_t outlen = 0;
4298  size_t enclen = 0;
4299 
4300  memset( key, 0, 32 );
4301  memset( iv , 0, 16 );
4302 
4303  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4304  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4305 
4306  memset( inbuf, 5, 64 );
4307  memset( encbuf, 0, 64 );
4308  memset( decbuf, 0, 64 );
4309 
4310  /* Check and get info structures */
4312  fct_chk( NULL != cipher_info );
4313  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
4314 
4315  /* Initialise enc and dec contexts */
4316  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4317  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4318 
4319  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4320  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4321 
4322  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4323  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4324 
4325  if( POLARSSL_MODE_CBC == cipher_info->mode )
4326  {
4327  enclen = cipher_get_block_size( &ctx_enc )
4328  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4329  }
4330  else
4331  {
4332  enclen = length;
4333  }
4334 
4335  /* encode length number of bytes from inbuf */
4336  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
4337  if( POLARSSL_MODE_CBC == cipher_info->mode )
4338  {
4339  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4340  }
4341  else
4342  {
4343  fct_chk( outlen == enclen );
4344  }
4345 
4346  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
4347  if( POLARSSL_MODE_CBC == cipher_info->mode )
4348  {
4349  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4350  }
4351  else
4352  {
4353  fct_chk( outlen == 0 );
4354  }
4355 
4356 
4357  /* decode the previously encoded string */
4358  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4359  if( POLARSSL_MODE_CBC == cipher_info->mode )
4360  {
4361  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4362  }
4363  else
4364  {
4365  fct_chk( enclen == outlen );
4366  }
4367 
4368  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4369  if( POLARSSL_MODE_CBC == cipher_info->mode )
4370  {
4371  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4372  }
4373  else
4374  {
4375  fct_chk( outlen == 0 );
4376  }
4377 
4378 
4379  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4380 
4381  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4382  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4383  FCT_TEST_END();
4384 #endif /* POLARSSL_CAMELLIA_C */
4385 #endif /* POLARSSL_CIPHER_MODE_CFB */
4386 
4387 #ifdef POLARSSL_CAMELLIA_C
4388 #ifdef POLARSSL_CIPHER_MODE_CFB
4389 
4390  FCT_TEST_BGN(camellia_encrypt_and_decrypt_48_bytes)
4391  size_t length = 48;
4392  unsigned char key[32];
4393  unsigned char iv[16];
4394 
4395  const cipher_info_t *cipher_info;
4396  cipher_context_t ctx_dec;
4397  cipher_context_t ctx_enc;
4398 
4399  unsigned char inbuf[64];
4400  unsigned char encbuf[64];
4401  unsigned char decbuf[64];
4402 
4403  size_t outlen = 0;
4404  size_t enclen = 0;
4405 
4406  memset( key, 0, 32 );
4407  memset( iv , 0, 16 );
4408 
4409  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4410  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4411 
4412  memset( inbuf, 5, 64 );
4413  memset( encbuf, 0, 64 );
4414  memset( decbuf, 0, 64 );
4415 
4416  /* Check and get info structures */
4418  fct_chk( NULL != cipher_info );
4419  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
4420 
4421  /* Initialise enc and dec contexts */
4422  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4423  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4424 
4425  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4426  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4427 
4428  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4429  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4430 
4431  if( POLARSSL_MODE_CBC == cipher_info->mode )
4432  {
4433  enclen = cipher_get_block_size( &ctx_enc )
4434  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4435  }
4436  else
4437  {
4438  enclen = length;
4439  }
4440 
4441  /* encode length number of bytes from inbuf */
4442  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
4443  if( POLARSSL_MODE_CBC == cipher_info->mode )
4444  {
4445  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4446  }
4447  else
4448  {
4449  fct_chk( outlen == enclen );
4450  }
4451 
4452  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
4453  if( POLARSSL_MODE_CBC == cipher_info->mode )
4454  {
4455  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4456  }
4457  else
4458  {
4459  fct_chk( outlen == 0 );
4460  }
4461 
4462 
4463  /* decode the previously encoded string */
4464  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4465  if( POLARSSL_MODE_CBC == cipher_info->mode )
4466  {
4467  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4468  }
4469  else
4470  {
4471  fct_chk( enclen == outlen );
4472  }
4473 
4474  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4475  if( POLARSSL_MODE_CBC == cipher_info->mode )
4476  {
4477  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4478  }
4479  else
4480  {
4481  fct_chk( outlen == 0 );
4482  }
4483 
4484 
4485  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4486 
4487  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4488  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4489  FCT_TEST_END();
4490 #endif /* POLARSSL_CAMELLIA_C */
4491 #endif /* POLARSSL_CIPHER_MODE_CFB */
4492 
4493 #ifdef POLARSSL_CAMELLIA_C
4494 #ifdef POLARSSL_CIPHER_MODE_CFB
4495 
4496  FCT_TEST_BGN(camellia_encrypt_and_decrypt_49_bytes)
4497  size_t length = 49;
4498  unsigned char key[32];
4499  unsigned char iv[16];
4500 
4501  const cipher_info_t *cipher_info;
4502  cipher_context_t ctx_dec;
4503  cipher_context_t ctx_enc;
4504 
4505  unsigned char inbuf[64];
4506  unsigned char encbuf[64];
4507  unsigned char decbuf[64];
4508 
4509  size_t outlen = 0;
4510  size_t enclen = 0;
4511 
4512  memset( key, 0, 32 );
4513  memset( iv , 0, 16 );
4514 
4515  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4516  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4517 
4518  memset( inbuf, 5, 64 );
4519  memset( encbuf, 0, 64 );
4520  memset( decbuf, 0, 64 );
4521 
4522  /* Check and get info structures */
4524  fct_chk( NULL != cipher_info );
4525  fct_chk( cipher_info_from_string( "CAMELLIA-128-CFB128" ) == cipher_info );
4526 
4527  /* Initialise enc and dec contexts */
4528  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4529  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4530 
4531  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4532  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4533 
4534  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4535  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4536 
4537  if( POLARSSL_MODE_CBC == cipher_info->mode )
4538  {
4539  enclen = cipher_get_block_size( &ctx_enc )
4540  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4541  }
4542  else
4543  {
4544  enclen = length;
4545  }
4546 
4547  /* encode length number of bytes from inbuf */
4548  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
4549  if( POLARSSL_MODE_CBC == cipher_info->mode )
4550  {
4551  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4552  }
4553  else
4554  {
4555  fct_chk( outlen == enclen );
4556  }
4557 
4558  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
4559  if( POLARSSL_MODE_CBC == cipher_info->mode )
4560  {
4561  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4562  }
4563  else
4564  {
4565  fct_chk( outlen == 0 );
4566  }
4567 
4568 
4569  /* decode the previously encoded string */
4570  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4571  if( POLARSSL_MODE_CBC == cipher_info->mode )
4572  {
4573  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4574  }
4575  else
4576  {
4577  fct_chk( enclen == outlen );
4578  }
4579 
4580  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4581  if( POLARSSL_MODE_CBC == cipher_info->mode )
4582  {
4583  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4584  }
4585  else
4586  {
4587  fct_chk( outlen == 0 );
4588  }
4589 
4590 
4591  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4592 
4593  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4594  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4595  FCT_TEST_END();
4596 #endif /* POLARSSL_CAMELLIA_C */
4597 #endif /* POLARSSL_CIPHER_MODE_CFB */
4598 
4599 #ifdef POLARSSL_CAMELLIA_C
4600 #ifdef POLARSSL_CIPHER_MODE_CFB
4601 
4602  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes_in_multiple_parts)
4603  size_t first_length = 0;
4604  size_t second_length = 0;
4605  size_t length = first_length + second_length;
4606  unsigned char key[32];
4607  unsigned char iv[16];
4608 
4609  cipher_context_t ctx_dec;
4610  cipher_context_t ctx_enc;
4611  const cipher_info_t *cipher_info;
4612 
4613  unsigned char inbuf[64];
4614  unsigned char encbuf[64];
4615  unsigned char decbuf[64];
4616 
4617  size_t outlen = 0;
4618  size_t totaloutlen = 0;
4619  size_t enclen = 0;
4620 
4621  memset( key, 0, 32 );
4622  memset( iv , 0, 16 );
4623 
4624  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4625  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4626 
4627  memset( inbuf, 5, 64 );
4628  memset( encbuf, 0, 64 );
4629  memset( decbuf, 0, 64 );
4630 
4631  /* Initialise enc and dec contexts */
4633  fct_chk( NULL != cipher_info);
4634 
4635  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4636  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4637 
4638  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4639  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4640 
4641  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4642  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4643 
4644  if( POLARSSL_MODE_CBC == cipher_info->mode )
4645  {
4646  enclen = cipher_get_block_size(&ctx_enc )
4647  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4648  }
4649  else
4650  {
4651  enclen = length;
4652  }
4653 
4654  /* encode length number of bytes from inbuf */
4655  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
4656  totaloutlen = outlen;
4657  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
4658  totaloutlen += outlen;
4659  if( POLARSSL_MODE_CBC == cipher_info->mode )
4660  {
4661  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4662  }
4663  else
4664  {
4665  fct_chk( totaloutlen == enclen );
4666  }
4667  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
4668  totaloutlen += outlen;
4669  if( POLARSSL_MODE_CBC == cipher_info->mode )
4670  {
4671  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4672  }
4673  else
4674  {
4675  fct_chk( outlen == 0 );
4676  }
4677 
4678  /* decode the previously encoded string */
4679  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4680  if( POLARSSL_MODE_CBC == cipher_info->mode )
4681  {
4682  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4683  }
4684  else
4685  {
4686  fct_chk( enclen == outlen );
4687  }
4688  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4689  if( POLARSSL_MODE_CBC == cipher_info->mode )
4690  {
4691  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4692  }
4693  else
4694  {
4695  fct_chk( outlen == 0 );
4696  }
4697 
4698 
4699  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4700 
4701  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4702  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4703  FCT_TEST_END();
4704 #endif /* POLARSSL_CAMELLIA_C */
4705 #endif /* POLARSSL_CIPHER_MODE_CFB */
4706 
4707 #ifdef POLARSSL_CAMELLIA_C
4708 #ifdef POLARSSL_CIPHER_MODE_CFB
4709 
4710  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
4711  size_t first_length = 1;
4712  size_t second_length = 0;
4713  size_t length = first_length + second_length;
4714  unsigned char key[32];
4715  unsigned char iv[16];
4716 
4717  cipher_context_t ctx_dec;
4718  cipher_context_t ctx_enc;
4719  const cipher_info_t *cipher_info;
4720 
4721  unsigned char inbuf[64];
4722  unsigned char encbuf[64];
4723  unsigned char decbuf[64];
4724 
4725  size_t outlen = 0;
4726  size_t totaloutlen = 0;
4727  size_t enclen = 0;
4728 
4729  memset( key, 0, 32 );
4730  memset( iv , 0, 16 );
4731 
4732  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4733  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4734 
4735  memset( inbuf, 5, 64 );
4736  memset( encbuf, 0, 64 );
4737  memset( decbuf, 0, 64 );
4738 
4739  /* Initialise enc and dec contexts */
4741  fct_chk( NULL != cipher_info);
4742 
4743  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4744  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4745 
4746  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4747  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4748 
4749  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4750  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4751 
4752  if( POLARSSL_MODE_CBC == cipher_info->mode )
4753  {
4754  enclen = cipher_get_block_size(&ctx_enc )
4755  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4756  }
4757  else
4758  {
4759  enclen = length;
4760  }
4761 
4762  /* encode length number of bytes from inbuf */
4763  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
4764  totaloutlen = outlen;
4765  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
4766  totaloutlen += outlen;
4767  if( POLARSSL_MODE_CBC == cipher_info->mode )
4768  {
4769  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4770  }
4771  else
4772  {
4773  fct_chk( totaloutlen == enclen );
4774  }
4775  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
4776  totaloutlen += outlen;
4777  if( POLARSSL_MODE_CBC == cipher_info->mode )
4778  {
4779  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4780  }
4781  else
4782  {
4783  fct_chk( outlen == 0 );
4784  }
4785 
4786  /* decode the previously encoded string */
4787  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4788  if( POLARSSL_MODE_CBC == cipher_info->mode )
4789  {
4790  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4791  }
4792  else
4793  {
4794  fct_chk( enclen == outlen );
4795  }
4796  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4797  if( POLARSSL_MODE_CBC == cipher_info->mode )
4798  {
4799  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4800  }
4801  else
4802  {
4803  fct_chk( outlen == 0 );
4804  }
4805 
4806 
4807  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4808 
4809  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4810  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4811  FCT_TEST_END();
4812 #endif /* POLARSSL_CAMELLIA_C */
4813 #endif /* POLARSSL_CIPHER_MODE_CFB */
4814 
4815 #ifdef POLARSSL_CAMELLIA_C
4816 #ifdef POLARSSL_CIPHER_MODE_CFB
4817 
4818  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
4819  size_t first_length = 0;
4820  size_t second_length = 1;
4821  size_t length = first_length + second_length;
4822  unsigned char key[32];
4823  unsigned char iv[16];
4824 
4825  cipher_context_t ctx_dec;
4826  cipher_context_t ctx_enc;
4827  const cipher_info_t *cipher_info;
4828 
4829  unsigned char inbuf[64];
4830  unsigned char encbuf[64];
4831  unsigned char decbuf[64];
4832 
4833  size_t outlen = 0;
4834  size_t totaloutlen = 0;
4835  size_t enclen = 0;
4836 
4837  memset( key, 0, 32 );
4838  memset( iv , 0, 16 );
4839 
4840  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4841  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4842 
4843  memset( inbuf, 5, 64 );
4844  memset( encbuf, 0, 64 );
4845  memset( decbuf, 0, 64 );
4846 
4847  /* Initialise enc and dec contexts */
4849  fct_chk( NULL != cipher_info);
4850 
4851  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4852  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4853 
4854  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4855  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4856 
4857  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4858  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4859 
4860  if( POLARSSL_MODE_CBC == cipher_info->mode )
4861  {
4862  enclen = cipher_get_block_size(&ctx_enc )
4863  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4864  }
4865  else
4866  {
4867  enclen = length;
4868  }
4869 
4870  /* encode length number of bytes from inbuf */
4871  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
4872  totaloutlen = outlen;
4873  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
4874  totaloutlen += outlen;
4875  if( POLARSSL_MODE_CBC == cipher_info->mode )
4876  {
4877  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4878  }
4879  else
4880  {
4881  fct_chk( totaloutlen == enclen );
4882  }
4883  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
4884  totaloutlen += outlen;
4885  if( POLARSSL_MODE_CBC == cipher_info->mode )
4886  {
4887  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4888  }
4889  else
4890  {
4891  fct_chk( outlen == 0 );
4892  }
4893 
4894  /* decode the previously encoded string */
4895  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
4896  if( POLARSSL_MODE_CBC == cipher_info->mode )
4897  {
4898  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
4899  }
4900  else
4901  {
4902  fct_chk( enclen == outlen );
4903  }
4904  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
4905  if( POLARSSL_MODE_CBC == cipher_info->mode )
4906  {
4907  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
4908  }
4909  else
4910  {
4911  fct_chk( outlen == 0 );
4912  }
4913 
4914 
4915  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
4916 
4917  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
4918  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
4919  FCT_TEST_END();
4920 #endif /* POLARSSL_CAMELLIA_C */
4921 #endif /* POLARSSL_CIPHER_MODE_CFB */
4922 
4923 #ifdef POLARSSL_CAMELLIA_C
4924 #ifdef POLARSSL_CIPHER_MODE_CFB
4925 
4926  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
4927  size_t first_length = 16;
4928  size_t second_length = 0;
4929  size_t length = first_length + second_length;
4930  unsigned char key[32];
4931  unsigned char iv[16];
4932 
4933  cipher_context_t ctx_dec;
4934  cipher_context_t ctx_enc;
4935  const cipher_info_t *cipher_info;
4936 
4937  unsigned char inbuf[64];
4938  unsigned char encbuf[64];
4939  unsigned char decbuf[64];
4940 
4941  size_t outlen = 0;
4942  size_t totaloutlen = 0;
4943  size_t enclen = 0;
4944 
4945  memset( key, 0, 32 );
4946  memset( iv , 0, 16 );
4947 
4948  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
4949  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
4950 
4951  memset( inbuf, 5, 64 );
4952  memset( encbuf, 0, 64 );
4953  memset( decbuf, 0, 64 );
4954 
4955  /* Initialise enc and dec contexts */
4957  fct_chk( NULL != cipher_info);
4958 
4959  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
4960  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
4961 
4962  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
4963  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
4964 
4965  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
4966  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
4967 
4968  if( POLARSSL_MODE_CBC == cipher_info->mode )
4969  {
4970  enclen = cipher_get_block_size(&ctx_enc )
4971  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
4972  }
4973  else
4974  {
4975  enclen = length;
4976  }
4977 
4978  /* encode length number of bytes from inbuf */
4979  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
4980  totaloutlen = outlen;
4981  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
4982  totaloutlen += outlen;
4983  if( POLARSSL_MODE_CBC == cipher_info->mode )
4984  {
4985  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
4986  }
4987  else
4988  {
4989  fct_chk( totaloutlen == enclen );
4990  }
4991  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
4992  totaloutlen += outlen;
4993  if( POLARSSL_MODE_CBC == cipher_info->mode )
4994  {
4995  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
4996  }
4997  else
4998  {
4999  fct_chk( outlen == 0 );
5000  }
5001 
5002  /* decode the previously encoded string */
5003  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5004  if( POLARSSL_MODE_CBC == cipher_info->mode )
5005  {
5006  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5007  }
5008  else
5009  {
5010  fct_chk( enclen == outlen );
5011  }
5012  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5013  if( POLARSSL_MODE_CBC == cipher_info->mode )
5014  {
5015  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5016  }
5017  else
5018  {
5019  fct_chk( outlen == 0 );
5020  }
5021 
5022 
5023  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5024 
5025  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5026  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5027  FCT_TEST_END();
5028 #endif /* POLARSSL_CAMELLIA_C */
5029 #endif /* POLARSSL_CIPHER_MODE_CFB */
5030 
5031 #ifdef POLARSSL_CAMELLIA_C
5032 #ifdef POLARSSL_CIPHER_MODE_CFB
5033 
5034  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
5035  size_t first_length = 0;
5036  size_t second_length = 16;
5037  size_t length = first_length + second_length;
5038  unsigned char key[32];
5039  unsigned char iv[16];
5040 
5041  cipher_context_t ctx_dec;
5042  cipher_context_t ctx_enc;
5043  const cipher_info_t *cipher_info;
5044 
5045  unsigned char inbuf[64];
5046  unsigned char encbuf[64];
5047  unsigned char decbuf[64];
5048 
5049  size_t outlen = 0;
5050  size_t totaloutlen = 0;
5051  size_t enclen = 0;
5052 
5053  memset( key, 0, 32 );
5054  memset( iv , 0, 16 );
5055 
5056  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5057  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5058 
5059  memset( inbuf, 5, 64 );
5060  memset( encbuf, 0, 64 );
5061  memset( decbuf, 0, 64 );
5062 
5063  /* Initialise enc and dec contexts */
5065  fct_chk( NULL != cipher_info);
5066 
5067  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5068  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5069 
5070  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5071  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5072 
5073  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5074  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5075 
5076  if( POLARSSL_MODE_CBC == cipher_info->mode )
5077  {
5078  enclen = cipher_get_block_size(&ctx_enc )
5079  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5080  }
5081  else
5082  {
5083  enclen = length;
5084  }
5085 
5086  /* encode length number of bytes from inbuf */
5087  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5088  totaloutlen = outlen;
5089  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5090  totaloutlen += outlen;
5091  if( POLARSSL_MODE_CBC == cipher_info->mode )
5092  {
5093  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5094  }
5095  else
5096  {
5097  fct_chk( totaloutlen == enclen );
5098  }
5099  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5100  totaloutlen += outlen;
5101  if( POLARSSL_MODE_CBC == cipher_info->mode )
5102  {
5103  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5104  }
5105  else
5106  {
5107  fct_chk( outlen == 0 );
5108  }
5109 
5110  /* decode the previously encoded string */
5111  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5112  if( POLARSSL_MODE_CBC == cipher_info->mode )
5113  {
5114  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5115  }
5116  else
5117  {
5118  fct_chk( enclen == outlen );
5119  }
5120  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5121  if( POLARSSL_MODE_CBC == cipher_info->mode )
5122  {
5123  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5124  }
5125  else
5126  {
5127  fct_chk( outlen == 0 );
5128  }
5129 
5130 
5131  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5132 
5133  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5134  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5135  FCT_TEST_END();
5136 #endif /* POLARSSL_CAMELLIA_C */
5137 #endif /* POLARSSL_CIPHER_MODE_CFB */
5138 
5139 #ifdef POLARSSL_CAMELLIA_C
5140 #ifdef POLARSSL_CIPHER_MODE_CFB
5141 
5142  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
5143  size_t first_length = 1;
5144  size_t second_length = 15;
5145  size_t length = first_length + second_length;
5146  unsigned char key[32];
5147  unsigned char iv[16];
5148 
5149  cipher_context_t ctx_dec;
5150  cipher_context_t ctx_enc;
5151  const cipher_info_t *cipher_info;
5152 
5153  unsigned char inbuf[64];
5154  unsigned char encbuf[64];
5155  unsigned char decbuf[64];
5156 
5157  size_t outlen = 0;
5158  size_t totaloutlen = 0;
5159  size_t enclen = 0;
5160 
5161  memset( key, 0, 32 );
5162  memset( iv , 0, 16 );
5163 
5164  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5165  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5166 
5167  memset( inbuf, 5, 64 );
5168  memset( encbuf, 0, 64 );
5169  memset( decbuf, 0, 64 );
5170 
5171  /* Initialise enc and dec contexts */
5173  fct_chk( NULL != cipher_info);
5174 
5175  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5176  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5177 
5178  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5179  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5180 
5181  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5182  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5183 
5184  if( POLARSSL_MODE_CBC == cipher_info->mode )
5185  {
5186  enclen = cipher_get_block_size(&ctx_enc )
5187  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5188  }
5189  else
5190  {
5191  enclen = length;
5192  }
5193 
5194  /* encode length number of bytes from inbuf */
5195  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5196  totaloutlen = outlen;
5197  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5198  totaloutlen += outlen;
5199  if( POLARSSL_MODE_CBC == cipher_info->mode )
5200  {
5201  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5202  }
5203  else
5204  {
5205  fct_chk( totaloutlen == enclen );
5206  }
5207  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5208  totaloutlen += outlen;
5209  if( POLARSSL_MODE_CBC == cipher_info->mode )
5210  {
5211  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5212  }
5213  else
5214  {
5215  fct_chk( outlen == 0 );
5216  }
5217 
5218  /* decode the previously encoded string */
5219  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5220  if( POLARSSL_MODE_CBC == cipher_info->mode )
5221  {
5222  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5223  }
5224  else
5225  {
5226  fct_chk( enclen == outlen );
5227  }
5228  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5229  if( POLARSSL_MODE_CBC == cipher_info->mode )
5230  {
5231  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5232  }
5233  else
5234  {
5235  fct_chk( outlen == 0 );
5236  }
5237 
5238 
5239  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5240 
5241  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5242  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5243  FCT_TEST_END();
5244 #endif /* POLARSSL_CAMELLIA_C */
5245 #endif /* POLARSSL_CIPHER_MODE_CFB */
5246 
5247 #ifdef POLARSSL_CAMELLIA_C
5248 #ifdef POLARSSL_CIPHER_MODE_CFB
5249 
5250  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
5251  size_t first_length = 15;
5252  size_t second_length = 1;
5253  size_t length = first_length + second_length;
5254  unsigned char key[32];
5255  unsigned char iv[16];
5256 
5257  cipher_context_t ctx_dec;
5258  cipher_context_t ctx_enc;
5259  const cipher_info_t *cipher_info;
5260 
5261  unsigned char inbuf[64];
5262  unsigned char encbuf[64];
5263  unsigned char decbuf[64];
5264 
5265  size_t outlen = 0;
5266  size_t totaloutlen = 0;
5267  size_t enclen = 0;
5268 
5269  memset( key, 0, 32 );
5270  memset( iv , 0, 16 );
5271 
5272  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5273  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5274 
5275  memset( inbuf, 5, 64 );
5276  memset( encbuf, 0, 64 );
5277  memset( decbuf, 0, 64 );
5278 
5279  /* Initialise enc and dec contexts */
5281  fct_chk( NULL != cipher_info);
5282 
5283  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5284  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5285 
5286  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5287  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5288 
5289  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5290  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5291 
5292  if( POLARSSL_MODE_CBC == cipher_info->mode )
5293  {
5294  enclen = cipher_get_block_size(&ctx_enc )
5295  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5296  }
5297  else
5298  {
5299  enclen = length;
5300  }
5301 
5302  /* encode length number of bytes from inbuf */
5303  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5304  totaloutlen = outlen;
5305  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5306  totaloutlen += outlen;
5307  if( POLARSSL_MODE_CBC == cipher_info->mode )
5308  {
5309  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5310  }
5311  else
5312  {
5313  fct_chk( totaloutlen == enclen );
5314  }
5315  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5316  totaloutlen += outlen;
5317  if( POLARSSL_MODE_CBC == cipher_info->mode )
5318  {
5319  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5320  }
5321  else
5322  {
5323  fct_chk( outlen == 0 );
5324  }
5325 
5326  /* decode the previously encoded string */
5327  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5328  if( POLARSSL_MODE_CBC == cipher_info->mode )
5329  {
5330  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5331  }
5332  else
5333  {
5334  fct_chk( enclen == outlen );
5335  }
5336  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5337  if( POLARSSL_MODE_CBC == cipher_info->mode )
5338  {
5339  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5340  }
5341  else
5342  {
5343  fct_chk( outlen == 0 );
5344  }
5345 
5346 
5347  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5348 
5349  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5350  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5351  FCT_TEST_END();
5352 #endif /* POLARSSL_CAMELLIA_C */
5353 #endif /* POLARSSL_CIPHER_MODE_CFB */
5354 
5355 #ifdef POLARSSL_CAMELLIA_C
5356 #ifdef POLARSSL_CIPHER_MODE_CFB
5357 
5358  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
5359  size_t first_length = 15;
5360  size_t second_length = 7;
5361  size_t length = first_length + second_length;
5362  unsigned char key[32];
5363  unsigned char iv[16];
5364 
5365  cipher_context_t ctx_dec;
5366  cipher_context_t ctx_enc;
5367  const cipher_info_t *cipher_info;
5368 
5369  unsigned char inbuf[64];
5370  unsigned char encbuf[64];
5371  unsigned char decbuf[64];
5372 
5373  size_t outlen = 0;
5374  size_t totaloutlen = 0;
5375  size_t enclen = 0;
5376 
5377  memset( key, 0, 32 );
5378  memset( iv , 0, 16 );
5379 
5380  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5381  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5382 
5383  memset( inbuf, 5, 64 );
5384  memset( encbuf, 0, 64 );
5385  memset( decbuf, 0, 64 );
5386 
5387  /* Initialise enc and dec contexts */
5389  fct_chk( NULL != cipher_info);
5390 
5391  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5392  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5393 
5394  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5395  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5396 
5397  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5398  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5399 
5400  if( POLARSSL_MODE_CBC == cipher_info->mode )
5401  {
5402  enclen = cipher_get_block_size(&ctx_enc )
5403  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5404  }
5405  else
5406  {
5407  enclen = length;
5408  }
5409 
5410  /* encode length number of bytes from inbuf */
5411  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5412  totaloutlen = outlen;
5413  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5414  totaloutlen += outlen;
5415  if( POLARSSL_MODE_CBC == cipher_info->mode )
5416  {
5417  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5418  }
5419  else
5420  {
5421  fct_chk( totaloutlen == enclen );
5422  }
5423  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5424  totaloutlen += outlen;
5425  if( POLARSSL_MODE_CBC == cipher_info->mode )
5426  {
5427  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5428  }
5429  else
5430  {
5431  fct_chk( outlen == 0 );
5432  }
5433 
5434  /* decode the previously encoded string */
5435  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5436  if( POLARSSL_MODE_CBC == cipher_info->mode )
5437  {
5438  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5439  }
5440  else
5441  {
5442  fct_chk( enclen == outlen );
5443  }
5444  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5445  if( POLARSSL_MODE_CBC == cipher_info->mode )
5446  {
5447  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5448  }
5449  else
5450  {
5451  fct_chk( outlen == 0 );
5452  }
5453 
5454 
5455  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5456 
5457  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5458  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5459  FCT_TEST_END();
5460 #endif /* POLARSSL_CAMELLIA_C */
5461 #endif /* POLARSSL_CIPHER_MODE_CFB */
5462 
5463 #ifdef POLARSSL_CAMELLIA_C
5464 #ifdef POLARSSL_CIPHER_MODE_CFB
5465 
5466  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
5467  size_t first_length = 16;
5468  size_t second_length = 6;
5469  size_t length = first_length + second_length;
5470  unsigned char key[32];
5471  unsigned char iv[16];
5472 
5473  cipher_context_t ctx_dec;
5474  cipher_context_t ctx_enc;
5475  const cipher_info_t *cipher_info;
5476 
5477  unsigned char inbuf[64];
5478  unsigned char encbuf[64];
5479  unsigned char decbuf[64];
5480 
5481  size_t outlen = 0;
5482  size_t totaloutlen = 0;
5483  size_t enclen = 0;
5484 
5485  memset( key, 0, 32 );
5486  memset( iv , 0, 16 );
5487 
5488  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5489  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5490 
5491  memset( inbuf, 5, 64 );
5492  memset( encbuf, 0, 64 );
5493  memset( decbuf, 0, 64 );
5494 
5495  /* Initialise enc and dec contexts */
5497  fct_chk( NULL != cipher_info);
5498 
5499  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5500  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5501 
5502  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5503  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5504 
5505  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5506  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5507 
5508  if( POLARSSL_MODE_CBC == cipher_info->mode )
5509  {
5510  enclen = cipher_get_block_size(&ctx_enc )
5511  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5512  }
5513  else
5514  {
5515  enclen = length;
5516  }
5517 
5518  /* encode length number of bytes from inbuf */
5519  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5520  totaloutlen = outlen;
5521  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5522  totaloutlen += outlen;
5523  if( POLARSSL_MODE_CBC == cipher_info->mode )
5524  {
5525  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5526  }
5527  else
5528  {
5529  fct_chk( totaloutlen == enclen );
5530  }
5531  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5532  totaloutlen += outlen;
5533  if( POLARSSL_MODE_CBC == cipher_info->mode )
5534  {
5535  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5536  }
5537  else
5538  {
5539  fct_chk( outlen == 0 );
5540  }
5541 
5542  /* decode the previously encoded string */
5543  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5544  if( POLARSSL_MODE_CBC == cipher_info->mode )
5545  {
5546  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5547  }
5548  else
5549  {
5550  fct_chk( enclen == outlen );
5551  }
5552  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5553  if( POLARSSL_MODE_CBC == cipher_info->mode )
5554  {
5555  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5556  }
5557  else
5558  {
5559  fct_chk( outlen == 0 );
5560  }
5561 
5562 
5563  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5564 
5565  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5566  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5567  FCT_TEST_END();
5568 #endif /* POLARSSL_CAMELLIA_C */
5569 #endif /* POLARSSL_CIPHER_MODE_CFB */
5570 
5571 #ifdef POLARSSL_CAMELLIA_C
5572 #ifdef POLARSSL_CIPHER_MODE_CFB
5573 
5574  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
5575  size_t first_length = 17;
5576  size_t second_length = 6;
5577  size_t length = first_length + second_length;
5578  unsigned char key[32];
5579  unsigned char iv[16];
5580 
5581  cipher_context_t ctx_dec;
5582  cipher_context_t ctx_enc;
5583  const cipher_info_t *cipher_info;
5584 
5585  unsigned char inbuf[64];
5586  unsigned char encbuf[64];
5587  unsigned char decbuf[64];
5588 
5589  size_t outlen = 0;
5590  size_t totaloutlen = 0;
5591  size_t enclen = 0;
5592 
5593  memset( key, 0, 32 );
5594  memset( iv , 0, 16 );
5595 
5596  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5597  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5598 
5599  memset( inbuf, 5, 64 );
5600  memset( encbuf, 0, 64 );
5601  memset( decbuf, 0, 64 );
5602 
5603  /* Initialise enc and dec contexts */
5605  fct_chk( NULL != cipher_info);
5606 
5607  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5608  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5609 
5610  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5611  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5612 
5613  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5614  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5615 
5616  if( POLARSSL_MODE_CBC == cipher_info->mode )
5617  {
5618  enclen = cipher_get_block_size(&ctx_enc )
5619  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5620  }
5621  else
5622  {
5623  enclen = length;
5624  }
5625 
5626  /* encode length number of bytes from inbuf */
5627  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5628  totaloutlen = outlen;
5629  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5630  totaloutlen += outlen;
5631  if( POLARSSL_MODE_CBC == cipher_info->mode )
5632  {
5633  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5634  }
5635  else
5636  {
5637  fct_chk( totaloutlen == enclen );
5638  }
5639  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5640  totaloutlen += outlen;
5641  if( POLARSSL_MODE_CBC == cipher_info->mode )
5642  {
5643  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5644  }
5645  else
5646  {
5647  fct_chk( outlen == 0 );
5648  }
5649 
5650  /* decode the previously encoded string */
5651  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5652  if( POLARSSL_MODE_CBC == cipher_info->mode )
5653  {
5654  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5655  }
5656  else
5657  {
5658  fct_chk( enclen == outlen );
5659  }
5660  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5661  if( POLARSSL_MODE_CBC == cipher_info->mode )
5662  {
5663  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5664  }
5665  else
5666  {
5667  fct_chk( outlen == 0 );
5668  }
5669 
5670 
5671  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5672 
5673  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5674  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5675  FCT_TEST_END();
5676 #endif /* POLARSSL_CAMELLIA_C */
5677 #endif /* POLARSSL_CIPHER_MODE_CFB */
5678 
5679 #ifdef POLARSSL_CAMELLIA_C
5680 #ifdef POLARSSL_CIPHER_MODE_CFB
5681 
5682  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
5683  size_t first_length = 16;
5684  size_t second_length = 16;
5685  size_t length = first_length + second_length;
5686  unsigned char key[32];
5687  unsigned char iv[16];
5688 
5689  cipher_context_t ctx_dec;
5690  cipher_context_t ctx_enc;
5691  const cipher_info_t *cipher_info;
5692 
5693  unsigned char inbuf[64];
5694  unsigned char encbuf[64];
5695  unsigned char decbuf[64];
5696 
5697  size_t outlen = 0;
5698  size_t totaloutlen = 0;
5699  size_t enclen = 0;
5700 
5701  memset( key, 0, 32 );
5702  memset( iv , 0, 16 );
5703 
5704  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5705  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5706 
5707  memset( inbuf, 5, 64 );
5708  memset( encbuf, 0, 64 );
5709  memset( decbuf, 0, 64 );
5710 
5711  /* Initialise enc and dec contexts */
5713  fct_chk( NULL != cipher_info);
5714 
5715  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5716  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5717 
5718  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5719  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5720 
5721  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5722  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5723 
5724  if( POLARSSL_MODE_CBC == cipher_info->mode )
5725  {
5726  enclen = cipher_get_block_size(&ctx_enc )
5727  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5728  }
5729  else
5730  {
5731  enclen = length;
5732  }
5733 
5734  /* encode length number of bytes from inbuf */
5735  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
5736  totaloutlen = outlen;
5737  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
5738  totaloutlen += outlen;
5739  if( POLARSSL_MODE_CBC == cipher_info->mode )
5740  {
5741  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5742  }
5743  else
5744  {
5745  fct_chk( totaloutlen == enclen );
5746  }
5747  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
5748  totaloutlen += outlen;
5749  if( POLARSSL_MODE_CBC == cipher_info->mode )
5750  {
5751  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5752  }
5753  else
5754  {
5755  fct_chk( outlen == 0 );
5756  }
5757 
5758  /* decode the previously encoded string */
5759  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5760  if( POLARSSL_MODE_CBC == cipher_info->mode )
5761  {
5762  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5763  }
5764  else
5765  {
5766  fct_chk( enclen == outlen );
5767  }
5768  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5769  if( POLARSSL_MODE_CBC == cipher_info->mode )
5770  {
5771  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5772  }
5773  else
5774  {
5775  fct_chk( outlen == 0 );
5776  }
5777 
5778 
5779  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5780 
5781  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5782  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5783  FCT_TEST_END();
5784 #endif /* POLARSSL_CAMELLIA_C */
5785 #endif /* POLARSSL_CIPHER_MODE_CFB */
5786 
5787 #ifdef POLARSSL_CAMELLIA_C
5788 #ifdef POLARSSL_CIPHER_MODE_CTR
5789 
5790  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes)
5791  size_t length = 0;
5792  unsigned char key[32];
5793  unsigned char iv[16];
5794 
5795  const cipher_info_t *cipher_info;
5796  cipher_context_t ctx_dec;
5797  cipher_context_t ctx_enc;
5798 
5799  unsigned char inbuf[64];
5800  unsigned char encbuf[64];
5801  unsigned char decbuf[64];
5802 
5803  size_t outlen = 0;
5804  size_t enclen = 0;
5805 
5806  memset( key, 0, 32 );
5807  memset( iv , 0, 16 );
5808 
5809  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5810  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5811 
5812  memset( inbuf, 5, 64 );
5813  memset( encbuf, 0, 64 );
5814  memset( decbuf, 0, 64 );
5815 
5816  /* Check and get info structures */
5818  fct_chk( NULL != cipher_info );
5819  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
5820 
5821  /* Initialise enc and dec contexts */
5822  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5823  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5824 
5825  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5826  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5827 
5828  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5829  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5830 
5831  if( POLARSSL_MODE_CBC == cipher_info->mode )
5832  {
5833  enclen = cipher_get_block_size( &ctx_enc )
5834  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5835  }
5836  else
5837  {
5838  enclen = length;
5839  }
5840 
5841  /* encode length number of bytes from inbuf */
5842  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
5843  if( POLARSSL_MODE_CBC == cipher_info->mode )
5844  {
5845  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5846  }
5847  else
5848  {
5849  fct_chk( outlen == enclen );
5850  }
5851 
5852  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
5853  if( POLARSSL_MODE_CBC == cipher_info->mode )
5854  {
5855  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5856  }
5857  else
5858  {
5859  fct_chk( outlen == 0 );
5860  }
5861 
5862 
5863  /* decode the previously encoded string */
5864  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5865  if( POLARSSL_MODE_CBC == cipher_info->mode )
5866  {
5867  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5868  }
5869  else
5870  {
5871  fct_chk( enclen == outlen );
5872  }
5873 
5874  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5875  if( POLARSSL_MODE_CBC == cipher_info->mode )
5876  {
5877  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5878  }
5879  else
5880  {
5881  fct_chk( outlen == 0 );
5882  }
5883 
5884 
5885  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5886 
5887  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5888  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5889  FCT_TEST_END();
5890 #endif /* POLARSSL_CAMELLIA_C */
5891 #endif /* POLARSSL_CIPHER_MODE_CTR */
5892 
5893 #ifdef POLARSSL_CAMELLIA_C
5894 #ifdef POLARSSL_CIPHER_MODE_CTR
5895 
5896  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_byte)
5897  size_t length = 1;
5898  unsigned char key[32];
5899  unsigned char iv[16];
5900 
5901  const cipher_info_t *cipher_info;
5902  cipher_context_t ctx_dec;
5903  cipher_context_t ctx_enc;
5904 
5905  unsigned char inbuf[64];
5906  unsigned char encbuf[64];
5907  unsigned char decbuf[64];
5908 
5909  size_t outlen = 0;
5910  size_t enclen = 0;
5911 
5912  memset( key, 0, 32 );
5913  memset( iv , 0, 16 );
5914 
5915  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
5916  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
5917 
5918  memset( inbuf, 5, 64 );
5919  memset( encbuf, 0, 64 );
5920  memset( decbuf, 0, 64 );
5921 
5922  /* Check and get info structures */
5924  fct_chk( NULL != cipher_info );
5925  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
5926 
5927  /* Initialise enc and dec contexts */
5928  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
5929  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
5930 
5931  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
5932  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
5933 
5934  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
5935  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
5936 
5937  if( POLARSSL_MODE_CBC == cipher_info->mode )
5938  {
5939  enclen = cipher_get_block_size( &ctx_enc )
5940  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
5941  }
5942  else
5943  {
5944  enclen = length;
5945  }
5946 
5947  /* encode length number of bytes from inbuf */
5948  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
5949  if( POLARSSL_MODE_CBC == cipher_info->mode )
5950  {
5951  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
5952  }
5953  else
5954  {
5955  fct_chk( outlen == enclen );
5956  }
5957 
5958  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
5959  if( POLARSSL_MODE_CBC == cipher_info->mode )
5960  {
5961  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
5962  }
5963  else
5964  {
5965  fct_chk( outlen == 0 );
5966  }
5967 
5968 
5969  /* decode the previously encoded string */
5970  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
5971  if( POLARSSL_MODE_CBC == cipher_info->mode )
5972  {
5973  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
5974  }
5975  else
5976  {
5977  fct_chk( enclen == outlen );
5978  }
5979 
5980  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
5981  if( POLARSSL_MODE_CBC == cipher_info->mode )
5982  {
5983  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
5984  }
5985  else
5986  {
5987  fct_chk( outlen == 0 );
5988  }
5989 
5990 
5991  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
5992 
5993  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
5994  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
5995  FCT_TEST_END();
5996 #endif /* POLARSSL_CAMELLIA_C */
5997 #endif /* POLARSSL_CIPHER_MODE_CTR */
5998 
5999 #ifdef POLARSSL_CAMELLIA_C
6000 #ifdef POLARSSL_CIPHER_MODE_CTR
6001 
6002  FCT_TEST_BGN(camellia_encrypt_and_decrypt_2_bytes)
6003  size_t length = 2;
6004  unsigned char key[32];
6005  unsigned char iv[16];
6006 
6007  const cipher_info_t *cipher_info;
6008  cipher_context_t ctx_dec;
6009  cipher_context_t ctx_enc;
6010 
6011  unsigned char inbuf[64];
6012  unsigned char encbuf[64];
6013  unsigned char decbuf[64];
6014 
6015  size_t outlen = 0;
6016  size_t enclen = 0;
6017 
6018  memset( key, 0, 32 );
6019  memset( iv , 0, 16 );
6020 
6021  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6022  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6023 
6024  memset( inbuf, 5, 64 );
6025  memset( encbuf, 0, 64 );
6026  memset( decbuf, 0, 64 );
6027 
6028  /* Check and get info structures */
6030  fct_chk( NULL != cipher_info );
6031  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6032 
6033  /* Initialise enc and dec contexts */
6034  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6035  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6036 
6037  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6038  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6039 
6040  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6041  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6042 
6043  if( POLARSSL_MODE_CBC == cipher_info->mode )
6044  {
6045  enclen = cipher_get_block_size( &ctx_enc )
6046  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6047  }
6048  else
6049  {
6050  enclen = length;
6051  }
6052 
6053  /* encode length number of bytes from inbuf */
6054  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6055  if( POLARSSL_MODE_CBC == cipher_info->mode )
6056  {
6057  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6058  }
6059  else
6060  {
6061  fct_chk( outlen == enclen );
6062  }
6063 
6064  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6065  if( POLARSSL_MODE_CBC == cipher_info->mode )
6066  {
6067  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6068  }
6069  else
6070  {
6071  fct_chk( outlen == 0 );
6072  }
6073 
6074 
6075  /* decode the previously encoded string */
6076  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6077  if( POLARSSL_MODE_CBC == cipher_info->mode )
6078  {
6079  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6080  }
6081  else
6082  {
6083  fct_chk( enclen == outlen );
6084  }
6085 
6086  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6087  if( POLARSSL_MODE_CBC == cipher_info->mode )
6088  {
6089  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6090  }
6091  else
6092  {
6093  fct_chk( outlen == 0 );
6094  }
6095 
6096 
6097  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6098 
6099  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6100  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6101  FCT_TEST_END();
6102 #endif /* POLARSSL_CAMELLIA_C */
6103 #endif /* POLARSSL_CIPHER_MODE_CTR */
6104 
6105 #ifdef POLARSSL_CAMELLIA_C
6106 #ifdef POLARSSL_CIPHER_MODE_CTR
6107 
6108  FCT_TEST_BGN(camellia_encrypt_and_decrypt_7_bytes)
6109  size_t length = 7;
6110  unsigned char key[32];
6111  unsigned char iv[16];
6112 
6113  const cipher_info_t *cipher_info;
6114  cipher_context_t ctx_dec;
6115  cipher_context_t ctx_enc;
6116 
6117  unsigned char inbuf[64];
6118  unsigned char encbuf[64];
6119  unsigned char decbuf[64];
6120 
6121  size_t outlen = 0;
6122  size_t enclen = 0;
6123 
6124  memset( key, 0, 32 );
6125  memset( iv , 0, 16 );
6126 
6127  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6128  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6129 
6130  memset( inbuf, 5, 64 );
6131  memset( encbuf, 0, 64 );
6132  memset( decbuf, 0, 64 );
6133 
6134  /* Check and get info structures */
6136  fct_chk( NULL != cipher_info );
6137  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6138 
6139  /* Initialise enc and dec contexts */
6140  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6141  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6142 
6143  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6144  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6145 
6146  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6147  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6148 
6149  if( POLARSSL_MODE_CBC == cipher_info->mode )
6150  {
6151  enclen = cipher_get_block_size( &ctx_enc )
6152  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6153  }
6154  else
6155  {
6156  enclen = length;
6157  }
6158 
6159  /* encode length number of bytes from inbuf */
6160  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6161  if( POLARSSL_MODE_CBC == cipher_info->mode )
6162  {
6163  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6164  }
6165  else
6166  {
6167  fct_chk( outlen == enclen );
6168  }
6169 
6170  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6171  if( POLARSSL_MODE_CBC == cipher_info->mode )
6172  {
6173  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6174  }
6175  else
6176  {
6177  fct_chk( outlen == 0 );
6178  }
6179 
6180 
6181  /* decode the previously encoded string */
6182  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6183  if( POLARSSL_MODE_CBC == cipher_info->mode )
6184  {
6185  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6186  }
6187  else
6188  {
6189  fct_chk( enclen == outlen );
6190  }
6191 
6192  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6193  if( POLARSSL_MODE_CBC == cipher_info->mode )
6194  {
6195  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6196  }
6197  else
6198  {
6199  fct_chk( outlen == 0 );
6200  }
6201 
6202 
6203  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6204 
6205  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6206  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6207  FCT_TEST_END();
6208 #endif /* POLARSSL_CAMELLIA_C */
6209 #endif /* POLARSSL_CIPHER_MODE_CTR */
6210 
6211 #ifdef POLARSSL_CAMELLIA_C
6212 #ifdef POLARSSL_CIPHER_MODE_CTR
6213 
6214  FCT_TEST_BGN(camellia_encrypt_and_decrypt_8_bytes)
6215  size_t length = 8;
6216  unsigned char key[32];
6217  unsigned char iv[16];
6218 
6219  const cipher_info_t *cipher_info;
6220  cipher_context_t ctx_dec;
6221  cipher_context_t ctx_enc;
6222 
6223  unsigned char inbuf[64];
6224  unsigned char encbuf[64];
6225  unsigned char decbuf[64];
6226 
6227  size_t outlen = 0;
6228  size_t enclen = 0;
6229 
6230  memset( key, 0, 32 );
6231  memset( iv , 0, 16 );
6232 
6233  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6234  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6235 
6236  memset( inbuf, 5, 64 );
6237  memset( encbuf, 0, 64 );
6238  memset( decbuf, 0, 64 );
6239 
6240  /* Check and get info structures */
6242  fct_chk( NULL != cipher_info );
6243  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6244 
6245  /* Initialise enc and dec contexts */
6246  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6247  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6248 
6249  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6250  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6251 
6252  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6253  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6254 
6255  if( POLARSSL_MODE_CBC == cipher_info->mode )
6256  {
6257  enclen = cipher_get_block_size( &ctx_enc )
6258  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6259  }
6260  else
6261  {
6262  enclen = length;
6263  }
6264 
6265  /* encode length number of bytes from inbuf */
6266  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6267  if( POLARSSL_MODE_CBC == cipher_info->mode )
6268  {
6269  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6270  }
6271  else
6272  {
6273  fct_chk( outlen == enclen );
6274  }
6275 
6276  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6277  if( POLARSSL_MODE_CBC == cipher_info->mode )
6278  {
6279  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6280  }
6281  else
6282  {
6283  fct_chk( outlen == 0 );
6284  }
6285 
6286 
6287  /* decode the previously encoded string */
6288  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6289  if( POLARSSL_MODE_CBC == cipher_info->mode )
6290  {
6291  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6292  }
6293  else
6294  {
6295  fct_chk( enclen == outlen );
6296  }
6297 
6298  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6299  if( POLARSSL_MODE_CBC == cipher_info->mode )
6300  {
6301  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6302  }
6303  else
6304  {
6305  fct_chk( outlen == 0 );
6306  }
6307 
6308 
6309  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6310 
6311  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6312  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6313  FCT_TEST_END();
6314 #endif /* POLARSSL_CAMELLIA_C */
6315 #endif /* POLARSSL_CIPHER_MODE_CTR */
6316 
6317 #ifdef POLARSSL_CAMELLIA_C
6318 #ifdef POLARSSL_CIPHER_MODE_CTR
6319 
6320  FCT_TEST_BGN(camellia_encrypt_and_decrypt_9_bytes)
6321  size_t length = 9;
6322  unsigned char key[32];
6323  unsigned char iv[16];
6324 
6325  const cipher_info_t *cipher_info;
6326  cipher_context_t ctx_dec;
6327  cipher_context_t ctx_enc;
6328 
6329  unsigned char inbuf[64];
6330  unsigned char encbuf[64];
6331  unsigned char decbuf[64];
6332 
6333  size_t outlen = 0;
6334  size_t enclen = 0;
6335 
6336  memset( key, 0, 32 );
6337  memset( iv , 0, 16 );
6338 
6339  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6340  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6341 
6342  memset( inbuf, 5, 64 );
6343  memset( encbuf, 0, 64 );
6344  memset( decbuf, 0, 64 );
6345 
6346  /* Check and get info structures */
6348  fct_chk( NULL != cipher_info );
6349  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6350 
6351  /* Initialise enc and dec contexts */
6352  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6353  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6354 
6355  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6356  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6357 
6358  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6359  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6360 
6361  if( POLARSSL_MODE_CBC == cipher_info->mode )
6362  {
6363  enclen = cipher_get_block_size( &ctx_enc )
6364  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6365  }
6366  else
6367  {
6368  enclen = length;
6369  }
6370 
6371  /* encode length number of bytes from inbuf */
6372  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6373  if( POLARSSL_MODE_CBC == cipher_info->mode )
6374  {
6375  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6376  }
6377  else
6378  {
6379  fct_chk( outlen == enclen );
6380  }
6381 
6382  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6383  if( POLARSSL_MODE_CBC == cipher_info->mode )
6384  {
6385  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6386  }
6387  else
6388  {
6389  fct_chk( outlen == 0 );
6390  }
6391 
6392 
6393  /* decode the previously encoded string */
6394  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6395  if( POLARSSL_MODE_CBC == cipher_info->mode )
6396  {
6397  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6398  }
6399  else
6400  {
6401  fct_chk( enclen == outlen );
6402  }
6403 
6404  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6405  if( POLARSSL_MODE_CBC == cipher_info->mode )
6406  {
6407  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6408  }
6409  else
6410  {
6411  fct_chk( outlen == 0 );
6412  }
6413 
6414 
6415  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6416 
6417  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6418  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6419  FCT_TEST_END();
6420 #endif /* POLARSSL_CAMELLIA_C */
6421 #endif /* POLARSSL_CIPHER_MODE_CTR */
6422 
6423 #ifdef POLARSSL_CAMELLIA_C
6424 #ifdef POLARSSL_CIPHER_MODE_CTR
6425 
6426  FCT_TEST_BGN(camellia_encrypt_and_decrypt_15_bytes)
6427  size_t length = 15;
6428  unsigned char key[32];
6429  unsigned char iv[16];
6430 
6431  const cipher_info_t *cipher_info;
6432  cipher_context_t ctx_dec;
6433  cipher_context_t ctx_enc;
6434 
6435  unsigned char inbuf[64];
6436  unsigned char encbuf[64];
6437  unsigned char decbuf[64];
6438 
6439  size_t outlen = 0;
6440  size_t enclen = 0;
6441 
6442  memset( key, 0, 32 );
6443  memset( iv , 0, 16 );
6444 
6445  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6446  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6447 
6448  memset( inbuf, 5, 64 );
6449  memset( encbuf, 0, 64 );
6450  memset( decbuf, 0, 64 );
6451 
6452  /* Check and get info structures */
6454  fct_chk( NULL != cipher_info );
6455  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6456 
6457  /* Initialise enc and dec contexts */
6458  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6459  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6460 
6461  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6462  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6463 
6464  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6465  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6466 
6467  if( POLARSSL_MODE_CBC == cipher_info->mode )
6468  {
6469  enclen = cipher_get_block_size( &ctx_enc )
6470  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6471  }
6472  else
6473  {
6474  enclen = length;
6475  }
6476 
6477  /* encode length number of bytes from inbuf */
6478  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6479  if( POLARSSL_MODE_CBC == cipher_info->mode )
6480  {
6481  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6482  }
6483  else
6484  {
6485  fct_chk( outlen == enclen );
6486  }
6487 
6488  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6489  if( POLARSSL_MODE_CBC == cipher_info->mode )
6490  {
6491  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6492  }
6493  else
6494  {
6495  fct_chk( outlen == 0 );
6496  }
6497 
6498 
6499  /* decode the previously encoded string */
6500  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6501  if( POLARSSL_MODE_CBC == cipher_info->mode )
6502  {
6503  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6504  }
6505  else
6506  {
6507  fct_chk( enclen == outlen );
6508  }
6509 
6510  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6511  if( POLARSSL_MODE_CBC == cipher_info->mode )
6512  {
6513  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6514  }
6515  else
6516  {
6517  fct_chk( outlen == 0 );
6518  }
6519 
6520 
6521  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6522 
6523  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6524  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6525  FCT_TEST_END();
6526 #endif /* POLARSSL_CAMELLIA_C */
6527 #endif /* POLARSSL_CIPHER_MODE_CTR */
6528 
6529 #ifdef POLARSSL_CAMELLIA_C
6530 #ifdef POLARSSL_CIPHER_MODE_CTR
6531 
6532  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes)
6533  size_t length = 16;
6534  unsigned char key[32];
6535  unsigned char iv[16];
6536 
6537  const cipher_info_t *cipher_info;
6538  cipher_context_t ctx_dec;
6539  cipher_context_t ctx_enc;
6540 
6541  unsigned char inbuf[64];
6542  unsigned char encbuf[64];
6543  unsigned char decbuf[64];
6544 
6545  size_t outlen = 0;
6546  size_t enclen = 0;
6547 
6548  memset( key, 0, 32 );
6549  memset( iv , 0, 16 );
6550 
6551  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6552  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6553 
6554  memset( inbuf, 5, 64 );
6555  memset( encbuf, 0, 64 );
6556  memset( decbuf, 0, 64 );
6557 
6558  /* Check and get info structures */
6560  fct_chk( NULL != cipher_info );
6561  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6562 
6563  /* Initialise enc and dec contexts */
6564  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6565  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6566 
6567  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6568  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6569 
6570  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6571  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6572 
6573  if( POLARSSL_MODE_CBC == cipher_info->mode )
6574  {
6575  enclen = cipher_get_block_size( &ctx_enc )
6576  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6577  }
6578  else
6579  {
6580  enclen = length;
6581  }
6582 
6583  /* encode length number of bytes from inbuf */
6584  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6585  if( POLARSSL_MODE_CBC == cipher_info->mode )
6586  {
6587  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6588  }
6589  else
6590  {
6591  fct_chk( outlen == enclen );
6592  }
6593 
6594  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6595  if( POLARSSL_MODE_CBC == cipher_info->mode )
6596  {
6597  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6598  }
6599  else
6600  {
6601  fct_chk( outlen == 0 );
6602  }
6603 
6604 
6605  /* decode the previously encoded string */
6606  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6607  if( POLARSSL_MODE_CBC == cipher_info->mode )
6608  {
6609  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6610  }
6611  else
6612  {
6613  fct_chk( enclen == outlen );
6614  }
6615 
6616  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6617  if( POLARSSL_MODE_CBC == cipher_info->mode )
6618  {
6619  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6620  }
6621  else
6622  {
6623  fct_chk( outlen == 0 );
6624  }
6625 
6626 
6627  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6628 
6629  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6630  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6631  FCT_TEST_END();
6632 #endif /* POLARSSL_CAMELLIA_C */
6633 #endif /* POLARSSL_CIPHER_MODE_CTR */
6634 
6635 #ifdef POLARSSL_CAMELLIA_C
6636 #ifdef POLARSSL_CIPHER_MODE_CTR
6637 
6638  FCT_TEST_BGN(camellia_encrypt_and_decrypt_17_bytes)
6639  size_t length = 17;
6640  unsigned char key[32];
6641  unsigned char iv[16];
6642 
6643  const cipher_info_t *cipher_info;
6644  cipher_context_t ctx_dec;
6645  cipher_context_t ctx_enc;
6646 
6647  unsigned char inbuf[64];
6648  unsigned char encbuf[64];
6649  unsigned char decbuf[64];
6650 
6651  size_t outlen = 0;
6652  size_t enclen = 0;
6653 
6654  memset( key, 0, 32 );
6655  memset( iv , 0, 16 );
6656 
6657  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6658  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6659 
6660  memset( inbuf, 5, 64 );
6661  memset( encbuf, 0, 64 );
6662  memset( decbuf, 0, 64 );
6663 
6664  /* Check and get info structures */
6666  fct_chk( NULL != cipher_info );
6667  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6668 
6669  /* Initialise enc and dec contexts */
6670  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6671  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6672 
6673  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6674  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6675 
6676  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6677  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6678 
6679  if( POLARSSL_MODE_CBC == cipher_info->mode )
6680  {
6681  enclen = cipher_get_block_size( &ctx_enc )
6682  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6683  }
6684  else
6685  {
6686  enclen = length;
6687  }
6688 
6689  /* encode length number of bytes from inbuf */
6690  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6691  if( POLARSSL_MODE_CBC == cipher_info->mode )
6692  {
6693  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6694  }
6695  else
6696  {
6697  fct_chk( outlen == enclen );
6698  }
6699 
6700  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6701  if( POLARSSL_MODE_CBC == cipher_info->mode )
6702  {
6703  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6704  }
6705  else
6706  {
6707  fct_chk( outlen == 0 );
6708  }
6709 
6710 
6711  /* decode the previously encoded string */
6712  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6713  if( POLARSSL_MODE_CBC == cipher_info->mode )
6714  {
6715  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6716  }
6717  else
6718  {
6719  fct_chk( enclen == outlen );
6720  }
6721 
6722  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6723  if( POLARSSL_MODE_CBC == cipher_info->mode )
6724  {
6725  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6726  }
6727  else
6728  {
6729  fct_chk( outlen == 0 );
6730  }
6731 
6732 
6733  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6734 
6735  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6736  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6737  FCT_TEST_END();
6738 #endif /* POLARSSL_CAMELLIA_C */
6739 #endif /* POLARSSL_CIPHER_MODE_CTR */
6740 
6741 #ifdef POLARSSL_CAMELLIA_C
6742 #ifdef POLARSSL_CIPHER_MODE_CTR
6743 
6744  FCT_TEST_BGN(camellia_encrypt_and_decrypt_31_bytes)
6745  size_t length = 31;
6746  unsigned char key[32];
6747  unsigned char iv[16];
6748 
6749  const cipher_info_t *cipher_info;
6750  cipher_context_t ctx_dec;
6751  cipher_context_t ctx_enc;
6752 
6753  unsigned char inbuf[64];
6754  unsigned char encbuf[64];
6755  unsigned char decbuf[64];
6756 
6757  size_t outlen = 0;
6758  size_t enclen = 0;
6759 
6760  memset( key, 0, 32 );
6761  memset( iv , 0, 16 );
6762 
6763  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6764  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6765 
6766  memset( inbuf, 5, 64 );
6767  memset( encbuf, 0, 64 );
6768  memset( decbuf, 0, 64 );
6769 
6770  /* Check and get info structures */
6772  fct_chk( NULL != cipher_info );
6773  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6774 
6775  /* Initialise enc and dec contexts */
6776  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6777  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6778 
6779  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6780  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6781 
6782  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6783  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6784 
6785  if( POLARSSL_MODE_CBC == cipher_info->mode )
6786  {
6787  enclen = cipher_get_block_size( &ctx_enc )
6788  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6789  }
6790  else
6791  {
6792  enclen = length;
6793  }
6794 
6795  /* encode length number of bytes from inbuf */
6796  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6797  if( POLARSSL_MODE_CBC == cipher_info->mode )
6798  {
6799  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6800  }
6801  else
6802  {
6803  fct_chk( outlen == enclen );
6804  }
6805 
6806  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6807  if( POLARSSL_MODE_CBC == cipher_info->mode )
6808  {
6809  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6810  }
6811  else
6812  {
6813  fct_chk( outlen == 0 );
6814  }
6815 
6816 
6817  /* decode the previously encoded string */
6818  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6819  if( POLARSSL_MODE_CBC == cipher_info->mode )
6820  {
6821  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6822  }
6823  else
6824  {
6825  fct_chk( enclen == outlen );
6826  }
6827 
6828  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6829  if( POLARSSL_MODE_CBC == cipher_info->mode )
6830  {
6831  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6832  }
6833  else
6834  {
6835  fct_chk( outlen == 0 );
6836  }
6837 
6838 
6839  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6840 
6841  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6842  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6843  FCT_TEST_END();
6844 #endif /* POLARSSL_CAMELLIA_C */
6845 #endif /* POLARSSL_CIPHER_MODE_CTR */
6846 
6847 #ifdef POLARSSL_CAMELLIA_C
6848 #ifdef POLARSSL_CIPHER_MODE_CTR
6849 
6850  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
6851  size_t length = 32;
6852  unsigned char key[32];
6853  unsigned char iv[16];
6854 
6855  const cipher_info_t *cipher_info;
6856  cipher_context_t ctx_dec;
6857  cipher_context_t ctx_enc;
6858 
6859  unsigned char inbuf[64];
6860  unsigned char encbuf[64];
6861  unsigned char decbuf[64];
6862 
6863  size_t outlen = 0;
6864  size_t enclen = 0;
6865 
6866  memset( key, 0, 32 );
6867  memset( iv , 0, 16 );
6868 
6869  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6870  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6871 
6872  memset( inbuf, 5, 64 );
6873  memset( encbuf, 0, 64 );
6874  memset( decbuf, 0, 64 );
6875 
6876  /* Check and get info structures */
6878  fct_chk( NULL != cipher_info );
6879  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6880 
6881  /* Initialise enc and dec contexts */
6882  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6883  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6884 
6885  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6886  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6887 
6888  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6889  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6890 
6891  if( POLARSSL_MODE_CBC == cipher_info->mode )
6892  {
6893  enclen = cipher_get_block_size( &ctx_enc )
6894  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
6895  }
6896  else
6897  {
6898  enclen = length;
6899  }
6900 
6901  /* encode length number of bytes from inbuf */
6902  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
6903  if( POLARSSL_MODE_CBC == cipher_info->mode )
6904  {
6905  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
6906  }
6907  else
6908  {
6909  fct_chk( outlen == enclen );
6910  }
6911 
6912  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
6913  if( POLARSSL_MODE_CBC == cipher_info->mode )
6914  {
6915  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
6916  }
6917  else
6918  {
6919  fct_chk( outlen == 0 );
6920  }
6921 
6922 
6923  /* decode the previously encoded string */
6924  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
6925  if( POLARSSL_MODE_CBC == cipher_info->mode )
6926  {
6927  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
6928  }
6929  else
6930  {
6931  fct_chk( enclen == outlen );
6932  }
6933 
6934  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
6935  if( POLARSSL_MODE_CBC == cipher_info->mode )
6936  {
6937  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
6938  }
6939  else
6940  {
6941  fct_chk( outlen == 0 );
6942  }
6943 
6944 
6945  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
6946 
6947  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
6948  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
6949  FCT_TEST_END();
6950 #endif /* POLARSSL_CAMELLIA_C */
6951 #endif /* POLARSSL_CIPHER_MODE_CTR */
6952 
6953 #ifdef POLARSSL_CAMELLIA_C
6954 #ifdef POLARSSL_CIPHER_MODE_CTR
6955 
6956  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
6957  size_t length = 33;
6958  unsigned char key[32];
6959  unsigned char iv[16];
6960 
6961  const cipher_info_t *cipher_info;
6962  cipher_context_t ctx_dec;
6963  cipher_context_t ctx_enc;
6964 
6965  unsigned char inbuf[64];
6966  unsigned char encbuf[64];
6967  unsigned char decbuf[64];
6968 
6969  size_t outlen = 0;
6970  size_t enclen = 0;
6971 
6972  memset( key, 0, 32 );
6973  memset( iv , 0, 16 );
6974 
6975  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
6976  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
6977 
6978  memset( inbuf, 5, 64 );
6979  memset( encbuf, 0, 64 );
6980  memset( decbuf, 0, 64 );
6981 
6982  /* Check and get info structures */
6984  fct_chk( NULL != cipher_info );
6985  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
6986 
6987  /* Initialise enc and dec contexts */
6988  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
6989  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
6990 
6991  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
6992  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
6993 
6994  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
6995  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
6996 
6997  if( POLARSSL_MODE_CBC == cipher_info->mode )
6998  {
6999  enclen = cipher_get_block_size( &ctx_enc )
7000  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7001  }
7002  else
7003  {
7004  enclen = length;
7005  }
7006 
7007  /* encode length number of bytes from inbuf */
7008  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
7009  if( POLARSSL_MODE_CBC == cipher_info->mode )
7010  {
7011  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7012  }
7013  else
7014  {
7015  fct_chk( outlen == enclen );
7016  }
7017 
7018  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
7019  if( POLARSSL_MODE_CBC == cipher_info->mode )
7020  {
7021  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7022  }
7023  else
7024  {
7025  fct_chk( outlen == 0 );
7026  }
7027 
7028 
7029  /* decode the previously encoded string */
7030  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7031  if( POLARSSL_MODE_CBC == cipher_info->mode )
7032  {
7033  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7034  }
7035  else
7036  {
7037  fct_chk( enclen == outlen );
7038  }
7039 
7040  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7041  if( POLARSSL_MODE_CBC == cipher_info->mode )
7042  {
7043  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7044  }
7045  else
7046  {
7047  fct_chk( outlen == 0 );
7048  }
7049 
7050 
7051  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7052 
7053  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7054  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7055  FCT_TEST_END();
7056 #endif /* POLARSSL_CAMELLIA_C */
7057 #endif /* POLARSSL_CIPHER_MODE_CTR */
7058 
7059 #ifdef POLARSSL_CAMELLIA_C
7060 #ifdef POLARSSL_CIPHER_MODE_CTR
7061 
7062  FCT_TEST_BGN(camellia_encrypt_and_decrypt_47_bytes)
7063  size_t length = 47;
7064  unsigned char key[32];
7065  unsigned char iv[16];
7066 
7067  const cipher_info_t *cipher_info;
7068  cipher_context_t ctx_dec;
7069  cipher_context_t ctx_enc;
7070 
7071  unsigned char inbuf[64];
7072  unsigned char encbuf[64];
7073  unsigned char decbuf[64];
7074 
7075  size_t outlen = 0;
7076  size_t enclen = 0;
7077 
7078  memset( key, 0, 32 );
7079  memset( iv , 0, 16 );
7080 
7081  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7082  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7083 
7084  memset( inbuf, 5, 64 );
7085  memset( encbuf, 0, 64 );
7086  memset( decbuf, 0, 64 );
7087 
7088  /* Check and get info structures */
7090  fct_chk( NULL != cipher_info );
7091  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
7092 
7093  /* Initialise enc and dec contexts */
7094  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7095  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7096 
7097  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7098  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7099 
7100  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7101  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7102 
7103  if( POLARSSL_MODE_CBC == cipher_info->mode )
7104  {
7105  enclen = cipher_get_block_size( &ctx_enc )
7106  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7107  }
7108  else
7109  {
7110  enclen = length;
7111  }
7112 
7113  /* encode length number of bytes from inbuf */
7114  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
7115  if( POLARSSL_MODE_CBC == cipher_info->mode )
7116  {
7117  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7118  }
7119  else
7120  {
7121  fct_chk( outlen == enclen );
7122  }
7123 
7124  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
7125  if( POLARSSL_MODE_CBC == cipher_info->mode )
7126  {
7127  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7128  }
7129  else
7130  {
7131  fct_chk( outlen == 0 );
7132  }
7133 
7134 
7135  /* decode the previously encoded string */
7136  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7137  if( POLARSSL_MODE_CBC == cipher_info->mode )
7138  {
7139  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7140  }
7141  else
7142  {
7143  fct_chk( enclen == outlen );
7144  }
7145 
7146  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7147  if( POLARSSL_MODE_CBC == cipher_info->mode )
7148  {
7149  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7150  }
7151  else
7152  {
7153  fct_chk( outlen == 0 );
7154  }
7155 
7156 
7157  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7158 
7159  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7160  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7161  FCT_TEST_END();
7162 #endif /* POLARSSL_CAMELLIA_C */
7163 #endif /* POLARSSL_CIPHER_MODE_CTR */
7164 
7165 #ifdef POLARSSL_CAMELLIA_C
7166 #ifdef POLARSSL_CIPHER_MODE_CTR
7167 
7168  FCT_TEST_BGN(camellia_encrypt_and_decrypt_48_bytes)
7169  size_t length = 48;
7170  unsigned char key[32];
7171  unsigned char iv[16];
7172 
7173  const cipher_info_t *cipher_info;
7174  cipher_context_t ctx_dec;
7175  cipher_context_t ctx_enc;
7176 
7177  unsigned char inbuf[64];
7178  unsigned char encbuf[64];
7179  unsigned char decbuf[64];
7180 
7181  size_t outlen = 0;
7182  size_t enclen = 0;
7183 
7184  memset( key, 0, 32 );
7185  memset( iv , 0, 16 );
7186 
7187  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7188  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7189 
7190  memset( inbuf, 5, 64 );
7191  memset( encbuf, 0, 64 );
7192  memset( decbuf, 0, 64 );
7193 
7194  /* Check and get info structures */
7196  fct_chk( NULL != cipher_info );
7197  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
7198 
7199  /* Initialise enc and dec contexts */
7200  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7201  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7202 
7203  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7204  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7205 
7206  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7207  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7208 
7209  if( POLARSSL_MODE_CBC == cipher_info->mode )
7210  {
7211  enclen = cipher_get_block_size( &ctx_enc )
7212  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7213  }
7214  else
7215  {
7216  enclen = length;
7217  }
7218 
7219  /* encode length number of bytes from inbuf */
7220  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
7221  if( POLARSSL_MODE_CBC == cipher_info->mode )
7222  {
7223  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7224  }
7225  else
7226  {
7227  fct_chk( outlen == enclen );
7228  }
7229 
7230  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
7231  if( POLARSSL_MODE_CBC == cipher_info->mode )
7232  {
7233  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7234  }
7235  else
7236  {
7237  fct_chk( outlen == 0 );
7238  }
7239 
7240 
7241  /* decode the previously encoded string */
7242  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7243  if( POLARSSL_MODE_CBC == cipher_info->mode )
7244  {
7245  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7246  }
7247  else
7248  {
7249  fct_chk( enclen == outlen );
7250  }
7251 
7252  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7253  if( POLARSSL_MODE_CBC == cipher_info->mode )
7254  {
7255  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7256  }
7257  else
7258  {
7259  fct_chk( outlen == 0 );
7260  }
7261 
7262 
7263  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7264 
7265  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7266  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7267  FCT_TEST_END();
7268 #endif /* POLARSSL_CAMELLIA_C */
7269 #endif /* POLARSSL_CIPHER_MODE_CTR */
7270 
7271 #ifdef POLARSSL_CAMELLIA_C
7272 #ifdef POLARSSL_CIPHER_MODE_CTR
7273 
7274  FCT_TEST_BGN(camellia_encrypt_and_decrypt_49_bytes)
7275  size_t length = 49;
7276  unsigned char key[32];
7277  unsigned char iv[16];
7278 
7279  const cipher_info_t *cipher_info;
7280  cipher_context_t ctx_dec;
7281  cipher_context_t ctx_enc;
7282 
7283  unsigned char inbuf[64];
7284  unsigned char encbuf[64];
7285  unsigned char decbuf[64];
7286 
7287  size_t outlen = 0;
7288  size_t enclen = 0;
7289 
7290  memset( key, 0, 32 );
7291  memset( iv , 0, 16 );
7292 
7293  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7294  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7295 
7296  memset( inbuf, 5, 64 );
7297  memset( encbuf, 0, 64 );
7298  memset( decbuf, 0, 64 );
7299 
7300  /* Check and get info structures */
7302  fct_chk( NULL != cipher_info );
7303  fct_chk( cipher_info_from_string( "CAMELLIA-128-CTR" ) == cipher_info );
7304 
7305  /* Initialise enc and dec contexts */
7306  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7307  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7308 
7309  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7310  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7311 
7312  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7313  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7314 
7315  if( POLARSSL_MODE_CBC == cipher_info->mode )
7316  {
7317  enclen = cipher_get_block_size( &ctx_enc )
7318  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7319  }
7320  else
7321  {
7322  enclen = length;
7323  }
7324 
7325  /* encode length number of bytes from inbuf */
7326  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
7327  if( POLARSSL_MODE_CBC == cipher_info->mode )
7328  {
7329  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7330  }
7331  else
7332  {
7333  fct_chk( outlen == enclen );
7334  }
7335 
7336  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
7337  if( POLARSSL_MODE_CBC == cipher_info->mode )
7338  {
7339  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7340  }
7341  else
7342  {
7343  fct_chk( outlen == 0 );
7344  }
7345 
7346 
7347  /* decode the previously encoded string */
7348  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7349  if( POLARSSL_MODE_CBC == cipher_info->mode )
7350  {
7351  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7352  }
7353  else
7354  {
7355  fct_chk( enclen == outlen );
7356  }
7357 
7358  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7359  if( POLARSSL_MODE_CBC == cipher_info->mode )
7360  {
7361  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7362  }
7363  else
7364  {
7365  fct_chk( outlen == 0 );
7366  }
7367 
7368 
7369  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7370 
7371  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7372  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7373  FCT_TEST_END();
7374 #endif /* POLARSSL_CAMELLIA_C */
7375 #endif /* POLARSSL_CIPHER_MODE_CTR */
7376 
7377 #ifdef POLARSSL_CAMELLIA_C
7378 #ifdef POLARSSL_CIPHER_MODE_CTR
7379 
7380  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes_in_multiple_parts)
7381  size_t first_length = 0;
7382  size_t second_length = 0;
7383  size_t length = first_length + second_length;
7384  unsigned char key[32];
7385  unsigned char iv[16];
7386 
7387  cipher_context_t ctx_dec;
7388  cipher_context_t ctx_enc;
7389  const cipher_info_t *cipher_info;
7390 
7391  unsigned char inbuf[64];
7392  unsigned char encbuf[64];
7393  unsigned char decbuf[64];
7394 
7395  size_t outlen = 0;
7396  size_t totaloutlen = 0;
7397  size_t enclen = 0;
7398 
7399  memset( key, 0, 32 );
7400  memset( iv , 0, 16 );
7401 
7402  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7403  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7404 
7405  memset( inbuf, 5, 64 );
7406  memset( encbuf, 0, 64 );
7407  memset( decbuf, 0, 64 );
7408 
7409  /* Initialise enc and dec contexts */
7411  fct_chk( NULL != cipher_info);
7412 
7413  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7414  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7415 
7416  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7417  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7418 
7419  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7420  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7421 
7422  if( POLARSSL_MODE_CBC == cipher_info->mode )
7423  {
7424  enclen = cipher_get_block_size(&ctx_enc )
7425  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7426  }
7427  else
7428  {
7429  enclen = length;
7430  }
7431 
7432  /* encode length number of bytes from inbuf */
7433  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
7434  totaloutlen = outlen;
7435  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
7436  totaloutlen += outlen;
7437  if( POLARSSL_MODE_CBC == cipher_info->mode )
7438  {
7439  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7440  }
7441  else
7442  {
7443  fct_chk( totaloutlen == enclen );
7444  }
7445  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
7446  totaloutlen += outlen;
7447  if( POLARSSL_MODE_CBC == cipher_info->mode )
7448  {
7449  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7450  }
7451  else
7452  {
7453  fct_chk( outlen == 0 );
7454  }
7455 
7456  /* decode the previously encoded string */
7457  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7458  if( POLARSSL_MODE_CBC == cipher_info->mode )
7459  {
7460  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7461  }
7462  else
7463  {
7464  fct_chk( enclen == outlen );
7465  }
7466  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7467  if( POLARSSL_MODE_CBC == cipher_info->mode )
7468  {
7469  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7470  }
7471  else
7472  {
7473  fct_chk( outlen == 0 );
7474  }
7475 
7476 
7477  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7478 
7479  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7480  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7481  FCT_TEST_END();
7482 #endif /* POLARSSL_CAMELLIA_C */
7483 #endif /* POLARSSL_CIPHER_MODE_CTR */
7484 
7485 #ifdef POLARSSL_CAMELLIA_C
7486 #ifdef POLARSSL_CIPHER_MODE_CTR
7487 
7488  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
7489  size_t first_length = 1;
7490  size_t second_length = 0;
7491  size_t length = first_length + second_length;
7492  unsigned char key[32];
7493  unsigned char iv[16];
7494 
7495  cipher_context_t ctx_dec;
7496  cipher_context_t ctx_enc;
7497  const cipher_info_t *cipher_info;
7498 
7499  unsigned char inbuf[64];
7500  unsigned char encbuf[64];
7501  unsigned char decbuf[64];
7502 
7503  size_t outlen = 0;
7504  size_t totaloutlen = 0;
7505  size_t enclen = 0;
7506 
7507  memset( key, 0, 32 );
7508  memset( iv , 0, 16 );
7509 
7510  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7511  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7512 
7513  memset( inbuf, 5, 64 );
7514  memset( encbuf, 0, 64 );
7515  memset( decbuf, 0, 64 );
7516 
7517  /* Initialise enc and dec contexts */
7519  fct_chk( NULL != cipher_info);
7520 
7521  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7522  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7523 
7524  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7525  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7526 
7527  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7528  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7529 
7530  if( POLARSSL_MODE_CBC == cipher_info->mode )
7531  {
7532  enclen = cipher_get_block_size(&ctx_enc )
7533  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7534  }
7535  else
7536  {
7537  enclen = length;
7538  }
7539 
7540  /* encode length number of bytes from inbuf */
7541  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
7542  totaloutlen = outlen;
7543  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
7544  totaloutlen += outlen;
7545  if( POLARSSL_MODE_CBC == cipher_info->mode )
7546  {
7547  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7548  }
7549  else
7550  {
7551  fct_chk( totaloutlen == enclen );
7552  }
7553  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
7554  totaloutlen += outlen;
7555  if( POLARSSL_MODE_CBC == cipher_info->mode )
7556  {
7557  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7558  }
7559  else
7560  {
7561  fct_chk( outlen == 0 );
7562  }
7563 
7564  /* decode the previously encoded string */
7565  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7566  if( POLARSSL_MODE_CBC == cipher_info->mode )
7567  {
7568  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7569  }
7570  else
7571  {
7572  fct_chk( enclen == outlen );
7573  }
7574  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7575  if( POLARSSL_MODE_CBC == cipher_info->mode )
7576  {
7577  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7578  }
7579  else
7580  {
7581  fct_chk( outlen == 0 );
7582  }
7583 
7584 
7585  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7586 
7587  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7588  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7589  FCT_TEST_END();
7590 #endif /* POLARSSL_CAMELLIA_C */
7591 #endif /* POLARSSL_CIPHER_MODE_CTR */
7592 
7593 #ifdef POLARSSL_CAMELLIA_C
7594 #ifdef POLARSSL_CIPHER_MODE_CTR
7595 
7596  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
7597  size_t first_length = 0;
7598  size_t second_length = 1;
7599  size_t length = first_length + second_length;
7600  unsigned char key[32];
7601  unsigned char iv[16];
7602 
7603  cipher_context_t ctx_dec;
7604  cipher_context_t ctx_enc;
7605  const cipher_info_t *cipher_info;
7606 
7607  unsigned char inbuf[64];
7608  unsigned char encbuf[64];
7609  unsigned char decbuf[64];
7610 
7611  size_t outlen = 0;
7612  size_t totaloutlen = 0;
7613  size_t enclen = 0;
7614 
7615  memset( key, 0, 32 );
7616  memset( iv , 0, 16 );
7617 
7618  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7619  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7620 
7621  memset( inbuf, 5, 64 );
7622  memset( encbuf, 0, 64 );
7623  memset( decbuf, 0, 64 );
7624 
7625  /* Initialise enc and dec contexts */
7627  fct_chk( NULL != cipher_info);
7628 
7629  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7630  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7631 
7632  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7633  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7634 
7635  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7636  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7637 
7638  if( POLARSSL_MODE_CBC == cipher_info->mode )
7639  {
7640  enclen = cipher_get_block_size(&ctx_enc )
7641  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7642  }
7643  else
7644  {
7645  enclen = length;
7646  }
7647 
7648  /* encode length number of bytes from inbuf */
7649  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
7650  totaloutlen = outlen;
7651  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
7652  totaloutlen += outlen;
7653  if( POLARSSL_MODE_CBC == cipher_info->mode )
7654  {
7655  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7656  }
7657  else
7658  {
7659  fct_chk( totaloutlen == enclen );
7660  }
7661  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
7662  totaloutlen += outlen;
7663  if( POLARSSL_MODE_CBC == cipher_info->mode )
7664  {
7665  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7666  }
7667  else
7668  {
7669  fct_chk( outlen == 0 );
7670  }
7671 
7672  /* decode the previously encoded string */
7673  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7674  if( POLARSSL_MODE_CBC == cipher_info->mode )
7675  {
7676  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7677  }
7678  else
7679  {
7680  fct_chk( enclen == outlen );
7681  }
7682  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7683  if( POLARSSL_MODE_CBC == cipher_info->mode )
7684  {
7685  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7686  }
7687  else
7688  {
7689  fct_chk( outlen == 0 );
7690  }
7691 
7692 
7693  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7694 
7695  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7696  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7697  FCT_TEST_END();
7698 #endif /* POLARSSL_CAMELLIA_C */
7699 #endif /* POLARSSL_CIPHER_MODE_CTR */
7700 
7701 #ifdef POLARSSL_CAMELLIA_C
7702 #ifdef POLARSSL_CIPHER_MODE_CTR
7703 
7704  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
7705  size_t first_length = 16;
7706  size_t second_length = 0;
7707  size_t length = first_length + second_length;
7708  unsigned char key[32];
7709  unsigned char iv[16];
7710 
7711  cipher_context_t ctx_dec;
7712  cipher_context_t ctx_enc;
7713  const cipher_info_t *cipher_info;
7714 
7715  unsigned char inbuf[64];
7716  unsigned char encbuf[64];
7717  unsigned char decbuf[64];
7718 
7719  size_t outlen = 0;
7720  size_t totaloutlen = 0;
7721  size_t enclen = 0;
7722 
7723  memset( key, 0, 32 );
7724  memset( iv , 0, 16 );
7725 
7726  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7727  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7728 
7729  memset( inbuf, 5, 64 );
7730  memset( encbuf, 0, 64 );
7731  memset( decbuf, 0, 64 );
7732 
7733  /* Initialise enc and dec contexts */
7735  fct_chk( NULL != cipher_info);
7736 
7737  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7738  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7739 
7740  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7741  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7742 
7743  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7744  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7745 
7746  if( POLARSSL_MODE_CBC == cipher_info->mode )
7747  {
7748  enclen = cipher_get_block_size(&ctx_enc )
7749  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7750  }
7751  else
7752  {
7753  enclen = length;
7754  }
7755 
7756  /* encode length number of bytes from inbuf */
7757  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
7758  totaloutlen = outlen;
7759  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
7760  totaloutlen += outlen;
7761  if( POLARSSL_MODE_CBC == cipher_info->mode )
7762  {
7763  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7764  }
7765  else
7766  {
7767  fct_chk( totaloutlen == enclen );
7768  }
7769  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
7770  totaloutlen += outlen;
7771  if( POLARSSL_MODE_CBC == cipher_info->mode )
7772  {
7773  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7774  }
7775  else
7776  {
7777  fct_chk( outlen == 0 );
7778  }
7779 
7780  /* decode the previously encoded string */
7781  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7782  if( POLARSSL_MODE_CBC == cipher_info->mode )
7783  {
7784  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7785  }
7786  else
7787  {
7788  fct_chk( enclen == outlen );
7789  }
7790  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7791  if( POLARSSL_MODE_CBC == cipher_info->mode )
7792  {
7793  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7794  }
7795  else
7796  {
7797  fct_chk( outlen == 0 );
7798  }
7799 
7800 
7801  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7802 
7803  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7804  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7805  FCT_TEST_END();
7806 #endif /* POLARSSL_CAMELLIA_C */
7807 #endif /* POLARSSL_CIPHER_MODE_CTR */
7808 
7809 #ifdef POLARSSL_CAMELLIA_C
7810 #ifdef POLARSSL_CIPHER_MODE_CTR
7811 
7812  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
7813  size_t first_length = 0;
7814  size_t second_length = 16;
7815  size_t length = first_length + second_length;
7816  unsigned char key[32];
7817  unsigned char iv[16];
7818 
7819  cipher_context_t ctx_dec;
7820  cipher_context_t ctx_enc;
7821  const cipher_info_t *cipher_info;
7822 
7823  unsigned char inbuf[64];
7824  unsigned char encbuf[64];
7825  unsigned char decbuf[64];
7826 
7827  size_t outlen = 0;
7828  size_t totaloutlen = 0;
7829  size_t enclen = 0;
7830 
7831  memset( key, 0, 32 );
7832  memset( iv , 0, 16 );
7833 
7834  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7835  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7836 
7837  memset( inbuf, 5, 64 );
7838  memset( encbuf, 0, 64 );
7839  memset( decbuf, 0, 64 );
7840 
7841  /* Initialise enc and dec contexts */
7843  fct_chk( NULL != cipher_info);
7844 
7845  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7846  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7847 
7848  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7849  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7850 
7851  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7852  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7853 
7854  if( POLARSSL_MODE_CBC == cipher_info->mode )
7855  {
7856  enclen = cipher_get_block_size(&ctx_enc )
7857  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7858  }
7859  else
7860  {
7861  enclen = length;
7862  }
7863 
7864  /* encode length number of bytes from inbuf */
7865  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
7866  totaloutlen = outlen;
7867  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
7868  totaloutlen += outlen;
7869  if( POLARSSL_MODE_CBC == cipher_info->mode )
7870  {
7871  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7872  }
7873  else
7874  {
7875  fct_chk( totaloutlen == enclen );
7876  }
7877  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
7878  totaloutlen += outlen;
7879  if( POLARSSL_MODE_CBC == cipher_info->mode )
7880  {
7881  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7882  }
7883  else
7884  {
7885  fct_chk( outlen == 0 );
7886  }
7887 
7888  /* decode the previously encoded string */
7889  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7890  if( POLARSSL_MODE_CBC == cipher_info->mode )
7891  {
7892  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
7893  }
7894  else
7895  {
7896  fct_chk( enclen == outlen );
7897  }
7898  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
7899  if( POLARSSL_MODE_CBC == cipher_info->mode )
7900  {
7901  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
7902  }
7903  else
7904  {
7905  fct_chk( outlen == 0 );
7906  }
7907 
7908 
7909  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
7910 
7911  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
7912  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
7913  FCT_TEST_END();
7914 #endif /* POLARSSL_CAMELLIA_C */
7915 #endif /* POLARSSL_CIPHER_MODE_CTR */
7916 
7917 #ifdef POLARSSL_CAMELLIA_C
7918 #ifdef POLARSSL_CIPHER_MODE_CTR
7919 
7920  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
7921  size_t first_length = 1;
7922  size_t second_length = 15;
7923  size_t length = first_length + second_length;
7924  unsigned char key[32];
7925  unsigned char iv[16];
7926 
7927  cipher_context_t ctx_dec;
7928  cipher_context_t ctx_enc;
7929  const cipher_info_t *cipher_info;
7930 
7931  unsigned char inbuf[64];
7932  unsigned char encbuf[64];
7933  unsigned char decbuf[64];
7934 
7935  size_t outlen = 0;
7936  size_t totaloutlen = 0;
7937  size_t enclen = 0;
7938 
7939  memset( key, 0, 32 );
7940  memset( iv , 0, 16 );
7941 
7942  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
7943  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
7944 
7945  memset( inbuf, 5, 64 );
7946  memset( encbuf, 0, 64 );
7947  memset( decbuf, 0, 64 );
7948 
7949  /* Initialise enc and dec contexts */
7951  fct_chk( NULL != cipher_info);
7952 
7953  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
7954  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
7955 
7956  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
7957  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
7958 
7959  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
7960  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
7961 
7962  if( POLARSSL_MODE_CBC == cipher_info->mode )
7963  {
7964  enclen = cipher_get_block_size(&ctx_enc )
7965  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
7966  }
7967  else
7968  {
7969  enclen = length;
7970  }
7971 
7972  /* encode length number of bytes from inbuf */
7973  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
7974  totaloutlen = outlen;
7975  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
7976  totaloutlen += outlen;
7977  if( POLARSSL_MODE_CBC == cipher_info->mode )
7978  {
7979  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
7980  }
7981  else
7982  {
7983  fct_chk( totaloutlen == enclen );
7984  }
7985  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
7986  totaloutlen += outlen;
7987  if( POLARSSL_MODE_CBC == cipher_info->mode )
7988  {
7989  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
7990  }
7991  else
7992  {
7993  fct_chk( outlen == 0 );
7994  }
7995 
7996  /* decode the previously encoded string */
7997  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
7998  if( POLARSSL_MODE_CBC == cipher_info->mode )
7999  {
8000  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8001  }
8002  else
8003  {
8004  fct_chk( enclen == outlen );
8005  }
8006  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8007  if( POLARSSL_MODE_CBC == cipher_info->mode )
8008  {
8009  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8010  }
8011  else
8012  {
8013  fct_chk( outlen == 0 );
8014  }
8015 
8016 
8017  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8018 
8019  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8020  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8021  FCT_TEST_END();
8022 #endif /* POLARSSL_CAMELLIA_C */
8023 #endif /* POLARSSL_CIPHER_MODE_CTR */
8024 
8025 #ifdef POLARSSL_CAMELLIA_C
8026 #ifdef POLARSSL_CIPHER_MODE_CTR
8027 
8028  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
8029  size_t first_length = 15;
8030  size_t second_length = 1;
8031  size_t length = first_length + second_length;
8032  unsigned char key[32];
8033  unsigned char iv[16];
8034 
8035  cipher_context_t ctx_dec;
8036  cipher_context_t ctx_enc;
8037  const cipher_info_t *cipher_info;
8038 
8039  unsigned char inbuf[64];
8040  unsigned char encbuf[64];
8041  unsigned char decbuf[64];
8042 
8043  size_t outlen = 0;
8044  size_t totaloutlen = 0;
8045  size_t enclen = 0;
8046 
8047  memset( key, 0, 32 );
8048  memset( iv , 0, 16 );
8049 
8050  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8051  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8052 
8053  memset( inbuf, 5, 64 );
8054  memset( encbuf, 0, 64 );
8055  memset( decbuf, 0, 64 );
8056 
8057  /* Initialise enc and dec contexts */
8059  fct_chk( NULL != cipher_info);
8060 
8061  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8062  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8063 
8064  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
8065  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
8066 
8067  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8068  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8069 
8070  if( POLARSSL_MODE_CBC == cipher_info->mode )
8071  {
8072  enclen = cipher_get_block_size(&ctx_enc )
8073  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8074  }
8075  else
8076  {
8077  enclen = length;
8078  }
8079 
8080  /* encode length number of bytes from inbuf */
8081  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
8082  totaloutlen = outlen;
8083  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
8084  totaloutlen += outlen;
8085  if( POLARSSL_MODE_CBC == cipher_info->mode )
8086  {
8087  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8088  }
8089  else
8090  {
8091  fct_chk( totaloutlen == enclen );
8092  }
8093  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
8094  totaloutlen += outlen;
8095  if( POLARSSL_MODE_CBC == cipher_info->mode )
8096  {
8097  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8098  }
8099  else
8100  {
8101  fct_chk( outlen == 0 );
8102  }
8103 
8104  /* decode the previously encoded string */
8105  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8106  if( POLARSSL_MODE_CBC == cipher_info->mode )
8107  {
8108  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8109  }
8110  else
8111  {
8112  fct_chk( enclen == outlen );
8113  }
8114  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8115  if( POLARSSL_MODE_CBC == cipher_info->mode )
8116  {
8117  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8118  }
8119  else
8120  {
8121  fct_chk( outlen == 0 );
8122  }
8123 
8124 
8125  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8126 
8127  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8128  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8129  FCT_TEST_END();
8130 #endif /* POLARSSL_CAMELLIA_C */
8131 #endif /* POLARSSL_CIPHER_MODE_CTR */
8132 
8133 #ifdef POLARSSL_CAMELLIA_C
8134 #ifdef POLARSSL_CIPHER_MODE_CTR
8135 
8136  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
8137  size_t first_length = 15;
8138  size_t second_length = 7;
8139  size_t length = first_length + second_length;
8140  unsigned char key[32];
8141  unsigned char iv[16];
8142 
8143  cipher_context_t ctx_dec;
8144  cipher_context_t ctx_enc;
8145  const cipher_info_t *cipher_info;
8146 
8147  unsigned char inbuf[64];
8148  unsigned char encbuf[64];
8149  unsigned char decbuf[64];
8150 
8151  size_t outlen = 0;
8152  size_t totaloutlen = 0;
8153  size_t enclen = 0;
8154 
8155  memset( key, 0, 32 );
8156  memset( iv , 0, 16 );
8157 
8158  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8159  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8160 
8161  memset( inbuf, 5, 64 );
8162  memset( encbuf, 0, 64 );
8163  memset( decbuf, 0, 64 );
8164 
8165  /* Initialise enc and dec contexts */
8167  fct_chk( NULL != cipher_info);
8168 
8169  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8170  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8171 
8172  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
8173  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
8174 
8175  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8176  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8177 
8178  if( POLARSSL_MODE_CBC == cipher_info->mode )
8179  {
8180  enclen = cipher_get_block_size(&ctx_enc )
8181  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8182  }
8183  else
8184  {
8185  enclen = length;
8186  }
8187 
8188  /* encode length number of bytes from inbuf */
8189  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
8190  totaloutlen = outlen;
8191  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
8192  totaloutlen += outlen;
8193  if( POLARSSL_MODE_CBC == cipher_info->mode )
8194  {
8195  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8196  }
8197  else
8198  {
8199  fct_chk( totaloutlen == enclen );
8200  }
8201  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
8202  totaloutlen += outlen;
8203  if( POLARSSL_MODE_CBC == cipher_info->mode )
8204  {
8205  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8206  }
8207  else
8208  {
8209  fct_chk( outlen == 0 );
8210  }
8211 
8212  /* decode the previously encoded string */
8213  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8214  if( POLARSSL_MODE_CBC == cipher_info->mode )
8215  {
8216  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8217  }
8218  else
8219  {
8220  fct_chk( enclen == outlen );
8221  }
8222  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8223  if( POLARSSL_MODE_CBC == cipher_info->mode )
8224  {
8225  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8226  }
8227  else
8228  {
8229  fct_chk( outlen == 0 );
8230  }
8231 
8232 
8233  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8234 
8235  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8236  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8237  FCT_TEST_END();
8238 #endif /* POLARSSL_CAMELLIA_C */
8239 #endif /* POLARSSL_CIPHER_MODE_CTR */
8240 
8241 #ifdef POLARSSL_CAMELLIA_C
8242 #ifdef POLARSSL_CIPHER_MODE_CTR
8243 
8244  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
8245  size_t first_length = 16;
8246  size_t second_length = 6;
8247  size_t length = first_length + second_length;
8248  unsigned char key[32];
8249  unsigned char iv[16];
8250 
8251  cipher_context_t ctx_dec;
8252  cipher_context_t ctx_enc;
8253  const cipher_info_t *cipher_info;
8254 
8255  unsigned char inbuf[64];
8256  unsigned char encbuf[64];
8257  unsigned char decbuf[64];
8258 
8259  size_t outlen = 0;
8260  size_t totaloutlen = 0;
8261  size_t enclen = 0;
8262 
8263  memset( key, 0, 32 );
8264  memset( iv , 0, 16 );
8265 
8266  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8267  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8268 
8269  memset( inbuf, 5, 64 );
8270  memset( encbuf, 0, 64 );
8271  memset( decbuf, 0, 64 );
8272 
8273  /* Initialise enc and dec contexts */
8275  fct_chk( NULL != cipher_info);
8276 
8277  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8278  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8279 
8280  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
8281  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
8282 
8283  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8284  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8285 
8286  if( POLARSSL_MODE_CBC == cipher_info->mode )
8287  {
8288  enclen = cipher_get_block_size(&ctx_enc )
8289  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8290  }
8291  else
8292  {
8293  enclen = length;
8294  }
8295 
8296  /* encode length number of bytes from inbuf */
8297  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
8298  totaloutlen = outlen;
8299  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
8300  totaloutlen += outlen;
8301  if( POLARSSL_MODE_CBC == cipher_info->mode )
8302  {
8303  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8304  }
8305  else
8306  {
8307  fct_chk( totaloutlen == enclen );
8308  }
8309  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
8310  totaloutlen += outlen;
8311  if( POLARSSL_MODE_CBC == cipher_info->mode )
8312  {
8313  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8314  }
8315  else
8316  {
8317  fct_chk( outlen == 0 );
8318  }
8319 
8320  /* decode the previously encoded string */
8321  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8322  if( POLARSSL_MODE_CBC == cipher_info->mode )
8323  {
8324  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8325  }
8326  else
8327  {
8328  fct_chk( enclen == outlen );
8329  }
8330  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8331  if( POLARSSL_MODE_CBC == cipher_info->mode )
8332  {
8333  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8334  }
8335  else
8336  {
8337  fct_chk( outlen == 0 );
8338  }
8339 
8340 
8341  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8342 
8343  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8344  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8345  FCT_TEST_END();
8346 #endif /* POLARSSL_CAMELLIA_C */
8347 #endif /* POLARSSL_CIPHER_MODE_CTR */
8348 
8349 #ifdef POLARSSL_CAMELLIA_C
8350 #ifdef POLARSSL_CIPHER_MODE_CTR
8351 
8352  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
8353  size_t first_length = 17;
8354  size_t second_length = 6;
8355  size_t length = first_length + second_length;
8356  unsigned char key[32];
8357  unsigned char iv[16];
8358 
8359  cipher_context_t ctx_dec;
8360  cipher_context_t ctx_enc;
8361  const cipher_info_t *cipher_info;
8362 
8363  unsigned char inbuf[64];
8364  unsigned char encbuf[64];
8365  unsigned char decbuf[64];
8366 
8367  size_t outlen = 0;
8368  size_t totaloutlen = 0;
8369  size_t enclen = 0;
8370 
8371  memset( key, 0, 32 );
8372  memset( iv , 0, 16 );
8373 
8374  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8375  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8376 
8377  memset( inbuf, 5, 64 );
8378  memset( encbuf, 0, 64 );
8379  memset( decbuf, 0, 64 );
8380 
8381  /* Initialise enc and dec contexts */
8383  fct_chk( NULL != cipher_info);
8384 
8385  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8386  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8387 
8388  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
8389  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
8390 
8391  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8392  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8393 
8394  if( POLARSSL_MODE_CBC == cipher_info->mode )
8395  {
8396  enclen = cipher_get_block_size(&ctx_enc )
8397  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8398  }
8399  else
8400  {
8401  enclen = length;
8402  }
8403 
8404  /* encode length number of bytes from inbuf */
8405  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
8406  totaloutlen = outlen;
8407  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
8408  totaloutlen += outlen;
8409  if( POLARSSL_MODE_CBC == cipher_info->mode )
8410  {
8411  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8412  }
8413  else
8414  {
8415  fct_chk( totaloutlen == enclen );
8416  }
8417  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
8418  totaloutlen += outlen;
8419  if( POLARSSL_MODE_CBC == cipher_info->mode )
8420  {
8421  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8422  }
8423  else
8424  {
8425  fct_chk( outlen == 0 );
8426  }
8427 
8428  /* decode the previously encoded string */
8429  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8430  if( POLARSSL_MODE_CBC == cipher_info->mode )
8431  {
8432  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8433  }
8434  else
8435  {
8436  fct_chk( enclen == outlen );
8437  }
8438  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8439  if( POLARSSL_MODE_CBC == cipher_info->mode )
8440  {
8441  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8442  }
8443  else
8444  {
8445  fct_chk( outlen == 0 );
8446  }
8447 
8448 
8449  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8450 
8451  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8452  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8453  FCT_TEST_END();
8454 #endif /* POLARSSL_CAMELLIA_C */
8455 #endif /* POLARSSL_CIPHER_MODE_CTR */
8456 
8457 #ifdef POLARSSL_CAMELLIA_C
8458 #ifdef POLARSSL_CIPHER_MODE_CTR
8459 
8460  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
8461  size_t first_length = 16;
8462  size_t second_length = 16;
8463  size_t length = first_length + second_length;
8464  unsigned char key[32];
8465  unsigned char iv[16];
8466 
8467  cipher_context_t ctx_dec;
8468  cipher_context_t ctx_enc;
8469  const cipher_info_t *cipher_info;
8470 
8471  unsigned char inbuf[64];
8472  unsigned char encbuf[64];
8473  unsigned char decbuf[64];
8474 
8475  size_t outlen = 0;
8476  size_t totaloutlen = 0;
8477  size_t enclen = 0;
8478 
8479  memset( key, 0, 32 );
8480  memset( iv , 0, 16 );
8481 
8482  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8483  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8484 
8485  memset( inbuf, 5, 64 );
8486  memset( encbuf, 0, 64 );
8487  memset( decbuf, 0, 64 );
8488 
8489  /* Initialise enc and dec contexts */
8491  fct_chk( NULL != cipher_info);
8492 
8493  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8494  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8495 
8496  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
8497  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 128, POLARSSL_ENCRYPT ) );
8498 
8499  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8500  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8501 
8502  if( POLARSSL_MODE_CBC == cipher_info->mode )
8503  {
8504  enclen = cipher_get_block_size(&ctx_enc )
8505  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8506  }
8507  else
8508  {
8509  enclen = length;
8510  }
8511 
8512  /* encode length number of bytes from inbuf */
8513  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
8514  totaloutlen = outlen;
8515  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
8516  totaloutlen += outlen;
8517  if( POLARSSL_MODE_CBC == cipher_info->mode )
8518  {
8519  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8520  }
8521  else
8522  {
8523  fct_chk( totaloutlen == enclen );
8524  }
8525  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
8526  totaloutlen += outlen;
8527  if( POLARSSL_MODE_CBC == cipher_info->mode )
8528  {
8529  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8530  }
8531  else
8532  {
8533  fct_chk( outlen == 0 );
8534  }
8535 
8536  /* decode the previously encoded string */
8537  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8538  if( POLARSSL_MODE_CBC == cipher_info->mode )
8539  {
8540  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8541  }
8542  else
8543  {
8544  fct_chk( enclen == outlen );
8545  }
8546  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8547  if( POLARSSL_MODE_CBC == cipher_info->mode )
8548  {
8549  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8550  }
8551  else
8552  {
8553  fct_chk( outlen == 0 );
8554  }
8555 
8556 
8557  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8558 
8559  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8560  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8561  FCT_TEST_END();
8562 #endif /* POLARSSL_CAMELLIA_C */
8563 #endif /* POLARSSL_CIPHER_MODE_CTR */
8564 
8565 #ifdef POLARSSL_CAMELLIA_C
8566 
8567  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes)
8568  size_t length = 0;
8569  unsigned char key[32];
8570  unsigned char iv[16];
8571 
8572  const cipher_info_t *cipher_info;
8573  cipher_context_t ctx_dec;
8574  cipher_context_t ctx_enc;
8575 
8576  unsigned char inbuf[64];
8577  unsigned char encbuf[64];
8578  unsigned char decbuf[64];
8579 
8580  size_t outlen = 0;
8581  size_t enclen = 0;
8582 
8583  memset( key, 0, 32 );
8584  memset( iv , 0, 16 );
8585 
8586  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8587  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8588 
8589  memset( inbuf, 5, 64 );
8590  memset( encbuf, 0, 64 );
8591  memset( decbuf, 0, 64 );
8592 
8593  /* Check and get info structures */
8595  fct_chk( NULL != cipher_info );
8596  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
8597 
8598  /* Initialise enc and dec contexts */
8599  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8600  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8601 
8602  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
8603  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
8604 
8605  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8606  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8607 
8608  if( POLARSSL_MODE_CBC == cipher_info->mode )
8609  {
8610  enclen = cipher_get_block_size( &ctx_enc )
8611  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8612  }
8613  else
8614  {
8615  enclen = length;
8616  }
8617 
8618  /* encode length number of bytes from inbuf */
8619  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
8620  if( POLARSSL_MODE_CBC == cipher_info->mode )
8621  {
8622  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8623  }
8624  else
8625  {
8626  fct_chk( outlen == enclen );
8627  }
8628 
8629  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
8630  if( POLARSSL_MODE_CBC == cipher_info->mode )
8631  {
8632  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8633  }
8634  else
8635  {
8636  fct_chk( outlen == 0 );
8637  }
8638 
8639 
8640  /* decode the previously encoded string */
8641  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8642  if( POLARSSL_MODE_CBC == cipher_info->mode )
8643  {
8644  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8645  }
8646  else
8647  {
8648  fct_chk( enclen == outlen );
8649  }
8650 
8651  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8652  if( POLARSSL_MODE_CBC == cipher_info->mode )
8653  {
8654  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8655  }
8656  else
8657  {
8658  fct_chk( outlen == 0 );
8659  }
8660 
8661 
8662  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8663 
8664  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8665  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8666  FCT_TEST_END();
8667 #endif /* POLARSSL_CAMELLIA_C */
8668 
8669 #ifdef POLARSSL_CAMELLIA_C
8670 
8671  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_byte)
8672  size_t length = 1;
8673  unsigned char key[32];
8674  unsigned char iv[16];
8675 
8676  const cipher_info_t *cipher_info;
8677  cipher_context_t ctx_dec;
8678  cipher_context_t ctx_enc;
8679 
8680  unsigned char inbuf[64];
8681  unsigned char encbuf[64];
8682  unsigned char decbuf[64];
8683 
8684  size_t outlen = 0;
8685  size_t enclen = 0;
8686 
8687  memset( key, 0, 32 );
8688  memset( iv , 0, 16 );
8689 
8690  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8691  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8692 
8693  memset( inbuf, 5, 64 );
8694  memset( encbuf, 0, 64 );
8695  memset( decbuf, 0, 64 );
8696 
8697  /* Check and get info structures */
8699  fct_chk( NULL != cipher_info );
8700  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
8701 
8702  /* Initialise enc and dec contexts */
8703  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8704  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8705 
8706  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
8707  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
8708 
8709  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8710  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8711 
8712  if( POLARSSL_MODE_CBC == cipher_info->mode )
8713  {
8714  enclen = cipher_get_block_size( &ctx_enc )
8715  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8716  }
8717  else
8718  {
8719  enclen = length;
8720  }
8721 
8722  /* encode length number of bytes from inbuf */
8723  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
8724  if( POLARSSL_MODE_CBC == cipher_info->mode )
8725  {
8726  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8727  }
8728  else
8729  {
8730  fct_chk( outlen == enclen );
8731  }
8732 
8733  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
8734  if( POLARSSL_MODE_CBC == cipher_info->mode )
8735  {
8736  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8737  }
8738  else
8739  {
8740  fct_chk( outlen == 0 );
8741  }
8742 
8743 
8744  /* decode the previously encoded string */
8745  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8746  if( POLARSSL_MODE_CBC == cipher_info->mode )
8747  {
8748  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8749  }
8750  else
8751  {
8752  fct_chk( enclen == outlen );
8753  }
8754 
8755  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8756  if( POLARSSL_MODE_CBC == cipher_info->mode )
8757  {
8758  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8759  }
8760  else
8761  {
8762  fct_chk( outlen == 0 );
8763  }
8764 
8765 
8766  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8767 
8768  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8769  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8770  FCT_TEST_END();
8771 #endif /* POLARSSL_CAMELLIA_C */
8772 
8773 #ifdef POLARSSL_CAMELLIA_C
8774 
8775  FCT_TEST_BGN(camellia_encrypt_and_decrypt_2_bytes)
8776  size_t length = 2;
8777  unsigned char key[32];
8778  unsigned char iv[16];
8779 
8780  const cipher_info_t *cipher_info;
8781  cipher_context_t ctx_dec;
8782  cipher_context_t ctx_enc;
8783 
8784  unsigned char inbuf[64];
8785  unsigned char encbuf[64];
8786  unsigned char decbuf[64];
8787 
8788  size_t outlen = 0;
8789  size_t enclen = 0;
8790 
8791  memset( key, 0, 32 );
8792  memset( iv , 0, 16 );
8793 
8794  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8795  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8796 
8797  memset( inbuf, 5, 64 );
8798  memset( encbuf, 0, 64 );
8799  memset( decbuf, 0, 64 );
8800 
8801  /* Check and get info structures */
8803  fct_chk( NULL != cipher_info );
8804  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
8805 
8806  /* Initialise enc and dec contexts */
8807  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8808  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8809 
8810  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
8811  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
8812 
8813  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8814  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8815 
8816  if( POLARSSL_MODE_CBC == cipher_info->mode )
8817  {
8818  enclen = cipher_get_block_size( &ctx_enc )
8819  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8820  }
8821  else
8822  {
8823  enclen = length;
8824  }
8825 
8826  /* encode length number of bytes from inbuf */
8827  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
8828  if( POLARSSL_MODE_CBC == cipher_info->mode )
8829  {
8830  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8831  }
8832  else
8833  {
8834  fct_chk( outlen == enclen );
8835  }
8836 
8837  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
8838  if( POLARSSL_MODE_CBC == cipher_info->mode )
8839  {
8840  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8841  }
8842  else
8843  {
8844  fct_chk( outlen == 0 );
8845  }
8846 
8847 
8848  /* decode the previously encoded string */
8849  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8850  if( POLARSSL_MODE_CBC == cipher_info->mode )
8851  {
8852  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8853  }
8854  else
8855  {
8856  fct_chk( enclen == outlen );
8857  }
8858 
8859  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8860  if( POLARSSL_MODE_CBC == cipher_info->mode )
8861  {
8862  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8863  }
8864  else
8865  {
8866  fct_chk( outlen == 0 );
8867  }
8868 
8869 
8870  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8871 
8872  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8873  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8874  FCT_TEST_END();
8875 #endif /* POLARSSL_CAMELLIA_C */
8876 
8877 #ifdef POLARSSL_CAMELLIA_C
8878 
8879  FCT_TEST_BGN(camellia_encrypt_and_decrypt_7_bytes)
8880  size_t length = 7;
8881  unsigned char key[32];
8882  unsigned char iv[16];
8883 
8884  const cipher_info_t *cipher_info;
8885  cipher_context_t ctx_dec;
8886  cipher_context_t ctx_enc;
8887 
8888  unsigned char inbuf[64];
8889  unsigned char encbuf[64];
8890  unsigned char decbuf[64];
8891 
8892  size_t outlen = 0;
8893  size_t enclen = 0;
8894 
8895  memset( key, 0, 32 );
8896  memset( iv , 0, 16 );
8897 
8898  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
8899  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
8900 
8901  memset( inbuf, 5, 64 );
8902  memset( encbuf, 0, 64 );
8903  memset( decbuf, 0, 64 );
8904 
8905  /* Check and get info structures */
8907  fct_chk( NULL != cipher_info );
8908  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
8909 
8910  /* Initialise enc and dec contexts */
8911  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
8912  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
8913 
8914  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
8915  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
8916 
8917  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
8918  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
8919 
8920  if( POLARSSL_MODE_CBC == cipher_info->mode )
8921  {
8922  enclen = cipher_get_block_size( &ctx_enc )
8923  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
8924  }
8925  else
8926  {
8927  enclen = length;
8928  }
8929 
8930  /* encode length number of bytes from inbuf */
8931  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
8932  if( POLARSSL_MODE_CBC == cipher_info->mode )
8933  {
8934  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
8935  }
8936  else
8937  {
8938  fct_chk( outlen == enclen );
8939  }
8940 
8941  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
8942  if( POLARSSL_MODE_CBC == cipher_info->mode )
8943  {
8944  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
8945  }
8946  else
8947  {
8948  fct_chk( outlen == 0 );
8949  }
8950 
8951 
8952  /* decode the previously encoded string */
8953  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
8954  if( POLARSSL_MODE_CBC == cipher_info->mode )
8955  {
8956  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
8957  }
8958  else
8959  {
8960  fct_chk( enclen == outlen );
8961  }
8962 
8963  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
8964  if( POLARSSL_MODE_CBC == cipher_info->mode )
8965  {
8966  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
8967  }
8968  else
8969  {
8970  fct_chk( outlen == 0 );
8971  }
8972 
8973 
8974  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
8975 
8976  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
8977  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
8978  FCT_TEST_END();
8979 #endif /* POLARSSL_CAMELLIA_C */
8980 
8981 #ifdef POLARSSL_CAMELLIA_C
8982 
8983  FCT_TEST_BGN(camellia_encrypt_and_decrypt_8_bytes)
8984  size_t length = 8;
8985  unsigned char key[32];
8986  unsigned char iv[16];
8987 
8988  const cipher_info_t *cipher_info;
8989  cipher_context_t ctx_dec;
8990  cipher_context_t ctx_enc;
8991 
8992  unsigned char inbuf[64];
8993  unsigned char encbuf[64];
8994  unsigned char decbuf[64];
8995 
8996  size_t outlen = 0;
8997  size_t enclen = 0;
8998 
8999  memset( key, 0, 32 );
9000  memset( iv , 0, 16 );
9001 
9002  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9003  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9004 
9005  memset( inbuf, 5, 64 );
9006  memset( encbuf, 0, 64 );
9007  memset( decbuf, 0, 64 );
9008 
9009  /* Check and get info structures */
9011  fct_chk( NULL != cipher_info );
9012  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9013 
9014  /* Initialise enc and dec contexts */
9015  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9016  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9017 
9018  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9019  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9020 
9021  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9022  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9023 
9024  if( POLARSSL_MODE_CBC == cipher_info->mode )
9025  {
9026  enclen = cipher_get_block_size( &ctx_enc )
9027  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9028  }
9029  else
9030  {
9031  enclen = length;
9032  }
9033 
9034  /* encode length number of bytes from inbuf */
9035  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9036  if( POLARSSL_MODE_CBC == cipher_info->mode )
9037  {
9038  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9039  }
9040  else
9041  {
9042  fct_chk( outlen == enclen );
9043  }
9044 
9045  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9046  if( POLARSSL_MODE_CBC == cipher_info->mode )
9047  {
9048  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9049  }
9050  else
9051  {
9052  fct_chk( outlen == 0 );
9053  }
9054 
9055 
9056  /* decode the previously encoded string */
9057  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9058  if( POLARSSL_MODE_CBC == cipher_info->mode )
9059  {
9060  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9061  }
9062  else
9063  {
9064  fct_chk( enclen == outlen );
9065  }
9066 
9067  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9068  if( POLARSSL_MODE_CBC == cipher_info->mode )
9069  {
9070  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9071  }
9072  else
9073  {
9074  fct_chk( outlen == 0 );
9075  }
9076 
9077 
9078  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9079 
9080  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9081  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9082  FCT_TEST_END();
9083 #endif /* POLARSSL_CAMELLIA_C */
9084 
9085 #ifdef POLARSSL_CAMELLIA_C
9086 
9087  FCT_TEST_BGN(camellia_encrypt_and_decrypt_9_bytes)
9088  size_t length = 9;
9089  unsigned char key[32];
9090  unsigned char iv[16];
9091 
9092  const cipher_info_t *cipher_info;
9093  cipher_context_t ctx_dec;
9094  cipher_context_t ctx_enc;
9095 
9096  unsigned char inbuf[64];
9097  unsigned char encbuf[64];
9098  unsigned char decbuf[64];
9099 
9100  size_t outlen = 0;
9101  size_t enclen = 0;
9102 
9103  memset( key, 0, 32 );
9104  memset( iv , 0, 16 );
9105 
9106  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9107  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9108 
9109  memset( inbuf, 5, 64 );
9110  memset( encbuf, 0, 64 );
9111  memset( decbuf, 0, 64 );
9112 
9113  /* Check and get info structures */
9115  fct_chk( NULL != cipher_info );
9116  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9117 
9118  /* Initialise enc and dec contexts */
9119  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9120  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9121 
9122  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9123  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9124 
9125  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9126  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9127 
9128  if( POLARSSL_MODE_CBC == cipher_info->mode )
9129  {
9130  enclen = cipher_get_block_size( &ctx_enc )
9131  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9132  }
9133  else
9134  {
9135  enclen = length;
9136  }
9137 
9138  /* encode length number of bytes from inbuf */
9139  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9140  if( POLARSSL_MODE_CBC == cipher_info->mode )
9141  {
9142  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9143  }
9144  else
9145  {
9146  fct_chk( outlen == enclen );
9147  }
9148 
9149  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9150  if( POLARSSL_MODE_CBC == cipher_info->mode )
9151  {
9152  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9153  }
9154  else
9155  {
9156  fct_chk( outlen == 0 );
9157  }
9158 
9159 
9160  /* decode the previously encoded string */
9161  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9162  if( POLARSSL_MODE_CBC == cipher_info->mode )
9163  {
9164  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9165  }
9166  else
9167  {
9168  fct_chk( enclen == outlen );
9169  }
9170 
9171  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9172  if( POLARSSL_MODE_CBC == cipher_info->mode )
9173  {
9174  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9175  }
9176  else
9177  {
9178  fct_chk( outlen == 0 );
9179  }
9180 
9181 
9182  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9183 
9184  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9185  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9186  FCT_TEST_END();
9187 #endif /* POLARSSL_CAMELLIA_C */
9188 
9189 #ifdef POLARSSL_CAMELLIA_C
9190 
9191  FCT_TEST_BGN(camellia_encrypt_and_decrypt_15_bytes)
9192  size_t length = 15;
9193  unsigned char key[32];
9194  unsigned char iv[16];
9195 
9196  const cipher_info_t *cipher_info;
9197  cipher_context_t ctx_dec;
9198  cipher_context_t ctx_enc;
9199 
9200  unsigned char inbuf[64];
9201  unsigned char encbuf[64];
9202  unsigned char decbuf[64];
9203 
9204  size_t outlen = 0;
9205  size_t enclen = 0;
9206 
9207  memset( key, 0, 32 );
9208  memset( iv , 0, 16 );
9209 
9210  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9211  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9212 
9213  memset( inbuf, 5, 64 );
9214  memset( encbuf, 0, 64 );
9215  memset( decbuf, 0, 64 );
9216 
9217  /* Check and get info structures */
9219  fct_chk( NULL != cipher_info );
9220  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9221 
9222  /* Initialise enc and dec contexts */
9223  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9224  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9225 
9226  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9227  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9228 
9229  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9230  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9231 
9232  if( POLARSSL_MODE_CBC == cipher_info->mode )
9233  {
9234  enclen = cipher_get_block_size( &ctx_enc )
9235  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9236  }
9237  else
9238  {
9239  enclen = length;
9240  }
9241 
9242  /* encode length number of bytes from inbuf */
9243  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9244  if( POLARSSL_MODE_CBC == cipher_info->mode )
9245  {
9246  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9247  }
9248  else
9249  {
9250  fct_chk( outlen == enclen );
9251  }
9252 
9253  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9254  if( POLARSSL_MODE_CBC == cipher_info->mode )
9255  {
9256  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9257  }
9258  else
9259  {
9260  fct_chk( outlen == 0 );
9261  }
9262 
9263 
9264  /* decode the previously encoded string */
9265  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9266  if( POLARSSL_MODE_CBC == cipher_info->mode )
9267  {
9268  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9269  }
9270  else
9271  {
9272  fct_chk( enclen == outlen );
9273  }
9274 
9275  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9276  if( POLARSSL_MODE_CBC == cipher_info->mode )
9277  {
9278  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9279  }
9280  else
9281  {
9282  fct_chk( outlen == 0 );
9283  }
9284 
9285 
9286  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9287 
9288  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9289  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9290  FCT_TEST_END();
9291 #endif /* POLARSSL_CAMELLIA_C */
9292 
9293 #ifdef POLARSSL_CAMELLIA_C
9294 
9295  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes)
9296  size_t length = 16;
9297  unsigned char key[32];
9298  unsigned char iv[16];
9299 
9300  const cipher_info_t *cipher_info;
9301  cipher_context_t ctx_dec;
9302  cipher_context_t ctx_enc;
9303 
9304  unsigned char inbuf[64];
9305  unsigned char encbuf[64];
9306  unsigned char decbuf[64];
9307 
9308  size_t outlen = 0;
9309  size_t enclen = 0;
9310 
9311  memset( key, 0, 32 );
9312  memset( iv , 0, 16 );
9313 
9314  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9315  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9316 
9317  memset( inbuf, 5, 64 );
9318  memset( encbuf, 0, 64 );
9319  memset( decbuf, 0, 64 );
9320 
9321  /* Check and get info structures */
9323  fct_chk( NULL != cipher_info );
9324  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9325 
9326  /* Initialise enc and dec contexts */
9327  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9328  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9329 
9330  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9331  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9332 
9333  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9334  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9335 
9336  if( POLARSSL_MODE_CBC == cipher_info->mode )
9337  {
9338  enclen = cipher_get_block_size( &ctx_enc )
9339  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9340  }
9341  else
9342  {
9343  enclen = length;
9344  }
9345 
9346  /* encode length number of bytes from inbuf */
9347  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9348  if( POLARSSL_MODE_CBC == cipher_info->mode )
9349  {
9350  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9351  }
9352  else
9353  {
9354  fct_chk( outlen == enclen );
9355  }
9356 
9357  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9358  if( POLARSSL_MODE_CBC == cipher_info->mode )
9359  {
9360  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9361  }
9362  else
9363  {
9364  fct_chk( outlen == 0 );
9365  }
9366 
9367 
9368  /* decode the previously encoded string */
9369  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9370  if( POLARSSL_MODE_CBC == cipher_info->mode )
9371  {
9372  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9373  }
9374  else
9375  {
9376  fct_chk( enclen == outlen );
9377  }
9378 
9379  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9380  if( POLARSSL_MODE_CBC == cipher_info->mode )
9381  {
9382  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9383  }
9384  else
9385  {
9386  fct_chk( outlen == 0 );
9387  }
9388 
9389 
9390  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9391 
9392  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9393  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9394  FCT_TEST_END();
9395 #endif /* POLARSSL_CAMELLIA_C */
9396 
9397 #ifdef POLARSSL_CAMELLIA_C
9398 
9399  FCT_TEST_BGN(camellia_encrypt_and_decrypt_17_bytes)
9400  size_t length = 17;
9401  unsigned char key[32];
9402  unsigned char iv[16];
9403 
9404  const cipher_info_t *cipher_info;
9405  cipher_context_t ctx_dec;
9406  cipher_context_t ctx_enc;
9407 
9408  unsigned char inbuf[64];
9409  unsigned char encbuf[64];
9410  unsigned char decbuf[64];
9411 
9412  size_t outlen = 0;
9413  size_t enclen = 0;
9414 
9415  memset( key, 0, 32 );
9416  memset( iv , 0, 16 );
9417 
9418  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9419  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9420 
9421  memset( inbuf, 5, 64 );
9422  memset( encbuf, 0, 64 );
9423  memset( decbuf, 0, 64 );
9424 
9425  /* Check and get info structures */
9427  fct_chk( NULL != cipher_info );
9428  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9429 
9430  /* Initialise enc and dec contexts */
9431  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9432  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9433 
9434  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9435  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9436 
9437  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9438  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9439 
9440  if( POLARSSL_MODE_CBC == cipher_info->mode )
9441  {
9442  enclen = cipher_get_block_size( &ctx_enc )
9443  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9444  }
9445  else
9446  {
9447  enclen = length;
9448  }
9449 
9450  /* encode length number of bytes from inbuf */
9451  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9452  if( POLARSSL_MODE_CBC == cipher_info->mode )
9453  {
9454  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9455  }
9456  else
9457  {
9458  fct_chk( outlen == enclen );
9459  }
9460 
9461  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9462  if( POLARSSL_MODE_CBC == cipher_info->mode )
9463  {
9464  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9465  }
9466  else
9467  {
9468  fct_chk( outlen == 0 );
9469  }
9470 
9471 
9472  /* decode the previously encoded string */
9473  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9474  if( POLARSSL_MODE_CBC == cipher_info->mode )
9475  {
9476  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9477  }
9478  else
9479  {
9480  fct_chk( enclen == outlen );
9481  }
9482 
9483  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9484  if( POLARSSL_MODE_CBC == cipher_info->mode )
9485  {
9486  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9487  }
9488  else
9489  {
9490  fct_chk( outlen == 0 );
9491  }
9492 
9493 
9494  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9495 
9496  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9497  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9498  FCT_TEST_END();
9499 #endif /* POLARSSL_CAMELLIA_C */
9500 
9501 #ifdef POLARSSL_CAMELLIA_C
9502 
9503  FCT_TEST_BGN(camellia_encrypt_and_decrypt_31_bytes)
9504  size_t length = 31;
9505  unsigned char key[32];
9506  unsigned char iv[16];
9507 
9508  const cipher_info_t *cipher_info;
9509  cipher_context_t ctx_dec;
9510  cipher_context_t ctx_enc;
9511 
9512  unsigned char inbuf[64];
9513  unsigned char encbuf[64];
9514  unsigned char decbuf[64];
9515 
9516  size_t outlen = 0;
9517  size_t enclen = 0;
9518 
9519  memset( key, 0, 32 );
9520  memset( iv , 0, 16 );
9521 
9522  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9523  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9524 
9525  memset( inbuf, 5, 64 );
9526  memset( encbuf, 0, 64 );
9527  memset( decbuf, 0, 64 );
9528 
9529  /* Check and get info structures */
9531  fct_chk( NULL != cipher_info );
9532  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9533 
9534  /* Initialise enc and dec contexts */
9535  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9536  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9537 
9538  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9539  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9540 
9541  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9542  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9543 
9544  if( POLARSSL_MODE_CBC == cipher_info->mode )
9545  {
9546  enclen = cipher_get_block_size( &ctx_enc )
9547  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9548  }
9549  else
9550  {
9551  enclen = length;
9552  }
9553 
9554  /* encode length number of bytes from inbuf */
9555  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9556  if( POLARSSL_MODE_CBC == cipher_info->mode )
9557  {
9558  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9559  }
9560  else
9561  {
9562  fct_chk( outlen == enclen );
9563  }
9564 
9565  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9566  if( POLARSSL_MODE_CBC == cipher_info->mode )
9567  {
9568  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9569  }
9570  else
9571  {
9572  fct_chk( outlen == 0 );
9573  }
9574 
9575 
9576  /* decode the previously encoded string */
9577  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9578  if( POLARSSL_MODE_CBC == cipher_info->mode )
9579  {
9580  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9581  }
9582  else
9583  {
9584  fct_chk( enclen == outlen );
9585  }
9586 
9587  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9588  if( POLARSSL_MODE_CBC == cipher_info->mode )
9589  {
9590  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9591  }
9592  else
9593  {
9594  fct_chk( outlen == 0 );
9595  }
9596 
9597 
9598  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9599 
9600  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9601  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9602  FCT_TEST_END();
9603 #endif /* POLARSSL_CAMELLIA_C */
9604 
9605 #ifdef POLARSSL_CAMELLIA_C
9606 
9607  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
9608  size_t length = 32;
9609  unsigned char key[32];
9610  unsigned char iv[16];
9611 
9612  const cipher_info_t *cipher_info;
9613  cipher_context_t ctx_dec;
9614  cipher_context_t ctx_enc;
9615 
9616  unsigned char inbuf[64];
9617  unsigned char encbuf[64];
9618  unsigned char decbuf[64];
9619 
9620  size_t outlen = 0;
9621  size_t enclen = 0;
9622 
9623  memset( key, 0, 32 );
9624  memset( iv , 0, 16 );
9625 
9626  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9627  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9628 
9629  memset( inbuf, 5, 64 );
9630  memset( encbuf, 0, 64 );
9631  memset( decbuf, 0, 64 );
9632 
9633  /* Check and get info structures */
9635  fct_chk( NULL != cipher_info );
9636  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9637 
9638  /* Initialise enc and dec contexts */
9639  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9640  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9641 
9642  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9643  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9644 
9645  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9646  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9647 
9648  if( POLARSSL_MODE_CBC == cipher_info->mode )
9649  {
9650  enclen = cipher_get_block_size( &ctx_enc )
9651  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9652  }
9653  else
9654  {
9655  enclen = length;
9656  }
9657 
9658  /* encode length number of bytes from inbuf */
9659  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9660  if( POLARSSL_MODE_CBC == cipher_info->mode )
9661  {
9662  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9663  }
9664  else
9665  {
9666  fct_chk( outlen == enclen );
9667  }
9668 
9669  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9670  if( POLARSSL_MODE_CBC == cipher_info->mode )
9671  {
9672  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9673  }
9674  else
9675  {
9676  fct_chk( outlen == 0 );
9677  }
9678 
9679 
9680  /* decode the previously encoded string */
9681  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9682  if( POLARSSL_MODE_CBC == cipher_info->mode )
9683  {
9684  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9685  }
9686  else
9687  {
9688  fct_chk( enclen == outlen );
9689  }
9690 
9691  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9692  if( POLARSSL_MODE_CBC == cipher_info->mode )
9693  {
9694  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9695  }
9696  else
9697  {
9698  fct_chk( outlen == 0 );
9699  }
9700 
9701 
9702  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9703 
9704  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9705  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9706  FCT_TEST_END();
9707 #endif /* POLARSSL_CAMELLIA_C */
9708 
9709 #ifdef POLARSSL_CAMELLIA_C
9710 
9711  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
9712  size_t length = 33;
9713  unsigned char key[32];
9714  unsigned char iv[16];
9715 
9716  const cipher_info_t *cipher_info;
9717  cipher_context_t ctx_dec;
9718  cipher_context_t ctx_enc;
9719 
9720  unsigned char inbuf[64];
9721  unsigned char encbuf[64];
9722  unsigned char decbuf[64];
9723 
9724  size_t outlen = 0;
9725  size_t enclen = 0;
9726 
9727  memset( key, 0, 32 );
9728  memset( iv , 0, 16 );
9729 
9730  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9731  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9732 
9733  memset( inbuf, 5, 64 );
9734  memset( encbuf, 0, 64 );
9735  memset( decbuf, 0, 64 );
9736 
9737  /* Check and get info structures */
9739  fct_chk( NULL != cipher_info );
9740  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9741 
9742  /* Initialise enc and dec contexts */
9743  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9744  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9745 
9746  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9747  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9748 
9749  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9750  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9751 
9752  if( POLARSSL_MODE_CBC == cipher_info->mode )
9753  {
9754  enclen = cipher_get_block_size( &ctx_enc )
9755  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9756  }
9757  else
9758  {
9759  enclen = length;
9760  }
9761 
9762  /* encode length number of bytes from inbuf */
9763  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9764  if( POLARSSL_MODE_CBC == cipher_info->mode )
9765  {
9766  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9767  }
9768  else
9769  {
9770  fct_chk( outlen == enclen );
9771  }
9772 
9773  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9774  if( POLARSSL_MODE_CBC == cipher_info->mode )
9775  {
9776  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9777  }
9778  else
9779  {
9780  fct_chk( outlen == 0 );
9781  }
9782 
9783 
9784  /* decode the previously encoded string */
9785  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9786  if( POLARSSL_MODE_CBC == cipher_info->mode )
9787  {
9788  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9789  }
9790  else
9791  {
9792  fct_chk( enclen == outlen );
9793  }
9794 
9795  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9796  if( POLARSSL_MODE_CBC == cipher_info->mode )
9797  {
9798  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9799  }
9800  else
9801  {
9802  fct_chk( outlen == 0 );
9803  }
9804 
9805 
9806  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9807 
9808  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9809  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9810  FCT_TEST_END();
9811 #endif /* POLARSSL_CAMELLIA_C */
9812 
9813 #ifdef POLARSSL_CAMELLIA_C
9814 
9815  FCT_TEST_BGN(camellia_encrypt_and_decrypt_47_bytes)
9816  size_t length = 47;
9817  unsigned char key[32];
9818  unsigned char iv[16];
9819 
9820  const cipher_info_t *cipher_info;
9821  cipher_context_t ctx_dec;
9822  cipher_context_t ctx_enc;
9823 
9824  unsigned char inbuf[64];
9825  unsigned char encbuf[64];
9826  unsigned char decbuf[64];
9827 
9828  size_t outlen = 0;
9829  size_t enclen = 0;
9830 
9831  memset( key, 0, 32 );
9832  memset( iv , 0, 16 );
9833 
9834  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9835  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9836 
9837  memset( inbuf, 5, 64 );
9838  memset( encbuf, 0, 64 );
9839  memset( decbuf, 0, 64 );
9840 
9841  /* Check and get info structures */
9843  fct_chk( NULL != cipher_info );
9844  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9845 
9846  /* Initialise enc and dec contexts */
9847  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9848  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9849 
9850  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9851  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9852 
9853  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9854  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9855 
9856  if( POLARSSL_MODE_CBC == cipher_info->mode )
9857  {
9858  enclen = cipher_get_block_size( &ctx_enc )
9859  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9860  }
9861  else
9862  {
9863  enclen = length;
9864  }
9865 
9866  /* encode length number of bytes from inbuf */
9867  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9868  if( POLARSSL_MODE_CBC == cipher_info->mode )
9869  {
9870  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9871  }
9872  else
9873  {
9874  fct_chk( outlen == enclen );
9875  }
9876 
9877  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9878  if( POLARSSL_MODE_CBC == cipher_info->mode )
9879  {
9880  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9881  }
9882  else
9883  {
9884  fct_chk( outlen == 0 );
9885  }
9886 
9887 
9888  /* decode the previously encoded string */
9889  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9890  if( POLARSSL_MODE_CBC == cipher_info->mode )
9891  {
9892  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9893  }
9894  else
9895  {
9896  fct_chk( enclen == outlen );
9897  }
9898 
9899  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
9900  if( POLARSSL_MODE_CBC == cipher_info->mode )
9901  {
9902  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
9903  }
9904  else
9905  {
9906  fct_chk( outlen == 0 );
9907  }
9908 
9909 
9910  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
9911 
9912  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
9913  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
9914  FCT_TEST_END();
9915 #endif /* POLARSSL_CAMELLIA_C */
9916 
9917 #ifdef POLARSSL_CAMELLIA_C
9918 
9919  FCT_TEST_BGN(camellia_encrypt_and_decrypt_48_bytes)
9920  size_t length = 48;
9921  unsigned char key[32];
9922  unsigned char iv[16];
9923 
9924  const cipher_info_t *cipher_info;
9925  cipher_context_t ctx_dec;
9926  cipher_context_t ctx_enc;
9927 
9928  unsigned char inbuf[64];
9929  unsigned char encbuf[64];
9930  unsigned char decbuf[64];
9931 
9932  size_t outlen = 0;
9933  size_t enclen = 0;
9934 
9935  memset( key, 0, 32 );
9936  memset( iv , 0, 16 );
9937 
9938  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
9939  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
9940 
9941  memset( inbuf, 5, 64 );
9942  memset( encbuf, 0, 64 );
9943  memset( decbuf, 0, 64 );
9944 
9945  /* Check and get info structures */
9947  fct_chk( NULL != cipher_info );
9948  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
9949 
9950  /* Initialise enc and dec contexts */
9951  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
9952  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
9953 
9954  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
9955  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
9956 
9957  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
9958  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
9959 
9960  if( POLARSSL_MODE_CBC == cipher_info->mode )
9961  {
9962  enclen = cipher_get_block_size( &ctx_enc )
9963  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
9964  }
9965  else
9966  {
9967  enclen = length;
9968  }
9969 
9970  /* encode length number of bytes from inbuf */
9971  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
9972  if( POLARSSL_MODE_CBC == cipher_info->mode )
9973  {
9974  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
9975  }
9976  else
9977  {
9978  fct_chk( outlen == enclen );
9979  }
9980 
9981  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
9982  if( POLARSSL_MODE_CBC == cipher_info->mode )
9983  {
9984  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
9985  }
9986  else
9987  {
9988  fct_chk( outlen == 0 );
9989  }
9990 
9991 
9992  /* decode the previously encoded string */
9993  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
9994  if( POLARSSL_MODE_CBC == cipher_info->mode )
9995  {
9996  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
9997  }
9998  else
9999  {
10000  fct_chk( enclen == outlen );
10001  }
10002 
10003  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10004  if( POLARSSL_MODE_CBC == cipher_info->mode )
10005  {
10006  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10007  }
10008  else
10009  {
10010  fct_chk( outlen == 0 );
10011  }
10012 
10013 
10014  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10015 
10016  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10017  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10018  FCT_TEST_END();
10019 #endif /* POLARSSL_CAMELLIA_C */
10020 
10021 #ifdef POLARSSL_CAMELLIA_C
10022 
10023  FCT_TEST_BGN(camellia_encrypt_and_decrypt_49_bytes)
10024  size_t length = 49;
10025  unsigned char key[32];
10026  unsigned char iv[16];
10027 
10028  const cipher_info_t *cipher_info;
10029  cipher_context_t ctx_dec;
10030  cipher_context_t ctx_enc;
10031 
10032  unsigned char inbuf[64];
10033  unsigned char encbuf[64];
10034  unsigned char decbuf[64];
10035 
10036  size_t outlen = 0;
10037  size_t enclen = 0;
10038 
10039  memset( key, 0, 32 );
10040  memset( iv , 0, 16 );
10041 
10042  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10043  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10044 
10045  memset( inbuf, 5, 64 );
10046  memset( encbuf, 0, 64 );
10047  memset( decbuf, 0, 64 );
10048 
10049  /* Check and get info structures */
10051  fct_chk( NULL != cipher_info );
10052  fct_chk( cipher_info_from_string( "CAMELLIA-192-CBC" ) == cipher_info );
10053 
10054  /* Initialise enc and dec contexts */
10055  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10056  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10057 
10058  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10059  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10060 
10061  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10062  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10063 
10064  if( POLARSSL_MODE_CBC == cipher_info->mode )
10065  {
10066  enclen = cipher_get_block_size( &ctx_enc )
10067  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10068  }
10069  else
10070  {
10071  enclen = length;
10072  }
10073 
10074  /* encode length number of bytes from inbuf */
10075  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
10076  if( POLARSSL_MODE_CBC == cipher_info->mode )
10077  {
10078  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10079  }
10080  else
10081  {
10082  fct_chk( outlen == enclen );
10083  }
10084 
10085  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
10086  if( POLARSSL_MODE_CBC == cipher_info->mode )
10087  {
10088  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10089  }
10090  else
10091  {
10092  fct_chk( outlen == 0 );
10093  }
10094 
10095 
10096  /* decode the previously encoded string */
10097  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10098  if( POLARSSL_MODE_CBC == cipher_info->mode )
10099  {
10100  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10101  }
10102  else
10103  {
10104  fct_chk( enclen == outlen );
10105  }
10106 
10107  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10108  if( POLARSSL_MODE_CBC == cipher_info->mode )
10109  {
10110  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10111  }
10112  else
10113  {
10114  fct_chk( outlen == 0 );
10115  }
10116 
10117 
10118  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10119 
10120  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10121  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10122  FCT_TEST_END();
10123 #endif /* POLARSSL_CAMELLIA_C */
10124 
10125 #ifdef POLARSSL_CAMELLIA_C
10126 
10127  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes_in_multiple_parts)
10128  size_t first_length = 0;
10129  size_t second_length = 0;
10130  size_t length = first_length + second_length;
10131  unsigned char key[32];
10132  unsigned char iv[16];
10133 
10134  cipher_context_t ctx_dec;
10135  cipher_context_t ctx_enc;
10136  const cipher_info_t *cipher_info;
10137 
10138  unsigned char inbuf[64];
10139  unsigned char encbuf[64];
10140  unsigned char decbuf[64];
10141 
10142  size_t outlen = 0;
10143  size_t totaloutlen = 0;
10144  size_t enclen = 0;
10145 
10146  memset( key, 0, 32 );
10147  memset( iv , 0, 16 );
10148 
10149  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10150  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10151 
10152  memset( inbuf, 5, 64 );
10153  memset( encbuf, 0, 64 );
10154  memset( decbuf, 0, 64 );
10155 
10156  /* Initialise enc and dec contexts */
10158  fct_chk( NULL != cipher_info);
10159 
10160  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10161  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10162 
10163  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10164  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10165 
10166  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10167  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10168 
10169  if( POLARSSL_MODE_CBC == cipher_info->mode )
10170  {
10171  enclen = cipher_get_block_size(&ctx_enc )
10172  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10173  }
10174  else
10175  {
10176  enclen = length;
10177  }
10178 
10179  /* encode length number of bytes from inbuf */
10180  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10181  totaloutlen = outlen;
10182  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10183  totaloutlen += outlen;
10184  if( POLARSSL_MODE_CBC == cipher_info->mode )
10185  {
10186  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10187  }
10188  else
10189  {
10190  fct_chk( totaloutlen == enclen );
10191  }
10192  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10193  totaloutlen += outlen;
10194  if( POLARSSL_MODE_CBC == cipher_info->mode )
10195  {
10196  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10197  }
10198  else
10199  {
10200  fct_chk( outlen == 0 );
10201  }
10202 
10203  /* decode the previously encoded string */
10204  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10205  if( POLARSSL_MODE_CBC == cipher_info->mode )
10206  {
10207  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10208  }
10209  else
10210  {
10211  fct_chk( enclen == outlen );
10212  }
10213  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10214  if( POLARSSL_MODE_CBC == cipher_info->mode )
10215  {
10216  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10217  }
10218  else
10219  {
10220  fct_chk( outlen == 0 );
10221  }
10222 
10223 
10224  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10225 
10226  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10227  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10228  FCT_TEST_END();
10229 #endif /* POLARSSL_CAMELLIA_C */
10230 
10231 #ifdef POLARSSL_CAMELLIA_C
10232 
10233  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
10234  size_t first_length = 1;
10235  size_t second_length = 0;
10236  size_t length = first_length + second_length;
10237  unsigned char key[32];
10238  unsigned char iv[16];
10239 
10240  cipher_context_t ctx_dec;
10241  cipher_context_t ctx_enc;
10242  const cipher_info_t *cipher_info;
10243 
10244  unsigned char inbuf[64];
10245  unsigned char encbuf[64];
10246  unsigned char decbuf[64];
10247 
10248  size_t outlen = 0;
10249  size_t totaloutlen = 0;
10250  size_t enclen = 0;
10251 
10252  memset( key, 0, 32 );
10253  memset( iv , 0, 16 );
10254 
10255  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10256  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10257 
10258  memset( inbuf, 5, 64 );
10259  memset( encbuf, 0, 64 );
10260  memset( decbuf, 0, 64 );
10261 
10262  /* Initialise enc and dec contexts */
10264  fct_chk( NULL != cipher_info);
10265 
10266  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10267  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10268 
10269  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10270  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10271 
10272  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10273  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10274 
10275  if( POLARSSL_MODE_CBC == cipher_info->mode )
10276  {
10277  enclen = cipher_get_block_size(&ctx_enc )
10278  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10279  }
10280  else
10281  {
10282  enclen = length;
10283  }
10284 
10285  /* encode length number of bytes from inbuf */
10286  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10287  totaloutlen = outlen;
10288  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10289  totaloutlen += outlen;
10290  if( POLARSSL_MODE_CBC == cipher_info->mode )
10291  {
10292  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10293  }
10294  else
10295  {
10296  fct_chk( totaloutlen == enclen );
10297  }
10298  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10299  totaloutlen += outlen;
10300  if( POLARSSL_MODE_CBC == cipher_info->mode )
10301  {
10302  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10303  }
10304  else
10305  {
10306  fct_chk( outlen == 0 );
10307  }
10308 
10309  /* decode the previously encoded string */
10310  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10311  if( POLARSSL_MODE_CBC == cipher_info->mode )
10312  {
10313  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10314  }
10315  else
10316  {
10317  fct_chk( enclen == outlen );
10318  }
10319  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10320  if( POLARSSL_MODE_CBC == cipher_info->mode )
10321  {
10322  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10323  }
10324  else
10325  {
10326  fct_chk( outlen == 0 );
10327  }
10328 
10329 
10330  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10331 
10332  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10333  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10334  FCT_TEST_END();
10335 #endif /* POLARSSL_CAMELLIA_C */
10336 
10337 #ifdef POLARSSL_CAMELLIA_C
10338 
10339  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
10340  size_t first_length = 0;
10341  size_t second_length = 1;
10342  size_t length = first_length + second_length;
10343  unsigned char key[32];
10344  unsigned char iv[16];
10345 
10346  cipher_context_t ctx_dec;
10347  cipher_context_t ctx_enc;
10348  const cipher_info_t *cipher_info;
10349 
10350  unsigned char inbuf[64];
10351  unsigned char encbuf[64];
10352  unsigned char decbuf[64];
10353 
10354  size_t outlen = 0;
10355  size_t totaloutlen = 0;
10356  size_t enclen = 0;
10357 
10358  memset( key, 0, 32 );
10359  memset( iv , 0, 16 );
10360 
10361  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10362  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10363 
10364  memset( inbuf, 5, 64 );
10365  memset( encbuf, 0, 64 );
10366  memset( decbuf, 0, 64 );
10367 
10368  /* Initialise enc and dec contexts */
10370  fct_chk( NULL != cipher_info);
10371 
10372  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10373  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10374 
10375  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10376  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10377 
10378  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10379  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10380 
10381  if( POLARSSL_MODE_CBC == cipher_info->mode )
10382  {
10383  enclen = cipher_get_block_size(&ctx_enc )
10384  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10385  }
10386  else
10387  {
10388  enclen = length;
10389  }
10390 
10391  /* encode length number of bytes from inbuf */
10392  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10393  totaloutlen = outlen;
10394  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10395  totaloutlen += outlen;
10396  if( POLARSSL_MODE_CBC == cipher_info->mode )
10397  {
10398  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10399  }
10400  else
10401  {
10402  fct_chk( totaloutlen == enclen );
10403  }
10404  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10405  totaloutlen += outlen;
10406  if( POLARSSL_MODE_CBC == cipher_info->mode )
10407  {
10408  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10409  }
10410  else
10411  {
10412  fct_chk( outlen == 0 );
10413  }
10414 
10415  /* decode the previously encoded string */
10416  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10417  if( POLARSSL_MODE_CBC == cipher_info->mode )
10418  {
10419  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10420  }
10421  else
10422  {
10423  fct_chk( enclen == outlen );
10424  }
10425  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10426  if( POLARSSL_MODE_CBC == cipher_info->mode )
10427  {
10428  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10429  }
10430  else
10431  {
10432  fct_chk( outlen == 0 );
10433  }
10434 
10435 
10436  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10437 
10438  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10439  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10440  FCT_TEST_END();
10441 #endif /* POLARSSL_CAMELLIA_C */
10442 
10443 #ifdef POLARSSL_CAMELLIA_C
10444 
10445  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
10446  size_t first_length = 16;
10447  size_t second_length = 0;
10448  size_t length = first_length + second_length;
10449  unsigned char key[32];
10450  unsigned char iv[16];
10451 
10452  cipher_context_t ctx_dec;
10453  cipher_context_t ctx_enc;
10454  const cipher_info_t *cipher_info;
10455 
10456  unsigned char inbuf[64];
10457  unsigned char encbuf[64];
10458  unsigned char decbuf[64];
10459 
10460  size_t outlen = 0;
10461  size_t totaloutlen = 0;
10462  size_t enclen = 0;
10463 
10464  memset( key, 0, 32 );
10465  memset( iv , 0, 16 );
10466 
10467  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10468  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10469 
10470  memset( inbuf, 5, 64 );
10471  memset( encbuf, 0, 64 );
10472  memset( decbuf, 0, 64 );
10473 
10474  /* Initialise enc and dec contexts */
10476  fct_chk( NULL != cipher_info);
10477 
10478  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10479  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10480 
10481  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10482  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10483 
10484  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10485  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10486 
10487  if( POLARSSL_MODE_CBC == cipher_info->mode )
10488  {
10489  enclen = cipher_get_block_size(&ctx_enc )
10490  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10491  }
10492  else
10493  {
10494  enclen = length;
10495  }
10496 
10497  /* encode length number of bytes from inbuf */
10498  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10499  totaloutlen = outlen;
10500  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10501  totaloutlen += outlen;
10502  if( POLARSSL_MODE_CBC == cipher_info->mode )
10503  {
10504  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10505  }
10506  else
10507  {
10508  fct_chk( totaloutlen == enclen );
10509  }
10510  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10511  totaloutlen += outlen;
10512  if( POLARSSL_MODE_CBC == cipher_info->mode )
10513  {
10514  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10515  }
10516  else
10517  {
10518  fct_chk( outlen == 0 );
10519  }
10520 
10521  /* decode the previously encoded string */
10522  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10523  if( POLARSSL_MODE_CBC == cipher_info->mode )
10524  {
10525  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10526  }
10527  else
10528  {
10529  fct_chk( enclen == outlen );
10530  }
10531  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10532  if( POLARSSL_MODE_CBC == cipher_info->mode )
10533  {
10534  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10535  }
10536  else
10537  {
10538  fct_chk( outlen == 0 );
10539  }
10540 
10541 
10542  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10543 
10544  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10545  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10546  FCT_TEST_END();
10547 #endif /* POLARSSL_CAMELLIA_C */
10548 
10549 #ifdef POLARSSL_CAMELLIA_C
10550 
10551  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
10552  size_t first_length = 0;
10553  size_t second_length = 16;
10554  size_t length = first_length + second_length;
10555  unsigned char key[32];
10556  unsigned char iv[16];
10557 
10558  cipher_context_t ctx_dec;
10559  cipher_context_t ctx_enc;
10560  const cipher_info_t *cipher_info;
10561 
10562  unsigned char inbuf[64];
10563  unsigned char encbuf[64];
10564  unsigned char decbuf[64];
10565 
10566  size_t outlen = 0;
10567  size_t totaloutlen = 0;
10568  size_t enclen = 0;
10569 
10570  memset( key, 0, 32 );
10571  memset( iv , 0, 16 );
10572 
10573  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10574  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10575 
10576  memset( inbuf, 5, 64 );
10577  memset( encbuf, 0, 64 );
10578  memset( decbuf, 0, 64 );
10579 
10580  /* Initialise enc and dec contexts */
10582  fct_chk( NULL != cipher_info);
10583 
10584  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10585  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10586 
10587  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10588  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10589 
10590  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10591  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10592 
10593  if( POLARSSL_MODE_CBC == cipher_info->mode )
10594  {
10595  enclen = cipher_get_block_size(&ctx_enc )
10596  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10597  }
10598  else
10599  {
10600  enclen = length;
10601  }
10602 
10603  /* encode length number of bytes from inbuf */
10604  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10605  totaloutlen = outlen;
10606  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10607  totaloutlen += outlen;
10608  if( POLARSSL_MODE_CBC == cipher_info->mode )
10609  {
10610  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10611  }
10612  else
10613  {
10614  fct_chk( totaloutlen == enclen );
10615  }
10616  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10617  totaloutlen += outlen;
10618  if( POLARSSL_MODE_CBC == cipher_info->mode )
10619  {
10620  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10621  }
10622  else
10623  {
10624  fct_chk( outlen == 0 );
10625  }
10626 
10627  /* decode the previously encoded string */
10628  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10629  if( POLARSSL_MODE_CBC == cipher_info->mode )
10630  {
10631  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10632  }
10633  else
10634  {
10635  fct_chk( enclen == outlen );
10636  }
10637  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10638  if( POLARSSL_MODE_CBC == cipher_info->mode )
10639  {
10640  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10641  }
10642  else
10643  {
10644  fct_chk( outlen == 0 );
10645  }
10646 
10647 
10648  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10649 
10650  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10651  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10652  FCT_TEST_END();
10653 #endif /* POLARSSL_CAMELLIA_C */
10654 
10655 #ifdef POLARSSL_CAMELLIA_C
10656 
10657  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
10658  size_t first_length = 1;
10659  size_t second_length = 15;
10660  size_t length = first_length + second_length;
10661  unsigned char key[32];
10662  unsigned char iv[16];
10663 
10664  cipher_context_t ctx_dec;
10665  cipher_context_t ctx_enc;
10666  const cipher_info_t *cipher_info;
10667 
10668  unsigned char inbuf[64];
10669  unsigned char encbuf[64];
10670  unsigned char decbuf[64];
10671 
10672  size_t outlen = 0;
10673  size_t totaloutlen = 0;
10674  size_t enclen = 0;
10675 
10676  memset( key, 0, 32 );
10677  memset( iv , 0, 16 );
10678 
10679  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10680  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10681 
10682  memset( inbuf, 5, 64 );
10683  memset( encbuf, 0, 64 );
10684  memset( decbuf, 0, 64 );
10685 
10686  /* Initialise enc and dec contexts */
10688  fct_chk( NULL != cipher_info);
10689 
10690  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10691  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10692 
10693  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10694  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10695 
10696  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10697  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10698 
10699  if( POLARSSL_MODE_CBC == cipher_info->mode )
10700  {
10701  enclen = cipher_get_block_size(&ctx_enc )
10702  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10703  }
10704  else
10705  {
10706  enclen = length;
10707  }
10708 
10709  /* encode length number of bytes from inbuf */
10710  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10711  totaloutlen = outlen;
10712  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10713  totaloutlen += outlen;
10714  if( POLARSSL_MODE_CBC == cipher_info->mode )
10715  {
10716  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10717  }
10718  else
10719  {
10720  fct_chk( totaloutlen == enclen );
10721  }
10722  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10723  totaloutlen += outlen;
10724  if( POLARSSL_MODE_CBC == cipher_info->mode )
10725  {
10726  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10727  }
10728  else
10729  {
10730  fct_chk( outlen == 0 );
10731  }
10732 
10733  /* decode the previously encoded string */
10734  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10735  if( POLARSSL_MODE_CBC == cipher_info->mode )
10736  {
10737  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10738  }
10739  else
10740  {
10741  fct_chk( enclen == outlen );
10742  }
10743  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10744  if( POLARSSL_MODE_CBC == cipher_info->mode )
10745  {
10746  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10747  }
10748  else
10749  {
10750  fct_chk( outlen == 0 );
10751  }
10752 
10753 
10754  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10755 
10756  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10757  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10758  FCT_TEST_END();
10759 #endif /* POLARSSL_CAMELLIA_C */
10760 
10761 #ifdef POLARSSL_CAMELLIA_C
10762 
10763  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
10764  size_t first_length = 15;
10765  size_t second_length = 1;
10766  size_t length = first_length + second_length;
10767  unsigned char key[32];
10768  unsigned char iv[16];
10769 
10770  cipher_context_t ctx_dec;
10771  cipher_context_t ctx_enc;
10772  const cipher_info_t *cipher_info;
10773 
10774  unsigned char inbuf[64];
10775  unsigned char encbuf[64];
10776  unsigned char decbuf[64];
10777 
10778  size_t outlen = 0;
10779  size_t totaloutlen = 0;
10780  size_t enclen = 0;
10781 
10782  memset( key, 0, 32 );
10783  memset( iv , 0, 16 );
10784 
10785  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10786  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10787 
10788  memset( inbuf, 5, 64 );
10789  memset( encbuf, 0, 64 );
10790  memset( decbuf, 0, 64 );
10791 
10792  /* Initialise enc and dec contexts */
10794  fct_chk( NULL != cipher_info);
10795 
10796  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10797  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10798 
10799  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10800  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10801 
10802  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10803  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10804 
10805  if( POLARSSL_MODE_CBC == cipher_info->mode )
10806  {
10807  enclen = cipher_get_block_size(&ctx_enc )
10808  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10809  }
10810  else
10811  {
10812  enclen = length;
10813  }
10814 
10815  /* encode length number of bytes from inbuf */
10816  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10817  totaloutlen = outlen;
10818  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10819  totaloutlen += outlen;
10820  if( POLARSSL_MODE_CBC == cipher_info->mode )
10821  {
10822  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10823  }
10824  else
10825  {
10826  fct_chk( totaloutlen == enclen );
10827  }
10828  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10829  totaloutlen += outlen;
10830  if( POLARSSL_MODE_CBC == cipher_info->mode )
10831  {
10832  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10833  }
10834  else
10835  {
10836  fct_chk( outlen == 0 );
10837  }
10838 
10839  /* decode the previously encoded string */
10840  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10841  if( POLARSSL_MODE_CBC == cipher_info->mode )
10842  {
10843  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10844  }
10845  else
10846  {
10847  fct_chk( enclen == outlen );
10848  }
10849  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10850  if( POLARSSL_MODE_CBC == cipher_info->mode )
10851  {
10852  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10853  }
10854  else
10855  {
10856  fct_chk( outlen == 0 );
10857  }
10858 
10859 
10860  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10861 
10862  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10863  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10864  FCT_TEST_END();
10865 #endif /* POLARSSL_CAMELLIA_C */
10866 
10867 #ifdef POLARSSL_CAMELLIA_C
10868 
10869  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
10870  size_t first_length = 15;
10871  size_t second_length = 7;
10872  size_t length = first_length + second_length;
10873  unsigned char key[32];
10874  unsigned char iv[16];
10875 
10876  cipher_context_t ctx_dec;
10877  cipher_context_t ctx_enc;
10878  const cipher_info_t *cipher_info;
10879 
10880  unsigned char inbuf[64];
10881  unsigned char encbuf[64];
10882  unsigned char decbuf[64];
10883 
10884  size_t outlen = 0;
10885  size_t totaloutlen = 0;
10886  size_t enclen = 0;
10887 
10888  memset( key, 0, 32 );
10889  memset( iv , 0, 16 );
10890 
10891  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10892  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10893 
10894  memset( inbuf, 5, 64 );
10895  memset( encbuf, 0, 64 );
10896  memset( decbuf, 0, 64 );
10897 
10898  /* Initialise enc and dec contexts */
10900  fct_chk( NULL != cipher_info);
10901 
10902  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
10903  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
10904 
10905  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
10906  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
10907 
10908  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
10909  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
10910 
10911  if( POLARSSL_MODE_CBC == cipher_info->mode )
10912  {
10913  enclen = cipher_get_block_size(&ctx_enc )
10914  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
10915  }
10916  else
10917  {
10918  enclen = length;
10919  }
10920 
10921  /* encode length number of bytes from inbuf */
10922  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
10923  totaloutlen = outlen;
10924  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
10925  totaloutlen += outlen;
10926  if( POLARSSL_MODE_CBC == cipher_info->mode )
10927  {
10928  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
10929  }
10930  else
10931  {
10932  fct_chk( totaloutlen == enclen );
10933  }
10934  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
10935  totaloutlen += outlen;
10936  if( POLARSSL_MODE_CBC == cipher_info->mode )
10937  {
10938  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
10939  }
10940  else
10941  {
10942  fct_chk( outlen == 0 );
10943  }
10944 
10945  /* decode the previously encoded string */
10946  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
10947  if( POLARSSL_MODE_CBC == cipher_info->mode )
10948  {
10949  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
10950  }
10951  else
10952  {
10953  fct_chk( enclen == outlen );
10954  }
10955  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
10956  if( POLARSSL_MODE_CBC == cipher_info->mode )
10957  {
10958  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
10959  }
10960  else
10961  {
10962  fct_chk( outlen == 0 );
10963  }
10964 
10965 
10966  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
10967 
10968  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
10969  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
10970  FCT_TEST_END();
10971 #endif /* POLARSSL_CAMELLIA_C */
10972 
10973 #ifdef POLARSSL_CAMELLIA_C
10974 
10975  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
10976  size_t first_length = 16;
10977  size_t second_length = 6;
10978  size_t length = first_length + second_length;
10979  unsigned char key[32];
10980  unsigned char iv[16];
10981 
10982  cipher_context_t ctx_dec;
10983  cipher_context_t ctx_enc;
10984  const cipher_info_t *cipher_info;
10985 
10986  unsigned char inbuf[64];
10987  unsigned char encbuf[64];
10988  unsigned char decbuf[64];
10989 
10990  size_t outlen = 0;
10991  size_t totaloutlen = 0;
10992  size_t enclen = 0;
10993 
10994  memset( key, 0, 32 );
10995  memset( iv , 0, 16 );
10996 
10997  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
10998  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
10999 
11000  memset( inbuf, 5, 64 );
11001  memset( encbuf, 0, 64 );
11002  memset( decbuf, 0, 64 );
11003 
11004  /* Initialise enc and dec contexts */
11006  fct_chk( NULL != cipher_info);
11007 
11008  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11009  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11010 
11011  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
11012  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
11013 
11014  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11015  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11016 
11017  if( POLARSSL_MODE_CBC == cipher_info->mode )
11018  {
11019  enclen = cipher_get_block_size(&ctx_enc )
11020  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11021  }
11022  else
11023  {
11024  enclen = length;
11025  }
11026 
11027  /* encode length number of bytes from inbuf */
11028  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
11029  totaloutlen = outlen;
11030  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
11031  totaloutlen += outlen;
11032  if( POLARSSL_MODE_CBC == cipher_info->mode )
11033  {
11034  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11035  }
11036  else
11037  {
11038  fct_chk( totaloutlen == enclen );
11039  }
11040  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
11041  totaloutlen += outlen;
11042  if( POLARSSL_MODE_CBC == cipher_info->mode )
11043  {
11044  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11045  }
11046  else
11047  {
11048  fct_chk( outlen == 0 );
11049  }
11050 
11051  /* decode the previously encoded string */
11052  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11053  if( POLARSSL_MODE_CBC == cipher_info->mode )
11054  {
11055  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11056  }
11057  else
11058  {
11059  fct_chk( enclen == outlen );
11060  }
11061  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11062  if( POLARSSL_MODE_CBC == cipher_info->mode )
11063  {
11064  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11065  }
11066  else
11067  {
11068  fct_chk( outlen == 0 );
11069  }
11070 
11071 
11072  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11073 
11074  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11075  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11076  FCT_TEST_END();
11077 #endif /* POLARSSL_CAMELLIA_C */
11078 
11079 #ifdef POLARSSL_CAMELLIA_C
11080 
11081  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
11082  size_t first_length = 17;
11083  size_t second_length = 6;
11084  size_t length = first_length + second_length;
11085  unsigned char key[32];
11086  unsigned char iv[16];
11087 
11088  cipher_context_t ctx_dec;
11089  cipher_context_t ctx_enc;
11090  const cipher_info_t *cipher_info;
11091 
11092  unsigned char inbuf[64];
11093  unsigned char encbuf[64];
11094  unsigned char decbuf[64];
11095 
11096  size_t outlen = 0;
11097  size_t totaloutlen = 0;
11098  size_t enclen = 0;
11099 
11100  memset( key, 0, 32 );
11101  memset( iv , 0, 16 );
11102 
11103  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11104  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11105 
11106  memset( inbuf, 5, 64 );
11107  memset( encbuf, 0, 64 );
11108  memset( decbuf, 0, 64 );
11109 
11110  /* Initialise enc and dec contexts */
11112  fct_chk( NULL != cipher_info);
11113 
11114  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11115  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11116 
11117  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
11118  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
11119 
11120  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11121  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11122 
11123  if( POLARSSL_MODE_CBC == cipher_info->mode )
11124  {
11125  enclen = cipher_get_block_size(&ctx_enc )
11126  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11127  }
11128  else
11129  {
11130  enclen = length;
11131  }
11132 
11133  /* encode length number of bytes from inbuf */
11134  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
11135  totaloutlen = outlen;
11136  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
11137  totaloutlen += outlen;
11138  if( POLARSSL_MODE_CBC == cipher_info->mode )
11139  {
11140  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11141  }
11142  else
11143  {
11144  fct_chk( totaloutlen == enclen );
11145  }
11146  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
11147  totaloutlen += outlen;
11148  if( POLARSSL_MODE_CBC == cipher_info->mode )
11149  {
11150  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11151  }
11152  else
11153  {
11154  fct_chk( outlen == 0 );
11155  }
11156 
11157  /* decode the previously encoded string */
11158  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11159  if( POLARSSL_MODE_CBC == cipher_info->mode )
11160  {
11161  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11162  }
11163  else
11164  {
11165  fct_chk( enclen == outlen );
11166  }
11167  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11168  if( POLARSSL_MODE_CBC == cipher_info->mode )
11169  {
11170  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11171  }
11172  else
11173  {
11174  fct_chk( outlen == 0 );
11175  }
11176 
11177 
11178  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11179 
11180  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11181  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11182  FCT_TEST_END();
11183 #endif /* POLARSSL_CAMELLIA_C */
11184 
11185 #ifdef POLARSSL_CAMELLIA_C
11186 
11187  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
11188  size_t first_length = 16;
11189  size_t second_length = 16;
11190  size_t length = first_length + second_length;
11191  unsigned char key[32];
11192  unsigned char iv[16];
11193 
11194  cipher_context_t ctx_dec;
11195  cipher_context_t ctx_enc;
11196  const cipher_info_t *cipher_info;
11197 
11198  unsigned char inbuf[64];
11199  unsigned char encbuf[64];
11200  unsigned char decbuf[64];
11201 
11202  size_t outlen = 0;
11203  size_t totaloutlen = 0;
11204  size_t enclen = 0;
11205 
11206  memset( key, 0, 32 );
11207  memset( iv , 0, 16 );
11208 
11209  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11210  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11211 
11212  memset( inbuf, 5, 64 );
11213  memset( encbuf, 0, 64 );
11214  memset( decbuf, 0, 64 );
11215 
11216  /* Initialise enc and dec contexts */
11218  fct_chk( NULL != cipher_info);
11219 
11220  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11221  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11222 
11223  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 192, POLARSSL_DECRYPT ) );
11224  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 192, POLARSSL_ENCRYPT ) );
11225 
11226  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11227  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11228 
11229  if( POLARSSL_MODE_CBC == cipher_info->mode )
11230  {
11231  enclen = cipher_get_block_size(&ctx_enc )
11232  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11233  }
11234  else
11235  {
11236  enclen = length;
11237  }
11238 
11239  /* encode length number of bytes from inbuf */
11240  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
11241  totaloutlen = outlen;
11242  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
11243  totaloutlen += outlen;
11244  if( POLARSSL_MODE_CBC == cipher_info->mode )
11245  {
11246  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11247  }
11248  else
11249  {
11250  fct_chk( totaloutlen == enclen );
11251  }
11252  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
11253  totaloutlen += outlen;
11254  if( POLARSSL_MODE_CBC == cipher_info->mode )
11255  {
11256  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11257  }
11258  else
11259  {
11260  fct_chk( outlen == 0 );
11261  }
11262 
11263  /* decode the previously encoded string */
11264  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11265  if( POLARSSL_MODE_CBC == cipher_info->mode )
11266  {
11267  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11268  }
11269  else
11270  {
11271  fct_chk( enclen == outlen );
11272  }
11273  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11274  if( POLARSSL_MODE_CBC == cipher_info->mode )
11275  {
11276  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11277  }
11278  else
11279  {
11280  fct_chk( outlen == 0 );
11281  }
11282 
11283 
11284  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11285 
11286  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11287  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11288  FCT_TEST_END();
11289 #endif /* POLARSSL_CAMELLIA_C */
11290 
11291 #ifdef POLARSSL_CAMELLIA_C
11292 
11293  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes)
11294  size_t length = 0;
11295  unsigned char key[32];
11296  unsigned char iv[16];
11297 
11298  const cipher_info_t *cipher_info;
11299  cipher_context_t ctx_dec;
11300  cipher_context_t ctx_enc;
11301 
11302  unsigned char inbuf[64];
11303  unsigned char encbuf[64];
11304  unsigned char decbuf[64];
11305 
11306  size_t outlen = 0;
11307  size_t enclen = 0;
11308 
11309  memset( key, 0, 32 );
11310  memset( iv , 0, 16 );
11311 
11312  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11313  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11314 
11315  memset( inbuf, 5, 64 );
11316  memset( encbuf, 0, 64 );
11317  memset( decbuf, 0, 64 );
11318 
11319  /* Check and get info structures */
11321  fct_chk( NULL != cipher_info );
11322  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11323 
11324  /* Initialise enc and dec contexts */
11325  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11326  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11327 
11328  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11329  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11330 
11331  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11332  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11333 
11334  if( POLARSSL_MODE_CBC == cipher_info->mode )
11335  {
11336  enclen = cipher_get_block_size( &ctx_enc )
11337  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11338  }
11339  else
11340  {
11341  enclen = length;
11342  }
11343 
11344  /* encode length number of bytes from inbuf */
11345  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11346  if( POLARSSL_MODE_CBC == cipher_info->mode )
11347  {
11348  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11349  }
11350  else
11351  {
11352  fct_chk( outlen == enclen );
11353  }
11354 
11355  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11356  if( POLARSSL_MODE_CBC == cipher_info->mode )
11357  {
11358  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11359  }
11360  else
11361  {
11362  fct_chk( outlen == 0 );
11363  }
11364 
11365 
11366  /* decode the previously encoded string */
11367  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11368  if( POLARSSL_MODE_CBC == cipher_info->mode )
11369  {
11370  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11371  }
11372  else
11373  {
11374  fct_chk( enclen == outlen );
11375  }
11376 
11377  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11378  if( POLARSSL_MODE_CBC == cipher_info->mode )
11379  {
11380  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11381  }
11382  else
11383  {
11384  fct_chk( outlen == 0 );
11385  }
11386 
11387 
11388  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11389 
11390  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11391  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11392  FCT_TEST_END();
11393 #endif /* POLARSSL_CAMELLIA_C */
11394 
11395 #ifdef POLARSSL_CAMELLIA_C
11396 
11397  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_byte)
11398  size_t length = 1;
11399  unsigned char key[32];
11400  unsigned char iv[16];
11401 
11402  const cipher_info_t *cipher_info;
11403  cipher_context_t ctx_dec;
11404  cipher_context_t ctx_enc;
11405 
11406  unsigned char inbuf[64];
11407  unsigned char encbuf[64];
11408  unsigned char decbuf[64];
11409 
11410  size_t outlen = 0;
11411  size_t enclen = 0;
11412 
11413  memset( key, 0, 32 );
11414  memset( iv , 0, 16 );
11415 
11416  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11417  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11418 
11419  memset( inbuf, 5, 64 );
11420  memset( encbuf, 0, 64 );
11421  memset( decbuf, 0, 64 );
11422 
11423  /* Check and get info structures */
11425  fct_chk( NULL != cipher_info );
11426  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11427 
11428  /* Initialise enc and dec contexts */
11429  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11430  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11431 
11432  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11433  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11434 
11435  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11436  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11437 
11438  if( POLARSSL_MODE_CBC == cipher_info->mode )
11439  {
11440  enclen = cipher_get_block_size( &ctx_enc )
11441  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11442  }
11443  else
11444  {
11445  enclen = length;
11446  }
11447 
11448  /* encode length number of bytes from inbuf */
11449  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11450  if( POLARSSL_MODE_CBC == cipher_info->mode )
11451  {
11452  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11453  }
11454  else
11455  {
11456  fct_chk( outlen == enclen );
11457  }
11458 
11459  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11460  if( POLARSSL_MODE_CBC == cipher_info->mode )
11461  {
11462  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11463  }
11464  else
11465  {
11466  fct_chk( outlen == 0 );
11467  }
11468 
11469 
11470  /* decode the previously encoded string */
11471  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11472  if( POLARSSL_MODE_CBC == cipher_info->mode )
11473  {
11474  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11475  }
11476  else
11477  {
11478  fct_chk( enclen == outlen );
11479  }
11480 
11481  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11482  if( POLARSSL_MODE_CBC == cipher_info->mode )
11483  {
11484  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11485  }
11486  else
11487  {
11488  fct_chk( outlen == 0 );
11489  }
11490 
11491 
11492  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11493 
11494  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11495  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11496  FCT_TEST_END();
11497 #endif /* POLARSSL_CAMELLIA_C */
11498 
11499 #ifdef POLARSSL_CAMELLIA_C
11500 
11501  FCT_TEST_BGN(camellia_encrypt_and_decrypt_2_bytes)
11502  size_t length = 2;
11503  unsigned char key[32];
11504  unsigned char iv[16];
11505 
11506  const cipher_info_t *cipher_info;
11507  cipher_context_t ctx_dec;
11508  cipher_context_t ctx_enc;
11509 
11510  unsigned char inbuf[64];
11511  unsigned char encbuf[64];
11512  unsigned char decbuf[64];
11513 
11514  size_t outlen = 0;
11515  size_t enclen = 0;
11516 
11517  memset( key, 0, 32 );
11518  memset( iv , 0, 16 );
11519 
11520  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11521  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11522 
11523  memset( inbuf, 5, 64 );
11524  memset( encbuf, 0, 64 );
11525  memset( decbuf, 0, 64 );
11526 
11527  /* Check and get info structures */
11529  fct_chk( NULL != cipher_info );
11530  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11531 
11532  /* Initialise enc and dec contexts */
11533  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11534  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11535 
11536  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11537  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11538 
11539  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11540  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11541 
11542  if( POLARSSL_MODE_CBC == cipher_info->mode )
11543  {
11544  enclen = cipher_get_block_size( &ctx_enc )
11545  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11546  }
11547  else
11548  {
11549  enclen = length;
11550  }
11551 
11552  /* encode length number of bytes from inbuf */
11553  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11554  if( POLARSSL_MODE_CBC == cipher_info->mode )
11555  {
11556  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11557  }
11558  else
11559  {
11560  fct_chk( outlen == enclen );
11561  }
11562 
11563  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11564  if( POLARSSL_MODE_CBC == cipher_info->mode )
11565  {
11566  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11567  }
11568  else
11569  {
11570  fct_chk( outlen == 0 );
11571  }
11572 
11573 
11574  /* decode the previously encoded string */
11575  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11576  if( POLARSSL_MODE_CBC == cipher_info->mode )
11577  {
11578  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11579  }
11580  else
11581  {
11582  fct_chk( enclen == outlen );
11583  }
11584 
11585  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11586  if( POLARSSL_MODE_CBC == cipher_info->mode )
11587  {
11588  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11589  }
11590  else
11591  {
11592  fct_chk( outlen == 0 );
11593  }
11594 
11595 
11596  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11597 
11598  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11599  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11600  FCT_TEST_END();
11601 #endif /* POLARSSL_CAMELLIA_C */
11602 
11603 #ifdef POLARSSL_CAMELLIA_C
11604 
11605  FCT_TEST_BGN(camellia_encrypt_and_decrypt_7_bytes)
11606  size_t length = 7;
11607  unsigned char key[32];
11608  unsigned char iv[16];
11609 
11610  const cipher_info_t *cipher_info;
11611  cipher_context_t ctx_dec;
11612  cipher_context_t ctx_enc;
11613 
11614  unsigned char inbuf[64];
11615  unsigned char encbuf[64];
11616  unsigned char decbuf[64];
11617 
11618  size_t outlen = 0;
11619  size_t enclen = 0;
11620 
11621  memset( key, 0, 32 );
11622  memset( iv , 0, 16 );
11623 
11624  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11625  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11626 
11627  memset( inbuf, 5, 64 );
11628  memset( encbuf, 0, 64 );
11629  memset( decbuf, 0, 64 );
11630 
11631  /* Check and get info structures */
11633  fct_chk( NULL != cipher_info );
11634  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11635 
11636  /* Initialise enc and dec contexts */
11637  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11638  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11639 
11640  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11641  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11642 
11643  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11644  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11645 
11646  if( POLARSSL_MODE_CBC == cipher_info->mode )
11647  {
11648  enclen = cipher_get_block_size( &ctx_enc )
11649  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11650  }
11651  else
11652  {
11653  enclen = length;
11654  }
11655 
11656  /* encode length number of bytes from inbuf */
11657  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11658  if( POLARSSL_MODE_CBC == cipher_info->mode )
11659  {
11660  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11661  }
11662  else
11663  {
11664  fct_chk( outlen == enclen );
11665  }
11666 
11667  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11668  if( POLARSSL_MODE_CBC == cipher_info->mode )
11669  {
11670  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11671  }
11672  else
11673  {
11674  fct_chk( outlen == 0 );
11675  }
11676 
11677 
11678  /* decode the previously encoded string */
11679  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11680  if( POLARSSL_MODE_CBC == cipher_info->mode )
11681  {
11682  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11683  }
11684  else
11685  {
11686  fct_chk( enclen == outlen );
11687  }
11688 
11689  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11690  if( POLARSSL_MODE_CBC == cipher_info->mode )
11691  {
11692  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11693  }
11694  else
11695  {
11696  fct_chk( outlen == 0 );
11697  }
11698 
11699 
11700  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11701 
11702  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11703  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11704  FCT_TEST_END();
11705 #endif /* POLARSSL_CAMELLIA_C */
11706 
11707 #ifdef POLARSSL_CAMELLIA_C
11708 
11709  FCT_TEST_BGN(camellia_encrypt_and_decrypt_8_bytes)
11710  size_t length = 8;
11711  unsigned char key[32];
11712  unsigned char iv[16];
11713 
11714  const cipher_info_t *cipher_info;
11715  cipher_context_t ctx_dec;
11716  cipher_context_t ctx_enc;
11717 
11718  unsigned char inbuf[64];
11719  unsigned char encbuf[64];
11720  unsigned char decbuf[64];
11721 
11722  size_t outlen = 0;
11723  size_t enclen = 0;
11724 
11725  memset( key, 0, 32 );
11726  memset( iv , 0, 16 );
11727 
11728  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11729  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11730 
11731  memset( inbuf, 5, 64 );
11732  memset( encbuf, 0, 64 );
11733  memset( decbuf, 0, 64 );
11734 
11735  /* Check and get info structures */
11737  fct_chk( NULL != cipher_info );
11738  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11739 
11740  /* Initialise enc and dec contexts */
11741  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11742  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11743 
11744  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11745  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11746 
11747  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11748  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11749 
11750  if( POLARSSL_MODE_CBC == cipher_info->mode )
11751  {
11752  enclen = cipher_get_block_size( &ctx_enc )
11753  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11754  }
11755  else
11756  {
11757  enclen = length;
11758  }
11759 
11760  /* encode length number of bytes from inbuf */
11761  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11762  if( POLARSSL_MODE_CBC == cipher_info->mode )
11763  {
11764  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11765  }
11766  else
11767  {
11768  fct_chk( outlen == enclen );
11769  }
11770 
11771  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11772  if( POLARSSL_MODE_CBC == cipher_info->mode )
11773  {
11774  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11775  }
11776  else
11777  {
11778  fct_chk( outlen == 0 );
11779  }
11780 
11781 
11782  /* decode the previously encoded string */
11783  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11784  if( POLARSSL_MODE_CBC == cipher_info->mode )
11785  {
11786  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11787  }
11788  else
11789  {
11790  fct_chk( enclen == outlen );
11791  }
11792 
11793  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11794  if( POLARSSL_MODE_CBC == cipher_info->mode )
11795  {
11796  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11797  }
11798  else
11799  {
11800  fct_chk( outlen == 0 );
11801  }
11802 
11803 
11804  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11805 
11806  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11807  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11808  FCT_TEST_END();
11809 #endif /* POLARSSL_CAMELLIA_C */
11810 
11811 #ifdef POLARSSL_CAMELLIA_C
11812 
11813  FCT_TEST_BGN(camellia_encrypt_and_decrypt_9_bytes)
11814  size_t length = 9;
11815  unsigned char key[32];
11816  unsigned char iv[16];
11817 
11818  const cipher_info_t *cipher_info;
11819  cipher_context_t ctx_dec;
11820  cipher_context_t ctx_enc;
11821 
11822  unsigned char inbuf[64];
11823  unsigned char encbuf[64];
11824  unsigned char decbuf[64];
11825 
11826  size_t outlen = 0;
11827  size_t enclen = 0;
11828 
11829  memset( key, 0, 32 );
11830  memset( iv , 0, 16 );
11831 
11832  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11833  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11834 
11835  memset( inbuf, 5, 64 );
11836  memset( encbuf, 0, 64 );
11837  memset( decbuf, 0, 64 );
11838 
11839  /* Check and get info structures */
11841  fct_chk( NULL != cipher_info );
11842  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11843 
11844  /* Initialise enc and dec contexts */
11845  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11846  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11847 
11848  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11849  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11850 
11851  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11852  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11853 
11854  if( POLARSSL_MODE_CBC == cipher_info->mode )
11855  {
11856  enclen = cipher_get_block_size( &ctx_enc )
11857  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11858  }
11859  else
11860  {
11861  enclen = length;
11862  }
11863 
11864  /* encode length number of bytes from inbuf */
11865  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11866  if( POLARSSL_MODE_CBC == cipher_info->mode )
11867  {
11868  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11869  }
11870  else
11871  {
11872  fct_chk( outlen == enclen );
11873  }
11874 
11875  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11876  if( POLARSSL_MODE_CBC == cipher_info->mode )
11877  {
11878  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11879  }
11880  else
11881  {
11882  fct_chk( outlen == 0 );
11883  }
11884 
11885 
11886  /* decode the previously encoded string */
11887  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11888  if( POLARSSL_MODE_CBC == cipher_info->mode )
11889  {
11890  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11891  }
11892  else
11893  {
11894  fct_chk( enclen == outlen );
11895  }
11896 
11897  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
11898  if( POLARSSL_MODE_CBC == cipher_info->mode )
11899  {
11900  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
11901  }
11902  else
11903  {
11904  fct_chk( outlen == 0 );
11905  }
11906 
11907 
11908  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
11909 
11910  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
11911  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
11912  FCT_TEST_END();
11913 #endif /* POLARSSL_CAMELLIA_C */
11914 
11915 #ifdef POLARSSL_CAMELLIA_C
11916 
11917  FCT_TEST_BGN(camellia_encrypt_and_decrypt_15_bytes)
11918  size_t length = 15;
11919  unsigned char key[32];
11920  unsigned char iv[16];
11921 
11922  const cipher_info_t *cipher_info;
11923  cipher_context_t ctx_dec;
11924  cipher_context_t ctx_enc;
11925 
11926  unsigned char inbuf[64];
11927  unsigned char encbuf[64];
11928  unsigned char decbuf[64];
11929 
11930  size_t outlen = 0;
11931  size_t enclen = 0;
11932 
11933  memset( key, 0, 32 );
11934  memset( iv , 0, 16 );
11935 
11936  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
11937  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
11938 
11939  memset( inbuf, 5, 64 );
11940  memset( encbuf, 0, 64 );
11941  memset( decbuf, 0, 64 );
11942 
11943  /* Check and get info structures */
11945  fct_chk( NULL != cipher_info );
11946  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
11947 
11948  /* Initialise enc and dec contexts */
11949  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
11950  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
11951 
11952  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
11953  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
11954 
11955  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
11956  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
11957 
11958  if( POLARSSL_MODE_CBC == cipher_info->mode )
11959  {
11960  enclen = cipher_get_block_size( &ctx_enc )
11961  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
11962  }
11963  else
11964  {
11965  enclen = length;
11966  }
11967 
11968  /* encode length number of bytes from inbuf */
11969  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
11970  if( POLARSSL_MODE_CBC == cipher_info->mode )
11971  {
11972  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
11973  }
11974  else
11975  {
11976  fct_chk( outlen == enclen );
11977  }
11978 
11979  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
11980  if( POLARSSL_MODE_CBC == cipher_info->mode )
11981  {
11982  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
11983  }
11984  else
11985  {
11986  fct_chk( outlen == 0 );
11987  }
11988 
11989 
11990  /* decode the previously encoded string */
11991  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
11992  if( POLARSSL_MODE_CBC == cipher_info->mode )
11993  {
11994  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
11995  }
11996  else
11997  {
11998  fct_chk( enclen == outlen );
11999  }
12000 
12001  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12002  if( POLARSSL_MODE_CBC == cipher_info->mode )
12003  {
12004  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12005  }
12006  else
12007  {
12008  fct_chk( outlen == 0 );
12009  }
12010 
12011 
12012  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12013 
12014  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12015  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12016  FCT_TEST_END();
12017 #endif /* POLARSSL_CAMELLIA_C */
12018 
12019 #ifdef POLARSSL_CAMELLIA_C
12020 
12021  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes)
12022  size_t length = 16;
12023  unsigned char key[32];
12024  unsigned char iv[16];
12025 
12026  const cipher_info_t *cipher_info;
12027  cipher_context_t ctx_dec;
12028  cipher_context_t ctx_enc;
12029 
12030  unsigned char inbuf[64];
12031  unsigned char encbuf[64];
12032  unsigned char decbuf[64];
12033 
12034  size_t outlen = 0;
12035  size_t enclen = 0;
12036 
12037  memset( key, 0, 32 );
12038  memset( iv , 0, 16 );
12039 
12040  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12041  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12042 
12043  memset( inbuf, 5, 64 );
12044  memset( encbuf, 0, 64 );
12045  memset( decbuf, 0, 64 );
12046 
12047  /* Check and get info structures */
12049  fct_chk( NULL != cipher_info );
12050  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12051 
12052  /* Initialise enc and dec contexts */
12053  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12054  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12055 
12056  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12057  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12058 
12059  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12060  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12061 
12062  if( POLARSSL_MODE_CBC == cipher_info->mode )
12063  {
12064  enclen = cipher_get_block_size( &ctx_enc )
12065  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12066  }
12067  else
12068  {
12069  enclen = length;
12070  }
12071 
12072  /* encode length number of bytes from inbuf */
12073  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12074  if( POLARSSL_MODE_CBC == cipher_info->mode )
12075  {
12076  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12077  }
12078  else
12079  {
12080  fct_chk( outlen == enclen );
12081  }
12082 
12083  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12084  if( POLARSSL_MODE_CBC == cipher_info->mode )
12085  {
12086  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12087  }
12088  else
12089  {
12090  fct_chk( outlen == 0 );
12091  }
12092 
12093 
12094  /* decode the previously encoded string */
12095  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12096  if( POLARSSL_MODE_CBC == cipher_info->mode )
12097  {
12098  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12099  }
12100  else
12101  {
12102  fct_chk( enclen == outlen );
12103  }
12104 
12105  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12106  if( POLARSSL_MODE_CBC == cipher_info->mode )
12107  {
12108  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12109  }
12110  else
12111  {
12112  fct_chk( outlen == 0 );
12113  }
12114 
12115 
12116  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12117 
12118  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12119  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12120  FCT_TEST_END();
12121 #endif /* POLARSSL_CAMELLIA_C */
12122 
12123 #ifdef POLARSSL_CAMELLIA_C
12124 
12125  FCT_TEST_BGN(camellia_encrypt_and_decrypt_17_bytes)
12126  size_t length = 17;
12127  unsigned char key[32];
12128  unsigned char iv[16];
12129 
12130  const cipher_info_t *cipher_info;
12131  cipher_context_t ctx_dec;
12132  cipher_context_t ctx_enc;
12133 
12134  unsigned char inbuf[64];
12135  unsigned char encbuf[64];
12136  unsigned char decbuf[64];
12137 
12138  size_t outlen = 0;
12139  size_t enclen = 0;
12140 
12141  memset( key, 0, 32 );
12142  memset( iv , 0, 16 );
12143 
12144  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12145  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12146 
12147  memset( inbuf, 5, 64 );
12148  memset( encbuf, 0, 64 );
12149  memset( decbuf, 0, 64 );
12150 
12151  /* Check and get info structures */
12153  fct_chk( NULL != cipher_info );
12154  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12155 
12156  /* Initialise enc and dec contexts */
12157  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12158  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12159 
12160  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12161  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12162 
12163  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12164  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12165 
12166  if( POLARSSL_MODE_CBC == cipher_info->mode )
12167  {
12168  enclen = cipher_get_block_size( &ctx_enc )
12169  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12170  }
12171  else
12172  {
12173  enclen = length;
12174  }
12175 
12176  /* encode length number of bytes from inbuf */
12177  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12178  if( POLARSSL_MODE_CBC == cipher_info->mode )
12179  {
12180  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12181  }
12182  else
12183  {
12184  fct_chk( outlen == enclen );
12185  }
12186 
12187  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12188  if( POLARSSL_MODE_CBC == cipher_info->mode )
12189  {
12190  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12191  }
12192  else
12193  {
12194  fct_chk( outlen == 0 );
12195  }
12196 
12197 
12198  /* decode the previously encoded string */
12199  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12200  if( POLARSSL_MODE_CBC == cipher_info->mode )
12201  {
12202  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12203  }
12204  else
12205  {
12206  fct_chk( enclen == outlen );
12207  }
12208 
12209  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12210  if( POLARSSL_MODE_CBC == cipher_info->mode )
12211  {
12212  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12213  }
12214  else
12215  {
12216  fct_chk( outlen == 0 );
12217  }
12218 
12219 
12220  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12221 
12222  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12223  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12224  FCT_TEST_END();
12225 #endif /* POLARSSL_CAMELLIA_C */
12226 
12227 #ifdef POLARSSL_CAMELLIA_C
12228 
12229  FCT_TEST_BGN(camellia_encrypt_and_decrypt_31_bytes)
12230  size_t length = 31;
12231  unsigned char key[32];
12232  unsigned char iv[16];
12233 
12234  const cipher_info_t *cipher_info;
12235  cipher_context_t ctx_dec;
12236  cipher_context_t ctx_enc;
12237 
12238  unsigned char inbuf[64];
12239  unsigned char encbuf[64];
12240  unsigned char decbuf[64];
12241 
12242  size_t outlen = 0;
12243  size_t enclen = 0;
12244 
12245  memset( key, 0, 32 );
12246  memset( iv , 0, 16 );
12247 
12248  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12249  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12250 
12251  memset( inbuf, 5, 64 );
12252  memset( encbuf, 0, 64 );
12253  memset( decbuf, 0, 64 );
12254 
12255  /* Check and get info structures */
12257  fct_chk( NULL != cipher_info );
12258  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12259 
12260  /* Initialise enc and dec contexts */
12261  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12262  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12263 
12264  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12265  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12266 
12267  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12268  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12269 
12270  if( POLARSSL_MODE_CBC == cipher_info->mode )
12271  {
12272  enclen = cipher_get_block_size( &ctx_enc )
12273  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12274  }
12275  else
12276  {
12277  enclen = length;
12278  }
12279 
12280  /* encode length number of bytes from inbuf */
12281  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12282  if( POLARSSL_MODE_CBC == cipher_info->mode )
12283  {
12284  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12285  }
12286  else
12287  {
12288  fct_chk( outlen == enclen );
12289  }
12290 
12291  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12292  if( POLARSSL_MODE_CBC == cipher_info->mode )
12293  {
12294  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12295  }
12296  else
12297  {
12298  fct_chk( outlen == 0 );
12299  }
12300 
12301 
12302  /* decode the previously encoded string */
12303  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12304  if( POLARSSL_MODE_CBC == cipher_info->mode )
12305  {
12306  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12307  }
12308  else
12309  {
12310  fct_chk( enclen == outlen );
12311  }
12312 
12313  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12314  if( POLARSSL_MODE_CBC == cipher_info->mode )
12315  {
12316  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12317  }
12318  else
12319  {
12320  fct_chk( outlen == 0 );
12321  }
12322 
12323 
12324  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12325 
12326  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12327  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12328  FCT_TEST_END();
12329 #endif /* POLARSSL_CAMELLIA_C */
12330 
12331 #ifdef POLARSSL_CAMELLIA_C
12332 
12333  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
12334  size_t length = 32;
12335  unsigned char key[32];
12336  unsigned char iv[16];
12337 
12338  const cipher_info_t *cipher_info;
12339  cipher_context_t ctx_dec;
12340  cipher_context_t ctx_enc;
12341 
12342  unsigned char inbuf[64];
12343  unsigned char encbuf[64];
12344  unsigned char decbuf[64];
12345 
12346  size_t outlen = 0;
12347  size_t enclen = 0;
12348 
12349  memset( key, 0, 32 );
12350  memset( iv , 0, 16 );
12351 
12352  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12353  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12354 
12355  memset( inbuf, 5, 64 );
12356  memset( encbuf, 0, 64 );
12357  memset( decbuf, 0, 64 );
12358 
12359  /* Check and get info structures */
12361  fct_chk( NULL != cipher_info );
12362  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12363 
12364  /* Initialise enc and dec contexts */
12365  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12366  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12367 
12368  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12369  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12370 
12371  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12372  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12373 
12374  if( POLARSSL_MODE_CBC == cipher_info->mode )
12375  {
12376  enclen = cipher_get_block_size( &ctx_enc )
12377  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12378  }
12379  else
12380  {
12381  enclen = length;
12382  }
12383 
12384  /* encode length number of bytes from inbuf */
12385  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12386  if( POLARSSL_MODE_CBC == cipher_info->mode )
12387  {
12388  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12389  }
12390  else
12391  {
12392  fct_chk( outlen == enclen );
12393  }
12394 
12395  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12396  if( POLARSSL_MODE_CBC == cipher_info->mode )
12397  {
12398  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12399  }
12400  else
12401  {
12402  fct_chk( outlen == 0 );
12403  }
12404 
12405 
12406  /* decode the previously encoded string */
12407  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12408  if( POLARSSL_MODE_CBC == cipher_info->mode )
12409  {
12410  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12411  }
12412  else
12413  {
12414  fct_chk( enclen == outlen );
12415  }
12416 
12417  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12418  if( POLARSSL_MODE_CBC == cipher_info->mode )
12419  {
12420  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12421  }
12422  else
12423  {
12424  fct_chk( outlen == 0 );
12425  }
12426 
12427 
12428  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12429 
12430  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12431  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12432  FCT_TEST_END();
12433 #endif /* POLARSSL_CAMELLIA_C */
12434 
12435 #ifdef POLARSSL_CAMELLIA_C
12436 
12437  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes)
12438  size_t length = 33;
12439  unsigned char key[32];
12440  unsigned char iv[16];
12441 
12442  const cipher_info_t *cipher_info;
12443  cipher_context_t ctx_dec;
12444  cipher_context_t ctx_enc;
12445 
12446  unsigned char inbuf[64];
12447  unsigned char encbuf[64];
12448  unsigned char decbuf[64];
12449 
12450  size_t outlen = 0;
12451  size_t enclen = 0;
12452 
12453  memset( key, 0, 32 );
12454  memset( iv , 0, 16 );
12455 
12456  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12457  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12458 
12459  memset( inbuf, 5, 64 );
12460  memset( encbuf, 0, 64 );
12461  memset( decbuf, 0, 64 );
12462 
12463  /* Check and get info structures */
12465  fct_chk( NULL != cipher_info );
12466  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12467 
12468  /* Initialise enc and dec contexts */
12469  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12470  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12471 
12472  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12473  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12474 
12475  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12476  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12477 
12478  if( POLARSSL_MODE_CBC == cipher_info->mode )
12479  {
12480  enclen = cipher_get_block_size( &ctx_enc )
12481  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12482  }
12483  else
12484  {
12485  enclen = length;
12486  }
12487 
12488  /* encode length number of bytes from inbuf */
12489  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12490  if( POLARSSL_MODE_CBC == cipher_info->mode )
12491  {
12492  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12493  }
12494  else
12495  {
12496  fct_chk( outlen == enclen );
12497  }
12498 
12499  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12500  if( POLARSSL_MODE_CBC == cipher_info->mode )
12501  {
12502  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12503  }
12504  else
12505  {
12506  fct_chk( outlen == 0 );
12507  }
12508 
12509 
12510  /* decode the previously encoded string */
12511  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12512  if( POLARSSL_MODE_CBC == cipher_info->mode )
12513  {
12514  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12515  }
12516  else
12517  {
12518  fct_chk( enclen == outlen );
12519  }
12520 
12521  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12522  if( POLARSSL_MODE_CBC == cipher_info->mode )
12523  {
12524  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12525  }
12526  else
12527  {
12528  fct_chk( outlen == 0 );
12529  }
12530 
12531 
12532  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12533 
12534  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12535  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12536  FCT_TEST_END();
12537 #endif /* POLARSSL_CAMELLIA_C */
12538 
12539 #ifdef POLARSSL_CAMELLIA_C
12540 
12541  FCT_TEST_BGN(camellia_encrypt_and_decrypt_47_bytes)
12542  size_t length = 47;
12543  unsigned char key[32];
12544  unsigned char iv[16];
12545 
12546  const cipher_info_t *cipher_info;
12547  cipher_context_t ctx_dec;
12548  cipher_context_t ctx_enc;
12549 
12550  unsigned char inbuf[64];
12551  unsigned char encbuf[64];
12552  unsigned char decbuf[64];
12553 
12554  size_t outlen = 0;
12555  size_t enclen = 0;
12556 
12557  memset( key, 0, 32 );
12558  memset( iv , 0, 16 );
12559 
12560  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12561  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12562 
12563  memset( inbuf, 5, 64 );
12564  memset( encbuf, 0, 64 );
12565  memset( decbuf, 0, 64 );
12566 
12567  /* Check and get info structures */
12569  fct_chk( NULL != cipher_info );
12570  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12571 
12572  /* Initialise enc and dec contexts */
12573  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12574  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12575 
12576  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12577  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12578 
12579  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12580  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12581 
12582  if( POLARSSL_MODE_CBC == cipher_info->mode )
12583  {
12584  enclen = cipher_get_block_size( &ctx_enc )
12585  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12586  }
12587  else
12588  {
12589  enclen = length;
12590  }
12591 
12592  /* encode length number of bytes from inbuf */
12593  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12594  if( POLARSSL_MODE_CBC == cipher_info->mode )
12595  {
12596  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12597  }
12598  else
12599  {
12600  fct_chk( outlen == enclen );
12601  }
12602 
12603  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12604  if( POLARSSL_MODE_CBC == cipher_info->mode )
12605  {
12606  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12607  }
12608  else
12609  {
12610  fct_chk( outlen == 0 );
12611  }
12612 
12613 
12614  /* decode the previously encoded string */
12615  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12616  if( POLARSSL_MODE_CBC == cipher_info->mode )
12617  {
12618  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12619  }
12620  else
12621  {
12622  fct_chk( enclen == outlen );
12623  }
12624 
12625  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12626  if( POLARSSL_MODE_CBC == cipher_info->mode )
12627  {
12628  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12629  }
12630  else
12631  {
12632  fct_chk( outlen == 0 );
12633  }
12634 
12635 
12636  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12637 
12638  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12639  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12640  FCT_TEST_END();
12641 #endif /* POLARSSL_CAMELLIA_C */
12642 
12643 #ifdef POLARSSL_CAMELLIA_C
12644 
12645  FCT_TEST_BGN(camellia_encrypt_and_decrypt_48_bytes)
12646  size_t length = 48;
12647  unsigned char key[32];
12648  unsigned char iv[16];
12649 
12650  const cipher_info_t *cipher_info;
12651  cipher_context_t ctx_dec;
12652  cipher_context_t ctx_enc;
12653 
12654  unsigned char inbuf[64];
12655  unsigned char encbuf[64];
12656  unsigned char decbuf[64];
12657 
12658  size_t outlen = 0;
12659  size_t enclen = 0;
12660 
12661  memset( key, 0, 32 );
12662  memset( iv , 0, 16 );
12663 
12664  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12665  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12666 
12667  memset( inbuf, 5, 64 );
12668  memset( encbuf, 0, 64 );
12669  memset( decbuf, 0, 64 );
12670 
12671  /* Check and get info structures */
12673  fct_chk( NULL != cipher_info );
12674  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12675 
12676  /* Initialise enc and dec contexts */
12677  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12678  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12679 
12680  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12681  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12682 
12683  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12684  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12685 
12686  if( POLARSSL_MODE_CBC == cipher_info->mode )
12687  {
12688  enclen = cipher_get_block_size( &ctx_enc )
12689  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12690  }
12691  else
12692  {
12693  enclen = length;
12694  }
12695 
12696  /* encode length number of bytes from inbuf */
12697  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12698  if( POLARSSL_MODE_CBC == cipher_info->mode )
12699  {
12700  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12701  }
12702  else
12703  {
12704  fct_chk( outlen == enclen );
12705  }
12706 
12707  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12708  if( POLARSSL_MODE_CBC == cipher_info->mode )
12709  {
12710  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12711  }
12712  else
12713  {
12714  fct_chk( outlen == 0 );
12715  }
12716 
12717 
12718  /* decode the previously encoded string */
12719  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12720  if( POLARSSL_MODE_CBC == cipher_info->mode )
12721  {
12722  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12723  }
12724  else
12725  {
12726  fct_chk( enclen == outlen );
12727  }
12728 
12729  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12730  if( POLARSSL_MODE_CBC == cipher_info->mode )
12731  {
12732  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12733  }
12734  else
12735  {
12736  fct_chk( outlen == 0 );
12737  }
12738 
12739 
12740  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12741 
12742  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12743  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12744  FCT_TEST_END();
12745 #endif /* POLARSSL_CAMELLIA_C */
12746 
12747 #ifdef POLARSSL_CAMELLIA_C
12748 
12749  FCT_TEST_BGN(camellia_encrypt_and_decrypt_49_bytes)
12750  size_t length = 49;
12751  unsigned char key[32];
12752  unsigned char iv[16];
12753 
12754  const cipher_info_t *cipher_info;
12755  cipher_context_t ctx_dec;
12756  cipher_context_t ctx_enc;
12757 
12758  unsigned char inbuf[64];
12759  unsigned char encbuf[64];
12760  unsigned char decbuf[64];
12761 
12762  size_t outlen = 0;
12763  size_t enclen = 0;
12764 
12765  memset( key, 0, 32 );
12766  memset( iv , 0, 16 );
12767 
12768  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12769  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12770 
12771  memset( inbuf, 5, 64 );
12772  memset( encbuf, 0, 64 );
12773  memset( decbuf, 0, 64 );
12774 
12775  /* Check and get info structures */
12777  fct_chk( NULL != cipher_info );
12778  fct_chk( cipher_info_from_string( "CAMELLIA-256-CBC" ) == cipher_info );
12779 
12780  /* Initialise enc and dec contexts */
12781  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12782  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12783 
12784  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12785  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12786 
12787  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12788  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12789 
12790  if( POLARSSL_MODE_CBC == cipher_info->mode )
12791  {
12792  enclen = cipher_get_block_size( &ctx_enc )
12793  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12794  }
12795  else
12796  {
12797  enclen = length;
12798  }
12799 
12800  /* encode length number of bytes from inbuf */
12801  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
12802  if( POLARSSL_MODE_CBC == cipher_info->mode )
12803  {
12804  fct_chk( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12805  }
12806  else
12807  {
12808  fct_chk( outlen == enclen );
12809  }
12810 
12811  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
12812  if( POLARSSL_MODE_CBC == cipher_info->mode )
12813  {
12814  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12815  }
12816  else
12817  {
12818  fct_chk( outlen == 0 );
12819  }
12820 
12821 
12822  /* decode the previously encoded string */
12823  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12824  if( POLARSSL_MODE_CBC == cipher_info->mode )
12825  {
12826  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12827  }
12828  else
12829  {
12830  fct_chk( enclen == outlen );
12831  }
12832 
12833  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12834  if( POLARSSL_MODE_CBC == cipher_info->mode )
12835  {
12836  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12837  }
12838  else
12839  {
12840  fct_chk( outlen == 0 );
12841  }
12842 
12843 
12844  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12845 
12846  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12847  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12848  FCT_TEST_END();
12849 #endif /* POLARSSL_CAMELLIA_C */
12850 
12851 #ifdef POLARSSL_CAMELLIA_C
12852 
12853  FCT_TEST_BGN(camellia_encrypt_and_decrypt_0_bytes_in_multiple_parts)
12854  size_t first_length = 0;
12855  size_t second_length = 0;
12856  size_t length = first_length + second_length;
12857  unsigned char key[32];
12858  unsigned char iv[16];
12859 
12860  cipher_context_t ctx_dec;
12861  cipher_context_t ctx_enc;
12862  const cipher_info_t *cipher_info;
12863 
12864  unsigned char inbuf[64];
12865  unsigned char encbuf[64];
12866  unsigned char decbuf[64];
12867 
12868  size_t outlen = 0;
12869  size_t totaloutlen = 0;
12870  size_t enclen = 0;
12871 
12872  memset( key, 0, 32 );
12873  memset( iv , 0, 16 );
12874 
12875  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12876  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12877 
12878  memset( inbuf, 5, 64 );
12879  memset( encbuf, 0, 64 );
12880  memset( decbuf, 0, 64 );
12881 
12882  /* Initialise enc and dec contexts */
12884  fct_chk( NULL != cipher_info);
12885 
12886  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12887  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12888 
12889  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12890  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12891 
12892  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12893  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
12894 
12895  if( POLARSSL_MODE_CBC == cipher_info->mode )
12896  {
12897  enclen = cipher_get_block_size(&ctx_enc )
12898  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
12899  }
12900  else
12901  {
12902  enclen = length;
12903  }
12904 
12905  /* encode length number of bytes from inbuf */
12906  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
12907  totaloutlen = outlen;
12908  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
12909  totaloutlen += outlen;
12910  if( POLARSSL_MODE_CBC == cipher_info->mode )
12911  {
12912  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
12913  }
12914  else
12915  {
12916  fct_chk( totaloutlen == enclen );
12917  }
12918  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
12919  totaloutlen += outlen;
12920  if( POLARSSL_MODE_CBC == cipher_info->mode )
12921  {
12922  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
12923  }
12924  else
12925  {
12926  fct_chk( outlen == 0 );
12927  }
12928 
12929  /* decode the previously encoded string */
12930  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
12931  if( POLARSSL_MODE_CBC == cipher_info->mode )
12932  {
12933  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
12934  }
12935  else
12936  {
12937  fct_chk( enclen == outlen );
12938  }
12939  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
12940  if( POLARSSL_MODE_CBC == cipher_info->mode )
12941  {
12942  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
12943  }
12944  else
12945  {
12946  fct_chk( outlen == 0 );
12947  }
12948 
12949 
12950  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
12951 
12952  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
12953  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
12954  FCT_TEST_END();
12955 #endif /* POLARSSL_CAMELLIA_C */
12956 
12957 #ifdef POLARSSL_CAMELLIA_C
12958 
12959  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
12960  size_t first_length = 1;
12961  size_t second_length = 0;
12962  size_t length = first_length + second_length;
12963  unsigned char key[32];
12964  unsigned char iv[16];
12965 
12966  cipher_context_t ctx_dec;
12967  cipher_context_t ctx_enc;
12968  const cipher_info_t *cipher_info;
12969 
12970  unsigned char inbuf[64];
12971  unsigned char encbuf[64];
12972  unsigned char decbuf[64];
12973 
12974  size_t outlen = 0;
12975  size_t totaloutlen = 0;
12976  size_t enclen = 0;
12977 
12978  memset( key, 0, 32 );
12979  memset( iv , 0, 16 );
12980 
12981  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
12982  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
12983 
12984  memset( inbuf, 5, 64 );
12985  memset( encbuf, 0, 64 );
12986  memset( decbuf, 0, 64 );
12987 
12988  /* Initialise enc and dec contexts */
12990  fct_chk( NULL != cipher_info);
12991 
12992  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
12993  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
12994 
12995  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
12996  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
12997 
12998  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
12999  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13000 
13001  if( POLARSSL_MODE_CBC == cipher_info->mode )
13002  {
13003  enclen = cipher_get_block_size(&ctx_enc )
13004  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13005  }
13006  else
13007  {
13008  enclen = length;
13009  }
13010 
13011  /* encode length number of bytes from inbuf */
13012  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13013  totaloutlen = outlen;
13014  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13015  totaloutlen += outlen;
13016  if( POLARSSL_MODE_CBC == cipher_info->mode )
13017  {
13018  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13019  }
13020  else
13021  {
13022  fct_chk( totaloutlen == enclen );
13023  }
13024  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13025  totaloutlen += outlen;
13026  if( POLARSSL_MODE_CBC == cipher_info->mode )
13027  {
13028  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13029  }
13030  else
13031  {
13032  fct_chk( outlen == 0 );
13033  }
13034 
13035  /* decode the previously encoded string */
13036  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13037  if( POLARSSL_MODE_CBC == cipher_info->mode )
13038  {
13039  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13040  }
13041  else
13042  {
13043  fct_chk( enclen == outlen );
13044  }
13045  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13046  if( POLARSSL_MODE_CBC == cipher_info->mode )
13047  {
13048  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13049  }
13050  else
13051  {
13052  fct_chk( outlen == 0 );
13053  }
13054 
13055 
13056  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13057 
13058  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13059  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13060  FCT_TEST_END();
13061 #endif /* POLARSSL_CAMELLIA_C */
13062 
13063 #ifdef POLARSSL_CAMELLIA_C
13064 
13065  FCT_TEST_BGN(camellia_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
13066  size_t first_length = 0;
13067  size_t second_length = 1;
13068  size_t length = first_length + second_length;
13069  unsigned char key[32];
13070  unsigned char iv[16];
13071 
13072  cipher_context_t ctx_dec;
13073  cipher_context_t ctx_enc;
13074  const cipher_info_t *cipher_info;
13075 
13076  unsigned char inbuf[64];
13077  unsigned char encbuf[64];
13078  unsigned char decbuf[64];
13079 
13080  size_t outlen = 0;
13081  size_t totaloutlen = 0;
13082  size_t enclen = 0;
13083 
13084  memset( key, 0, 32 );
13085  memset( iv , 0, 16 );
13086 
13087  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13088  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13089 
13090  memset( inbuf, 5, 64 );
13091  memset( encbuf, 0, 64 );
13092  memset( decbuf, 0, 64 );
13093 
13094  /* Initialise enc and dec contexts */
13096  fct_chk( NULL != cipher_info);
13097 
13098  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13099  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13100 
13101  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13102  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13103 
13104  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13105  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13106 
13107  if( POLARSSL_MODE_CBC == cipher_info->mode )
13108  {
13109  enclen = cipher_get_block_size(&ctx_enc )
13110  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13111  }
13112  else
13113  {
13114  enclen = length;
13115  }
13116 
13117  /* encode length number of bytes from inbuf */
13118  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13119  totaloutlen = outlen;
13120  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13121  totaloutlen += outlen;
13122  if( POLARSSL_MODE_CBC == cipher_info->mode )
13123  {
13124  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13125  }
13126  else
13127  {
13128  fct_chk( totaloutlen == enclen );
13129  }
13130  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13131  totaloutlen += outlen;
13132  if( POLARSSL_MODE_CBC == cipher_info->mode )
13133  {
13134  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13135  }
13136  else
13137  {
13138  fct_chk( outlen == 0 );
13139  }
13140 
13141  /* decode the previously encoded string */
13142  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13143  if( POLARSSL_MODE_CBC == cipher_info->mode )
13144  {
13145  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13146  }
13147  else
13148  {
13149  fct_chk( enclen == outlen );
13150  }
13151  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13152  if( POLARSSL_MODE_CBC == cipher_info->mode )
13153  {
13154  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13155  }
13156  else
13157  {
13158  fct_chk( outlen == 0 );
13159  }
13160 
13161 
13162  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13163 
13164  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13165  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13166  FCT_TEST_END();
13167 #endif /* POLARSSL_CAMELLIA_C */
13168 
13169 #ifdef POLARSSL_CAMELLIA_C
13170 
13171  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
13172  size_t first_length = 16;
13173  size_t second_length = 0;
13174  size_t length = first_length + second_length;
13175  unsigned char key[32];
13176  unsigned char iv[16];
13177 
13178  cipher_context_t ctx_dec;
13179  cipher_context_t ctx_enc;
13180  const cipher_info_t *cipher_info;
13181 
13182  unsigned char inbuf[64];
13183  unsigned char encbuf[64];
13184  unsigned char decbuf[64];
13185 
13186  size_t outlen = 0;
13187  size_t totaloutlen = 0;
13188  size_t enclen = 0;
13189 
13190  memset( key, 0, 32 );
13191  memset( iv , 0, 16 );
13192 
13193  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13194  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13195 
13196  memset( inbuf, 5, 64 );
13197  memset( encbuf, 0, 64 );
13198  memset( decbuf, 0, 64 );
13199 
13200  /* Initialise enc and dec contexts */
13202  fct_chk( NULL != cipher_info);
13203 
13204  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13205  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13206 
13207  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13208  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13209 
13210  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13211  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13212 
13213  if( POLARSSL_MODE_CBC == cipher_info->mode )
13214  {
13215  enclen = cipher_get_block_size(&ctx_enc )
13216  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13217  }
13218  else
13219  {
13220  enclen = length;
13221  }
13222 
13223  /* encode length number of bytes from inbuf */
13224  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13225  totaloutlen = outlen;
13226  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13227  totaloutlen += outlen;
13228  if( POLARSSL_MODE_CBC == cipher_info->mode )
13229  {
13230  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13231  }
13232  else
13233  {
13234  fct_chk( totaloutlen == enclen );
13235  }
13236  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13237  totaloutlen += outlen;
13238  if( POLARSSL_MODE_CBC == cipher_info->mode )
13239  {
13240  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13241  }
13242  else
13243  {
13244  fct_chk( outlen == 0 );
13245  }
13246 
13247  /* decode the previously encoded string */
13248  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13249  if( POLARSSL_MODE_CBC == cipher_info->mode )
13250  {
13251  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13252  }
13253  else
13254  {
13255  fct_chk( enclen == outlen );
13256  }
13257  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13258  if( POLARSSL_MODE_CBC == cipher_info->mode )
13259  {
13260  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13261  }
13262  else
13263  {
13264  fct_chk( outlen == 0 );
13265  }
13266 
13267 
13268  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13269 
13270  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13271  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13272  FCT_TEST_END();
13273 #endif /* POLARSSL_CAMELLIA_C */
13274 
13275 #ifdef POLARSSL_CAMELLIA_C
13276 
13277  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
13278  size_t first_length = 0;
13279  size_t second_length = 16;
13280  size_t length = first_length + second_length;
13281  unsigned char key[32];
13282  unsigned char iv[16];
13283 
13284  cipher_context_t ctx_dec;
13285  cipher_context_t ctx_enc;
13286  const cipher_info_t *cipher_info;
13287 
13288  unsigned char inbuf[64];
13289  unsigned char encbuf[64];
13290  unsigned char decbuf[64];
13291 
13292  size_t outlen = 0;
13293  size_t totaloutlen = 0;
13294  size_t enclen = 0;
13295 
13296  memset( key, 0, 32 );
13297  memset( iv , 0, 16 );
13298 
13299  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13300  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13301 
13302  memset( inbuf, 5, 64 );
13303  memset( encbuf, 0, 64 );
13304  memset( decbuf, 0, 64 );
13305 
13306  /* Initialise enc and dec contexts */
13308  fct_chk( NULL != cipher_info);
13309 
13310  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13311  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13312 
13313  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13314  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13315 
13316  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13317  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13318 
13319  if( POLARSSL_MODE_CBC == cipher_info->mode )
13320  {
13321  enclen = cipher_get_block_size(&ctx_enc )
13322  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13323  }
13324  else
13325  {
13326  enclen = length;
13327  }
13328 
13329  /* encode length number of bytes from inbuf */
13330  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13331  totaloutlen = outlen;
13332  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13333  totaloutlen += outlen;
13334  if( POLARSSL_MODE_CBC == cipher_info->mode )
13335  {
13336  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13337  }
13338  else
13339  {
13340  fct_chk( totaloutlen == enclen );
13341  }
13342  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13343  totaloutlen += outlen;
13344  if( POLARSSL_MODE_CBC == cipher_info->mode )
13345  {
13346  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13347  }
13348  else
13349  {
13350  fct_chk( outlen == 0 );
13351  }
13352 
13353  /* decode the previously encoded string */
13354  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13355  if( POLARSSL_MODE_CBC == cipher_info->mode )
13356  {
13357  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13358  }
13359  else
13360  {
13361  fct_chk( enclen == outlen );
13362  }
13363  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13364  if( POLARSSL_MODE_CBC == cipher_info->mode )
13365  {
13366  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13367  }
13368  else
13369  {
13370  fct_chk( outlen == 0 );
13371  }
13372 
13373 
13374  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13375 
13376  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13377  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13378  FCT_TEST_END();
13379 #endif /* POLARSSL_CAMELLIA_C */
13380 
13381 #ifdef POLARSSL_CAMELLIA_C
13382 
13383  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
13384  size_t first_length = 1;
13385  size_t second_length = 15;
13386  size_t length = first_length + second_length;
13387  unsigned char key[32];
13388  unsigned char iv[16];
13389 
13390  cipher_context_t ctx_dec;
13391  cipher_context_t ctx_enc;
13392  const cipher_info_t *cipher_info;
13393 
13394  unsigned char inbuf[64];
13395  unsigned char encbuf[64];
13396  unsigned char decbuf[64];
13397 
13398  size_t outlen = 0;
13399  size_t totaloutlen = 0;
13400  size_t enclen = 0;
13401 
13402  memset( key, 0, 32 );
13403  memset( iv , 0, 16 );
13404 
13405  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13406  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13407 
13408  memset( inbuf, 5, 64 );
13409  memset( encbuf, 0, 64 );
13410  memset( decbuf, 0, 64 );
13411 
13412  /* Initialise enc and dec contexts */
13414  fct_chk( NULL != cipher_info);
13415 
13416  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13417  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13418 
13419  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13420  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13421 
13422  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13423  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13424 
13425  if( POLARSSL_MODE_CBC == cipher_info->mode )
13426  {
13427  enclen = cipher_get_block_size(&ctx_enc )
13428  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13429  }
13430  else
13431  {
13432  enclen = length;
13433  }
13434 
13435  /* encode length number of bytes from inbuf */
13436  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13437  totaloutlen = outlen;
13438  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13439  totaloutlen += outlen;
13440  if( POLARSSL_MODE_CBC == cipher_info->mode )
13441  {
13442  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13443  }
13444  else
13445  {
13446  fct_chk( totaloutlen == enclen );
13447  }
13448  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13449  totaloutlen += outlen;
13450  if( POLARSSL_MODE_CBC == cipher_info->mode )
13451  {
13452  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13453  }
13454  else
13455  {
13456  fct_chk( outlen == 0 );
13457  }
13458 
13459  /* decode the previously encoded string */
13460  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13461  if( POLARSSL_MODE_CBC == cipher_info->mode )
13462  {
13463  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13464  }
13465  else
13466  {
13467  fct_chk( enclen == outlen );
13468  }
13469  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13470  if( POLARSSL_MODE_CBC == cipher_info->mode )
13471  {
13472  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13473  }
13474  else
13475  {
13476  fct_chk( outlen == 0 );
13477  }
13478 
13479 
13480  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13481 
13482  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13483  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13484  FCT_TEST_END();
13485 #endif /* POLARSSL_CAMELLIA_C */
13486 
13487 #ifdef POLARSSL_CAMELLIA_C
13488 
13489  FCT_TEST_BGN(camellia_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
13490  size_t first_length = 15;
13491  size_t second_length = 1;
13492  size_t length = first_length + second_length;
13493  unsigned char key[32];
13494  unsigned char iv[16];
13495 
13496  cipher_context_t ctx_dec;
13497  cipher_context_t ctx_enc;
13498  const cipher_info_t *cipher_info;
13499 
13500  unsigned char inbuf[64];
13501  unsigned char encbuf[64];
13502  unsigned char decbuf[64];
13503 
13504  size_t outlen = 0;
13505  size_t totaloutlen = 0;
13506  size_t enclen = 0;
13507 
13508  memset( key, 0, 32 );
13509  memset( iv , 0, 16 );
13510 
13511  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13512  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13513 
13514  memset( inbuf, 5, 64 );
13515  memset( encbuf, 0, 64 );
13516  memset( decbuf, 0, 64 );
13517 
13518  /* Initialise enc and dec contexts */
13520  fct_chk( NULL != cipher_info);
13521 
13522  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13523  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13524 
13525  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13526  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13527 
13528  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13529  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13530 
13531  if( POLARSSL_MODE_CBC == cipher_info->mode )
13532  {
13533  enclen = cipher_get_block_size(&ctx_enc )
13534  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13535  }
13536  else
13537  {
13538  enclen = length;
13539  }
13540 
13541  /* encode length number of bytes from inbuf */
13542  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13543  totaloutlen = outlen;
13544  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13545  totaloutlen += outlen;
13546  if( POLARSSL_MODE_CBC == cipher_info->mode )
13547  {
13548  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13549  }
13550  else
13551  {
13552  fct_chk( totaloutlen == enclen );
13553  }
13554  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13555  totaloutlen += outlen;
13556  if( POLARSSL_MODE_CBC == cipher_info->mode )
13557  {
13558  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13559  }
13560  else
13561  {
13562  fct_chk( outlen == 0 );
13563  }
13564 
13565  /* decode the previously encoded string */
13566  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13567  if( POLARSSL_MODE_CBC == cipher_info->mode )
13568  {
13569  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13570  }
13571  else
13572  {
13573  fct_chk( enclen == outlen );
13574  }
13575  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13576  if( POLARSSL_MODE_CBC == cipher_info->mode )
13577  {
13578  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13579  }
13580  else
13581  {
13582  fct_chk( outlen == 0 );
13583  }
13584 
13585 
13586  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13587 
13588  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13589  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13590  FCT_TEST_END();
13591 #endif /* POLARSSL_CAMELLIA_C */
13592 
13593 #ifdef POLARSSL_CAMELLIA_C
13594 
13595  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
13596  size_t first_length = 15;
13597  size_t second_length = 7;
13598  size_t length = first_length + second_length;
13599  unsigned char key[32];
13600  unsigned char iv[16];
13601 
13602  cipher_context_t ctx_dec;
13603  cipher_context_t ctx_enc;
13604  const cipher_info_t *cipher_info;
13605 
13606  unsigned char inbuf[64];
13607  unsigned char encbuf[64];
13608  unsigned char decbuf[64];
13609 
13610  size_t outlen = 0;
13611  size_t totaloutlen = 0;
13612  size_t enclen = 0;
13613 
13614  memset( key, 0, 32 );
13615  memset( iv , 0, 16 );
13616 
13617  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13618  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13619 
13620  memset( inbuf, 5, 64 );
13621  memset( encbuf, 0, 64 );
13622  memset( decbuf, 0, 64 );
13623 
13624  /* Initialise enc and dec contexts */
13626  fct_chk( NULL != cipher_info);
13627 
13628  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13629  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13630 
13631  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13632  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13633 
13634  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13635  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13636 
13637  if( POLARSSL_MODE_CBC == cipher_info->mode )
13638  {
13639  enclen = cipher_get_block_size(&ctx_enc )
13640  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13641  }
13642  else
13643  {
13644  enclen = length;
13645  }
13646 
13647  /* encode length number of bytes from inbuf */
13648  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13649  totaloutlen = outlen;
13650  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13651  totaloutlen += outlen;
13652  if( POLARSSL_MODE_CBC == cipher_info->mode )
13653  {
13654  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13655  }
13656  else
13657  {
13658  fct_chk( totaloutlen == enclen );
13659  }
13660  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13661  totaloutlen += outlen;
13662  if( POLARSSL_MODE_CBC == cipher_info->mode )
13663  {
13664  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13665  }
13666  else
13667  {
13668  fct_chk( outlen == 0 );
13669  }
13670 
13671  /* decode the previously encoded string */
13672  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13673  if( POLARSSL_MODE_CBC == cipher_info->mode )
13674  {
13675  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13676  }
13677  else
13678  {
13679  fct_chk( enclen == outlen );
13680  }
13681  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13682  if( POLARSSL_MODE_CBC == cipher_info->mode )
13683  {
13684  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13685  }
13686  else
13687  {
13688  fct_chk( outlen == 0 );
13689  }
13690 
13691 
13692  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13693 
13694  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13695  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13696  FCT_TEST_END();
13697 #endif /* POLARSSL_CAMELLIA_C */
13698 
13699 #ifdef POLARSSL_CAMELLIA_C
13700 
13701  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
13702  size_t first_length = 16;
13703  size_t second_length = 6;
13704  size_t length = first_length + second_length;
13705  unsigned char key[32];
13706  unsigned char iv[16];
13707 
13708  cipher_context_t ctx_dec;
13709  cipher_context_t ctx_enc;
13710  const cipher_info_t *cipher_info;
13711 
13712  unsigned char inbuf[64];
13713  unsigned char encbuf[64];
13714  unsigned char decbuf[64];
13715 
13716  size_t outlen = 0;
13717  size_t totaloutlen = 0;
13718  size_t enclen = 0;
13719 
13720  memset( key, 0, 32 );
13721  memset( iv , 0, 16 );
13722 
13723  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13724  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13725 
13726  memset( inbuf, 5, 64 );
13727  memset( encbuf, 0, 64 );
13728  memset( decbuf, 0, 64 );
13729 
13730  /* Initialise enc and dec contexts */
13732  fct_chk( NULL != cipher_info);
13733 
13734  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13735  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13736 
13737  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13738  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13739 
13740  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13741  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13742 
13743  if( POLARSSL_MODE_CBC == cipher_info->mode )
13744  {
13745  enclen = cipher_get_block_size(&ctx_enc )
13746  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13747  }
13748  else
13749  {
13750  enclen = length;
13751  }
13752 
13753  /* encode length number of bytes from inbuf */
13754  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13755  totaloutlen = outlen;
13756  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13757  totaloutlen += outlen;
13758  if( POLARSSL_MODE_CBC == cipher_info->mode )
13759  {
13760  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13761  }
13762  else
13763  {
13764  fct_chk( totaloutlen == enclen );
13765  }
13766  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13767  totaloutlen += outlen;
13768  if( POLARSSL_MODE_CBC == cipher_info->mode )
13769  {
13770  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13771  }
13772  else
13773  {
13774  fct_chk( outlen == 0 );
13775  }
13776 
13777  /* decode the previously encoded string */
13778  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13779  if( POLARSSL_MODE_CBC == cipher_info->mode )
13780  {
13781  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13782  }
13783  else
13784  {
13785  fct_chk( enclen == outlen );
13786  }
13787  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13788  if( POLARSSL_MODE_CBC == cipher_info->mode )
13789  {
13790  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13791  }
13792  else
13793  {
13794  fct_chk( outlen == 0 );
13795  }
13796 
13797 
13798  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13799 
13800  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13801  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13802  FCT_TEST_END();
13803 #endif /* POLARSSL_CAMELLIA_C */
13804 
13805 #ifdef POLARSSL_CAMELLIA_C
13806 
13807  FCT_TEST_BGN(camellia_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
13808  size_t first_length = 17;
13809  size_t second_length = 6;
13810  size_t length = first_length + second_length;
13811  unsigned char key[32];
13812  unsigned char iv[16];
13813 
13814  cipher_context_t ctx_dec;
13815  cipher_context_t ctx_enc;
13816  const cipher_info_t *cipher_info;
13817 
13818  unsigned char inbuf[64];
13819  unsigned char encbuf[64];
13820  unsigned char decbuf[64];
13821 
13822  size_t outlen = 0;
13823  size_t totaloutlen = 0;
13824  size_t enclen = 0;
13825 
13826  memset( key, 0, 32 );
13827  memset( iv , 0, 16 );
13828 
13829  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13830  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13831 
13832  memset( inbuf, 5, 64 );
13833  memset( encbuf, 0, 64 );
13834  memset( decbuf, 0, 64 );
13835 
13836  /* Initialise enc and dec contexts */
13838  fct_chk( NULL != cipher_info);
13839 
13840  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13841  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13842 
13843  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13844  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13845 
13846  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13847  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13848 
13849  if( POLARSSL_MODE_CBC == cipher_info->mode )
13850  {
13851  enclen = cipher_get_block_size(&ctx_enc )
13852  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13853  }
13854  else
13855  {
13856  enclen = length;
13857  }
13858 
13859  /* encode length number of bytes from inbuf */
13860  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13861  totaloutlen = outlen;
13862  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13863  totaloutlen += outlen;
13864  if( POLARSSL_MODE_CBC == cipher_info->mode )
13865  {
13866  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13867  }
13868  else
13869  {
13870  fct_chk( totaloutlen == enclen );
13871  }
13872  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13873  totaloutlen += outlen;
13874  if( POLARSSL_MODE_CBC == cipher_info->mode )
13875  {
13876  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13877  }
13878  else
13879  {
13880  fct_chk( outlen == 0 );
13881  }
13882 
13883  /* decode the previously encoded string */
13884  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13885  if( POLARSSL_MODE_CBC == cipher_info->mode )
13886  {
13887  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13888  }
13889  else
13890  {
13891  fct_chk( enclen == outlen );
13892  }
13893  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
13894  if( POLARSSL_MODE_CBC == cipher_info->mode )
13895  {
13896  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
13897  }
13898  else
13899  {
13900  fct_chk( outlen == 0 );
13901  }
13902 
13903 
13904  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
13905 
13906  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
13907  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
13908  FCT_TEST_END();
13909 #endif /* POLARSSL_CAMELLIA_C */
13910 
13911 #ifdef POLARSSL_CAMELLIA_C
13912 
13913  FCT_TEST_BGN(camellia_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
13914  size_t first_length = 16;
13915  size_t second_length = 16;
13916  size_t length = first_length + second_length;
13917  unsigned char key[32];
13918  unsigned char iv[16];
13919 
13920  cipher_context_t ctx_dec;
13921  cipher_context_t ctx_enc;
13922  const cipher_info_t *cipher_info;
13923 
13924  unsigned char inbuf[64];
13925  unsigned char encbuf[64];
13926  unsigned char decbuf[64];
13927 
13928  size_t outlen = 0;
13929  size_t totaloutlen = 0;
13930  size_t enclen = 0;
13931 
13932  memset( key, 0, 32 );
13933  memset( iv , 0, 16 );
13934 
13935  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
13936  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
13937 
13938  memset( inbuf, 5, 64 );
13939  memset( encbuf, 0, 64 );
13940  memset( decbuf, 0, 64 );
13941 
13942  /* Initialise enc and dec contexts */
13944  fct_chk( NULL != cipher_info);
13945 
13946  fct_chk( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
13947  fct_chk( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
13948 
13949  fct_chk( 0 == cipher_setkey( &ctx_dec, key, 256, POLARSSL_DECRYPT ) );
13950  fct_chk( 0 == cipher_setkey( &ctx_enc, key, 256, POLARSSL_ENCRYPT ) );
13951 
13952  fct_chk( 0 == cipher_reset( &ctx_dec, iv ) );
13953  fct_chk( 0 == cipher_reset( &ctx_enc, iv ) );
13954 
13955  if( POLARSSL_MODE_CBC == cipher_info->mode )
13956  {
13957  enclen = cipher_get_block_size(&ctx_enc )
13958  * ( 1 + length / cipher_get_block_size( &ctx_enc ) );
13959  }
13960  else
13961  {
13962  enclen = length;
13963  }
13964 
13965  /* encode length number of bytes from inbuf */
13966  fct_chk( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
13967  totaloutlen = outlen;
13968  fct_chk( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
13969  totaloutlen += outlen;
13970  if( POLARSSL_MODE_CBC == cipher_info->mode )
13971  {
13972  fct_chk( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
13973  }
13974  else
13975  {
13976  fct_chk( totaloutlen == enclen );
13977  }
13978  fct_chk( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
13979  totaloutlen += outlen;
13980  if( POLARSSL_MODE_CBC == cipher_info->mode )
13981  {
13982  fct_chk( outlen == cipher_get_block_size ( &ctx_enc ) );
13983  }
13984  else
13985  {
13986  fct_chk( outlen == 0 );
13987  }
13988 
13989  /* decode the previously encoded string */
13990  fct_chk( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
13991  if( POLARSSL_MODE_CBC == cipher_info->mode )
13992  {
13993  fct_chk( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
13994  }
13995  else
13996  {
13997  fct_chk( enclen == outlen );
13998  }
13999  fct_chk( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
14000  if( POLARSSL_MODE_CBC == cipher_info->mode )
14001  {
14002  fct_chk( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
14003  }
14004  else
14005  {
14006  fct_chk( outlen == 0 );
14007  }
14008 
14009 
14010  fct_chk( 0 == memcmp(inbuf, decbuf, length) );
14011 
14012  fct_chk( 0 == cipher_free_ctx( &ctx_dec ) );
14013  fct_chk( 0 == cipher_free_ctx( &ctx_enc ) );
14014  FCT_TEST_END();
14015 #endif /* POLARSSL_CAMELLIA_C */
14016 
14017  }
14018  FCT_SUITE_END();
14019 
14020 #endif /* POLARSSL_CIPHER_C */
14021 
14022 }
14023 FCT_END();
14024