Mercurial > gnulib
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 |
rev | line source |
---|---|
6392 | 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 | 3 * Written by Simon Josefsson |
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 | 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 | 9 * |
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. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
19190 | 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
6392 | 17 |
18 /* Written by Simon Josefsson. */ | |
19 | |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
6392
diff
changeset
|
20 #include <config.h> |
6392 | 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 | 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 | 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 | 33 |
34 int | |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
35 main (void) |
6392 | 36 { |
37 /* Test vectors from RFC 1321. */ | |
38 | |
39 const char *in1 = "abc"; | |
40 const char *out1 = | |
41 "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72"; | |
42 const char *in2 = "message digest"; | |
43 const char *out2 = | |
44 "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0"; | |
45 char buf[MD5_DIGEST_SIZE]; | |
46 | |
47 if (memcmp (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE) != 0) | |
48 { | |
49 size_t i; | |
50 printf ("expected:\n"); | |
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 | 53 printf ("\ncomputed:\n"); |
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 | 56 printf ("\n"); |
57 return 1; | |
58 } | |
59 | |
60 if (memcmp (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE) != 0) | |
61 { | |
62 size_t i; | |
63 printf ("expected:\n"); | |
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 | 66 printf ("\ncomputed:\n"); |
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 | 69 printf ("\n"); |
70 return 1; | |
71 } | |
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 | 79 return 0; |
80 } |