attribute: const/pure defaults to unsequenced/reproducible
[gnulib.git] / tests / test-gc-hmac-md5.c
blob5c71e7d3c320e3b6b032583b89db85c29b5a5ca7
1 /*
2 * Copyright (C) 2005, 2010-2024 Free Software Foundation, Inc.
3 * Written by Simon Josefsson
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.
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.
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/>. */
18 #include <config.h>
20 #include "gc.h"
22 #include <stdio.h>
23 #include <string.h>
25 int
26 main (int argc, char *argv[])
28 Gc_rc rc;
30 rc = gc_init ();
31 if (rc != GC_OK)
33 printf ("gc_init() failed\n");
34 return 1;
37 /* Test vectors from RFC 2104. */
40 const 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 const char *data = "Hi There";
44 size_t data_len = 8;
45 const char *digest =
46 "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
47 char out[16];
50 key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
51 key_len = 16 bytes
52 data = "Hi There"
53 data_len = 8 bytes
54 digest = 0x9294727a3638bb1c13f48ef8158bfc9d
57 if (gc_hmac_md5 (key, key_len, data, data_len, out) != 0)
59 printf ("call failure\n");
60 return 1;
63 if (memcmp (digest, out, 16) != 0)
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;
77 gc_done ();
79 return 0;