PolarSSL v1.3.9
test_suite_mdx.c
Go to the documentation of this file.
1 #if !defined(POLARSSL_CONFIG_FILE)
2 #include <polarssl/config.h>
3 #else
4 #include POLARSSL_CONFIG_FILE
5 #endif
6 
7 
8 #include <polarssl/md2.h>
9 #include <polarssl/md4.h>
10 #include <polarssl/md5.h>
11 #include <polarssl/ripemd160.h>
12 
13 
14 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
15 #include "polarssl/memory.h"
16 #endif
17 
18 #if defined(POLARSSL_PLATFORM_C)
19 #include "polarssl/platform.h"
20 #else
21 #define polarssl_malloc malloc
22 #define polarssl_free free
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 
124 static unsigned char *zero_alloc( size_t len )
125 {
126  void *p;
127  size_t actual_len = len != 0 ? len : 1;
128 
129  p = polarssl_malloc( actual_len );
130  assert( p != NULL );
131 
132  memset( p, 0x00, actual_len );
133 
134  return( p );
135 }
136 
147 static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
148 {
149  unsigned char *obuf;
150 
151  *olen = strlen(ibuf) / 2;
152 
153  if( *olen == 0 )
154  return( zero_alloc( *olen ) );
155 
156  obuf = polarssl_malloc( *olen );
157  assert( obuf != NULL );
158 
159  (void) unhexify( obuf, ibuf );
160 
161  return( obuf );
162 }
163 
173 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
174 {
175 #if !defined(__OpenBSD__)
176  size_t i;
177 
178  if( rng_state != NULL )
179  rng_state = NULL;
180 
181  for( i = 0; i < len; ++i )
182  output[i] = rand();
183 #else
184  if( rng_state != NULL )
185  rng_state = NULL;
186 
187  arc4random_buf( output, len );
188 #endif /* !OpenBSD */
189 
190  return( 0 );
191 }
192 
198 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
199 {
200  if( rng_state != NULL )
201  rng_state = NULL;
202 
203  memset( output, 0, len );
204 
205  return( 0 );
206 }
207 
208 typedef struct
209 {
210  unsigned char *buf;
211  size_t length;
212 } rnd_buf_info;
213 
225 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
226 {
227  rnd_buf_info *info = (rnd_buf_info *) rng_state;
228  size_t use_len;
229 
230  if( rng_state == NULL )
231  return( rnd_std_rand( NULL, output, len ) );
232 
233  use_len = len;
234  if( len > info->length )
235  use_len = info->length;
236 
237  if( use_len )
238  {
239  memcpy( output, info->buf, use_len );
240  info->buf += use_len;
241  info->length -= use_len;
242  }
243 
244  if( len - use_len > 0 )
245  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
246 
247  return( 0 );
248 }
249 
257 typedef struct
258 {
259  uint32_t key[16];
260  uint32_t v0, v1;
262 
271 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
272 {
273  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
274  uint32_t i, *k, sum, delta=0x9E3779B9;
275  unsigned char result[4], *out = output;
276 
277  if( rng_state == NULL )
278  return( rnd_std_rand( NULL, output, len ) );
279 
280  k = info->key;
281 
282  while( len > 0 )
283  {
284  size_t use_len = ( len > 4 ) ? 4 : len;
285  sum = 0;
286 
287  for( i = 0; i < 32; i++ )
288  {
289  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
290  sum += delta;
291  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
292  }
293 
294  PUT_UINT32_BE( info->v0, result, 0 );
295  memcpy( out, result, use_len );
296  len -= use_len;
297  out += 4;
298  }
299 
300  return( 0 );
301 }
302 
303 
304 #include <stdio.h>
305 #include <string.h>
306 
307 #if defined(POLARSSL_PLATFORM_C)
308 #include "polarssl/platform.h"
309 #else
310 #define polarssl_printf printf
311 #define polarssl_malloc malloc
312 #define polarssl_free free
313 #endif
314 
315 static int test_errors = 0;
316 
317 
318 #define TEST_SUITE_ACTIVE
319 
320 static int test_assert( int correct, const char *test )
321 {
322  if( correct )
323  return( 0 );
324 
325  test_errors++;
326  if( test_errors == 1 )
327  printf( "FAILED\n" );
328  printf( " %s\n", test );
329 
330  return( 1 );
331 }
332 
333 #define TEST_ASSERT( TEST ) \
334  do { test_assert( (TEST) ? 1 : 0, #TEST ); \
335  if( test_errors) goto exit; \
336  } while (0)
337 
338 int verify_string( char **str )
339 {
340  if( (*str)[0] != '"' ||
341  (*str)[strlen( *str ) - 1] != '"' )
342  {
343  printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
344  return( -1 );
345  }
346 
347  (*str)++;
348  (*str)[strlen( *str ) - 1] = '\0';
349 
350  return( 0 );
351 }
352 
353 int verify_int( char *str, int *value )
354 {
355  size_t i;
356  int minus = 0;
357  int digits = 1;
358  int hex = 0;
359 
360  for( i = 0; i < strlen( str ); i++ )
361  {
362  if( i == 0 && str[i] == '-' )
363  {
364  minus = 1;
365  continue;
366  }
367 
368  if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
369  str[i - 1] == '0' && str[i] == 'x' )
370  {
371  hex = 1;
372  continue;
373  }
374 
375  if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
376  ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
377  ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
378  {
379  digits = 0;
380  break;
381  }
382  }
383 
384  if( digits )
385  {
386  if( hex )
387  *value = strtol( str, NULL, 16 );
388  else
389  *value = strtol( str, NULL, 10 );
390 
391  return( 0 );
392  }
393 
394 
395 
396  printf( "Expected integer for parameter and got: %s\n", str );
397  return( -1 );
398 }
399 
400 #ifdef POLARSSL_MD2_C
401 void test_suite_md2_text( char *text_src_string, char *hex_hash_string )
402 {
403  unsigned char src_str[100];
404  unsigned char hash_str[33];
405  unsigned char output[16];
406 
407  memset( src_str, 0x00, sizeof src_str );
408  memset( hash_str, 0x00, sizeof hash_str );
409  memset( output, 0x00, sizeof output );
410 
411  strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
412 
413  md2( src_str, strlen( (char *) src_str ), output );
414  hexify( hash_str, output, sizeof output );
415 
416  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
417 
418 exit:
419  return;
420 }
421 #endif /* POLARSSL_MD2_C */
422 
423 #ifdef POLARSSL_MD4_C
424 void test_suite_md4_text( char *text_src_string, char *hex_hash_string )
425 {
426  unsigned char src_str[100];
427  unsigned char hash_str[33];
428  unsigned char output[16];
429 
430  memset( src_str, 0x00, sizeof src_str );
431  memset( hash_str, 0x00, sizeof hash_str );
432  memset( output, 0x00, sizeof output );
433 
434  strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
435 
436  md4( src_str, strlen( (char *) src_str ), output );
437  hexify( hash_str, output, sizeof output );
438 
439  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
440 
441 exit:
442  return;
443 }
444 #endif /* POLARSSL_MD4_C */
445 
446 #ifdef POLARSSL_MD5_C
447 void test_suite_md5_text( char *text_src_string, char *hex_hash_string )
448 {
449  unsigned char src_str[100];
450  unsigned char hash_str[33];
451  unsigned char output[16];
452 
453  memset( src_str, 0x00, sizeof src_str );
454  memset( hash_str, 0x00, sizeof hash_str );
455  memset( output, 0x00, sizeof output );
456 
457  strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
458 
459  md5( src_str, strlen( (char *) src_str ), output );
460  hexify( hash_str, output, sizeof output );
461 
462  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
463 
464 exit:
465  return;
466 }
467 #endif /* POLARSSL_MD5_C */
468 
469 #ifdef POLARSSL_RIPEMD160_C
470 void test_suite_ripemd160_text( char *text_src_string, char *hex_hash_string )
471 {
472  unsigned char src_str[100];
473  unsigned char hash_str[41];
474  unsigned char output[20];
475 
476  memset(src_str, 0x00, sizeof src_str);
477  memset(hash_str, 0x00, sizeof hash_str);
478  memset(output, 0x00, sizeof output);
479 
480  strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
481 
482  ripemd160( src_str, strlen( (char *) src_str ), output );
483  hexify( hash_str, output, sizeof output );
484 
485  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
486 
487 exit:
488  return;
489 }
490 #endif /* POLARSSL_RIPEMD160_C */
491 
492 #ifdef POLARSSL_MD2_C
493 void test_suite_md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
494  char *hex_hash_string )
495 {
496  unsigned char src_str[200];
497  unsigned char key_str[200];
498  unsigned char hash_str[33];
499  unsigned char output[16];
500  int key_len, src_len;
501  md2_context ctx;
502 
503  memset( src_str, 0x00, sizeof src_str );
504  memset( key_str, 0x00, sizeof key_str );
505  md2_init( &ctx );
506 
507  key_len = unhexify( key_str, hex_key_string );
508  src_len = unhexify( src_str, hex_src_string );
509 
510  /* Test the all-in-one interface */
511  memset( hash_str, 0x00, sizeof hash_str );
512  memset( output, 0x00, sizeof output );
513 
514  md2_hmac( key_str, key_len, src_str, src_len, output );
515 
516  hexify( hash_str, output, sizeof output );
517  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
518 
519  /* Also test the "streaming" interface */
520  memset( hash_str, 0x00, sizeof hash_str );
521  memset( output, 0x00, sizeof output );
522  memset( &ctx, 0x00, sizeof ctx );
523 
524  md2_hmac_starts( &ctx, key_str, key_len );
525  md2_hmac_update( &ctx, src_str, 0 );
526  md2_hmac_update( &ctx, src_str, src_len / 2 );
527  md2_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
528  md2_hmac_update( &ctx, src_str + src_len, 0 );
529  md2_hmac_finish( &ctx, output );
530 
531  hexify( hash_str, output, sizeof output );
532  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
533 
534  /* Again, to test hmac_reset() */
535  memset( hash_str, 0x00, sizeof hash_str );
536  memset( output, 0x00, sizeof output );
537 
538  md2_hmac_reset( &ctx );
539  md2_hmac_update( &ctx, src_str, src_len / 2 );
540  md2_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
541  md2_hmac_finish( &ctx, output );
542 
543  hexify( hash_str, output, sizeof output );
544  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
545 
546 exit:
547  md2_free( &ctx );
548 }
549 #endif /* POLARSSL_MD2_C */
550 
551 #ifdef POLARSSL_MD4_C
552 void test_suite_md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
553  char *hex_hash_string )
554 {
555  unsigned char src_str[200];
556  unsigned char key_str[200];
557  unsigned char hash_str[33];
558  unsigned char output[16];
559  int key_len, src_len;
560  md4_context ctx;
561 
562  memset( src_str, 0x00, sizeof src_str );
563  memset( key_str, 0x00, sizeof key_str );
564  md4_init( &ctx );
565 
566  key_len = unhexify( key_str, hex_key_string );
567  src_len = unhexify( src_str, hex_src_string );
568 
569  /* Test the all-in-one interface */
570  memset( hash_str, 0x00, sizeof hash_str );
571  memset( output, 0x00, sizeof output );
572 
573  md4_hmac( key_str, key_len, src_str, src_len, output );
574 
575  hexify( hash_str, output, sizeof output );
576  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
577 
578  /* Also test the "streaming" interface */
579  memset( hash_str, 0x00, sizeof hash_str );
580  memset( output, 0x00, sizeof output );
581  memset( &ctx, 0x00, sizeof ctx );
582 
583  md4_hmac_starts( &ctx, key_str, key_len );
584  md4_hmac_update( &ctx, src_str, 0 );
585  md4_hmac_update( &ctx, src_str, src_len / 2 );
586  md4_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
587  md4_hmac_update( &ctx, src_str + src_len, 0 );
588  md4_hmac_finish( &ctx, output );
589 
590  hexify( hash_str, output, sizeof output );
591  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
592 
593  /* Again, to test hmac_reset() */
594  memset( hash_str, 0x00, sizeof hash_str );
595  memset( output, 0x00, sizeof output );
596 
597  md4_hmac_reset( &ctx );
598  md4_hmac_update( &ctx, src_str, src_len / 2 );
599  md4_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
600  md4_hmac_finish( &ctx, output );
601 
602  hexify( hash_str, output, sizeof output );
603  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
604 
605 exit:
606  md4_free( &ctx );
607 }
608 #endif /* POLARSSL_MD4_C */
609 
610 #ifdef POLARSSL_MD5_C
611 void test_suite_md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
612  char *hex_hash_string )
613 {
614  unsigned char src_str[200];
615  unsigned char key_str[200];
616  unsigned char hash_str[33];
617  unsigned char output[16];
618  int key_len, src_len;
619  md5_context ctx;
620 
621  memset( src_str, 0x00, sizeof src_str );
622  memset( key_str, 0x00, sizeof key_str );
623  md5_init( &ctx );
624 
625  key_len = unhexify( key_str, hex_key_string );
626  src_len = unhexify( src_str, hex_src_string );
627 
628  /* Test the all-in-one interface */
629  memset( hash_str, 0x00, sizeof hash_str );
630  memset( output, 0x00, sizeof output );
631 
632  md5_hmac( key_str, key_len, src_str, src_len, output );
633 
634  hexify( hash_str, output, sizeof output );
635  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
636 
637  /* Also test the "streaming" interface */
638  memset( hash_str, 0x00, sizeof hash_str );
639  memset( output, 0x00, sizeof output );
640  memset( &ctx, 0x00, sizeof ctx );
641 
642  md5_hmac_starts( &ctx, key_str, key_len );
643  md5_hmac_update( &ctx, src_str, 0 );
644  md5_hmac_update( &ctx, src_str, src_len / 2 );
645  md5_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
646  md5_hmac_update( &ctx, src_str + src_len, 0 );
647  md5_hmac_finish( &ctx, output );
648 
649  hexify( hash_str, output, sizeof output );
650  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
651 
652  /* Again, to test hmac_reset() */
653  memset( hash_str, 0x00, sizeof hash_str );
654  memset( output, 0x00, sizeof output );
655 
656  md5_hmac_reset( &ctx );
657  md5_hmac_update( &ctx, src_str, src_len / 2 );
658  md5_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
659  md5_hmac_finish( &ctx, output );
660 
661  hexify( hash_str, output, sizeof output );
662  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
663 
664 exit:
665  md5_free( &ctx );
666 }
667 #endif /* POLARSSL_MD5_C */
668 
669 #ifdef POLARSSL_RIPEMD160_C
670 void test_suite_ripemd160_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
671  char *hex_hash_string )
672 {
673  unsigned char src_str[200];
674  unsigned char key_str[200];
675  unsigned char hash_str[41];
676  unsigned char output[20];
677  int key_len, src_len;
678  ripemd160_context ctx;
679 
680  memset( src_str, 0x00, sizeof src_str );
681  memset( key_str, 0x00, sizeof key_str );
682  ripemd160_init( &ctx );
683 
684  key_len = unhexify( key_str, hex_key_string );
685  src_len = unhexify( src_str, hex_src_string );
686 
687  /* Test the all-in-one interface */
688  memset( hash_str, 0x00, sizeof hash_str );
689  memset( output, 0x00, sizeof output );
690 
691  ripemd160_hmac( key_str, key_len, src_str, src_len, output );
692 
693  hexify( hash_str, output, sizeof output );
694  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
695 
696  /* Also test the "streaming" interface */
697  memset( hash_str, 0x00, sizeof hash_str );
698  memset( output, 0x00, sizeof output );
699  memset( &ctx, 0x00, sizeof ctx );
700 
701  ripemd160_hmac_starts( &ctx, key_str, key_len );
702  ripemd160_hmac_update( &ctx, src_str, 0 );
703  ripemd160_hmac_update( &ctx, src_str, src_len / 2 );
704  ripemd160_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
705  ripemd160_hmac_update( &ctx, src_str + src_len, 0 );
706  ripemd160_hmac_finish( &ctx, output );
707 
708  hexify( hash_str, output, sizeof output );
709  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
710 
711  /* Again, to test hmac_reset() */
712  memset( hash_str, 0x00, sizeof hash_str );
713  memset( output, 0x00, sizeof output );
714 
715  ripemd160_hmac_reset( &ctx );
716  ripemd160_hmac_update( &ctx, src_str, src_len / 2 );
717  ripemd160_hmac_update( &ctx, src_str + src_len / 2, src_len - src_len / 2 );
718  ripemd160_hmac_finish( &ctx, output );
719 
720  hexify( hash_str, output, sizeof output );
721  TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
722 
723 exit:
724  ripemd160_free( &ctx );
725 }
726 #endif /* POLARSSL_RIPEMD160_C */
727 
728 #ifdef POLARSSL_MD2_C
729 #ifdef POLARSSL_FS_IO
730 void test_suite_md2_file( char *filename, char *hex_hash_string )
731 {
732  unsigned char hash_str[33];
733  unsigned char output[16];
734 
735  memset( hash_str, 0x00, sizeof hash_str );
736  memset( output, 0x00, sizeof output );
737 
738  md2_file( filename, output);
739  hexify( hash_str, output, sizeof output );
740 
741  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
742 
743 exit:
744  return;
745 }
746 #endif /* POLARSSL_MD2_C */
747 #endif /* POLARSSL_FS_IO */
748 
749 #ifdef POLARSSL_MD4_C
750 #ifdef POLARSSL_FS_IO
751 void test_suite_md4_file( char *filename, char *hex_hash_string )
752 {
753  unsigned char hash_str[33];
754  unsigned char output[16];
755 
756  memset( hash_str, 0x00, sizeof hash_str );
757  memset( output, 0x00, sizeof output );
758 
759  md4_file( filename, output);
760  hexify( hash_str, output, sizeof output );
761 
762  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
763 
764 exit:
765  return;
766 }
767 #endif /* POLARSSL_MD4_C */
768 #endif /* POLARSSL_FS_IO */
769 
770 #ifdef POLARSSL_MD5_C
771 #ifdef POLARSSL_FS_IO
772 void test_suite_md5_file( char *filename, char *hex_hash_string )
773 {
774  unsigned char hash_str[33];
775  unsigned char output[16];
776 
777  memset( hash_str, 0x00, sizeof hash_str );
778  memset( output, 0x00, sizeof output );
779 
780  md5_file( filename, output);
781  hexify( hash_str, output, sizeof output );
782 
783  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
784 
785 exit:
786  return;
787 }
788 #endif /* POLARSSL_MD5_C */
789 #endif /* POLARSSL_FS_IO */
790 
791 #ifdef POLARSSL_RIPEMD160_C
792 #ifdef POLARSSL_FS_IO
793 void test_suite_ripemd160_file( char *filename, char *hex_hash_string )
794 {
795  unsigned char hash_str[41];
796  unsigned char output[20];
797 
798  memset(hash_str, 0x00, sizeof hash_str );
799  memset(output, 0x00, sizeof output );
800 
801  ripemd160_file( filename, output);
802  hexify( hash_str, output, sizeof output );
803 
804  TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
805 
806 exit:
807  return;
808 }
809 #endif /* POLARSSL_RIPEMD160_C */
810 #endif /* POLARSSL_FS_IO */
811 
812 #ifdef POLARSSL_MD2_C
813 #ifdef POLARSSL_SELF_TEST
814 void test_suite_md2_selftest()
815 {
816  TEST_ASSERT( md2_self_test( 0 ) == 0 );
817 
818 exit:
819  return;
820 }
821 #endif /* POLARSSL_MD2_C */
822 #endif /* POLARSSL_SELF_TEST */
823 
824 #ifdef POLARSSL_MD4_C
825 #ifdef POLARSSL_SELF_TEST
826 void test_suite_md4_selftest()
827 {
828  TEST_ASSERT( md4_self_test( 0 ) == 0 );
829 
830 exit:
831  return;
832 }
833 #endif /* POLARSSL_MD4_C */
834 #endif /* POLARSSL_SELF_TEST */
835 
836 #ifdef POLARSSL_MD5_C
837 #ifdef POLARSSL_SELF_TEST
838 void test_suite_md5_selftest()
839 {
840  TEST_ASSERT( md5_self_test( 0 ) == 0 );
841 
842 exit:
843  return;
844 }
845 #endif /* POLARSSL_MD5_C */
846 #endif /* POLARSSL_SELF_TEST */
847 
848 #ifdef POLARSSL_RIPEMD160_C
849 #ifdef POLARSSL_SELF_TEST
850 void test_suite_ripemd160_selftest()
851 {
852  TEST_ASSERT( ripemd160_self_test( 0 ) == 0 );
853 
854 exit:
855  return;
856 }
857 #endif /* POLARSSL_RIPEMD160_C */
858 #endif /* POLARSSL_SELF_TEST */
859 
860 
861 
862 
863 int dep_check( char *str )
864 {
865  if( str == NULL )
866  return( 1 );
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], "md2_text" ) == 0 )
881  {
882  #ifdef POLARSSL_MD2_C
883 
884  char *param1 = params[1];
885  char *param2 = params[2];
886 
887  if( cnt != 3 )
888  {
889  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
890  return( 2 );
891  }
892 
893  if( verify_string( &param1 ) != 0 ) return( 2 );
894  if( verify_string( &param2 ) != 0 ) return( 2 );
895 
896  test_suite_md2_text( param1, param2 );
897  return ( 0 );
898  #endif /* POLARSSL_MD2_C */
899 
900  return ( 3 );
901  }
902  else
903  if( strcmp( params[0], "md4_text" ) == 0 )
904  {
905  #ifdef POLARSSL_MD4_C
906 
907  char *param1 = params[1];
908  char *param2 = params[2];
909 
910  if( cnt != 3 )
911  {
912  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
913  return( 2 );
914  }
915 
916  if( verify_string( &param1 ) != 0 ) return( 2 );
917  if( verify_string( &param2 ) != 0 ) return( 2 );
918 
919  test_suite_md4_text( param1, param2 );
920  return ( 0 );
921  #endif /* POLARSSL_MD4_C */
922 
923  return ( 3 );
924  }
925  else
926  if( strcmp( params[0], "md5_text" ) == 0 )
927  {
928  #ifdef POLARSSL_MD5_C
929 
930  char *param1 = params[1];
931  char *param2 = params[2];
932 
933  if( cnt != 3 )
934  {
935  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
936  return( 2 );
937  }
938 
939  if( verify_string( &param1 ) != 0 ) return( 2 );
940  if( verify_string( &param2 ) != 0 ) return( 2 );
941 
942  test_suite_md5_text( param1, param2 );
943  return ( 0 );
944  #endif /* POLARSSL_MD5_C */
945 
946  return ( 3 );
947  }
948  else
949  if( strcmp( params[0], "ripemd160_text" ) == 0 )
950  {
951  #ifdef POLARSSL_RIPEMD160_C
952 
953  char *param1 = params[1];
954  char *param2 = params[2];
955 
956  if( cnt != 3 )
957  {
958  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
959  return( 2 );
960  }
961 
962  if( verify_string( &param1 ) != 0 ) return( 2 );
963  if( verify_string( &param2 ) != 0 ) return( 2 );
964 
965  test_suite_ripemd160_text( param1, param2 );
966  return ( 0 );
967  #endif /* POLARSSL_RIPEMD160_C */
968 
969  return ( 3 );
970  }
971  else
972  if( strcmp( params[0], "md2_hmac" ) == 0 )
973  {
974  #ifdef POLARSSL_MD2_C
975 
976  int param1;
977  char *param2 = params[2];
978  char *param3 = params[3];
979  char *param4 = params[4];
980 
981  if( cnt != 5 )
982  {
983  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
984  return( 2 );
985  }
986 
987  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
988  if( verify_string( &param2 ) != 0 ) return( 2 );
989  if( verify_string( &param3 ) != 0 ) return( 2 );
990  if( verify_string( &param4 ) != 0 ) return( 2 );
991 
992  test_suite_md2_hmac( param1, param2, param3, param4 );
993  return ( 0 );
994  #endif /* POLARSSL_MD2_C */
995 
996  return ( 3 );
997  }
998  else
999  if( strcmp( params[0], "md4_hmac" ) == 0 )
1000  {
1001  #ifdef POLARSSL_MD4_C
1002 
1003  int param1;
1004  char *param2 = params[2];
1005  char *param3 = params[3];
1006  char *param4 = params[4];
1007 
1008  if( cnt != 5 )
1009  {
1010  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1011  return( 2 );
1012  }
1013 
1014  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1015  if( verify_string( &param2 ) != 0 ) return( 2 );
1016  if( verify_string( &param3 ) != 0 ) return( 2 );
1017  if( verify_string( &param4 ) != 0 ) return( 2 );
1018 
1019  test_suite_md4_hmac( param1, param2, param3, param4 );
1020  return ( 0 );
1021  #endif /* POLARSSL_MD4_C */
1022 
1023  return ( 3 );
1024  }
1025  else
1026  if( strcmp( params[0], "md5_hmac" ) == 0 )
1027  {
1028  #ifdef POLARSSL_MD5_C
1029 
1030  int param1;
1031  char *param2 = params[2];
1032  char *param3 = params[3];
1033  char *param4 = params[4];
1034 
1035  if( cnt != 5 )
1036  {
1037  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1038  return( 2 );
1039  }
1040 
1041  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1042  if( verify_string( &param2 ) != 0 ) return( 2 );
1043  if( verify_string( &param3 ) != 0 ) return( 2 );
1044  if( verify_string( &param4 ) != 0 ) return( 2 );
1045 
1046  test_suite_md5_hmac( param1, param2, param3, param4 );
1047  return ( 0 );
1048  #endif /* POLARSSL_MD5_C */
1049 
1050  return ( 3 );
1051  }
1052  else
1053  if( strcmp( params[0], "ripemd160_hmac" ) == 0 )
1054  {
1055  #ifdef POLARSSL_RIPEMD160_C
1056 
1057  int param1;
1058  char *param2 = params[2];
1059  char *param3 = params[3];
1060  char *param4 = params[4];
1061 
1062  if( cnt != 5 )
1063  {
1064  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1065  return( 2 );
1066  }
1067 
1068  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1069  if( verify_string( &param2 ) != 0 ) return( 2 );
1070  if( verify_string( &param3 ) != 0 ) return( 2 );
1071  if( verify_string( &param4 ) != 0 ) return( 2 );
1072 
1073  test_suite_ripemd160_hmac( param1, param2, param3, param4 );
1074  return ( 0 );
1075  #endif /* POLARSSL_RIPEMD160_C */
1076 
1077  return ( 3 );
1078  }
1079  else
1080  if( strcmp( params[0], "md2_file" ) == 0 )
1081  {
1082  #ifdef POLARSSL_MD2_C
1083  #ifdef POLARSSL_FS_IO
1084 
1085  char *param1 = params[1];
1086  char *param2 = params[2];
1087 
1088  if( cnt != 3 )
1089  {
1090  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1091  return( 2 );
1092  }
1093 
1094  if( verify_string( &param1 ) != 0 ) return( 2 );
1095  if( verify_string( &param2 ) != 0 ) return( 2 );
1096 
1097  test_suite_md2_file( param1, param2 );
1098  return ( 0 );
1099  #endif /* POLARSSL_MD2_C */
1100  #endif /* POLARSSL_FS_IO */
1101 
1102  return ( 3 );
1103  }
1104  else
1105  if( strcmp( params[0], "md4_file" ) == 0 )
1106  {
1107  #ifdef POLARSSL_MD4_C
1108  #ifdef POLARSSL_FS_IO
1109 
1110  char *param1 = params[1];
1111  char *param2 = params[2];
1112 
1113  if( cnt != 3 )
1114  {
1115  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1116  return( 2 );
1117  }
1118 
1119  if( verify_string( &param1 ) != 0 ) return( 2 );
1120  if( verify_string( &param2 ) != 0 ) return( 2 );
1121 
1122  test_suite_md4_file( param1, param2 );
1123  return ( 0 );
1124  #endif /* POLARSSL_MD4_C */
1125  #endif /* POLARSSL_FS_IO */
1126 
1127  return ( 3 );
1128  }
1129  else
1130  if( strcmp( params[0], "md5_file" ) == 0 )
1131  {
1132  #ifdef POLARSSL_MD5_C
1133  #ifdef POLARSSL_FS_IO
1134 
1135  char *param1 = params[1];
1136  char *param2 = params[2];
1137 
1138  if( cnt != 3 )
1139  {
1140  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1141  return( 2 );
1142  }
1143 
1144  if( verify_string( &param1 ) != 0 ) return( 2 );
1145  if( verify_string( &param2 ) != 0 ) return( 2 );
1146 
1147  test_suite_md5_file( param1, param2 );
1148  return ( 0 );
1149  #endif /* POLARSSL_MD5_C */
1150  #endif /* POLARSSL_FS_IO */
1151 
1152  return ( 3 );
1153  }
1154  else
1155  if( strcmp( params[0], "ripemd160_file" ) == 0 )
1156  {
1157  #ifdef POLARSSL_RIPEMD160_C
1158  #ifdef POLARSSL_FS_IO
1159 
1160  char *param1 = params[1];
1161  char *param2 = params[2];
1162 
1163  if( cnt != 3 )
1164  {
1165  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1166  return( 2 );
1167  }
1168 
1169  if( verify_string( &param1 ) != 0 ) return( 2 );
1170  if( verify_string( &param2 ) != 0 ) return( 2 );
1171 
1172  test_suite_ripemd160_file( param1, param2 );
1173  return ( 0 );
1174  #endif /* POLARSSL_RIPEMD160_C */
1175  #endif /* POLARSSL_FS_IO */
1176 
1177  return ( 3 );
1178  }
1179  else
1180  if( strcmp( params[0], "md2_selftest" ) == 0 )
1181  {
1182  #ifdef POLARSSL_MD2_C
1183  #ifdef POLARSSL_SELF_TEST
1184 
1185 
1186  if( cnt != 1 )
1187  {
1188  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1189  return( 2 );
1190  }
1191 
1192 
1193  test_suite_md2_selftest( );
1194  return ( 0 );
1195  #endif /* POLARSSL_MD2_C */
1196  #endif /* POLARSSL_SELF_TEST */
1197 
1198  return ( 3 );
1199  }
1200  else
1201  if( strcmp( params[0], "md4_selftest" ) == 0 )
1202  {
1203  #ifdef POLARSSL_MD4_C
1204  #ifdef POLARSSL_SELF_TEST
1205 
1206 
1207  if( cnt != 1 )
1208  {
1209  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1210  return( 2 );
1211  }
1212 
1213 
1214  test_suite_md4_selftest( );
1215  return ( 0 );
1216  #endif /* POLARSSL_MD4_C */
1217  #endif /* POLARSSL_SELF_TEST */
1218 
1219  return ( 3 );
1220  }
1221  else
1222  if( strcmp( params[0], "md5_selftest" ) == 0 )
1223  {
1224  #ifdef POLARSSL_MD5_C
1225  #ifdef POLARSSL_SELF_TEST
1226 
1227 
1228  if( cnt != 1 )
1229  {
1230  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1231  return( 2 );
1232  }
1233 
1234 
1235  test_suite_md5_selftest( );
1236  return ( 0 );
1237  #endif /* POLARSSL_MD5_C */
1238  #endif /* POLARSSL_SELF_TEST */
1239 
1240  return ( 3 );
1241  }
1242  else
1243  if( strcmp( params[0], "ripemd160_selftest" ) == 0 )
1244  {
1245  #ifdef POLARSSL_RIPEMD160_C
1246  #ifdef POLARSSL_SELF_TEST
1247 
1248 
1249  if( cnt != 1 )
1250  {
1251  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1252  return( 2 );
1253  }
1254 
1255 
1256  test_suite_ripemd160_selftest( );
1257  return ( 0 );
1258  #endif /* POLARSSL_RIPEMD160_C */
1259  #endif /* POLARSSL_SELF_TEST */
1260 
1261  return ( 3 );
1262  }
1263  else
1264 
1265  {
1266  fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
1267  fflush( stdout );
1268  return( 1 );
1269  }
1270 #else
1271  return( 3 );
1272 #endif
1273  return( ret );
1274 }
1275 
1276 int get_line( FILE *f, char *buf, size_t len )
1277 {
1278  char *ret;
1279 
1280  ret = fgets( buf, len, f );
1281  if( ret == NULL )
1282  return( -1 );
1283 
1284  if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
1285  buf[strlen(buf) - 1] = '\0';
1286  if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
1287  buf[strlen(buf) - 1] = '\0';
1288 
1289  return( 0 );
1290 }
1291 
1292 int parse_arguments( char *buf, size_t len, char *params[50] )
1293 {
1294  int cnt = 0, i;
1295  char *cur = buf;
1296  char *p = buf, *q;
1297 
1298  params[cnt++] = cur;
1299 
1300  while( *p != '\0' && p < buf + len )
1301  {
1302  if( *p == '\\' )
1303  {
1304  p++;
1305  p++;
1306  continue;
1307  }
1308  if( *p == ':' )
1309  {
1310  if( p + 1 < buf + len )
1311  {
1312  cur = p + 1;
1313  params[cnt++] = cur;
1314  }
1315  *p = '\0';
1316  }
1317 
1318  p++;
1319  }
1320 
1321  // Replace newlines, question marks and colons in strings
1322  for( i = 0; i < cnt; i++ )
1323  {
1324  p = params[i];
1325  q = params[i];
1326 
1327  while( *p != '\0' )
1328  {
1329  if( *p == '\\' && *(p + 1) == 'n' )
1330  {
1331  p += 2;
1332  *(q++) = '\n';
1333  }
1334  else if( *p == '\\' && *(p + 1) == ':' )
1335  {
1336  p += 2;
1337  *(q++) = ':';
1338  }
1339  else if( *p == '\\' && *(p + 1) == '?' )
1340  {
1341  p += 2;
1342  *(q++) = '?';
1343  }
1344  else
1345  *(q++) = *(p++);
1346  }
1347  *q = '\0';
1348  }
1349 
1350  return( cnt );
1351 }
1352 
1353 int main()
1354 {
1355  int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1356  const char *filename = "/root/rpmbuild/BUILD/polarssl-1.3.9/tests/suites/test_suite_mdx.data";
1357  FILE *file;
1358  char buf[5000];
1359  char *params[50];
1360 
1361 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1362  unsigned char alloc_buf[1000000];
1363  memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
1364 #endif
1365 
1366  file = fopen( filename, "r" );
1367  if( file == NULL )
1368  {
1369  fprintf( stderr, "Failed to open\n" );
1370  return( 1 );
1371  }
1372 
1373  while( !feof( file ) )
1374  {
1375  int skip = 0;
1376 
1377  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1378  break;
1379  fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
1380  fprintf( stdout, " " );
1381  for( i = strlen( buf ) + 1; i < 67; i++ )
1382  fprintf( stdout, "." );
1383  fprintf( stdout, " " );
1384  fflush( stdout );
1385 
1386  total_tests++;
1387 
1388  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1389  break;
1390  cnt = parse_arguments( buf, strlen(buf), params );
1391 
1392  if( strcmp( params[0], "depends_on" ) == 0 )
1393  {
1394  for( i = 1; i < cnt; i++ )
1395  if( dep_check( params[i] ) != 0 )
1396  skip = 1;
1397 
1398  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1399  break;
1400  cnt = parse_arguments( buf, strlen(buf), params );
1401  }
1402 
1403  if( skip == 0 )
1404  {
1405  test_errors = 0;
1406  ret = dispatch_test( cnt, params );
1407  }
1408 
1409  if( skip == 1 || ret == 3 )
1410  {
1411  total_skipped++;
1412  fprintf( stdout, "----\n" );
1413  fflush( stdout );
1414  }
1415  else if( ret == 0 && test_errors == 0 )
1416  {
1417  fprintf( stdout, "PASS\n" );
1418  fflush( stdout );
1419  }
1420  else if( ret == 2 )
1421  {
1422  fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
1423  fclose(file);
1424  exit( 2 );
1425  }
1426  else
1427  total_errors++;
1428 
1429  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1430  break;
1431  if( strlen(buf) != 0 )
1432  {
1433  fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
1434  return( 1 );
1435  }
1436  }
1437  fclose(file);
1438 
1439  fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
1440  if( total_errors == 0 )
1441  fprintf( stdout, "PASSED" );
1442  else
1443  fprintf( stdout, "FAILED" );
1444 
1445  fprintf( stdout, " (%d / %d tests (%d skipped))\n",
1446  total_tests - total_errors, total_tests, total_skipped );
1447 
1448 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1449 #if defined(POLARSSL_MEMORY_DEBUG)
1450  memory_buffer_alloc_status();
1451 #endif
1453 #endif
1454 
1455  return( total_errors != 0 );
1456 }
1457 
1458 
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
Memory allocation layer (Deprecated to platform layer)
void ripemd160_hmac_finish(ripemd160_context *ctx, unsigned char output[20])
RIPEMD-160 HMAC final digest.
Info structure for the pseudo random function.
void md2_init(md2_context *ctx)
Initialize MD2 context.
void ripemd160_hmac_starts(ripemd160_context *ctx, const unsigned char *key, size_t keylen)
RIPEMD-160 HMAC context setup.
void md2_hmac_update(md2_context *ctx, const unsigned char *input, size_t ilen)
MD2 HMAC process buffer.
void ripemd160_hmac_reset(ripemd160_context *ctx)
RIPEMD-160 HMAC context reset.
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
RIPEMD-160 context structure.
Definition: ripemd160.h:58
int md4_self_test(int verbose)
Checkup routine.
void md4_init(md4_context *ctx)
Initialize MD4 context.
int get_line(FILE *f, char *buf, size_t len)
void md4_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[16])
Output = HMAC-MD4( hmac key, input buffer )
Configuration options (set of defines)
void md2(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD2( input buffer )
PolarSSL Platform abstraction layer.
void ripemd160(const unsigned char *input, size_t ilen, unsigned char output[20])
Output = RIPEMD-160( input buffer )
void md5_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[16])
Output = HMAC-MD5( hmac key, input buffer )
void ripemd160_init(ripemd160_context *ctx)
Initialize RIPEMD-160 context.
int verify_int(char *str, int *value)
void md4(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD4( input buffer )
#define polarssl_malloc
void md5_free(md5_context *ctx)
Clear MD5 context.
RIPE MD-160 message digest.
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
void md2_hmac_finish(md2_context *ctx, unsigned char output[16])
MD2 HMAC final digest.
int main()
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])
int md2_file(const char *path, unsigned char output[16])
Output = MD2( file contents )
int md5_self_test(int verbose)
Checkup routine.
void md2_free(md2_context *ctx)
Clear MD2 context.
int md5_file(const char *path, unsigned char output[16])
Output = MD5( file contents )
void md5_hmac_starts(md5_context *ctx, const unsigned char *key, size_t keylen)
MD5 HMAC context setup.
void md4_hmac_starts(md4_context *ctx, const unsigned char *key, size_t keylen)
MD4 HMAC context setup.
void md4_hmac_finish(md4_context *ctx, unsigned char output[16])
MD4 HMAC final digest.
MD4 context structure.
Definition: md4.h:58
void md5_hmac_reset(md5_context *ctx)
MD5 HMAC context reset.
int parse_arguments(char *buf, size_t len, char *params[50])
void ripemd160_hmac_update(ripemd160_context *ctx, const unsigned char *input, size_t ilen)
RIPEMD-160 HMAC process buffer.
void md5_hmac_finish(md5_context *ctx, unsigned char output[16])
MD5 HMAC final digest.
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
MD5 context structure.
Definition: md5.h:58
static int unhexify(unsigned char *obuf, const char *ibuf)
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
static int test_errors
int md2_self_test(int verbose)
Checkup routine.
void md5_init(md5_context *ctx)
Initialize MD5 context.
int verify_string(char **str)
void md2_hmac_starts(md2_context *ctx, const unsigned char *key, size_t keylen)
MD2 HMAC context setup.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
void ripemd160_free(ripemd160_context *ctx)
Clear RIPEMD-160 context.
void ripemd160_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[20])
Output = HMAC-RIPEMD-160( hmac key, input buffer )
void md2_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[16])
Output = HMAC-MD2( hmac key, input buffer )
unsigned char * buf
int dep_check(char *str)
#define TEST_ASSERT(TEST)
void md4_free(md4_context *ctx)
Clear MD4 context.
void md2_hmac_reset(md2_context *ctx)
MD2 HMAC context reset.
int ripemd160_self_test(int verbose)
Checkup routine.
MD2 context structure.
Definition: md2.h:51
static int test_assert(int correct, const char *test)
MD4 message digest algorithm (hash function)
void md5_hmac_update(md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 HMAC process buffer.
int md4_file(const char *path, unsigned char output[16])
Output = MD4( file contents )
MD5 message digest algorithm (hash function)
void md5(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD5( input buffer )
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
#define PUT_UINT32_BE(n, b, i)
MD2 message digest algorithm (hash function)
void md4_hmac_reset(md4_context *ctx)
MD4 HMAC context reset.
void md4_hmac_update(md4_context *ctx, const unsigned char *input, size_t ilen)
MD4 HMAC process buffer.
int ripemd160_file(const char *path, unsigned char output[20])
Output = RIPEMD-160( file contents )
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.