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