annotate tests/test-md5.c @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
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 /*
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 39712
diff changeset
2 * Copyright (C) 2005, 2009-2019 Free Software Foundation, Inc.
6392
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 *
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
5 * This program is free software: you can redistribute it and/or modify
6392
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
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
7 * the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
8 * (at your option) any later version.
6392
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
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
17
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
18 /* Written by Simon Josefsson. */
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
19
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 6392
diff changeset
20 #include <config.h>
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
21
19260
8fc416080bd2 crypto/*: Verify that the header file is self-contained.
Bruno Haible <bruno@clisp.org>
parents: 19190
diff changeset
22 #include "md5.h"
8fc416080bd2 crypto/*: Verify that the header file is self-contained.
Bruno Haible <bruno@clisp.org>
parents: 19190
diff changeset
23
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
24 #include <stdio.h>
19603
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
25 #include <stdlib.h>
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
26 #include <string.h>
19603
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
27 #include <unistd.h>
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
28
39712
250d25415d0e af_alg tests: Add another test.
Bruno Haible <bruno@clisp.org>
parents: 19603
diff changeset
29 #include "macros.h"
250d25415d0e af_alg tests: Add another test.
Bruno Haible <bruno@clisp.org>
parents: 19603
diff changeset
30
19603
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
31 #define TESTFILE "test-md5.data"
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
32 #include "test-digest.h"
6392
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 int
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
35 main (void)
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
36 {
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
37 /* Test vectors from RFC 1321. */
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
38
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
39 const char *in1 = "abc";
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
40 const char *out1 =
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
41 "\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
42 const char *in2 = "message digest";
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
43 const char *out2 =
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
44 "\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
45 char buf[MD5_DIGEST_SIZE];
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
46
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
47 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
48 {
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
49 size_t i;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
50 printf ("expected:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
51 for (i = 0; i < MD5_DIGEST_SIZE; i++)
17975
e9738bb175fe tests: pacify GCC 5.1's stricter printf checking
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
52 printf ("%02x ", out1[i] & 0xFFu);
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
53 printf ("\ncomputed:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
54 for (i = 0; i < MD5_DIGEST_SIZE; i++)
17975
e9738bb175fe tests: pacify GCC 5.1's stricter printf checking
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
55 printf ("%02x ", buf[i] & 0xFFu);
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
56 printf ("\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
57 return 1;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
58 }
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
59
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
60 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
61 {
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
62 size_t i;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
63 printf ("expected:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
64 for (i = 0; i < MD5_DIGEST_SIZE; i++)
17975
e9738bb175fe tests: pacify GCC 5.1's stricter printf checking
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
65 printf ("%02x ", out2[i] & 0xFFu);
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
66 printf ("\ncomputed:\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
67 for (i = 0; i < MD5_DIGEST_SIZE; i++)
17975
e9738bb175fe tests: pacify GCC 5.1's stricter printf checking
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
68 printf ("%02x ", buf[i] & 0xFFu);
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
69 printf ("\n");
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
70 return 1;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
71 }
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
72
19603
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
73 /* Test md5_stream. */
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
74 test_digest_on_files (md5_stream, "md5_stream", 16,
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
75 "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e",
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
76 "\x0d\x70\x06\xcd\x05\x5e\x94\xcf\x61\x45\x87\xe1\xd2\xae\x0c\x8e",
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
77 "\xec\x99\x67\x9b\xff\xc0\xf9\xb0\x6d\x18\x30\x6b\x06\xd6\x56\x23");
825bd15365fd md5 tests: Add test for md5_stream.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
78
6392
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
79 return 0;
a79c1b684e52 Add md5-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
80 }