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