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. */
28 hmac_check (const void *key
, size_t key_len
,
29 const void *data
, size_t data_len
, const char *digest
)
33 if (hmac_sha1 (key
, key_len
, data
, data_len
, out
) != 0)
35 printf ("call failure\n");
39 if (memcmp (digest
, out
, 20) != 0)
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);
54 main (int argc
, char *argv
[])
58 size_t key_len
= sizeof key
;
59 memset (key
, '\x0b', sizeof key
);
60 char *data
= "Hi There";
63 "\x67\x5b\x0b\x3a\x1b\x4d\xdf\x4e\x12\x48\x72\xda\x6c\x2f\x63\x2b"
65 hmac_check (key
, key_len
, data
, data_len
, digest
);
71 char *data
= "what do ya want for nothing?";
74 "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c"
76 hmac_check (key
, key_len
, data
, data_len
, digest
);
81 size_t key_len
= sizeof key
;
82 memset (key
, '\xAA', sizeof key
);
84 size_t data_len
= sizeof data
;
85 memset (data
, '\xDD', sizeof data
);
87 "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f"
89 hmac_check (key
, key_len
, data
, data_len
, digest
);
94 size_t key_len
= sizeof key
;
95 memset (key
, '\x0b', sizeof key
);
96 char *data
= "Hi There";
99 "\x29\xda\xa9\xe9\xcc\x4b\x9f\x09\x48\x29\xdc\xd4\x03\xc0\x69\x27"
101 hmac_check (key
, key_len
, data
, data_len
, digest
);