blob: aa35c583eb463ce3b65b7c08c92630cd6a9ee7c2 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/md2.h"
3#include "mbedtls/md4.h"
4#include "mbedtls/md5.h"
5#include "mbedtls/ripemd160.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02006/* END_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00007
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02008/* BEGIN_CASE depends_on:MBEDTLS_MD2_C */
Ronald Cronac6ae352020-06-26 14:33:03 +02009void md2_text( char * text_src_string, data_t * hash )
Paul Bakker367dae42009-06-28 21:50:27 +000010{
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010011 int ret;
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010012 unsigned char src_str[100];
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010013 unsigned char output[16];
Paul Bakker367dae42009-06-28 21:50:27 +000014
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010015 memset( src_str, 0x00, sizeof src_str );
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010016 memset( output, 0x00, sizeof output );
Paul Bakker367dae42009-06-28 21:50:27 +000017
Paul Bakkerdd0aae92014-04-17 16:06:37 +020018 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
Paul Bakker367dae42009-06-28 21:50:27 +000019
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010020 ret = mbedtls_md2_ret( src_str, strlen( (char *) src_str ), output );
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010021 TEST_ASSERT( ret == 0 ) ;
Paul Bakker367dae42009-06-28 21:50:27 +000022
Ronald Cronac6ae352020-06-26 14:33:03 +020023 TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
24 sizeof output, hash->len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000025}
Paul Bakker33b43f12013-08-20 11:48:36 +020026/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028/* BEGIN_CASE depends_on:MBEDTLS_MD4_C */
Ronald Cronac6ae352020-06-26 14:33:03 +020029void md4_text( char * text_src_string, data_t * hash )
Paul Bakker367dae42009-06-28 21:50:27 +000030{
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010031 int ret;
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010032 unsigned char src_str[100];
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010033 unsigned char output[16];
Paul Bakker367dae42009-06-28 21:50:27 +000034
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010035 memset( src_str, 0x00, sizeof src_str );
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010036 memset( output, 0x00, sizeof output );
Paul Bakker367dae42009-06-28 21:50:27 +000037
Paul Bakkerdd0aae92014-04-17 16:06:37 +020038 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
Paul Bakker367dae42009-06-28 21:50:27 +000039
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010040 ret = mbedtls_md4_ret( src_str, strlen( (char *) src_str ), output );
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010041 TEST_ASSERT( ret == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000042
Ronald Cronac6ae352020-06-26 14:33:03 +020043 TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
44 sizeof output, hash->len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000045}
Paul Bakker33b43f12013-08-20 11:48:36 +020046/* END_CASE */
Paul Bakker367dae42009-06-28 21:50:27 +000047
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048/* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
Ronald Cronac6ae352020-06-26 14:33:03 +020049void md5_text( char * text_src_string, data_t * hash )
Paul Bakker367dae42009-06-28 21:50:27 +000050{
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010051 int ret;
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010052 unsigned char src_str[100];
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010053 unsigned char output[16];
Paul Bakker367dae42009-06-28 21:50:27 +000054
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010055 memset( src_str, 0x00, sizeof src_str );
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010056 memset( output, 0x00, sizeof output );
Paul Bakker367dae42009-06-28 21:50:27 +000057
Paul Bakkerdd0aae92014-04-17 16:06:37 +020058 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
Paul Bakker367dae42009-06-28 21:50:27 +000059
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010060 ret = mbedtls_md5_ret( src_str, strlen( (char *) src_str ), output );
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010061 TEST_ASSERT( ret == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000062
Ronald Cronac6ae352020-06-26 14:33:03 +020063 TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
64 sizeof output, hash->len ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000065}
Paul Bakker33b43f12013-08-20 11:48:36 +020066/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000067
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
Ronald Cronac6ae352020-06-26 14:33:03 +020069void ripemd160_text( char * text_src_string, data_t * hash )
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010070{
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010071 int ret;
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010072 unsigned char src_str[100];
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010073 unsigned char output[20];
74
75 memset(src_str, 0x00, sizeof src_str);
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010076 memset(output, 0x00, sizeof output);
77
Paul Bakkerdd0aae92014-04-17 16:06:37 +020078 strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010079
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010080 ret = mbedtls_ripemd160_ret( src_str, strlen( (char *) src_str ), output );
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010081 TEST_ASSERT( ret == 0 );
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010082
Ronald Cronac6ae352020-06-26 14:33:03 +020083 TEST_ASSERT( mbedtls_test_hexcmp( output, hash->x,
84 sizeof output, hash->len ) == 0 );
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010085}
86/* END_CASE */
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088/* BEGIN_CASE depends_on:MBEDTLS_MD2_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010089void md2_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +000090{
Andres AG93012e82016-09-09 09:10:28 +010091 TEST_ASSERT( mbedtls_md2_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +000092}
Paul Bakker33b43f12013-08-20 11:48:36 +020093/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000094
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095/* BEGIN_CASE depends_on:MBEDTLS_MD4_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010096void md4_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +000097{
Andres AG93012e82016-09-09 09:10:28 +010098 TEST_ASSERT( mbedtls_md4_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +000099}
Paul Bakker33b43f12013-08-20 11:48:36 +0200100/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102/* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100103void md5_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +0000104{
Andres AG93012e82016-09-09 09:10:28 +0100105 TEST_ASSERT( mbedtls_md5_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000106}
Paul Bakker33b43f12013-08-20 11:48:36 +0200107/* END_CASE */
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +0100108
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100110void ripemd160_selftest( )
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +0100111{
Andres AG93012e82016-09-09 09:10:28 +0100112 TEST_ASSERT( mbedtls_ripemd160_self_test( 1 ) == 0 );
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +0100113}
114/* END_CASE */