2015-03-27 13:09:27 +00:00
|
|
|
/*
|
|
|
|
* BIRD Library -- MD5 message-digest algorithm Tests
|
|
|
|
*
|
|
|
|
* (c) 2015 CZ.NIC z.s.p.o.
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "test/birdtest.h"
|
|
|
|
#include "sysdep/config.h"
|
|
|
|
#include "lib/md5.h"
|
|
|
|
#include "lib/md5.c" /* REMOVE ME */
|
|
|
|
|
2015-04-22 09:02:46 +00:00
|
|
|
#define MD5_SIZE 16
|
|
|
|
#define MD5_HEX_SIZE 33
|
2015-03-27 13:09:27 +00:00
|
|
|
|
|
|
|
static void
|
2015-04-22 09:02:46 +00:00
|
|
|
get_md5(const char *str, char (*out_hash)[MD5_HEX_SIZE])
|
2015-03-27 13:09:27 +00:00
|
|
|
{
|
2015-04-22 09:02:46 +00:00
|
|
|
unsigned char hash[MD5_SIZE];
|
2015-03-27 13:09:27 +00:00
|
|
|
struct MD5Context ctxt;
|
|
|
|
|
|
|
|
MD5Init(&ctxt);
|
|
|
|
MD5Update(&ctxt, str, strlen(str));
|
|
|
|
MD5Final(hash, &ctxt);
|
|
|
|
|
|
|
|
int i;
|
2015-04-22 09:02:46 +00:00
|
|
|
for(i = 0; i < MD5_SIZE; i++)
|
2015-04-13 08:57:47 +00:00
|
|
|
sprintf(*out_hash + i*2, "%02x", hash[i]);
|
2015-03-27 13:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
t_md5(void)
|
|
|
|
{
|
2015-04-15 10:11:50 +00:00
|
|
|
struct in_out {
|
2015-04-13 08:57:47 +00:00
|
|
|
char *in;
|
2015-04-22 09:02:46 +00:00
|
|
|
char out[MD5_HEX_SIZE];
|
2015-04-15 10:11:50 +00:00
|
|
|
} in_out[] = {
|
2015-04-13 08:57:47 +00:00
|
|
|
{
|
|
|
|
.in = "",
|
|
|
|
.out = "d41d8cd98f00b204e9800998ecf8427e",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.in = "a",
|
|
|
|
.out = "0cc175b9c0f1b6a831c399e269772661",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.in = "abc",
|
|
|
|
.out = "900150983cd24fb0d6963f7d28e17f72",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.in = "message digest",
|
|
|
|
.out = "f96b697d7cb7938d525a2f31aaf161d0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.in = "abcdefghijklmnopqrstuvwxyz",
|
|
|
|
.out = "c3fcd3d76192e4007dfb496cca67e13b",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.in = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
|
|
.out = "d174ab98d277d9f5a5611c2c9f419d9f",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.in = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
|
|
|
.out = "57edf4a22be3c955ac49da2e2107b67a",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-04-22 09:02:46 +00:00
|
|
|
bt_assert_fn_in_out(get_md5, in_out, "'%s'", "'%s'");
|
2015-03-27 13:09:27 +00:00
|
|
|
|
|
|
|
return BT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
bt_init(argc, argv);
|
|
|
|
|
2015-04-22 09:02:46 +00:00
|
|
|
bt_test_suite(t_md5, "Test Suite by RFC 1321");
|
2015-03-27 13:09:27 +00:00
|
|
|
|
2015-04-13 08:52:21 +00:00
|
|
|
return bt_end();
|
2015-03-27 13:09:27 +00:00
|
|
|
}
|