Back to index

glibc  2.9
md5test.c
Go to the documentation of this file.
00001 #include <string.h>
00002 #include "md5.h"
00003 
00004 static const struct
00005 {
00006   const char *input;
00007   const char result[16];
00008 } tests[] =
00009   {
00010     { "",
00011       "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e" },
00012     { "a",
00013       "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61" },
00014     { "abc",
00015       "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72" },
00016     { "message digest",
00017       "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0" },
00018     { "abcdefghijklmnopqrstuvwxyz",
00019       "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b" },
00020     { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
00021       "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f" },
00022     { "123456789012345678901234567890123456789012345678901234567890"
00023       "12345678901234567890",
00024       "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6\x7a" }
00025   };
00026 
00027 
00028 int
00029 main (int argc, char *argv[])
00030 {
00031   struct md5_ctx ctx;
00032   char sum[16];
00033   int result = 0;
00034   int cnt;
00035 
00036   for (cnt = 0; cnt < (int) (sizeof (tests) / sizeof (tests[0])); ++cnt)
00037     {
00038       int i;
00039 
00040       __md5_init_ctx (&ctx);
00041       __md5_process_bytes (tests[cnt].input, strlen (tests[cnt].input), &ctx);
00042       __md5_finish_ctx (&ctx, sum);
00043       result |= memcmp (tests[cnt].result, sum, 16);
00044 
00045       __md5_init_ctx (&ctx);
00046       for (i = 0; tests[cnt].input[i] != '\0'; ++i)
00047        __md5_process_bytes (&tests[cnt].input[i], 1, &ctx);
00048       __md5_finish_ctx (&ctx, sum);
00049       result |= memcmp (tests[cnt].result, sum, 16);
00050     }
00051 
00052   return result;
00053 }