sys_ioctl: Simplify.
[gnulib.git] / tests / test-hmac-sha1.c
blob07647cc57b5b0ba538314b307f14e3f7b0499bd6
1 /*
2 * Copyright (C) 2005, 2010-2020 Free Software Foundation, Inc.
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 3 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Simon Josefsson. */
19 #include <config.h>
21 #include "hmac.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 static void
28 hmac_check (const void *key, size_t key_len,
29 const void *data, size_t data_len, const char *digest)
31 char out[20];
33 if (hmac_sha1 (key, key_len, data, data_len, out) != 0)
35 printf ("call failure\n");
36 exit (1);
39 if (memcmp (digest, out, 20) != 0)
41 size_t i;
42 printf ("hash 1 mismatch. expected:\n");
43 for (i = 0; i < 20; i++)
44 printf ("%02x ", digest[i] & 0xFF);
45 printf ("\ncomputed:\n");
46 for (i = 0; i < 20; i++)
47 printf ("%02x ", out[i] & 0xFF);
48 printf ("\n");
49 exit (1);
53 int
54 main (int argc, char *argv[])
57 char key[16];
58 size_t key_len = sizeof key;
59 memset (key, '\x0b', sizeof key);
60 char *data = "Hi There";
61 size_t data_len = 8;
62 char *digest =
63 "\x67\x5b\x0b\x3a\x1b\x4d\xdf\x4e\x12\x48\x72\xda\x6c\x2f\x63\x2b"
64 "\xfe\xd9\x57\xe9";
65 hmac_check (key, key_len, data, data_len, digest);
69 char *key = "Jefe";
70 size_t key_len = 4;
71 char *data = "what do ya want for nothing?";
72 size_t data_len = 28;
73 char *digest =
74 "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c"
75 "\x25\x9a\x7c\x79";
76 hmac_check (key, key_len, data, data_len, digest);
80 char key[20];
81 size_t key_len = sizeof key;
82 memset (key, '\xAA', sizeof key);
83 char data[50];
84 size_t data_len = sizeof data;
85 memset (data, '\xDD', sizeof data);
86 char *digest =
87 "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f"
88 "\x63\xf1\x75\xd3";
89 hmac_check (key, key_len, data, data_len, digest);
93 char key[65];
94 size_t key_len = sizeof key;
95 memset (key, '\x0b', sizeof key);
96 char *data = "Hi There";
97 size_t data_len = 8;
98 char *digest =
99 "\x29\xda\xa9\xe9\xcc\x4b\x9f\x09\x48\x29\xdc\xd4\x03\xc0\x69\x27"
100 "\xd8\xa9\x53\x93";
101 hmac_check (key, key_len, data, data_len, digest);
103 return 0;