1 /*
2 * Copyright (C) 2005, 2010-2021 Free Software Foundation, Inc.
3 * Written by Simon Josefsson
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
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
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. */
17
18 #include <config.h>
19
20 #include "gc.h"
21
22 #include <stdio.h>
23 #include <string.h>
24
25 int
26 main (int argc, char *argv[])
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
27 {
28 Gc_rc rc;
29
30 rc = gc_init ();
31 if (rc != GC_OK)
32 {
33 printf ("gc_init() failed\n");
34 return 1;
35 }
36
37 /* Test vectors from RFC 2104. */
38
39 {
40 char *key =
41 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
42 size_t key_len = 16;
43 char *data = "Hi There";
44 size_t data_len = 8;
45 char *digest =
46 "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
47 char out[16];
48
49 /*
50 key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
51 key_len = 16 bytes
52 data = "Hi There"
53 data_len = 8 bytes
54 digest = 0x9294727a3638bb1c13f48ef8158bfc9d
55 */
56
57 if (gc_hmac_md5 (key, key_len, data, data_len, out) != 0)
58 {
59 printf ("call failure\n");
60 return 1;
61 }
62
63 if (memcmp (digest, out, 16) != 0)
64 {
65 size_t i;
66 printf ("hash 1 mismatch. expected:\n");
67 for (i = 0; i < 16; i++)
68 printf ("%02x ", digest[i] & 0xFF);
69 printf ("\ncomputed:\n");
70 for (i = 0; i < 16; i++)
71 printf ("%02x ", out[i] & 0xFF);
72 printf ("\n");
73 return 1;
74 }
75 }
76
77 gc_done ();
78
79 return 0;
80 }