blob: df94d16e144548924e6bd65525785c23a67baaa8 [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/md5.h"
3#include "mbedtls/ripemd160.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02004/* END_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00005
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02006/* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
Gilles Peskine449bd832023-01-11 14:50:10 +01007void md5_text(char *text_src_string, data_t *hash)
Paul Bakker367dae42009-06-28 21:50:27 +00008{
Andres Amaya Garciab71b6302017-06-28 10:51:17 +01009 int ret;
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010010 unsigned char src_str[100];
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010011 unsigned char output[16];
Paul Bakker367dae42009-06-28 21:50:27 +000012
Dave Rodgman6dd757a2023-02-02 12:40:50 +000013 memset(src_str, 0x00, sizeof(src_str));
14 memset(output, 0x00, sizeof(output));
Paul Bakker367dae42009-06-28 21:50:27 +000015
Gilles Peskine449bd832023-01-11 14:50:10 +010016 strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
Paul Bakker367dae42009-06-28 21:50:27 +000017
Gilles Peskine449bd832023-01-11 14:50:10 +010018 ret = mbedtls_md5(src_str, strlen((char *) src_str), output);
19 TEST_ASSERT(ret == 0);
Paul Bakker367dae42009-06-28 21:50:27 +000020
Gilles Peskine449bd832023-01-11 14:50:10 +010021 TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
Dave Rodgman6dd757a2023-02-02 12:40:50 +000022 sizeof(output), hash->len) == 0);
Paul Bakker367dae42009-06-28 21:50:27 +000023}
Paul Bakker33b43f12013-08-20 11:48:36 +020024/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
Gilles Peskine449bd832023-01-11 14:50:10 +010027void ripemd160_text(char *text_src_string, data_t *hash)
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010028{
Andres Amaya Garciab71b6302017-06-28 10:51:17 +010029 int ret;
Manuel Pégourié-Gonnard130fe972014-01-17 14:23:48 +010030 unsigned char src_str[100];
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010031 unsigned char output[20];
32
Dave Rodgman6dd757a2023-02-02 12:40:50 +000033 memset(src_str, 0x00, sizeof(src_str));
34 memset(output, 0x00, sizeof(output));
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010035
Gilles Peskine449bd832023-01-11 14:50:10 +010036 strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010037
Gilles Peskine449bd832023-01-11 14:50:10 +010038 ret = mbedtls_ripemd160(src_str, strlen((char *) src_str), output);
39 TEST_ASSERT(ret == 0);
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010040
Gilles Peskine449bd832023-01-11 14:50:10 +010041 TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
Dave Rodgman6dd757a2023-02-02 12:40:50 +000042 sizeof(output), hash->len) == 0);
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010043}
44/* END_CASE */
45
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020046/* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */
Gilles Peskine449bd832023-01-11 14:50:10 +010047void md5_selftest()
Paul Bakkere896fea2009-07-06 06:40:23 +000048{
Gilles Peskine449bd832023-01-11 14:50:10 +010049 TEST_ASSERT(mbedtls_md5_self_test(1) == 0);
Paul Bakkere896fea2009-07-06 06:40:23 +000050}
Paul Bakker33b43f12013-08-20 11:48:36 +020051/* END_CASE */
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053/* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */
Gilles Peskine449bd832023-01-11 14:50:10 +010054void ripemd160_selftest()
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010055{
Gilles Peskine449bd832023-01-11 14:50:10 +010056 TEST_ASSERT(mbedtls_ripemd160_self_test(1) == 0);
Manuel Pégourié-Gonnardcab4a882014-01-17 12:42:35 +010057}
58/* END_CASE */