annotate tests/test-hmac-sha1.c @ 17363:5a51fb7777a9

sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin Problem reported by Marco Atzeri in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>. * lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]: Simply delegate to the system <sys/select.h> in this case too. Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to be needed on Solaris either. * lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]: Simply delgate to the system <sys/time.h> in this case.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:08:47 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
1 /*
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 * Copyright (C) 2005, 2010-2013 Free Software Foundation, Inc.
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
3 *
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
4 * This program is free software: you can redistribute it and/or modify
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
5 * 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
6 * 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
7 * (at your option) any later version.
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
8 *
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
12 * GNU General Public License for more details.
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
13 *
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
16
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
17 /* Written by Simon Josefsson. */
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 6436
diff changeset
19 #include <config.h>
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
20
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
21 #include <stdio.h>
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
22 #include <string.h>
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
23 #include "hmac.h"
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
24
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
25 int
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
26 main (int argc, char *argv[])
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
27 {
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
28 {
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
29 char *key =
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
30 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
31 size_t key_len = 16;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
32 char *data = "Hi There";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
33 size_t data_len = 8;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
34 char *digest =
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
35 "\x67\x5b\x0b\x3a\x1b\x4d\xdf\x4e\x12\x48\x72\xda\x6c\x2f\x63\x2b\xfe\xd9\x57\xe9";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
36 char out[20];
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
37
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
38 if (hmac_sha1 (key, key_len, data, data_len, out) != 0)
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
39 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
40 printf ("call failure\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
41 return 1;
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
42 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
43
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
44 if (memcmp (digest, out, 20) != 0)
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
45 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
46 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
47 printf ("hash 1 mismatch. expected:\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
48 for (i = 0; i < 20; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
49 printf ("%02x ", digest[i] & 0xFF);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
50 printf ("\ncomputed:\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
51 for (i = 0; i < 20; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
52 printf ("%02x ", out[i] & 0xFF);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
53 printf ("\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
54 return 1;
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
55 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
56 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
57
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
58 {
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
59 char *key = "Jefe";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
60 size_t key_len = 4;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
61 char *data = "what do ya want for nothing?";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
62 size_t data_len = 28;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
63 char *digest =
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
64 "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
65 char out[20];
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
66
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
67 if (hmac_sha1 (key, key_len, data, data_len, out) != 0)
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
68 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
69 printf ("call failure\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
70 return 1;
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
71 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
72
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
73 if (memcmp (digest, out, 20) != 0)
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
74 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
75 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
76 printf ("hash 2 mismatch. expected:\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
77 for (i = 0; i < 20; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
78 printf ("%02x ", digest[i] & 0xFF);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
79 printf ("\ncomputed:\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
80 for (i = 0; i < 20; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
81 printf ("%02x ", out[i] & 0xFF);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
82 printf ("\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
83 return 1;
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
84 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
85 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
86
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
87 {
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
88 char *key =
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
89 "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
90 size_t key_len = 16;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
91 char *data = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
92 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
93 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
94 "\xDD\xDD";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
95 size_t data_len = 50;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
96 char *digest =
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
97 "\xd7\x30\x59\x4d\x16\x7e\x35\xd5\x95\x6f\xd8\x00\x3d\x0d\xb3\xd3\xf4\x6d\xc7\xbb";
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
98 char out[20];
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
99
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
100 if (hmac_sha1 (key, key_len, data, data_len, out) != 0)
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
101 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
102 printf ("call failure\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
103 return 1;
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
104 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
105
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
106 if (memcmp (digest, out, 20) != 0)
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
107 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
108 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
109 printf ("hash 3 mismatch. expected:\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
110 for (i = 0; i < 20; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
111 printf ("%02x ", digest[i] & 0xFF);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
112 printf ("\ncomputed:\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
113 for (i = 0; i < 20; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
114 printf ("%02x ", out[i] & 0xFF);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
115 printf ("\n");
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
116 return 1;
6364
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
117 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
118 }
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
119
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
120 return 0;
fb852f022f3f Add hmac-sha1 module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
121 }