Add MD2 and hash fixes.
[gnulib.git] / tests / test-md2.c
1 /*
2  * Copyright (C) 2005 Free Software Foundation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.  */
18
19 /* Written by Simon Josefsson. */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <stdio.h>
26 #include <string.h>
27
28 #include "md2.h"
29
30 int
31 main (int argc, char *argv[])
32 {
33   const char *in1 = "abc";
34   const char *out1 =
35     "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde\xd6\xbb";
36   const char *in2 = "abcdefghijklmnopqrstuvwxyz";
37   const char *out2 =
38     "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b";
39   char buf[MD2_DIGEST_SIZE];
40
41   if (memcmp (md2_buffer (in1, strlen (in1), buf), out1, MD2_DIGEST_SIZE) !=
42       0)
43     {
44       size_t i;
45       printf ("expected:\n");
46       for (i = 0; i < MD2_DIGEST_SIZE; i++)
47         printf ("%02x ", out1[i] & 0xFF);
48       printf ("\ncomputed:\n");
49       for (i = 0; i < MD2_DIGEST_SIZE; i++)
50         printf ("%02x ", buf[i] & 0xFF);
51       printf ("\n");
52       return 1;
53     }
54
55   if (memcmp (md2_buffer (in2, strlen (in2), buf), out2, MD2_DIGEST_SIZE) !=
56       0)
57     {
58       size_t i;
59       printf ("expected:\n");
60       for (i = 0; i < MD2_DIGEST_SIZE; i++)
61         printf ("%02x ", out2[i] & 0xFF);
62       printf ("\ncomputed:\n");
63       for (i = 0; i < MD2_DIGEST_SIZE; i++)
64         printf ("%02x ", buf[i] & 0xFF);
65       printf ("\n");
66       return 1;
67     }
68
69   return 0;
70 }