2 * Copyright (C) 2005 Free Software Foundation
3 * Written by Simon Josefsson
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 main (int argc, char *argv[])
32 /* Test vectors from RFC 1321. */
35 char *in = "abcdefghijklmnopqrstuvwxyz";
36 size_t inlen = strlen (in);
38 "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b";
41 /* MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */
43 if (gc_md5 (in, inlen, out) != 0)
45 printf ("gc_md5 call failed\n");
49 if (memcmp (out, expect, 16) != 0)
52 printf ("md5 1 missmatch. expected:\n");
53 for (i = 0; i < 16; i++)
54 printf ("%02x ", expect[i] & 0xFF);
55 printf ("\ncomputed:\n");
56 for (i = 0; i < 16; i++)
57 printf ("%02x ", out[i] & 0xFF);
63 /* Test vectors from RFC 2104. */
67 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
69 char *data = "Hi There";
72 "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
76 key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
80 digest = 0x9294727a3638bb1c13f48ef8158bfc9d
83 if (gc_hmac_md5 (key, key_len, data, data_len, out) != 0)
85 printf ("call failure\n");
89 if (memcmp (digest, out, 16) != 0)
92 printf ("hash 1 missmatch. expected:\n");
93 for (i = 0; i < 16; i++)
94 printf ("%02x ", digest[i] & 0xFF);
95 printf ("\ncomputed:\n");
96 for (i = 0; i < 16; i++)
97 printf ("%02x ", out[i] & 0xFF);