Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 2 | #include "mbedtls/md2.h" |
| 3 | #include "mbedtls/md4.h" |
| 4 | #include "mbedtls/md5.h" |
| 5 | #include "mbedtls/ripemd160.h" |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 6 | /* END_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 7 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 8 | /* BEGIN_CASE depends_on:MBEDTLS_MD2_C */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 9 | void md2_text( char * text_src_string, data_t * hex_hash_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 10 | { |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 11 | int ret; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 12 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 13 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 14 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 15 | memset( src_str, 0x00, sizeof src_str ); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 16 | memset( output, 0x00, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 17 | |
Paul Bakker | dd0aae9 | 2014-04-17 16:06:37 +0200 | [diff] [blame] | 18 | strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 19 | |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 20 | ret = mbedtls_md2_ret( src_str, strlen( (char *) src_str ), output ); |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 21 | TEST_ASSERT( ret == 0 ) ; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 22 | |
Ronald Cron | 2dbba99 | 2020-06-10 11:42:32 +0200 | [diff] [blame] | 23 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, |
| 24 | sizeof output, |
| 25 | hex_hash_string->len ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 26 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 27 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 29 | /* BEGIN_CASE depends_on:MBEDTLS_MD4_C */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 30 | void md4_text( char * text_src_string, data_t * hex_hash_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 31 | { |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 32 | int ret; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 33 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 34 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 35 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 36 | memset( src_str, 0x00, sizeof src_str ); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 37 | memset( output, 0x00, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 38 | |
Paul Bakker | dd0aae9 | 2014-04-17 16:06:37 +0200 | [diff] [blame] | 39 | strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 40 | |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 41 | ret = mbedtls_md4_ret( src_str, strlen( (char *) src_str ), output ); |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 42 | TEST_ASSERT( ret == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 43 | |
Ronald Cron | 2dbba99 | 2020-06-10 11:42:32 +0200 | [diff] [blame] | 44 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, |
| 45 | sizeof output, |
| 46 | hex_hash_string->len ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 47 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 48 | /* END_CASE */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 49 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 50 | /* BEGIN_CASE depends_on:MBEDTLS_MD5_C */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 51 | void md5_text( char * text_src_string, data_t * hex_hash_string ) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 52 | { |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 53 | int ret; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 54 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 55 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 56 | |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 57 | memset( src_str, 0x00, sizeof src_str ); |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 58 | memset( output, 0x00, sizeof output ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 59 | |
Paul Bakker | dd0aae9 | 2014-04-17 16:06:37 +0200 | [diff] [blame] | 60 | strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 61 | |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 62 | ret = mbedtls_md5_ret( src_str, strlen( (char *) src_str ), output ); |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 63 | TEST_ASSERT( ret == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 64 | |
Ronald Cron | 2dbba99 | 2020-06-10 11:42:32 +0200 | [diff] [blame] | 65 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, |
| 66 | sizeof output, |
| 67 | hex_hash_string->len ) == 0 ); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 68 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 69 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 70 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 71 | /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 72 | void ripemd160_text( char * text_src_string, data_t * hex_hash_string ) |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 73 | { |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 74 | int ret; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 75 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 76 | unsigned char output[20]; |
| 77 | |
| 78 | memset(src_str, 0x00, sizeof src_str); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 79 | memset(output, 0x00, sizeof output); |
| 80 | |
Paul Bakker | dd0aae9 | 2014-04-17 16:06:37 +0200 | [diff] [blame] | 81 | strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 82 | |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 83 | ret = mbedtls_ripemd160_ret( src_str, strlen( (char *) src_str ), output ); |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 84 | TEST_ASSERT( ret == 0 ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 85 | |
Ronald Cron | 2dbba99 | 2020-06-10 11:42:32 +0200 | [diff] [blame] | 86 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_hash_string->x, |
| 87 | sizeof output, |
| 88 | hex_hash_string->len ) == 0 ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 89 | } |
| 90 | /* END_CASE */ |
| 91 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 92 | /* BEGIN_CASE depends_on:MBEDTLS_MD2_C:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 93 | void md2_selftest( ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 94 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 95 | TEST_ASSERT( mbedtls_md2_self_test( 1 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 96 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 97 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 98 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | /* BEGIN_CASE depends_on:MBEDTLS_MD4_C:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 100 | void md4_selftest( ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 101 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 102 | TEST_ASSERT( mbedtls_md4_self_test( 1 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 103 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 104 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 105 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 106 | /* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 107 | void md5_selftest( ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 108 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 109 | TEST_ASSERT( mbedtls_md5_self_test( 1 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 110 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 111 | /* END_CASE */ |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 112 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 113 | /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 114 | void ripemd160_selftest( ) |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 115 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 116 | TEST_ASSERT( mbedtls_ripemd160_self_test( 1 ) == 0 ); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 117 | } |
| 118 | /* END_CASE */ |