Commit 8c92e659 authored by Pekka Pessi's avatar Pekka Pessi

Added md5 testing to su_torture.c.

darcs-hash:20051007073151-65a35-f2d0b8ad3c280ce61d27775f01782de4d6bc17a5.gz
parent 01596d74
......@@ -489,37 +489,3 @@ su_md5_transform(uint32_t buf[4], const unsigned char inraw[64])
buf[3] += d;
}
#endif
#ifdef TEST
/* Simple test program. Can use it to manually run the tests from
RFC1321 for example. */
#include <stdio.h>
int
main (int argc, char **argv)
{
su_md5_t context;
unsigned char checksum[16];
int i;
int j;
if (argc < 2)
{
fprintf (stderr, "usage: %s string-to-hash\n", argv[0]);
exit (1);
}
for (j = 1; j < argc; ++j)
{
printf ("MD5 (\"%s\") = ", argv[j]);
su_md5_init(&context);
su_md5_update(&context, argv[j], strlen (argv[j]));
su_md5_digest(&context, checksum);
for (i = 0; i < 16; i++)
{
printf ("%02x", (unsigned int) checksum[i]);
}
printf ("\n");
}
return 0;
}
#endif /* TEST */
......@@ -59,27 +59,6 @@ void usage(void)
fprintf(stderr, "usage: %s [-v]\n", name);
}
int main(int argc, char *argv[])
{
int retval = 0;
int i;
su_init();
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else
usage();
}
retval |= test_sockaddr();
su_deinit();
return retval;
}
/** */
int test_sockaddr(void)
{
......@@ -179,3 +158,145 @@ int test_sockaddr(void)
END();
}
#include <su_md5.h>
int test_md5(void)
{
BEGIN();
su_md5_t md5[1], md5i[1];
uint8_t digest[SU_MD5_DIGEST_SIZE];
char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1];
struct { char *input; uint8_t digest[SU_MD5_DIGEST_SIZE]; } suite[] = {
{ (""),
{ 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } },
{ ("a"), { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8,
0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } },
{ ("abc"), { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0,
0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } },
{ ("message digest"),
{ 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d,
0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 } },
{ ("abcdefghijklmnopqrstuvwxyz"),
{ 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00,
0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b } },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
{ 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5,
0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f } },
{ "123456789012345678901234567890123456789012345678901234567890123456"
"78901234567890",
{ 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55,
0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a } }};
su_md5_init(md5);
su_md5_update(md5, suite[0].input, 0);
su_md5_digest(md5, digest);
TEST_M(digest, suite[0].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_strupdate(md5, suite[1].input);
su_md5_digest(md5, digest);
TEST_M(digest, suite[1].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_iupdate(md5, suite[2].input, 3);
su_md5_digest(md5, digest);
TEST_M(digest, suite[2].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_striupdate(md5, suite[3].input);
su_md5_digest(md5, digest);
TEST_M(digest, suite[3].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_iupdate(md5, suite[4].input, 13);
su_md5_striupdate(md5, suite[4].input + 13);
su_md5_digest(md5, digest);
TEST_M(digest, suite[4].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_update(md5, suite[5].input, 13);
su_md5_strupdate(md5, suite[5].input + 13);
su_md5_digest(md5, digest);
TEST_M(digest, suite[5].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_update(md5, suite[6].input, 13);
su_md5_strupdate(md5, suite[6].input + 13);
su_md5_digest(md5, digest);
TEST_M(digest, suite[6].digest, SU_MD5_DIGEST_SIZE);
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_str0update(md5, NULL);
su_md5_hexdigest(md5, hexdigest);
TEST_S(hexdigest, "93b885adfe0da089cdf634904fd59f71");
su_md5_deinit(md5);
su_md5_init(md5);
su_md5_stri0update(md5, NULL);
su_md5_stri0update(md5, "ABBADABBADOO");
su_md5_hexdigest(md5, hexdigest);
TEST_S(hexdigest, "101e6dd7cfabdb5c74f44b4c545c05cc");
su_md5_init(md5);
su_md5_update(md5, "\0abbadabbadoo\0", 14);
su_md5_hexdigest(md5, hexdigest);
TEST_S(hexdigest, "101e6dd7cfabdb5c74f44b4c545c05cc");
su_md5_deinit(md5);
/* Calculate md5 sum of 512 MB of zero */
if (getenv("EXPENSIVE_CHECKS")) {
char zerokilo[1024] = { '\0' };
int i;
su_md5_init(md5);
su_md5_iupdate(md5, zerokilo, 19);
for (i = 1; i < 512 * 1024; i++)
su_md5_update(md5, zerokilo, 1024);
*md5i = *md5;
su_md5_update(md5, zerokilo, 1024 - 19);
su_md5_hexdigest(md5, hexdigest);
TEST_S(hexdigest, "aa559b4e3523a6c931f08f4df52d58f2");
su_md5_deinit(md5);
su_md5_iupdate(md5i, zerokilo, 1024 - 19);
su_md5_hexdigest(md5i, hexdigest);
TEST_S(hexdigest, "aa559b4e3523a6c931f08f4df52d58f2");
}
END();
}
int main(int argc, char *argv[])
{
int retval = 0;
int i;
su_init();
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else
usage();
}
retval |= test_sockaddr();
retval |= test_md5(); fflush(stdout);
su_deinit();
return retval;
}
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