annotate tests/test-md5.c @ 8891:633babea5f62

Unconditionally include <config.h> in unit tests. * tests/test-alloca-opt.c: Remove #ifdef HAVE_CONFIG_H. * tests/test-allocsa.c, tests/test-arcfour.c, tests/test-arctwo.c, tests/test-argmatch.c, tests/test-argp.c, tests/test-array_list.c, tests/test-array_oset.c, tests/test-atexit.c, test-avltree_list.c, test-avltree_oset.c, test-avltreehash_list.c, test-base64.c, test-binary-io.c, test-c-ctype.c, test-c-strcasecmp.c, test-c-strcasestr.c, test-c-strncasecmp.c, test-c-strstr.c, test-canonicalize-lgpl.c, test-carray_list.c, test-crc.c, test-des.c, test-dirname.c, test-fflush.c, test-fprintf-posix.c, test-gc-arcfour.c, test-gc-arctwo.c, test-gc-des.c, test-gc-hmac-md5.c, test-gc-hmac-sha1.c, test-gc-md2.c, test-gc-md4.c, test-gc-md5.c, test-gc-pbkdf2-sha1.c, test-gc-rijndael.c, test-gc-sha1.c, test-gc.c, test-getpass.c, test-hmac-md5.c, test-hmac-sha1.c, test-iconv.c, test-linked_list.c, test-linkedhash_list.c, test-lock.c, test-mbscasecmp.c, test-mbscasestr1.c, test-mbscasestr2.c, test-mbscasestr3.c, test-mbscasestr4.c, test-mbschr.c, test-mbscspn.c, test-mbsncasecmp.c, test-mbspbrk.c, test-mbspcasecmp.c, test-mbsrchr.c, test-mbsspn.c, test-mbsstr1.c, test-mbsstr2.c, test-mbsstr3.c, test-md2.c, test-md4.c, test-md5.c, test-memmem.c, test-printf-posix.c, test-rbtree_list.c, test-rbtree_oset.c, test-rbtreehash_list.c, test-read-file.c, test-rijndael.c, test-snprintf-posix.c, test-snprintf.c, test-sprintf-posix.c, test-stdint.c, test-strcasestr.c, test-striconv.c, test-striconveh.c, test-striconveha.c, test-tls.c, test-vasnprintf-posix.c, test-vasnprintf-posix2.c, test-vasnprintf.c, test-vasprintf-posix.c, test-vasprintf.c, test-verify.c, test-vfprintf-posix.c, test-vprintf-posix.c, test-vsnprintf-posix.c, test-vsnprintf.c, test-vsprintf-posix.c, test-xvasprintf.c: Likewise.
author Eric Blake <ebb9@byu.net>
date Mon, 28 May 2007 16:49:41 +0000
parents a79c1b684e52
children bbbbbf4cd1c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
1 /*
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
2 * Copyright (C) 2005 Free Software Foundation
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
3 * Written by Simon Josefsson
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
4 *
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
7 * the Free Software Foundation; either version 2, or (at your option)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
8 * any later version.
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
9 *
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
13 * GNU General Public License for more details.
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
14 *
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
18 * 02110-1301, USA. */
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
19
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
20 /* Written by Simon Josefsson. */
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
21
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 6392
diff changeset
22 #include <config.h>
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
23
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
24 #include <stdio.h>
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
25 #include <string.h>
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
26
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
27 #include "md5.h"
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
28
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
29 int
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
30 main (int argc, char *argv[])
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
31 {
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
32 /* Test vectors from RFC 1321. */
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
33
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
34 const char *in1 = "abc";
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
35 const char *out1 =
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
36 "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72";
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
37 const char *in2 = "message digest";
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
38 const char *out2 =
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
39 "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0";
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
40 char buf[MD5_DIGEST_SIZE];
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
41
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
42 if (memcmp (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE) != 0)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
43 {
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
44 size_t i;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
45 printf ("expected:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
46 for (i = 0; i < MD5_DIGEST_SIZE; i++)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
47 printf ("%02x ", out1[i] & 0xFF);
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
48 printf ("\ncomputed:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
49 for (i = 0; i < MD5_DIGEST_SIZE; i++)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
50 printf ("%02x ", buf[i] & 0xFF);
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
51 printf ("\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
52 return 1;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
53 }
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
54
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
55 if (memcmp (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE) != 0)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
56 {
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
57 size_t i;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
58 printf ("expected:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
59 for (i = 0; i < MD5_DIGEST_SIZE; i++)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
60 printf ("%02x ", out2[i] & 0xFF);
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
61 printf ("\ncomputed:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
62 for (i = 0; i < MD5_DIGEST_SIZE; i++)
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
63 printf ("%02x ", buf[i] & 0xFF);
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
64 printf ("\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
65 return 1;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
66 }
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
67
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
68 return 0;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
69 }