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/md5.h" |
| 3 | #include "mbedtls/ripemd160.h" |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 4 | /* END_HEADER */ |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 5 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 6 | /* BEGIN_CASE depends_on:MBEDTLS_MD5_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 7 | void md5_text(char *text_src_string, data_t *hash) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 8 | { |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 9 | int ret; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 10 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 11 | unsigned char output[16]; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 12 | |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 13 | memset(src_str, 0x00, sizeof(src_str)); |
| 14 | memset(output, 0x00, sizeof(output)); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 15 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 16 | strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 17 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 18 | ret = mbedtls_md5(src_str, strlen((char *) src_str), output); |
| 19 | TEST_ASSERT(ret == 0); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 20 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 21 | TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 22 | sizeof(output), hash->len) == 0); |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 23 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 24 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 25 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 26 | /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 27 | void ripemd160_text(char *text_src_string, data_t *hash) |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 28 | { |
Andres Amaya Garcia | b71b630 | 2017-06-28 10:51:17 +0100 | [diff] [blame] | 29 | int ret; |
Manuel Pégourié-Gonnard | 130fe97 | 2014-01-17 14:23:48 +0100 | [diff] [blame] | 30 | unsigned char src_str[100]; |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 31 | unsigned char output[20]; |
| 32 | |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 33 | memset(src_str, 0x00, sizeof(src_str)); |
| 34 | memset(output, 0x00, sizeof(output)); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 35 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 36 | 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] | 37 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 38 | ret = mbedtls_ripemd160(src_str, strlen((char *) src_str), output); |
| 39 | TEST_ASSERT(ret == 0); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 40 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 41 | TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 42 | sizeof(output), hash->len) == 0); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 43 | } |
| 44 | /* END_CASE */ |
| 45 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 46 | /* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 47 | void md5_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 48 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 49 | TEST_ASSERT(mbedtls_md5_self_test(1) == 0); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 50 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 51 | /* END_CASE */ |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 52 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 53 | /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 54 | void ripemd160_selftest() |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 55 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 56 | TEST_ASSERT(mbedtls_ripemd160_self_test(1) == 0); |
Manuel Pégourié-Gonnard | cab4a88 | 2014-01-17 12:42:35 +0100 | [diff] [blame] | 57 | } |
| 58 | /* END_CASE */ |