PolarSSL v1.3.2
test_suite_cipher.null.c
Go to the documentation of this file.
1 #include <polarssl/config.h>
2 
3 #ifdef POLARSSL_CIPHER_C
4 
5 #include <polarssl/cipher.h>
6 
7 #if defined(POLARSSL_GCM_C)
8 #include <polarssl/gcm.h>
9 #endif
10 #endif /* POLARSSL_CIPHER_C */
11 
12 
13 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
14 #include "polarssl/memory.h"
15 #endif
16 
17 #if defined(WANT_NOT_RND_MPI)
18 #if defined(POLARSSL_BIGNUM_C)
19 #include "polarssl/bignum.h"
20 #else
21 #error "not_rnd_mpi() need bignum.c"
22 #endif
23 #endif
24 
25 #ifdef _MSC_VER
26 #include <basetsd.h>
27 typedef UINT32 uint32_t;
28 #else
29 #include <inttypes.h>
30 #endif
31 
32 #include <assert.h>
33 #include <stdlib.h>
34 #include <string.h>
35 
36 /*
37  * 32-bit integer manipulation macros (big endian)
38  */
39 #ifndef GET_UINT32_BE
40 #define GET_UINT32_BE(n,b,i) \
41 { \
42  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
43  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
44  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
45  | ( (uint32_t) (b)[(i) + 3] ); \
46 }
47 #endif
48 
49 #ifndef PUT_UINT32_BE
50 #define PUT_UINT32_BE(n,b,i) \
51 { \
52  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
53  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
54  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
55  (b)[(i) + 3] = (unsigned char) ( (n) ); \
56 }
57 #endif
58 
59 static int unhexify(unsigned char *obuf, const char *ibuf)
60 {
61  unsigned char c, c2;
62  int len = strlen(ibuf) / 2;
63  assert(!(strlen(ibuf) %1)); // must be even number of bytes
64 
65  while (*ibuf != 0)
66  {
67  c = *ibuf++;
68  if( c >= '0' && c <= '9' )
69  c -= '0';
70  else if( c >= 'a' && c <= 'f' )
71  c -= 'a' - 10;
72  else if( c >= 'A' && c <= 'F' )
73  c -= 'A' - 10;
74  else
75  assert( 0 );
76 
77  c2 = *ibuf++;
78  if( c2 >= '0' && c2 <= '9' )
79  c2 -= '0';
80  else if( c2 >= 'a' && c2 <= 'f' )
81  c2 -= 'a' - 10;
82  else if( c2 >= 'A' && c2 <= 'F' )
83  c2 -= 'A' - 10;
84  else
85  assert( 0 );
86 
87  *obuf++ = ( c << 4 ) | c2;
88  }
89 
90  return len;
91 }
92 
93 static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
94 {
95  unsigned char l, h;
96 
97  while (len != 0)
98  {
99  h = (*ibuf) / 16;
100  l = (*ibuf) % 16;
101 
102  if( h < 10 )
103  *obuf++ = '0' + h;
104  else
105  *obuf++ = 'a' + h - 10;
106 
107  if( l < 10 )
108  *obuf++ = '0' + l;
109  else
110  *obuf++ = 'a' + l - 10;
111 
112  ++ibuf;
113  len--;
114  }
115 }
116 
126 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
127 {
128  size_t i;
129 
130  if( rng_state != NULL )
131  rng_state = NULL;
132 
133  for( i = 0; i < len; ++i )
134  output[i] = rand();
135 
136  return( 0 );
137 }
138 
144 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
145 {
146  if( rng_state != NULL )
147  rng_state = NULL;
148 
149  memset( output, 0, len );
150 
151  return( 0 );
152 }
153 
154 typedef struct
155 {
156  unsigned char *buf;
157  size_t length;
158 } rnd_buf_info;
159 
171 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
172 {
173  rnd_buf_info *info = (rnd_buf_info *) rng_state;
174  size_t use_len;
175 
176  if( rng_state == NULL )
177  return( rnd_std_rand( NULL, output, len ) );
178 
179  use_len = len;
180  if( len > info->length )
181  use_len = info->length;
182 
183  if( use_len )
184  {
185  memcpy( output, info->buf, use_len );
186  info->buf += use_len;
187  info->length -= use_len;
188  }
189 
190  if( len - use_len > 0 )
191  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
192 
193  return( 0 );
194 }
195 
203 typedef struct
204 {
205  uint32_t key[16];
206  uint32_t v0, v1;
208 
217 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
218 {
219  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
220  uint32_t i, *k, sum, delta=0x9E3779B9;
221  unsigned char result[4];
222 
223  if( rng_state == NULL )
224  return( rnd_std_rand( NULL, output, len ) );
225 
226  k = info->key;
227 
228  while( len > 0 )
229  {
230  size_t use_len = ( len > 4 ) ? 4 : len;
231  sum = 0;
232 
233  for( i = 0; i < 32; i++ )
234  {
235  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
236  sum += delta;
237  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
238  }
239 
240  PUT_UINT32_BE( info->v0, result, 0 );
241  memcpy( output, result, use_len );
242  len -= use_len;
243  }
244 
245  return( 0 );
246 }
247 
248 #if defined(WANT_NOT_RND_MPI)
249 
257 #define ciL (sizeof(t_uint)) /* chars in limb */
258 #define CHARS_TO_LIMBS(i) (((i) + ciL - 1) / ciL)
259 static int not_rnd_mpi( void *in, unsigned char *out, size_t len )
260 {
261  char *str = (char *) in;
262  mpi X;
263 
264  /*
265  * The 'in' pointer we get is from an MPI prepared by mpi_fill_random(),
266  * just reconstruct the rest in order to be able to call mpi_read_string()
267  */
268  X.s = 1;
269  X.p = (t_uint *) out;
270  X.n = CHARS_TO_LIMBS( len );
271 
272  /*
273  * If str is too long, mpi_read_string() will try to allocate a new buffer
274  * for X.p, which we want to avoid at all costs.
275  */
276  assert( strlen( str ) / 2 == len );
277 
278  return( mpi_read_string( &X, 16, str ) );
279 }
280 #endif /* WANT_NOT_RND_MPI */
281 
282 
283 #include <stdio.h>
284 #include <string.h>
285 
286 static int test_errors = 0;
287 
288 #ifdef POLARSSL_CIPHER_C
289 
290 #define TEST_SUITE_ACTIVE
291 
292 static int test_assert( int correct, char *test )
293 {
294  if( correct )
295  return( 0 );
296 
297  test_errors++;
298  if( test_errors == 1 )
299  printf( "FAILED\n" );
300  printf( " %s\n", test );
301 
302  return( 1 );
303 }
304 
305 #define TEST_ASSERT( TEST ) \
306  do { test_assert( (TEST) ? 1 : 0, #TEST ); \
307  if( test_errors) return; \
308  } while (0)
309 
310 int verify_string( char **str )
311 {
312  if( (*str)[0] != '"' ||
313  (*str)[strlen( *str ) - 1] != '"' )
314  {
315  printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
316  return( -1 );
317  }
318 
319  (*str)++;
320  (*str)[strlen( *str ) - 1] = '\0';
321 
322  return( 0 );
323 }
324 
325 int verify_int( char *str, int *value )
326 {
327  size_t i;
328  int minus = 0;
329  int digits = 1;
330  int hex = 0;
331 
332  for( i = 0; i < strlen( str ); i++ )
333  {
334  if( i == 0 && str[i] == '-' )
335  {
336  minus = 1;
337  continue;
338  }
339 
340  if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
341  str[i - 1] == '0' && str[i] == 'x' )
342  {
343  hex = 1;
344  continue;
345  }
346 
347  if( str[i] < '0' || str[i] > '9' )
348  {
349  digits = 0;
350  break;
351  }
352  }
353 
354  if( digits )
355  {
356  if( hex )
357  *value = strtol( str, NULL, 16 );
358  else
359  *value = strtol( str, NULL, 10 );
360 
361  return( 0 );
362  }
363 
364  if( strcmp( str, "POLARSSL_CIPHER_NULL" ) == 0 )
365  {
366  *value = ( POLARSSL_CIPHER_NULL );
367  return( 0 );
368  }
369  if( strcmp( str, "-1" ) == 0 )
370  {
371  *value = ( -1 );
372  return( 0 );
373  }
374 
375 
376  printf( "Expected integer for parameter and got: %s\n", str );
377  return( -1 );
378 }
379 
380 void test_suite_enc_dec_buf( int cipher_id, char *cipher_string, int key_len,
381  int length_val, int pad_mode )
382 {
383  size_t length = length_val, outlen, total_len, i;
384  unsigned char key[32];
385  unsigned char iv[16];
386  unsigned char ad[13];
387  unsigned char tag[16];
388  unsigned char inbuf[64];
389  unsigned char encbuf[64];
390  unsigned char decbuf[64];
391 
392  const cipher_info_t *cipher_info;
393  cipher_context_t ctx_dec;
394  cipher_context_t ctx_enc;
395 
396  /*
397  * Prepare contexts
398  */
399  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
400  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
401 
402  memset( key, 0x2a, sizeof( key ) );
403 
404  /* Check and get info structures */
405  cipher_info = cipher_info_from_type( cipher_id );
406  TEST_ASSERT( NULL != cipher_info );
407  TEST_ASSERT( cipher_info_from_string( cipher_string ) == cipher_info );
408 
409  /* Initialise enc and dec contexts */
410  TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
411  TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
412 
413  TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, key_len, POLARSSL_DECRYPT ) );
414  TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, key_len, POLARSSL_ENCRYPT ) );
415 
416 #if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
417  if( -1 != pad_mode )
418  {
419  TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx_dec, pad_mode ) );
420  TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx_enc, pad_mode ) );
421  }
422 #else
423  (void) pad_mode;
424 #endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
425 
426  /*
427  * Do a few encode/decode cycles
428  */
429  for( i = 0; i < 3; i++ )
430  {
431  memset( iv , 0x00 + i, sizeof( iv ) );
432  memset( ad, 0x10 + i, sizeof( ad ) );
433  memset( inbuf, 0x20 + i, sizeof( inbuf ) );
434 
435  memset( encbuf, 0, sizeof( encbuf ) );
436  memset( decbuf, 0, sizeof( decbuf ) );
437  memset( tag, 0, sizeof( tag ) );
438 
439  TEST_ASSERT( 0 == cipher_set_iv( &ctx_dec, iv, sizeof( iv ) ) );
440  TEST_ASSERT( 0 == cipher_set_iv( &ctx_enc, iv, sizeof( iv ) ) );
441 
442  TEST_ASSERT( 0 == cipher_reset( &ctx_dec ) );
443  TEST_ASSERT( 0 == cipher_reset( &ctx_enc ) );
444 
445 #if defined(POLARSSL_CIPHER_MODE_AEAD)
446  TEST_ASSERT( 0 == cipher_update_ad( &ctx_dec, ad, sizeof( ad ) - i ) );
447  TEST_ASSERT( 0 == cipher_update_ad( &ctx_enc, ad, sizeof( ad ) - i ) );
448 #endif /* POLARSSL_CIPHER_MODE_AEAD */
449 
450  /* encode length number of bytes from inbuf */
451  TEST_ASSERT( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
452  total_len = outlen;
453 
454  TEST_ASSERT( total_len == length ||
455  ( total_len % cipher_get_block_size( &ctx_enc ) == 0 &&
456  total_len < length &&
457  total_len + cipher_get_block_size( &ctx_enc ) > length ) );
458 
459  TEST_ASSERT( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
460  total_len += outlen;
461 
462 #if defined(POLARSSL_CIPHER_MODE_AEAD)
463  TEST_ASSERT( 0 == cipher_write_tag( &ctx_enc, tag, sizeof( tag ) ) );
464 #endif /* POLARSSL_CIPHER_MODE_AEAD */
465 
466  TEST_ASSERT( total_len == length ||
467  ( total_len % cipher_get_block_size( &ctx_enc ) == 0 &&
468  total_len > length &&
469  total_len <= length + cipher_get_block_size( &ctx_enc ) ) );
470 
471  /* decode the previously encoded string */
472  TEST_ASSERT( 0 == cipher_update( &ctx_dec, encbuf, total_len, decbuf, &outlen ) );
473  total_len = outlen;
474 
475  TEST_ASSERT( total_len == length ||
476  ( total_len % cipher_get_block_size( &ctx_dec ) == 0 &&
477  total_len < length &&
478  total_len + cipher_get_block_size( &ctx_dec ) >= length ) );
479 
480  TEST_ASSERT( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
481  total_len += outlen;
482 
483 #if defined(POLARSSL_CIPHER_MODE_AEAD)
484  TEST_ASSERT( 0 == cipher_check_tag( &ctx_dec, tag, sizeof( tag ) ) );
485 #endif /* POLARSSL_CIPHER_MODE_AEAD */
486 
487  /* check result */
488  TEST_ASSERT( total_len == length );
489  TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
490  }
491 
492  /*
493  * Done
494  */
495  TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
496  TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
497 }
498 
499 void test_suite_enc_fail( int cipher_id, int pad_mode, int key_len,
500  int length_val, int ret )
501 {
502  size_t length = length_val;
503  unsigned char key[32];
504  unsigned char iv[16];
505 
506  const cipher_info_t *cipher_info;
507  cipher_context_t ctx;
508 
509  unsigned char inbuf[64];
510  unsigned char encbuf[64];
511 
512  size_t outlen = 0;
513 
514  memset( key, 0, 32 );
515  memset( iv , 0, 16 );
516 
517  memset( &ctx, 0, sizeof( ctx ) );
518 
519  memset( inbuf, 5, 64 );
520  memset( encbuf, 0, 64 );
521 
522  /* Check and get info structures */
523  cipher_info = cipher_info_from_type( cipher_id );
524  TEST_ASSERT( NULL != cipher_info );
525 
526  /* Initialise context */
527  TEST_ASSERT( 0 == cipher_init_ctx( &ctx, cipher_info ) );
528  TEST_ASSERT( 0 == cipher_setkey( &ctx, key, key_len, POLARSSL_ENCRYPT ) );
529 #if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
530  TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, pad_mode ) );
531 #else
532  (void) pad_mode;
533 #endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
534  TEST_ASSERT( 0 == cipher_set_iv( &ctx, iv, 16 ) );
535  TEST_ASSERT( 0 == cipher_reset( &ctx ) );
536 #if defined(POLARSSL_CIPHER_MODE_AEAD)
537  TEST_ASSERT( 0 == cipher_update_ad( &ctx, NULL, 0 ) );
538 #endif /* POLARSSL_CIPHER_MODE_AEAD */
539 
540  /* encode length number of bytes from inbuf */
541  TEST_ASSERT( 0 == cipher_update( &ctx, inbuf, length, encbuf, &outlen ) );
542  TEST_ASSERT( ret == cipher_finish( &ctx, encbuf + outlen, &outlen ) );
543 
544  /* done */
545  TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
546 }
547 
548 void test_suite_dec_empty_buf()
549 {
550  unsigned char key[32];
551  unsigned char iv[16];
552 
553  cipher_context_t ctx_dec;
554  const cipher_info_t *cipher_info;
555 
556  unsigned char encbuf[64];
557  unsigned char decbuf[64];
558 
559  size_t outlen = 0;
560 
561  memset( key, 0, 32 );
562  memset( iv , 0, 16 );
563 
564  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
565 
566  memset( encbuf, 0, 64 );
567  memset( decbuf, 0, 64 );
568 
569  /* Initialise context */
571  TEST_ASSERT( NULL != cipher_info);
572 
573  TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
574 
575  TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
576 
577  TEST_ASSERT( 0 == cipher_set_iv( &ctx_dec, iv, 16 ) );
578 
579  TEST_ASSERT( 0 == cipher_reset( &ctx_dec ) );
580 
581 #if defined(POLARSSL_CIPHER_MODE_AEAD)
582  TEST_ASSERT( 0 == cipher_update_ad( &ctx_dec, NULL, 0 ) );
583 #endif /* POLARSSL_CIPHER_MODE_AEAD */
584 
585  /* decode 0-byte string */
586  TEST_ASSERT( 0 == cipher_update( &ctx_dec, encbuf, 0, decbuf, &outlen ) );
587  TEST_ASSERT( 0 == outlen );
589  &ctx_dec, decbuf + outlen, &outlen ) );
590  TEST_ASSERT( 0 == outlen );
591 
592  TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
593 }
594 
595 void test_suite_enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val,
596  int second_length_val )
597 {
598  size_t first_length = first_length_val;
599  size_t second_length = second_length_val;
600  size_t length = first_length + second_length;
601  unsigned char key[32];
602  unsigned char iv[16];
603 
604  cipher_context_t ctx_dec;
605  cipher_context_t ctx_enc;
606  const cipher_info_t *cipher_info;
607 
608  unsigned char inbuf[64];
609  unsigned char encbuf[64];
610  unsigned char decbuf[64];
611 
612  size_t outlen = 0;
613  size_t totaloutlen = 0;
614 
615  memset( key, 0, 32 );
616  memset( iv , 0, 16 );
617 
618  memset( &ctx_dec, 0, sizeof( ctx_dec ) );
619  memset( &ctx_enc, 0, sizeof( ctx_enc ) );
620 
621  memset( inbuf, 5, 64 );
622  memset( encbuf, 0, 64 );
623  memset( decbuf, 0, 64 );
624 
625  /* Initialise enc and dec contexts */
626  cipher_info = cipher_info_from_type( cipher_id );
627  TEST_ASSERT( NULL != cipher_info);
628 
629  TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
630  TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
631 
632  TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, key_len, POLARSSL_DECRYPT ) );
633  TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, key_len, POLARSSL_ENCRYPT ) );
634 
635  TEST_ASSERT( 0 == cipher_set_iv( &ctx_dec, iv, 16 ) );
636  TEST_ASSERT( 0 == cipher_set_iv( &ctx_enc, iv, 16 ) );
637 
638  TEST_ASSERT( 0 == cipher_reset( &ctx_dec ) );
639  TEST_ASSERT( 0 == cipher_reset( &ctx_enc ) );
640 
641 #if defined(POLARSSL_CIPHER_MODE_AEAD)
642  TEST_ASSERT( 0 == cipher_update_ad( &ctx_dec, NULL, 0 ) );
643  TEST_ASSERT( 0 == cipher_update_ad( &ctx_enc, NULL, 0 ) );
644 #endif /* POLARSSL_CIPHER_MODE_AEAD */
645 
646  /* encode length number of bytes from inbuf */
647  TEST_ASSERT( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
648  totaloutlen = outlen;
649  TEST_ASSERT( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
650  totaloutlen += outlen;
651  TEST_ASSERT( totaloutlen == length ||
652  ( totaloutlen % cipher_get_block_size( &ctx_enc ) == 0 &&
653  totaloutlen < length &&
654  totaloutlen + cipher_get_block_size( &ctx_enc ) > length ) );
655 
656  TEST_ASSERT( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
657  totaloutlen += outlen;
658  TEST_ASSERT( totaloutlen == length ||
659  ( totaloutlen % cipher_get_block_size( &ctx_enc ) == 0 &&
660  totaloutlen > length &&
661  totaloutlen <= length + cipher_get_block_size( &ctx_enc ) ) );
662 
663  /* decode the previously encoded string */
664  TEST_ASSERT( 0 == cipher_update( &ctx_dec, encbuf, totaloutlen, decbuf, &outlen ) );
665  totaloutlen = outlen;
666 
667  TEST_ASSERT( totaloutlen == length ||
668  ( totaloutlen % cipher_get_block_size( &ctx_dec ) == 0 &&
669  totaloutlen < length &&
670  totaloutlen + cipher_get_block_size( &ctx_dec ) >= length ) );
671 
672  TEST_ASSERT( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
673  totaloutlen += outlen;
674 
675  TEST_ASSERT( totaloutlen == length );
676 
677  TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
678 
679  TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
680  TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
681 }
682 
683 void test_suite_decrypt_test_vec( int cipher_id, int pad_mode,
684  char *hex_key, char *hex_iv,
685  char *hex_cipher, char *hex_clear,
686  char *hex_ad, char *hex_tag,
687  int finish_result, int tag_result )
688 {
689  unsigned char key[50];
690  unsigned char iv[50];
691  unsigned char cipher[200];
692  unsigned char clear[200];
693  unsigned char ad[200];
694  unsigned char tag[20];
695  size_t key_len, iv_len, cipher_len, clear_len;
696 #if defined(POLARSSL_CIPHER_MODE_AEAD)
697  size_t ad_len, tag_len;
698 #endif
699  cipher_context_t ctx;
700  unsigned char output[200];
701  size_t outlen, total_len;
702 
703  memset( key, 0x00, sizeof( key ) );
704  memset( iv, 0x00, sizeof( iv ) );
705  memset( cipher, 0x00, sizeof( cipher ) );
706  memset( clear, 0x00, sizeof( clear ) );
707  memset( ad, 0x00, sizeof( ad ) );
708  memset( tag, 0x00, sizeof( tag ) );
709  memset( output, 0x00, sizeof( output ) );
710 
711  key_len = unhexify( key, hex_key );
712  iv_len = unhexify( iv, hex_iv );
713  cipher_len = unhexify( cipher, hex_cipher );
714  clear_len = unhexify( clear, hex_clear );
715 #if defined(POLARSSL_CIPHER_MODE_AEAD)
716  ad_len = unhexify( ad, hex_ad );
717  tag_len = unhexify( tag, hex_tag );
718 #else
719  ((void) hex_ad);
720  ((void) hex_tag);
721 #endif
722 
723  /* Prepare context */
724  TEST_ASSERT( 0 == cipher_init_ctx( &ctx,
725  cipher_info_from_type( cipher_id ) ) );
726  TEST_ASSERT( 0 == cipher_setkey( &ctx, key, 8 * key_len, POLARSSL_DECRYPT ) );
727 #if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
728  if( pad_mode != -1 )
729  TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, pad_mode ) );
730 #else
731  (void) pad_mode;
732 #endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
733  TEST_ASSERT( 0 == cipher_set_iv( &ctx, iv, iv_len ) );
734  TEST_ASSERT( 0 == cipher_reset( &ctx ) );
735 #if defined(POLARSSL_CIPHER_MODE_AEAD)
736  TEST_ASSERT( 0 == cipher_update_ad( &ctx, ad, ad_len ) );
737 #endif /* POLARSSL_CIPHER_MODE_AEAD */
738 
739  /* decode buffer and check tag */
740  total_len = 0;
741  TEST_ASSERT( 0 == cipher_update( &ctx, cipher, cipher_len, output, &outlen ) );
742  total_len += outlen;
743  TEST_ASSERT( finish_result == cipher_finish( &ctx, output + outlen,
744  &outlen ) );
745  total_len += outlen;
746 #if defined(POLARSSL_CIPHER_MODE_AEAD)
747  TEST_ASSERT( tag_result == cipher_check_tag( &ctx, tag, tag_len ) );
748 #endif /* POLARSSL_CIPHER_MODE_AEAD */
749 
750  /* check plaintext only if everything went fine */
751  if( 0 == finish_result && 0 == tag_result )
752  {
753  TEST_ASSERT( total_len == clear_len );
754  TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) );
755  }
756 
757  cipher_free_ctx( &ctx );
758 }
759 
760 void test_suite_test_vec_ecb( int cipher_id, int operation, char *hex_key,
761  char *hex_input, char *hex_result,
762  int finish_result )
763 {
764  unsigned char key[50];
765  unsigned char input[16];
766  unsigned char result[16];
767  size_t key_len;
768  cipher_context_t ctx;
769  unsigned char output[32];
770  size_t outlen;
771 
772  memset( key, 0x00, sizeof( key ) );
773  memset( input, 0x00, sizeof( input ) );
774  memset( result, 0x00, sizeof( result ) );
775  memset( output, 0x00, sizeof( output ) );
776 
777  /* Prepare context */
778  TEST_ASSERT( 0 == cipher_init_ctx( &ctx,
779  cipher_info_from_type( cipher_id ) ) );
780 
781  key_len = unhexify( key, hex_key );
782  TEST_ASSERT( unhexify( input, hex_input ) ==
783  (int) cipher_get_block_size( &ctx ) );
784  TEST_ASSERT( unhexify( result, hex_result ) ==
785  (int) cipher_get_block_size( &ctx ) );
786 
787  TEST_ASSERT( 0 == cipher_setkey( &ctx, key, 8 * key_len, operation ) );
788 
789  TEST_ASSERT( 0 == cipher_update( &ctx, input,
790  cipher_get_block_size( &ctx ),
791  output, &outlen ) );
792  TEST_ASSERT( outlen == cipher_get_block_size( &ctx ) );
793  TEST_ASSERT( finish_result == cipher_finish( &ctx, output + outlen,
794  &outlen ) );
795  TEST_ASSERT( 0 == outlen );
796 
797  /* check plaintext only if everything went fine */
798  if( 0 == finish_result )
799  TEST_ASSERT( 0 == memcmp( output, result,
800  cipher_get_block_size( &ctx ) ) );
801 
802  cipher_free_ctx( &ctx );
803 }
804 
805 #ifdef POLARSSL_CIPHER_MODE_WITH_PADDING
806 void test_suite_set_padding( int cipher_id, int pad_mode, int ret )
807 {
808  const cipher_info_t *cipher_info;
809  cipher_context_t ctx;
810 
811  cipher_info = cipher_info_from_type( cipher_id );
812  TEST_ASSERT( NULL != cipher_info );
813  TEST_ASSERT( 0 == cipher_init_ctx( &ctx, cipher_info ) );
814 
815  TEST_ASSERT( ret == cipher_set_padding_mode( &ctx, pad_mode ) );
816 
817  TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
818 }
819 #endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
820 
821 #ifdef POLARSSL_CIPHER_MODE_CBC
822 void test_suite_check_padding( int pad_mode, char *input_str, int ret, int dlen_check )
823 {
824  cipher_info_t cipher_info;
825  cipher_context_t ctx;
826  unsigned char input[16];
827  size_t ilen, dlen;
828 
829  /* build a fake context just for getting access to get_padding */
830  memset( &ctx, 0, sizeof( ctx ) );
831  cipher_info.mode = POLARSSL_MODE_CBC;
832  ctx.cipher_info = &cipher_info;
833 
834  TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, pad_mode ) );
835 
836  ilen = unhexify( input, input_str );
837 
838  TEST_ASSERT( ret == ctx.get_padding( input, ilen, &dlen ) );
839  if( 0 == ret )
840  TEST_ASSERT( dlen == (size_t) dlen_check );
841 }
842 #endif /* POLARSSL_CIPHER_MODE_CBC */
843 
844 #ifdef POLARSSL_SELF_TEST
845 void test_suite_cipher_selftest()
846 {
847  TEST_ASSERT( cipher_self_test( 0 ) == 0 );
848 }
849 #endif /* POLARSSL_SELF_TEST */
850 
851 
852 #endif /* POLARSSL_CIPHER_C */
853 
854 
855 int dep_check( char *str )
856 {
857  if( str == NULL )
858  return( 1 );
859 
860  if( strcmp( str, "POLARSSL_CIPHER_NULL_CIPHER" ) == 0 )
861  {
862 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
863  return( 0 );
864 #else
865  return( 1 );
866 #endif
867  }
868 
869 
870  return( 1 );
871 }
872 
873 int dispatch_test(int cnt, char *params[50])
874 {
875  int ret;
876  ((void) cnt);
877  ((void) params);
878 
879 #if defined(TEST_SUITE_ACTIVE)
880  if( strcmp( params[0], "enc_dec_buf" ) == 0 )
881  {
882 
883  int param1;
884  char *param2 = params[2];
885  int param3;
886  int param4;
887  int param5;
888 
889  if( cnt != 6 )
890  {
891  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 6 );
892  return( 2 );
893  }
894 
895  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
896  if( verify_string( &param2 ) != 0 ) return( 2 );
897  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
898  if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
899  if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
900 
901  test_suite_enc_dec_buf( param1, param2, param3, param4, param5 );
902  return ( 0 );
903 
904  return ( 3 );
905  }
906  else
907  if( strcmp( params[0], "enc_fail" ) == 0 )
908  {
909 
910  int param1;
911  int param2;
912  int param3;
913  int param4;
914  int param5;
915 
916  if( cnt != 6 )
917  {
918  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 6 );
919  return( 2 );
920  }
921 
922  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
923  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
924  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
925  if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
926  if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
927 
928  test_suite_enc_fail( param1, param2, param3, param4, param5 );
929  return ( 0 );
930 
931  return ( 3 );
932  }
933  else
934  if( strcmp( params[0], "dec_empty_buf" ) == 0 )
935  {
936 
937 
938  if( cnt != 1 )
939  {
940  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
941  return( 2 );
942  }
943 
944 
945  test_suite_dec_empty_buf( );
946  return ( 0 );
947 
948  return ( 3 );
949  }
950  else
951  if( strcmp( params[0], "enc_dec_buf_multipart" ) == 0 )
952  {
953 
954  int param1;
955  int param2;
956  int param3;
957  int param4;
958 
959  if( cnt != 5 )
960  {
961  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
962  return( 2 );
963  }
964 
965  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
966  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
967  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
968  if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
969 
970  test_suite_enc_dec_buf_multipart( param1, param2, param3, param4 );
971  return ( 0 );
972 
973  return ( 3 );
974  }
975  else
976  if( strcmp( params[0], "decrypt_test_vec" ) == 0 )
977  {
978 
979  int param1;
980  int param2;
981  char *param3 = params[3];
982  char *param4 = params[4];
983  char *param5 = params[5];
984  char *param6 = params[6];
985  char *param7 = params[7];
986  char *param8 = params[8];
987  int param9;
988  int param10;
989 
990  if( cnt != 11 )
991  {
992  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 11 );
993  return( 2 );
994  }
995 
996  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
997  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
998  if( verify_string( &param3 ) != 0 ) return( 2 );
999  if( verify_string( &param4 ) != 0 ) return( 2 );
1000  if( verify_string( &param5 ) != 0 ) return( 2 );
1001  if( verify_string( &param6 ) != 0 ) return( 2 );
1002  if( verify_string( &param7 ) != 0 ) return( 2 );
1003  if( verify_string( &param8 ) != 0 ) return( 2 );
1004  if( verify_int( params[9], &param9 ) != 0 ) return( 2 );
1005  if( verify_int( params[10], &param10 ) != 0 ) return( 2 );
1006 
1007  test_suite_decrypt_test_vec( param1, param2, param3, param4, param5, param6, param7, param8, param9, param10 );
1008  return ( 0 );
1009 
1010  return ( 3 );
1011  }
1012  else
1013  if( strcmp( params[0], "test_vec_ecb" ) == 0 )
1014  {
1015 
1016  int param1;
1017  int param2;
1018  char *param3 = params[3];
1019  char *param4 = params[4];
1020  char *param5 = params[5];
1021  int param6;
1022 
1023  if( cnt != 7 )
1024  {
1025  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1026  return( 2 );
1027  }
1028 
1029  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1030  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
1031  if( verify_string( &param3 ) != 0 ) return( 2 );
1032  if( verify_string( &param4 ) != 0 ) return( 2 );
1033  if( verify_string( &param5 ) != 0 ) return( 2 );
1034  if( verify_int( params[6], &param6 ) != 0 ) return( 2 );
1035 
1036  test_suite_test_vec_ecb( param1, param2, param3, param4, param5, param6 );
1037  return ( 0 );
1038 
1039  return ( 3 );
1040  }
1041  else
1042  if( strcmp( params[0], "set_padding" ) == 0 )
1043  {
1044  #ifdef POLARSSL_CIPHER_MODE_WITH_PADDING
1045 
1046  int param1;
1047  int param2;
1048  int param3;
1049 
1050  if( cnt != 4 )
1051  {
1052  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
1053  return( 2 );
1054  }
1055 
1056  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1057  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
1058  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1059 
1060  test_suite_set_padding( param1, param2, param3 );
1061  return ( 0 );
1062  #endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
1063 
1064  return ( 3 );
1065  }
1066  else
1067  if( strcmp( params[0], "check_padding" ) == 0 )
1068  {
1069  #ifdef POLARSSL_CIPHER_MODE_CBC
1070 
1071  int param1;
1072  char *param2 = params[2];
1073  int param3;
1074  int param4;
1075 
1076  if( cnt != 5 )
1077  {
1078  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1079  return( 2 );
1080  }
1081 
1082  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1083  if( verify_string( &param2 ) != 0 ) return( 2 );
1084  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1085  if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
1086 
1087  test_suite_check_padding( param1, param2, param3, param4 );
1088  return ( 0 );
1089  #endif /* POLARSSL_CIPHER_MODE_CBC */
1090 
1091  return ( 3 );
1092  }
1093  else
1094  if( strcmp( params[0], "cipher_selftest" ) == 0 )
1095  {
1096  #ifdef POLARSSL_SELF_TEST
1097 
1098 
1099  if( cnt != 1 )
1100  {
1101  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1102  return( 2 );
1103  }
1104 
1105 
1106  test_suite_cipher_selftest( );
1107  return ( 0 );
1108  #endif /* POLARSSL_SELF_TEST */
1109 
1110  return ( 3 );
1111  }
1112  else
1113 
1114  {
1115  fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
1116  fflush( stdout );
1117  return( 1 );
1118  }
1119 #else
1120  return( 3 );
1121 #endif
1122  return( ret );
1123 }
1124 
1125 int get_line( FILE *f, char *buf, size_t len )
1126 {
1127  char *ret;
1128 
1129  ret = fgets( buf, len, f );
1130  if( ret == NULL )
1131  return( -1 );
1132 
1133  if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
1134  buf[strlen(buf) - 1] = '\0';
1135  if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
1136  buf[strlen(buf) - 1] = '\0';
1137 
1138  return( 0 );
1139 }
1140 
1141 int parse_arguments( char *buf, size_t len, char *params[50] )
1142 {
1143  int cnt = 0, i;
1144  char *cur = buf;
1145  char *p = buf, *q;
1146 
1147  params[cnt++] = cur;
1148 
1149  while( *p != '\0' && p < buf + len )
1150  {
1151  if( *p == '\\' )
1152  {
1153  *p++;
1154  *p++;
1155  continue;
1156  }
1157  if( *p == ':' )
1158  {
1159  if( p + 1 < buf + len )
1160  {
1161  cur = p + 1;
1162  params[cnt++] = cur;
1163  }
1164  *p = '\0';
1165  }
1166 
1167  *p++;
1168  }
1169 
1170  // Replace newlines, question marks and colons in strings
1171  for( i = 0; i < cnt; i++ )
1172  {
1173  p = params[i];
1174  q = params[i];
1175 
1176  while( *p != '\0' )
1177  {
1178  if( *p == '\\' && *(p + 1) == 'n' )
1179  {
1180  p += 2;
1181  *(q++) = '\n';
1182  }
1183  else if( *p == '\\' && *(p + 1) == ':' )
1184  {
1185  p += 2;
1186  *(q++) = ':';
1187  }
1188  else if( *p == '\\' && *(p + 1) == '?' )
1189  {
1190  p += 2;
1191  *(q++) = '?';
1192  }
1193  else
1194  *(q++) = *(p++);
1195  }
1196  *q = '\0';
1197  }
1198 
1199  return( cnt );
1200 }
1201 
1202 int main()
1203 {
1204  int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1205  const char *filename = "/tmp/B.6b9404fc-5e27-486e-9bbd-77463d7343ee/BUILD/polarssl-1.3.2/tests/suites/test_suite_cipher.null.data";
1206  FILE *file;
1207  char buf[5000];
1208  char *params[50];
1209 
1210 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1211  unsigned char alloc_buf[1000000];
1212  memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
1213 #endif
1214 
1215  file = fopen( filename, "r" );
1216  if( file == NULL )
1217  {
1218  fprintf( stderr, "Failed to open\n" );
1219  return( 1 );
1220  }
1221 
1222  while( !feof( file ) )
1223  {
1224  int skip = 0;
1225 
1226  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1227  break;
1228  fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
1229  fprintf( stdout, " " );
1230  for( i = strlen( buf ) + 1; i < 67; i++ )
1231  fprintf( stdout, "." );
1232  fprintf( stdout, " " );
1233  fflush( stdout );
1234 
1235  total_tests++;
1236 
1237  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1238  break;
1239  cnt = parse_arguments( buf, strlen(buf), params );
1240 
1241  if( strcmp( params[0], "depends_on" ) == 0 )
1242  {
1243  for( i = 1; i < cnt; i++ )
1244  if( dep_check( params[i] ) != 0 )
1245  skip = 1;
1246 
1247  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1248  break;
1249  cnt = parse_arguments( buf, strlen(buf), params );
1250  }
1251 
1252  if( skip == 0 )
1253  {
1254  test_errors = 0;
1255  ret = dispatch_test( cnt, params );
1256  }
1257 
1258  if( skip == 1 || ret == 3 )
1259  {
1260  total_skipped++;
1261  fprintf( stdout, "----\n" );
1262  fflush( stdout );
1263  }
1264  else if( ret == 0 && test_errors == 0 )
1265  {
1266  fprintf( stdout, "PASS\n" );
1267  fflush( stdout );
1268  }
1269  else if( ret == 2 )
1270  {
1271  fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
1272  fclose(file);
1273  exit( 2 );
1274  }
1275  else
1276  total_errors++;
1277 
1278  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1279  break;
1280  if( strlen(buf) != 0 )
1281  {
1282  fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
1283  return( 1 );
1284  }
1285  }
1286  fclose(file);
1287 
1288  fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
1289  if( total_errors == 0 )
1290  fprintf( stdout, "PASSED" );
1291  else
1292  fprintf( stdout, "FAILED" );
1293 
1294  fprintf( stdout, " (%d / %d tests (%d skipped))\n",
1295  total_tests - total_errors, total_tests, total_skipped );
1296 
1297 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1298 #if defined(POLARSSL_MEMORY_DEBUG)
1299  memory_buffer_alloc_status();
1300 #endif
1301  memory_buffer_alloc_free();
1302 #endif
1303 
1304  return( total_errors != 0 );
1305 }
1306 
1307 
int cipher_finish(cipher_context_t *ctx, unsigned char *output, size_t *olen)
Generic cipher finalisation function.
Memory allocation layer.
Generic cipher context.
Definition: cipher.h:239
uint32_t t_uint
Definition: bignum.h:149
Info structure for the pseudo random function.
int cipher_write_tag(cipher_context_t *ctx, unsigned char *tag, size_t tag_len)
Write tag for AEAD ciphers.
int s
Definition: bignum.h:173
Cipher information.
Definition: cipher.h:207
const cipher_info_t * cipher_info_from_type(const cipher_type_t cipher_type)
Returns the cipher information structure associated with the given cipher type.
static unsigned int cipher_get_block_size(const cipher_context_t *ctx)
Returns the block size of the given cipher.
Definition: cipher.h:348
const cipher_info_t * cipher_info_from_string(const char *cipher_name)
Returns the cipher information structure associated with the given cipher name.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
int(* get_padding)(unsigned char *input, size_t ilen, size_t *data_len)
Definition: cipher.h:251
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
Configuration options (set of defines)
MPI structure.
Definition: bignum.h:171
static int test_assert(int correct, char *test)
#define PUT_UINT32_BE(n, b, i)
int main(int argc, char *argv[])
Multi-precision integer library.
int dep_check(char *str)
const cipher_info_t * cipher_info
Information about the associated cipher.
Definition: cipher.h:241
#define TEST_ASSERT(TEST)
int cipher_free_ctx(cipher_context_t *ctx)
Free the cipher-specific context of ctx.
int cipher_update_ad(cipher_context_t *ctx, const unsigned char *ad, size_t ad_len)
Add additional data (for AEAD ciphers).
int cipher_set_iv(cipher_context_t *ctx, const unsigned char *iv, size_t iv_len)
Set the initialization vector (IV) or nonce.
int cipher_update(cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
Generic cipher update function.
#define POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED
Decryption of block requires a full block.
Definition: cipher.h:57
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
Generic cipher wrapper.
int parse_arguments(char *buf, size_t len, char *params[50])
int cipher_reset(cipher_context_t *ctx)
Finish preparation of the given context.
int cipher_set_padding_mode(cipher_context_t *ctx, cipher_padding_t mode)
Set padding mode, for cipher modes that use padding.
cipher_mode_t mode
Cipher mode (e.g.
Definition: cipher.h:212
int mpi_read_string(mpi *X, int radix, const char *s)
Import from an ASCII string.
int cipher_init_ctx(cipher_context_t *ctx, const cipher_info_t *cipher_info)
Initialises and fills the cipher context structure with the appropriate values.
int cipher_setkey(cipher_context_t *ctx, const unsigned char *key, int key_length, const operation_t operation)
Set the key to use with the given context.
t_uint * p
Definition: bignum.h:175
int verify_string(char **str)
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
int dispatch_test(int cnt, char *params[50])
size_t n
Definition: bignum.h:174
Galois/Counter mode for 128-bit block ciphers.
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
unsigned char * buf
static int unhexify(unsigned char *obuf, const char *ibuf)
int verify_int(char *str, int *value)
static int test_errors
int cipher_self_test(int verbose)
Checkup routine.
int cipher_check_tag(cipher_context_t *ctx, const unsigned char *tag, size_t tag_len)
Check tag for AEAD ciphers.
int get_line(FILE *f, char *buf, size_t len)