Commit c5f35e8a authored by Davide Galassi's avatar Davide Galassi

MD5 RFC 1321 test vectors (not working)

parent 358c9723
#include "test.h"
#include <cry/md5.h>
struct md5_param {
size_t len;
unsigned char *data;
unsigned char hash[CRY_MD5_DIGEST_SIZE];
};
static void param_init(struct md5_param *par, int argc, char *argv[])
{
memset(par, 0, sizeof(*par));
par->len = strlen(argv[0]) >> 1;
par->data = malloc(par->len);
par->len = raw_init(par->data, par->len, argv[0]);
raw_init(par->hash, CRY_MD5_DIGEST_SIZE, argv[1]);
}
static void cry_md5(unsigned char *out, unsigned char *data, size_t len)
{
struct cry_md5_ctx ctx;
cry_md5_init(&ctx);
cry_md5_update(&ctx, data, len);
cry_md5_digest(&ctx, out);
}
static void md5_digest(int argc, char *argv[])
{
struct md5_param par;
unsigned char out[CRY_MD5_DIGEST_SIZE];
param_init(&par, argc, argv);
cry_md5(out, par.data, par.len);
ASSERT_EQ_BUF(out, par.hash, CRY_MD5_DIGEST_SIZE);
free(par.data);
}
static void dispatch(int argc, char *argv[])
{
char *test = *argv;
argv++;
argc--;
ASSERT(argc == 2);
if (strcmp(test, "md5_digest") == 0)
md5_digest(argc, argv);
else
printf("Test '%s' not defined\n", test);
}
static char *input[] = {
"This file is part of CRY software.",
"CRY is free software",
......@@ -11,19 +60,28 @@ static const char md5_hash[] = {
0x12,0x0d,0x02,0x46,0xeb,0x4d,0xa6,0x69
};
void md5_test(void)
static void test_old(void)
{
struct cry_md5_ctx md5;
size_t len, i;
unsigned char buf[16];
cry_md5_init(&md5);
for (i = 0; i < ARLEN(input); i++) {
len = strlen(input[i]);
PRINT_ASC("input", input[i], len);
cry_md5_update(&md5, input[i], len);
cry_md5_update(&md5, (unsigned char *)input[i], len);
}
cry_md5_digest(&md5, buf);
PRINT_HEX("md5", buf, 16);
ASSERT_EQ_BUF(buf, md5_hash, 16);
}
void md5_test(void)
{
test_old();
printf("* MD5 RFC 1321 Vectors\n");
func_test("md5_test.data", dispatch);
printf("\n");
}
################################################################################
#
# MD5 RFC1321 Test Vectors
#
################################################################################
################################################################################
# MD5 vectors
# p0 data
# p1 out
################################################################################
mbedtls_md5 Test vector RFC1321 #1
md5_digest
NULL
d41d8cd98f00b204e9800998ecf8427e
mbedtls_md5 Test vector RFC1321 #2
md5_digest
a
0cc175b9c0f1b6a831c399e269772661
mbedtls_md5 Test vector RFC1321 #3
md5_digest
abc
900150983cd24fb0d6963f7d28e17f72
mbedtls_md5 Test vector RFC1321 #4
md5_digest
message digest
f96b697d7cb7938d525a2f31aaf161d0
mbedtls_md5 Test vector RFC1321 #5
md5_digest
abcdefghijklmnopqrstuvwxyz
c3fcd3d76192e4007dfb496cca67e13b
mbedtls_md5 Test vector RFC1321 #6
md5_digest
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
d174ab98d277d9f5a5611c2c9f419d9f
mbedtls_md5 Test vector RFC1321 #7
md5_digest
12345678901234567890123456789012345678901234567890123456789012345678901234567890
57edf4a22be3c955ac49da2e2107b67a
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment