Coverage Report

Created: 2022-12-08 06:10

/src/libgcrypt/cipher/mac-hmac.c
Line
Count
Source (jump to first uncovered line)
1
/* mac-hmac.c  -  HMAC glue for MAC API
2
 * Copyright (C) 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
3
 * Copyright (C) 2008 Free Software Foundation, Inc.
4
 *
5
 * This file is part of Libgcrypt.
6
 *
7
 * Libgcrypt is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser general Public License as
9
 * published by the Free Software Foundation; either version 2.1 of
10
 * the License, or (at your option) any later version.
11
 *
12
 * Libgcrypt is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include <config.h>
22
#include <stdio.h>
23
#include <stdlib.h>
24
#include <string.h>
25
#include <errno.h>
26
27
#include "g10lib.h"
28
#include "./mac-internal.h"
29
#include "bufhelp.h"
30
#include "cipher.h"
31
32
33
static int
34
map_mac_algo_to_md (int mac_algo)
35
0
{
36
0
  switch (mac_algo)
37
0
    {
38
0
    default:
39
0
      return GCRY_MD_NONE;
40
0
    case GCRY_MAC_HMAC_MD2:
41
0
      return GCRY_MD_MD2;
42
0
    case GCRY_MAC_HMAC_MD4:
43
0
      return GCRY_MD_MD4;
44
0
    case GCRY_MAC_HMAC_MD5:
45
0
      return GCRY_MD_MD5;
46
0
    case GCRY_MAC_HMAC_SHA1:
47
0
      return GCRY_MD_SHA1;
48
0
    case GCRY_MAC_HMAC_SHA224:
49
0
      return GCRY_MD_SHA224;
50
0
    case GCRY_MAC_HMAC_SHA256:
51
0
      return GCRY_MD_SHA256;
52
0
    case GCRY_MAC_HMAC_SHA384:
53
0
      return GCRY_MD_SHA384;
54
0
    case GCRY_MAC_HMAC_SHA512:
55
0
      return GCRY_MD_SHA512;
56
0
    case GCRY_MAC_HMAC_SHA512_256:
57
0
      return GCRY_MD_SHA512_256;
58
0
    case GCRY_MAC_HMAC_SHA512_224:
59
0
      return GCRY_MD_SHA512_224;
60
0
    case GCRY_MAC_HMAC_SHA3_224:
61
0
      return GCRY_MD_SHA3_224;
62
0
    case GCRY_MAC_HMAC_SHA3_256:
63
0
      return GCRY_MD_SHA3_256;
64
0
    case GCRY_MAC_HMAC_SHA3_384:
65
0
      return GCRY_MD_SHA3_384;
66
0
    case GCRY_MAC_HMAC_SHA3_512:
67
0
      return GCRY_MD_SHA3_512;
68
0
    case GCRY_MAC_HMAC_RMD160:
69
0
      return GCRY_MD_RMD160;
70
0
    case GCRY_MAC_HMAC_TIGER1:
71
0
      return GCRY_MD_TIGER1;
72
0
    case GCRY_MAC_HMAC_WHIRLPOOL:
73
0
      return GCRY_MD_WHIRLPOOL;
74
0
    case GCRY_MAC_HMAC_GOSTR3411_94:
75
0
      return GCRY_MD_GOSTR3411_94;
76
0
    case GCRY_MAC_HMAC_GOSTR3411_CP:
77
0
      return GCRY_MD_GOSTR3411_CP;
78
0
    case GCRY_MAC_HMAC_STRIBOG256:
79
0
      return GCRY_MD_STRIBOG256;
80
0
    case GCRY_MAC_HMAC_STRIBOG512:
81
0
      return GCRY_MD_STRIBOG512;
82
0
    case GCRY_MAC_HMAC_BLAKE2B_512:
83
0
      return GCRY_MD_BLAKE2B_512;
84
0
    case GCRY_MAC_HMAC_BLAKE2B_384:
85
0
      return GCRY_MD_BLAKE2B_384;
86
0
    case GCRY_MAC_HMAC_BLAKE2B_256:
87
0
      return GCRY_MD_BLAKE2B_256;
88
0
    case GCRY_MAC_HMAC_BLAKE2B_160:
89
0
      return GCRY_MD_BLAKE2B_160;
90
0
    case GCRY_MAC_HMAC_BLAKE2S_256:
91
0
      return GCRY_MD_BLAKE2S_256;
92
0
    case GCRY_MAC_HMAC_BLAKE2S_224:
93
0
      return GCRY_MD_BLAKE2S_224;
94
0
    case GCRY_MAC_HMAC_BLAKE2S_160:
95
0
      return GCRY_MD_BLAKE2S_160;
96
0
    case GCRY_MAC_HMAC_BLAKE2S_128:
97
0
      return GCRY_MD_BLAKE2S_128;
98
0
    case GCRY_MAC_HMAC_SM3:
99
0
      return GCRY_MD_SM3;
100
0
    }
101
0
}
102
103
104
static gcry_err_code_t
105
hmac_open (gcry_mac_hd_t h)
106
0
{
107
0
  gcry_err_code_t err;
108
0
  gcry_md_hd_t hd;
109
0
  int secure = (h->magic == CTX_MAC_MAGIC_SECURE);
110
0
  unsigned int flags;
111
0
  int md_algo;
112
113
0
  md_algo = map_mac_algo_to_md (h->spec->algo);
114
115
0
  flags = GCRY_MD_FLAG_HMAC;
116
0
  flags |= (secure ? GCRY_MD_FLAG_SECURE : 0);
117
118
0
  err = _gcry_md_open (&hd, md_algo, flags);
119
0
  if (err)
120
0
    return err;
121
122
0
  h->u.hmac.md_algo = md_algo;
123
0
  h->u.hmac.md_ctx = hd;
124
0
  return 0;
125
0
}
126
127
128
static void
129
hmac_close (gcry_mac_hd_t h)
130
0
{
131
0
  _gcry_md_close (h->u.hmac.md_ctx);
132
0
  h->u.hmac.md_ctx = NULL;
133
0
}
134
135
136
static gcry_err_code_t
137
hmac_setkey (gcry_mac_hd_t h, const unsigned char *key, size_t keylen)
138
0
{
139
0
  return _gcry_md_setkey (h->u.hmac.md_ctx, key, keylen);
140
0
}
141
142
143
static gcry_err_code_t
144
hmac_reset (gcry_mac_hd_t h)
145
0
{
146
0
  _gcry_md_reset (h->u.hmac.md_ctx);
147
0
  return 0;
148
0
}
149
150
151
static gcry_err_code_t
152
hmac_write (gcry_mac_hd_t h, const unsigned char *buf, size_t buflen)
153
0
{
154
0
  _gcry_md_write (h->u.hmac.md_ctx, buf, buflen);
155
0
  return 0;
156
0
}
157
158
159
static gcry_err_code_t
160
hmac_read (gcry_mac_hd_t h, unsigned char *outbuf, size_t * outlen)
161
0
{
162
0
  unsigned int dlen;
163
0
  const unsigned char *digest;
164
165
0
  dlen = _gcry_md_get_algo_dlen (h->u.hmac.md_algo);
166
0
  digest = _gcry_md_read (h->u.hmac.md_ctx, h->u.hmac.md_algo);
167
168
0
  if (*outlen <= dlen)
169
0
    buf_cpy (outbuf, digest, *outlen);
170
0
  else
171
0
    {
172
0
      buf_cpy (outbuf, digest, dlen);
173
0
      *outlen = dlen;
174
0
    }
175
176
0
  return 0;
177
0
}
178
179
180
static gcry_err_code_t
181
hmac_verify (gcry_mac_hd_t h, const unsigned char *buf, size_t buflen)
182
0
{
183
0
  unsigned int dlen;
184
0
  const unsigned char *digest;
185
186
0
  dlen = _gcry_md_get_algo_dlen (h->u.hmac.md_algo);
187
0
  digest = _gcry_md_read (h->u.hmac.md_ctx, h->u.hmac.md_algo);
188
189
0
  if (buflen > dlen)
190
0
    return GPG_ERR_INV_LENGTH;
191
192
0
  return buf_eq_const (buf, digest, buflen) ? 0 : GPG_ERR_CHECKSUM;
193
0
}
194
195
196
static unsigned int
197
hmac_get_maclen (int algo)
198
0
{
199
0
  return _gcry_md_get_algo_dlen (map_mac_algo_to_md (algo));
200
0
}
201
202
203
static unsigned int
204
hmac_get_keylen (int algo)
205
0
{
206
  /* Return blocksize for default key length. */
207
0
  switch (algo)
208
0
    {
209
0
    case GCRY_MD_SHA3_224:
210
0
      return 1152 / 8;
211
0
    case GCRY_MD_SHA3_256:
212
0
      return 1088 / 8;
213
0
    case GCRY_MD_SHA3_384:
214
0
      return 832 / 8;
215
0
    case GCRY_MD_SHA3_512:
216
0
      return 576 / 8;
217
0
    case GCRY_MAC_HMAC_SHA384:
218
0
    case GCRY_MAC_HMAC_SHA512:
219
0
      return 128;
220
0
    case GCRY_MAC_HMAC_GOSTR3411_94:
221
0
      return 32;
222
0
    default:
223
0
      return 64;
224
0
    }
225
0
}
226
227
228
/* Check one HMAC with digest ALGO using the regualr HAMC
229
 * API. (DATA,DATALEN) is the data to be MACed, (KEY,KEYLEN) the key
230
 * and (EXPECT,EXPECTLEN) the expected result.  If TRUNC is set, the
231
 * EXPECTLEN may be less than the digest length.  Returns NULL on
232
 * success or a string describing the failure.  */
233
static const char *
234
check_one (int algo,
235
           const void *data, size_t datalen,
236
           const void *key, size_t keylen,
237
           const void *expect, size_t expectlen, int trunc)
238
0
{
239
0
  gcry_md_hd_t hd;
240
0
  const unsigned char *digest;
241
242
/*   printf ("HMAC algo %d\n", algo); */
243
244
  /* Skip test with shoter key in FIPS mode.  */
245
0
  if (fips_mode () && keylen < 14)
246
0
    return NULL;
247
248
0
  if (trunc)
249
0
    {
250
0
      if (_gcry_md_get_algo_dlen (algo) < expectlen)
251
0
        return "invalid tests data";
252
0
    }
253
0
  else
254
0
    {
255
0
      if (_gcry_md_get_algo_dlen (algo) != expectlen)
256
0
        return "invalid tests data";
257
0
    }
258
0
  if (_gcry_md_open (&hd, algo, GCRY_MD_FLAG_HMAC))
259
0
    return "gcry_md_open failed";
260
0
  if (_gcry_md_setkey (hd, key, keylen))
261
0
    {
262
0
      _gcry_md_close (hd);
263
0
      return "gcry_md_setkey failed";
264
0
    }
265
0
  _gcry_md_write (hd, data, datalen);
266
0
  digest = _gcry_md_read (hd, algo);
267
0
  if (!digest)
268
0
    {
269
0
      _gcry_md_close (hd);
270
0
      return "gcry_md_read failed";
271
0
    }
272
0
  if (memcmp (digest, expect, expectlen))
273
0
    {
274
/*       int i; */
275
276
/*       fputs ("        {", stdout); */
277
/*       for (i=0; i < expectlen-1; i++) */
278
/*         { */
279
/*           if (i && !(i % 8)) */
280
/*             fputs ("\n         ", stdout); */
281
/*           printf (" 0x%02x,", digest[i]); */
282
/*         } */
283
/*       printf (" 0x%02x } },\n", digest[i]); */
284
285
0
      _gcry_md_close (hd);
286
0
      return "does not match";
287
0
    }
288
0
  _gcry_md_close (hd);
289
0
  return NULL;
290
0
}
291
292
293
static gpg_err_code_t
294
selftests_sha1 (int extended, selftest_report_func_t report)
295
0
{
296
0
  const char *what;
297
0
  const char *errtxt;
298
0
  unsigned char key[128];
299
0
  int i, j;
300
301
0
  what = "FIPS-198a, A.1";
302
0
  for (i=0; i < 64; i++)
303
0
    key[i] = i;
304
0
  errtxt = check_one (GCRY_MD_SHA1,
305
0
                      "Sample #1", 9,
306
0
                      key, 64,
307
0
                      "\x4f\x4c\xa3\xd5\xd6\x8b\xa7\xcc\x0a\x12"
308
0
                      "\x08\xc9\xc6\x1e\x9c\x5d\xa0\x40\x3c\x0a", 20, 0);
309
0
  if (errtxt)
310
0
    goto failed;
311
312
0
  if (extended)
313
0
    {
314
0
      what = "FIPS-198a, A.2";
315
0
      for (i=0, j=0x30; i < 20; i++)
316
0
        key[i] = j++;
317
0
      errtxt = check_one (GCRY_MD_SHA1,
318
0
                          "Sample #2", 9,
319
0
                          key, 20,
320
0
                          "\x09\x22\xd3\x40\x5f\xaa\x3d\x19\x4f\x82"
321
0
                          "\xa4\x58\x30\x73\x7d\x5c\xc6\xc7\x5d\x24", 20, 0);
322
0
      if (errtxt)
323
0
        goto failed;
324
325
0
      what = "FIPS-198a, A.3";
326
0
      for (i=0, j=0x50; i < 100; i++)
327
0
        key[i] = j++;
328
0
      errtxt = check_one (GCRY_MD_SHA1,
329
0
                          "Sample #3", 9,
330
0
                          key, 100,
331
0
                          "\xbc\xf4\x1e\xab\x8b\xb2\xd8\x02\xf3\xd0"
332
0
                          "\x5c\xaf\x7c\xb0\x92\xec\xf8\xd1\xa3\xaa", 20, 0);
333
0
      if (errtxt)
334
0
        goto failed;
335
336
0
      what = "FIPS-198a, A.4";
337
0
      for (i=0, j=0x70; i < 49; i++)
338
0
        key[i] = j++;
339
0
      errtxt = check_one (GCRY_MD_SHA1,
340
0
                          "Sample #4", 9,
341
0
                          key, 49,
342
0
                          "\x9e\xa8\x86\xef\xe2\x68\xdb\xec\xce\x42"
343
0
                          "\x0c\x75\x24\xdf\x32\xe0\x75\x1a\x2a\x26", 20, 0);
344
0
      if (errtxt)
345
0
        goto failed;
346
0
    }
347
348
0
  return 0; /* Succeeded. */
349
350
0
 failed:
351
0
  if (report)
352
0
    report ("hmac", GCRY_MD_SHA1, what, errtxt);
353
0
  return GPG_ERR_SELFTEST_FAILED;
354
0
}
355
356
357
358
static gpg_err_code_t
359
selftests_sha224 (int extended, selftest_report_func_t report)
360
0
{
361
0
  static struct
362
0
  {
363
0
    const char * const desc;
364
0
    const char * const data;
365
0
    const char * const key;
366
0
    const char expect[28];
367
0
  } tv[] =
368
0
    {
369
0
      { "data-28 key-4",
370
0
        "what do ya want for nothing?",
371
0
        "Jefe",
372
0
        { 0xa3, 0x0e, 0x01, 0x09, 0x8b, 0xc6, 0xdb, 0xbf,
373
0
          0x45, 0x69, 0x0f, 0x3a, 0x7e, 0x9e, 0x6d, 0x0f,
374
0
          0x8b, 0xbe, 0xa2, 0xa3, 0x9e, 0x61, 0x48, 0x00,
375
0
          0x8f, 0xd0, 0x5e, 0x44 } },
376
377
0
      { "data-9 key-20",
378
0
        "Hi There",
379
0
  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
380
0
        "\x0b\x0b\x0b\x0b",
381
0
        { 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
382
0
          0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
383
0
          0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
384
0
          0x53, 0x68, 0x4b, 0x22 } },
385
386
0
      { "data-50 key-20",
387
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
388
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
389
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
390
0
        "\xdd\xdd",
391
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
392
0
        "\xaa\xaa\xaa\xaa",
393
0
        { 0x7f, 0xb3, 0xcb, 0x35, 0x88, 0xc6, 0xc1, 0xf6,
394
0
          0xff, 0xa9, 0x69, 0x4d, 0x7d, 0x6a, 0xd2, 0x64,
395
0
          0x93, 0x65, 0xb0, 0xc1, 0xf6, 0x5d, 0x69, 0xd1,
396
0
          0xec, 0x83, 0x33, 0xea } },
397
398
0
      { "data-50 key-26",
399
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
400
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
401
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
402
0
        "\xcd\xcd",
403
0
  "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
404
0
        "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
405
0
        { 0x6c, 0x11, 0x50, 0x68, 0x74, 0x01, 0x3c, 0xac,
406
0
          0x6a, 0x2a, 0xbc, 0x1b, 0xb3, 0x82, 0x62, 0x7c,
407
0
          0xec, 0x6a, 0x90, 0xd8, 0x6e, 0xfc, 0x01, 0x2d,
408
0
          0xe7, 0xaf, 0xec, 0x5a } },
409
410
0
      { "data-54 key-131",
411
0
        "Test Using Larger Than Block-Size Key - Hash Key First",
412
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
413
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
414
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
415
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
416
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
417
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
418
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
419
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
420
0
        "\xaa\xaa\xaa",
421
0
        { 0x95, 0xe9, 0xa0, 0xdb, 0x96, 0x20, 0x95, 0xad,
422
0
          0xae, 0xbe, 0x9b, 0x2d, 0x6f, 0x0d, 0xbc, 0xe2,
423
0
          0xd4, 0x99, 0xf1, 0x12, 0xf2, 0xd2, 0xb7, 0x27,
424
0
          0x3f, 0xa6, 0x87, 0x0e } },
425
426
0
      { "data-152 key-131",
427
0
        "This is a test using a larger than block-size key and a larger "
428
0
        "than block-size data. The key needs to be hashed before being "
429
0
        "used by the HMAC algorithm.",
430
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
431
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
432
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
433
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
434
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
435
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
436
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
437
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
438
0
        "\xaa\xaa\xaa",
439
0
        { 0x3a, 0x85, 0x41, 0x66, 0xac, 0x5d, 0x9f, 0x02,
440
0
          0x3f, 0x54, 0xd5, 0x17, 0xd0, 0xb3, 0x9d, 0xbd,
441
0
          0x94, 0x67, 0x70, 0xdb, 0x9c, 0x2b, 0x95, 0xc9,
442
0
          0xf6, 0xf5, 0x65, 0xd1 } },
443
444
0
      { NULL }
445
0
    };
446
0
  const char *what;
447
0
  const char *errtxt;
448
0
  int tvidx;
449
450
0
  for (tvidx=0; tv[tvidx].desc; tvidx++)
451
0
    {
452
0
      what = tv[tvidx].desc;
453
0
      errtxt = check_one (GCRY_MD_SHA224,
454
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
455
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
456
0
                          tv[tvidx].expect, DIM (tv[tvidx].expect), 0);
457
0
      if (errtxt)
458
0
        goto failed;
459
0
      if (!extended)
460
0
        break;
461
0
    }
462
463
0
  return 0; /* Succeeded. */
464
465
0
 failed:
466
0
  if (report)
467
0
    report ("hmac", GCRY_MD_SHA224, what, errtxt);
468
0
  return GPG_ERR_SELFTEST_FAILED;
469
0
}
470
471
472
static gpg_err_code_t
473
selftests_sha256 (int extended, selftest_report_func_t report)
474
0
{
475
0
  static struct
476
0
  {
477
0
    const char * const desc;
478
0
    const char * const data;
479
0
    const char * const key;
480
0
    const char expect[32];
481
0
  } tv[] =
482
0
    {
483
0
      { "data-28 key-4",
484
0
        "what do ya want for nothing?",
485
0
        "Jefe",
486
0
  { 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
487
0
          0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
488
0
          0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
489
0
          0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43 } },
490
491
0
      { "data-9 key-20",
492
0
        "Hi There",
493
0
  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
494
0
        "\x0b\x0b\x0b\x0b",
495
0
        { 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
496
0
          0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
497
0
          0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
498
0
          0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7 } },
499
500
0
      { "data-50 key-20",
501
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
502
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
503
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
504
0
        "\xdd\xdd",
505
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
506
0
        "\xaa\xaa\xaa\xaa",
507
0
        { 0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46,
508
0
          0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7,
509
0
          0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
510
0
          0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5, 0x65, 0xfe } },
511
512
0
      { "data-50 key-26",
513
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
514
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
515
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
516
0
        "\xcd\xcd",
517
0
  "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
518
0
        "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
519
0
  { 0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e,
520
0
          0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a,
521
0
          0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
522
0
          0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29, 0x66, 0x5b } },
523
524
0
      { "data-54 key-131",
525
0
        "Test Using Larger Than Block-Size Key - Hash Key First",
526
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
527
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
528
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
529
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
530
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
531
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
532
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
533
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
534
0
        "\xaa\xaa\xaa",
535
0
  { 0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f,
536
0
          0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f,
537
0
          0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
538
0
          0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3, 0x7f, 0x54 } },
539
540
0
      { "data-152 key-131",
541
0
        "This is a test using a larger than block-size key and a larger "
542
0
        "than block-size data. The key needs to be hashed before being "
543
0
        "used by the HMAC algorithm.",
544
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
545
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
546
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
547
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
548
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
549
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
550
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
551
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
552
0
        "\xaa\xaa\xaa",
553
0
  { 0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb,
554
0
          0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44,
555
0
          0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
556
0
          0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2 } },
557
558
0
      { NULL }
559
0
    };
560
0
  const char *what;
561
0
  const char *errtxt;
562
0
  int tvidx;
563
564
0
  for (tvidx=0; tv[tvidx].desc; tvidx++)
565
0
    {
566
0
      what = tv[tvidx].desc;
567
0
      errtxt = check_one (GCRY_MD_SHA256,
568
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
569
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
570
0
                          tv[tvidx].expect, DIM (tv[tvidx].expect), 0);
571
0
      if (errtxt)
572
0
        goto failed;
573
0
      if (!extended)
574
0
        break;
575
0
    }
576
577
0
  return 0; /* Succeeded. */
578
579
0
 failed:
580
0
  if (report)
581
0
    report ("hmac", GCRY_MD_SHA256, what, errtxt);
582
0
  return GPG_ERR_SELFTEST_FAILED;
583
0
}
584
585
586
static gpg_err_code_t
587
selftests_sha384 (int extended, selftest_report_func_t report)
588
0
{
589
0
  static struct
590
0
  {
591
0
    const char * const desc;
592
0
    const char * const data;
593
0
    const char * const key;
594
0
    const char expect[48];
595
0
  } tv[] =
596
0
    {
597
0
      { "data-28 key-4",
598
0
        "what do ya want for nothing?",
599
0
        "Jefe",
600
0
        { 0xaf, 0x45, 0xd2, 0xe3, 0x76, 0x48, 0x40, 0x31,
601
0
          0x61, 0x7f, 0x78, 0xd2, 0xb5, 0x8a, 0x6b, 0x1b,
602
0
          0x9c, 0x7e, 0xf4, 0x64, 0xf5, 0xa0, 0x1b, 0x47,
603
0
          0xe4, 0x2e, 0xc3, 0x73, 0x63, 0x22, 0x44, 0x5e,
604
0
          0x8e, 0x22, 0x40, 0xca, 0x5e, 0x69, 0xe2, 0xc7,
605
0
          0x8b, 0x32, 0x39, 0xec, 0xfa, 0xb2, 0x16, 0x49 } },
606
607
0
      { "data-9 key-20",
608
0
        "Hi There",
609
0
  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
610
0
        "\x0b\x0b\x0b\x0b",
611
0
        { 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
612
0
          0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
613
0
          0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
614
0
          0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
615
0
          0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
616
0
          0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6 } },
617
618
0
      { "data-50 key-20",
619
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
620
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
621
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
622
0
        "\xdd\xdd",
623
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
624
0
        "\xaa\xaa\xaa\xaa",
625
0
        { 0x88, 0x06, 0x26, 0x08, 0xd3, 0xe6, 0xad, 0x8a,
626
0
          0x0a, 0xa2, 0xac, 0xe0, 0x14, 0xc8, 0xa8, 0x6f,
627
0
          0x0a, 0xa6, 0x35, 0xd9, 0x47, 0xac, 0x9f, 0xeb,
628
0
          0xe8, 0x3e, 0xf4, 0xe5, 0x59, 0x66, 0x14, 0x4b,
629
0
          0x2a, 0x5a, 0xb3, 0x9d, 0xc1, 0x38, 0x14, 0xb9,
630
0
          0x4e, 0x3a, 0xb6, 0xe1, 0x01, 0xa3, 0x4f, 0x27 } },
631
632
0
      { "data-50 key-26",
633
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
634
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
635
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
636
0
        "\xcd\xcd",
637
0
  "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
638
0
        "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
639
0
        { 0x3e, 0x8a, 0x69, 0xb7, 0x78, 0x3c, 0x25, 0x85,
640
0
          0x19, 0x33, 0xab, 0x62, 0x90, 0xaf, 0x6c, 0xa7,
641
0
          0x7a, 0x99, 0x81, 0x48, 0x08, 0x50, 0x00, 0x9c,
642
0
          0xc5, 0x57, 0x7c, 0x6e, 0x1f, 0x57, 0x3b, 0x4e,
643
0
          0x68, 0x01, 0xdd, 0x23, 0xc4, 0xa7, 0xd6, 0x79,
644
0
          0xcc, 0xf8, 0xa3, 0x86, 0xc6, 0x74, 0xcf, 0xfb } },
645
646
0
      { "data-54 key-131",
647
0
        "Test Using Larger Than Block-Size Key - Hash Key First",
648
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
649
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
650
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
651
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
652
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
653
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
654
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
655
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
656
0
        "\xaa\xaa\xaa",
657
0
        { 0x4e, 0xce, 0x08, 0x44, 0x85, 0x81, 0x3e, 0x90,
658
0
          0x88, 0xd2, 0xc6, 0x3a, 0x04, 0x1b, 0xc5, 0xb4,
659
0
          0x4f, 0x9e, 0xf1, 0x01, 0x2a, 0x2b, 0x58, 0x8f,
660
0
          0x3c, 0xd1, 0x1f, 0x05, 0x03, 0x3a, 0xc4, 0xc6,
661
0
          0x0c, 0x2e, 0xf6, 0xab, 0x40, 0x30, 0xfe, 0x82,
662
0
          0x96, 0x24, 0x8d, 0xf1, 0x63, 0xf4, 0x49, 0x52 } },
663
664
0
      { "data-152 key-131",
665
0
        "This is a test using a larger than block-size key and a larger "
666
0
        "than block-size data. The key needs to be hashed before being "
667
0
        "used by the HMAC algorithm.",
668
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
669
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
670
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
671
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
672
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
673
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
674
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
675
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
676
0
        "\xaa\xaa\xaa",
677
0
        { 0x66, 0x17, 0x17, 0x8e, 0x94, 0x1f, 0x02, 0x0d,
678
0
          0x35, 0x1e, 0x2f, 0x25, 0x4e, 0x8f, 0xd3, 0x2c,
679
0
          0x60, 0x24, 0x20, 0xfe, 0xb0, 0xb8, 0xfb, 0x9a,
680
0
          0xdc, 0xce, 0xbb, 0x82, 0x46, 0x1e, 0x99, 0xc5,
681
0
          0xa6, 0x78, 0xcc, 0x31, 0xe7, 0x99, 0x17, 0x6d,
682
0
          0x38, 0x60, 0xe6, 0x11, 0x0c, 0x46, 0x52, 0x3e } },
683
684
0
      { NULL }
685
0
    };
686
0
  const char *what;
687
0
  const char *errtxt;
688
0
  int tvidx;
689
690
0
  for (tvidx=0; tv[tvidx].desc; tvidx++)
691
0
    {
692
0
      what = tv[tvidx].desc;
693
0
      errtxt = check_one (GCRY_MD_SHA384,
694
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
695
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
696
0
                          tv[tvidx].expect, DIM (tv[tvidx].expect), 0);
697
0
      if (errtxt)
698
0
        goto failed;
699
0
      if (!extended)
700
0
        break;
701
0
    }
702
703
0
  return 0; /* Succeeded. */
704
705
0
 failed:
706
0
  if (report)
707
0
    report ("hmac", GCRY_MD_SHA384, what, errtxt);
708
0
  return GPG_ERR_SELFTEST_FAILED;
709
0
}
710
711
712
static gpg_err_code_t
713
selftests_sha512 (int extended, selftest_report_func_t report)
714
0
{
715
0
  static struct
716
0
  {
717
0
    const char * const desc;
718
0
    const char * const data;
719
0
    const char * const key;
720
0
    const char expect[64];
721
0
  } tv[] =
722
0
    {
723
0
      { "data-28 key-4",
724
0
        "what do ya want for nothing?",
725
0
        "Jefe",
726
0
        { 0x16, 0x4b, 0x7a, 0x7b, 0xfc, 0xf8, 0x19, 0xe2,
727
0
          0xe3, 0x95, 0xfb, 0xe7, 0x3b, 0x56, 0xe0, 0xa3,
728
0
          0x87, 0xbd, 0x64, 0x22, 0x2e, 0x83, 0x1f, 0xd6,
729
0
          0x10, 0x27, 0x0c, 0xd7, 0xea, 0x25, 0x05, 0x54,
730
0
          0x97, 0x58, 0xbf, 0x75, 0xc0, 0x5a, 0x99, 0x4a,
731
0
          0x6d, 0x03, 0x4f, 0x65, 0xf8, 0xf0, 0xe6, 0xfd,
732
0
          0xca, 0xea, 0xb1, 0xa3, 0x4d, 0x4a, 0x6b, 0x4b,
733
0
          0x63, 0x6e, 0x07, 0x0a, 0x38, 0xbc, 0xe7, 0x37 } },
734
735
0
      { "data-9 key-20",
736
0
        "Hi There",
737
0
  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
738
0
        "\x0b\x0b\x0b\x0b",
739
0
        { 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
740
0
          0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
741
0
          0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
742
0
          0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
743
0
          0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
744
0
          0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
745
0
          0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
746
0
          0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54 } },
747
748
0
      { "data-50 key-20",
749
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
750
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
751
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
752
0
        "\xdd\xdd",
753
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
754
0
        "\xaa\xaa\xaa\xaa",
755
0
        { 0xfa, 0x73, 0xb0, 0x08, 0x9d, 0x56, 0xa2, 0x84,
756
0
          0xef, 0xb0, 0xf0, 0x75, 0x6c, 0x89, 0x0b, 0xe9,
757
0
          0xb1, 0xb5, 0xdb, 0xdd, 0x8e, 0xe8, 0x1a, 0x36,
758
0
          0x55, 0xf8, 0x3e, 0x33, 0xb2, 0x27, 0x9d, 0x39,
759
0
          0xbf, 0x3e, 0x84, 0x82, 0x79, 0xa7, 0x22, 0xc8,
760
0
          0x06, 0xb4, 0x85, 0xa4, 0x7e, 0x67, 0xc8, 0x07,
761
0
          0xb9, 0x46, 0xa3, 0x37, 0xbe, 0xe8, 0x94, 0x26,
762
0
          0x74, 0x27, 0x88, 0x59, 0xe1, 0x32, 0x92, 0xfb } },
763
764
0
      { "data-50 key-26",
765
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
766
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
767
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
768
0
        "\xcd\xcd",
769
0
  "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
770
0
        "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
771
0
        { 0xb0, 0xba, 0x46, 0x56, 0x37, 0x45, 0x8c, 0x69,
772
0
          0x90, 0xe5, 0xa8, 0xc5, 0xf6, 0x1d, 0x4a, 0xf7,
773
0
          0xe5, 0x76, 0xd9, 0x7f, 0xf9, 0x4b, 0x87, 0x2d,
774
0
          0xe7, 0x6f, 0x80, 0x50, 0x36, 0x1e, 0xe3, 0xdb,
775
0
          0xa9, 0x1c, 0xa5, 0xc1, 0x1a, 0xa2, 0x5e, 0xb4,
776
0
          0xd6, 0x79, 0x27, 0x5c, 0xc5, 0x78, 0x80, 0x63,
777
0
          0xa5, 0xf1, 0x97, 0x41, 0x12, 0x0c, 0x4f, 0x2d,
778
0
          0xe2, 0xad, 0xeb, 0xeb, 0x10, 0xa2, 0x98, 0xdd } },
779
780
0
      { "data-54 key-131",
781
0
        "Test Using Larger Than Block-Size Key - Hash Key First",
782
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
783
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
784
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
785
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
786
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
787
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
788
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
789
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
790
0
        "\xaa\xaa\xaa",
791
0
        { 0x80, 0xb2, 0x42, 0x63, 0xc7, 0xc1, 0xa3, 0xeb,
792
0
          0xb7, 0x14, 0x93, 0xc1, 0xdd, 0x7b, 0xe8, 0xb4,
793
0
          0x9b, 0x46, 0xd1, 0xf4, 0x1b, 0x4a, 0xee, 0xc1,
794
0
          0x12, 0x1b, 0x01, 0x37, 0x83, 0xf8, 0xf3, 0x52,
795
0
          0x6b, 0x56, 0xd0, 0x37, 0xe0, 0x5f, 0x25, 0x98,
796
0
          0xbd, 0x0f, 0xd2, 0x21, 0x5d, 0x6a, 0x1e, 0x52,
797
0
          0x95, 0xe6, 0x4f, 0x73, 0xf6, 0x3f, 0x0a, 0xec,
798
0
          0x8b, 0x91, 0x5a, 0x98, 0x5d, 0x78, 0x65, 0x98 } },
799
800
0
      { "data-152 key-131",
801
0
        "This is a test using a larger than block-size key and a larger "
802
0
        "than block-size data. The key needs to be hashed before being "
803
0
        "used by the HMAC algorithm.",
804
0
  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
805
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
806
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
807
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
808
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
809
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
810
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
811
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
812
0
        "\xaa\xaa\xaa",
813
0
        { 0xe3, 0x7b, 0x6a, 0x77, 0x5d, 0xc8, 0x7d, 0xba,
814
0
          0xa4, 0xdf, 0xa9, 0xf9, 0x6e, 0x5e, 0x3f, 0xfd,
815
0
          0xde, 0xbd, 0x71, 0xf8, 0x86, 0x72, 0x89, 0x86,
816
0
          0x5d, 0xf5, 0xa3, 0x2d, 0x20, 0xcd, 0xc9, 0x44,
817
0
          0xb6, 0x02, 0x2c, 0xac, 0x3c, 0x49, 0x82, 0xb1,
818
0
          0x0d, 0x5e, 0xeb, 0x55, 0xc3, 0xe4, 0xde, 0x15,
819
0
          0x13, 0x46, 0x76, 0xfb, 0x6d, 0xe0, 0x44, 0x60,
820
0
          0x65, 0xc9, 0x74, 0x40, 0xfa, 0x8c, 0x6a, 0x58 } },
821
822
0
      { NULL }
823
0
    };
824
0
  const char *what;
825
0
  const char *errtxt;
826
0
  int tvidx;
827
828
0
  for (tvidx=0; tv[tvidx].desc; tvidx++)
829
0
    {
830
0
      what = tv[tvidx].desc;
831
0
      errtxt = check_one (GCRY_MD_SHA512,
832
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
833
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
834
0
                          tv[tvidx].expect, DIM (tv[tvidx].expect), 0);
835
0
      if (errtxt)
836
0
        goto failed;
837
0
      if (!extended)
838
0
        break;
839
0
    }
840
841
0
  return 0; /* Succeeded. */
842
843
0
 failed:
844
0
  if (report)
845
0
    report ("hmac", GCRY_MD_SHA512, what, errtxt);
846
0
  return GPG_ERR_SELFTEST_FAILED;
847
0
}
848
849
850
851
/* Test for the SHA3 algorithms.  Vectors taken on 2017-07-18 from
852
 * http://www.wolfgang-ehrhardt.de/hmac-sha3-testvectors.html  */
853
static gpg_err_code_t
854
selftests_sha3 (int hashalgo, int extended, selftest_report_func_t report)
855
0
{
856
0
  static struct
857
0
  {
858
0
    const char * const desc;
859
0
    const char * const data;
860
0
    const char * const key;
861
0
    const char expect_224[28];
862
0
    const char expect_256[32];
863
0
    const char expect_384[48];
864
0
    const char expect_512[64];
865
0
    unsigned char trunc;
866
0
  } tv[] =
867
0
    {
868
0
      { "data-9 key-20", /* Test 1 */
869
0
        "Hi There",
870
0
  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
871
0
        "\x0b\x0b\x0b\x0b",
872
873
0
        { 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
874
0
          0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
875
0
          0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
876
0
          0xf3, 0xc8, 0x60, 0xf7                          },
877
0
        { 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
878
0
          0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
879
0
          0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
880
0
          0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb  },
881
0
        { 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
882
0
          0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
883
0
          0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
884
0
          0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
885
0
          0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
886
0
          0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd  },
887
0
        { 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
888
0
          0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
889
0
          0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
890
0
          0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
891
0
          0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
892
0
          0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
893
0
          0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
894
0
          0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e  }
895
0
      },
896
897
0
      { "data-28 key-4",  /* Test 2  */
898
        /* Test with a key shorter than the length of the HMAC output. */
899
0
        "what do ya want for nothing?",
900
0
        "Jefe",
901
902
0
        { 0x7f, 0xdb, 0x8d, 0xd8, 0x8b, 0xd2, 0xf6, 0x0d,
903
0
          0x1b, 0x79, 0x86, 0x34, 0xad, 0x38, 0x68, 0x11,
904
0
          0xc2, 0xcf, 0xc8, 0x5b, 0xfa, 0xf5, 0xd5, 0x2b,
905
0
          0xba, 0xce, 0x5e, 0x66                          },
906
0
        { 0xc7, 0xd4, 0x07, 0x2e, 0x78, 0x88, 0x77, 0xae,
907
0
          0x35, 0x96, 0xbb, 0xb0, 0xda, 0x73, 0xb8, 0x87,
908
0
          0xc9, 0x17, 0x1f, 0x93, 0x09, 0x5b, 0x29, 0x4a,
909
0
          0xe8, 0x57, 0xfb, 0xe2, 0x64, 0x5e, 0x1b, 0xa5  },
910
0
        { 0xf1, 0x10, 0x1f, 0x8c, 0xbf, 0x97, 0x66, 0xfd,
911
0
          0x67, 0x64, 0xd2, 0xed, 0x61, 0x90, 0x3f, 0x21,
912
0
          0xca, 0x9b, 0x18, 0xf5, 0x7c, 0xf3, 0xe1, 0xa2,
913
0
          0x3c, 0xa1, 0x35, 0x08, 0xa9, 0x32, 0x43, 0xce,
914
0
          0x48, 0xc0, 0x45, 0xdc, 0x00, 0x7f, 0x26, 0xa2,
915
0
          0x1b, 0x3f, 0x5e, 0x0e, 0x9d, 0xf4, 0xc2, 0x0a  },
916
0
        { 0x5a, 0x4b, 0xfe, 0xab, 0x61, 0x66, 0x42, 0x7c,
917
0
          0x7a, 0x36, 0x47, 0xb7, 0x47, 0x29, 0x2b, 0x83,
918
0
          0x84, 0x53, 0x7c, 0xdb, 0x89, 0xaf, 0xb3, 0xbf,
919
0
          0x56, 0x65, 0xe4, 0xc5, 0xe7, 0x09, 0x35, 0x0b,
920
0
          0x28, 0x7b, 0xae, 0xc9, 0x21, 0xfd, 0x7c, 0xa0,
921
0
          0xee, 0x7a, 0x0c, 0x31, 0xd0, 0x22, 0xa9, 0x5e,
922
0
          0x1f, 0xc9, 0x2b, 0xa9, 0xd7, 0x7d, 0xf8, 0x83,
923
0
          0x96, 0x02, 0x75, 0xbe, 0xb4, 0xe6, 0x20, 0x24  }
924
0
      },
925
926
0
      { "data-50 key-20",  /* Test 3 */
927
        /* Test with a combined length of key and data that is larger
928
         * than 64 bytes (= block-size of SHA-224 and SHA-256).  */
929
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
930
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
931
0
        "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
932
0
        "\xdd\xdd",
933
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
934
0
        "\xaa\xaa\xaa\xaa",
935
936
0
        { 0x67, 0x6c, 0xfc, 0x7d, 0x16, 0x15, 0x36, 0x38,
937
0
          0x78, 0x03, 0x90, 0x69, 0x2b, 0xe1, 0x42, 0xd2,
938
0
          0xdf, 0x7c, 0xe9, 0x24, 0xb9, 0x09, 0xc0, 0xc0,
939
0
          0x8d, 0xbf, 0xdc, 0x1a  },
940
0
        { 0x84, 0xec, 0x79, 0x12, 0x4a, 0x27, 0x10, 0x78,
941
0
          0x65, 0xce, 0xdd, 0x8b, 0xd8, 0x2d, 0xa9, 0x96,
942
0
          0x5e, 0x5e, 0xd8, 0xc3, 0x7b, 0x0a, 0xc9, 0x80,
943
0
          0x05, 0xa7, 0xf3, 0x9e, 0xd5, 0x8a, 0x42, 0x07  },
944
0
        { 0x27, 0x5c, 0xd0, 0xe6, 0x61, 0xbb, 0x8b, 0x15,
945
0
          0x1c, 0x64, 0xd2, 0x88, 0xf1, 0xf7, 0x82, 0xfb,
946
0
          0x91, 0xa8, 0xab, 0xd5, 0x68, 0x58, 0xd7, 0x2b,
947
0
          0xab, 0xb2, 0xd4, 0x76, 0xf0, 0x45, 0x83, 0x73,
948
0
          0xb4, 0x1b, 0x6a, 0xb5, 0xbf, 0x17, 0x4b, 0xec,
949
0
          0x42, 0x2e, 0x53, 0xfc, 0x31, 0x35, 0xac, 0x6e  },
950
0
        { 0x30, 0x9e, 0x99, 0xf9, 0xec, 0x07, 0x5e, 0xc6,
951
0
          0xc6, 0xd4, 0x75, 0xed, 0xa1, 0x18, 0x06, 0x87,
952
0
          0xfc, 0xf1, 0x53, 0x11, 0x95, 0x80, 0x2a, 0x99,
953
0
          0xb5, 0x67, 0x74, 0x49, 0xa8, 0x62, 0x51, 0x82,
954
0
          0x85, 0x1c, 0xb3, 0x32, 0xaf, 0xb6, 0xa8, 0x9c,
955
0
          0x41, 0x13, 0x25, 0xfb, 0xcb, 0xcd, 0x42, 0xaf,
956
0
          0xcb, 0x7b, 0x6e, 0x5a, 0xab, 0x7e, 0xa4, 0x2c,
957
0
          0x66, 0x0f, 0x97, 0xfd, 0x85, 0x84, 0xbf, 0x03  }
958
0
      },
959
960
0
      { "data-50 key-25",  /* Test 4 */
961
        /* Test with a combined length of key and data that is larger
962
         * than 64 bytes (= block-size of SHA-224 and SHA-256).  */
963
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
964
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
965
0
        "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
966
0
        "\xcd\xcd",
967
0
        "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
968
0
        "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
969
970
0
        { 0xa9, 0xd7, 0x68, 0x5a, 0x19, 0xc4, 0xe0, 0xdb,
971
0
          0xd9, 0xdf, 0x25, 0x56, 0xcc, 0x8a, 0x7d, 0x2a,
972
0
          0x77, 0x33, 0xb6, 0x76, 0x25, 0xce, 0x59, 0x4c,
973
0
          0x78, 0x27, 0x0e, 0xeb   },
974
0
        { 0x57, 0x36, 0x6a, 0x45, 0xe2, 0x30, 0x53, 0x21,
975
0
          0xa4, 0xbc, 0x5a, 0xa5, 0xfe, 0x2e, 0xf8, 0xa9,
976
0
          0x21, 0xf6, 0xaf, 0x82, 0x73, 0xd7, 0xfe, 0x7b,
977
0
          0xe6, 0xcf, 0xed, 0xb3, 0xf0, 0xae, 0xa6, 0xd7  },
978
0
        { 0x3a, 0x5d, 0x7a, 0x87, 0x97, 0x02, 0xc0, 0x86,
979
0
          0xbc, 0x96, 0xd1, 0xdd, 0x8a, 0xa1, 0x5d, 0x9c,
980
0
          0x46, 0x44, 0x6b, 0x95, 0x52, 0x13, 0x11, 0xc6,
981
0
          0x06, 0xfd, 0xc4, 0xe3, 0x08, 0xf4, 0xb9, 0x84,
982
0
          0xda, 0x2d, 0x0f, 0x94, 0x49, 0xb3, 0xba, 0x84,
983
0
          0x25, 0xec, 0x7f, 0xb8, 0xc3, 0x1b, 0xc1, 0x36  },
984
0
        { 0xb2, 0x7e, 0xab, 0x1d, 0x6e, 0x8d, 0x87, 0x46,
985
0
          0x1c, 0x29, 0xf7, 0xf5, 0x73, 0x9d, 0xd5, 0x8e,
986
0
          0x98, 0xaa, 0x35, 0xf8, 0xe8, 0x23, 0xad, 0x38,
987
0
          0xc5, 0x49, 0x2a, 0x20, 0x88, 0xfa, 0x02, 0x81,
988
0
          0x99, 0x3b, 0xbf, 0xff, 0x9a, 0x0e, 0x9c, 0x6b,
989
0
          0xf1, 0x21, 0xae, 0x9e, 0xc9, 0xbb, 0x09, 0xd8,
990
0
          0x4a, 0x5e, 0xba, 0xc8, 0x17, 0x18, 0x2e, 0xa9,
991
0
          0x74, 0x67, 0x3f, 0xb1, 0x33, 0xca, 0x0d, 0x1d  }
992
0
      },
993
994
0
      { "data-20 key-20 trunc",  /* Test 5 */
995
        /* Test with a truncation of output to 128 bits.  */
996
0
        "Test With Truncation",
997
0
        "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
998
0
        "\x0c\x0c\x0c\x0c",
999
1000
0
        { 0x49, 0xfd, 0xd3, 0xab, 0xd0, 0x05, 0xeb, 0xb8,
1001
0
          0xae, 0x63, 0xfe, 0xa9, 0x46, 0xd1, 0x88, 0x3c  },
1002
0
        { 0x6e, 0x02, 0xc6, 0x45, 0x37, 0xfb, 0x11, 0x80,
1003
0
          0x57, 0xab, 0xb7, 0xfb, 0x66, 0xa2, 0x3b, 0x3c  },
1004
0
        { 0x47, 0xc5, 0x1a, 0xce, 0x1f, 0xfa, 0xcf, 0xfd,
1005
0
          0x74, 0x94, 0x72, 0x46, 0x82, 0x61, 0x57, 0x83  },
1006
0
        { 0x0f, 0xa7, 0x47, 0x59, 0x48, 0xf4, 0x3f, 0x48,
1007
0
          0xca, 0x05, 0x16, 0x67, 0x1e, 0x18, 0x97, 0x8c  },
1008
0
        16
1009
0
      },
1010
1011
0
      { "data-54 key-131",  /* Test 6 */
1012
        /* Test with a key larger than 128 bytes (= block-size of
1013
         * SHA-384 and SHA-512).  */
1014
0
        "Test Using Larger Than Block-Size Key - Hash Key First",
1015
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1016
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1017
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1018
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1019
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1020
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1021
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1022
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1023
0
        "\xaa\xaa\xaa",
1024
1025
0
        { 0xb4, 0xa1, 0xf0, 0x4c, 0x00, 0x28, 0x7a, 0x9b,
1026
0
          0x7f, 0x60, 0x75, 0xb3, 0x13, 0xd2, 0x79, 0xb8,
1027
0
          0x33, 0xbc, 0x8f, 0x75, 0x12, 0x43, 0x52, 0xd0,
1028
0
          0x5f, 0xb9, 0x99, 0x5f  },
1029
0
        { 0xed, 0x73, 0xa3, 0x74, 0xb9, 0x6c, 0x00, 0x52,
1030
0
          0x35, 0xf9, 0x48, 0x03, 0x2f, 0x09, 0x67, 0x4a,
1031
0
          0x58, 0xc0, 0xce, 0x55, 0x5c, 0xfc, 0x1f, 0x22,
1032
0
          0x3b, 0x02, 0x35, 0x65, 0x60, 0x31, 0x2c, 0x3b  },
1033
0
        { 0x0f, 0xc1, 0x95, 0x13, 0xbf, 0x6b, 0xd8, 0x78,
1034
0
          0x03, 0x70, 0x16, 0x70, 0x6a, 0x0e, 0x57, 0xbc,
1035
0
          0x52, 0x81, 0x39, 0x83, 0x6b, 0x9a, 0x42, 0xc3,
1036
0
          0xd4, 0x19, 0xe4, 0x98, 0xe0, 0xe1, 0xfb, 0x96,
1037
0
          0x16, 0xfd, 0x66, 0x91, 0x38, 0xd3, 0x3a, 0x11,
1038
0
          0x05, 0xe0, 0x7c, 0x72, 0xb6, 0x95, 0x3b, 0xcc  },
1039
0
        { 0x00, 0xf7, 0x51, 0xa9, 0xe5, 0x06, 0x95, 0xb0,
1040
0
          0x90, 0xed, 0x69, 0x11, 0xa4, 0xb6, 0x55, 0x24,
1041
0
          0x95, 0x1c, 0xdc, 0x15, 0xa7, 0x3a, 0x5d, 0x58,
1042
0
          0xbb, 0x55, 0x21, 0x5e, 0xa2, 0xcd, 0x83, 0x9a,
1043
0
          0xc7, 0x9d, 0x2b, 0x44, 0xa3, 0x9b, 0xaf, 0xab,
1044
0
          0x27, 0xe8, 0x3f, 0xde, 0x9e, 0x11, 0xf6, 0x34,
1045
0
          0x0b, 0x11, 0xd9, 0x91, 0xb1, 0xb9, 0x1b, 0xf2,
1046
0
          0xee, 0xe7, 0xfc, 0x87, 0x24, 0x26, 0xc3, 0xa4  }
1047
0
      },
1048
1049
0
      { "data-54 key-147",  /* Test 6a */
1050
        /* Test with a key larger than 144 bytes (= block-size of
1051
         * SHA3-224).  */
1052
0
        "Test Using Larger Than Block-Size Key - Hash Key First",
1053
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1054
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1055
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1056
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1057
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1058
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1059
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1060
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1061
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1062
0
        "\xaa\xaa\xaa",
1063
1064
0
        { 0xb9, 0x6d, 0x73, 0x0c, 0x14, 0x8c, 0x2d, 0xaa,
1065
0
          0xd8, 0x64, 0x9d, 0x83, 0xde, 0xfa, 0xa3, 0x71,
1066
0
          0x97, 0x38, 0xd3, 0x47, 0x75, 0x39, 0x7b, 0x75,
1067
0
          0x71, 0xc3, 0x85, 0x15  },
1068
0
        { 0xa6, 0x07, 0x2f, 0x86, 0xde, 0x52, 0xb3, 0x8b,
1069
0
          0xb3, 0x49, 0xfe, 0x84, 0xcd, 0x6d, 0x97, 0xfb,
1070
0
          0x6a, 0x37, 0xc4, 0xc0, 0xf6, 0x2a, 0xae, 0x93,
1071
0
          0x98, 0x11, 0x93, 0xa7, 0x22, 0x9d, 0x34, 0x67  },
1072
0
        { 0x71, 0x3d, 0xff, 0x03, 0x02, 0xc8, 0x50, 0x86,
1073
0
          0xec, 0x5a, 0xd0, 0x76, 0x8d, 0xd6, 0x5a, 0x13,
1074
0
          0xdd, 0xd7, 0x90, 0x68, 0xd8, 0xd4, 0xc6, 0x21,
1075
0
          0x2b, 0x71, 0x2e, 0x41, 0x64, 0x94, 0x49, 0x11,
1076
0
          0x14, 0x80, 0x23, 0x00, 0x44, 0x18, 0x5a, 0x99,
1077
0
          0x10, 0x3e, 0xd8, 0x20, 0x04, 0xdd, 0xbf, 0xcc  },
1078
0
        { 0xb1, 0x48, 0x35, 0xc8, 0x19, 0xa2, 0x90, 0xef,
1079
0
          0xb0, 0x10, 0xac, 0xe6, 0xd8, 0x56, 0x8d, 0xc6,
1080
0
          0xb8, 0x4d, 0xe6, 0x0b, 0xc4, 0x9b, 0x00, 0x4c,
1081
0
          0x3b, 0x13, 0xed, 0xa7, 0x63, 0x58, 0x94, 0x51,
1082
0
          0xe5, 0xdd, 0x74, 0x29, 0x28, 0x84, 0xd1, 0xbd,
1083
0
          0xce, 0x64, 0xe6, 0xb9, 0x19, 0xdd, 0x61, 0xdc,
1084
0
          0x9c, 0x56, 0xa2, 0x82, 0xa8, 0x1c, 0x0b, 0xd1,
1085
0
          0x4f, 0x1f, 0x36, 0x5b, 0x49, 0xb8, 0x3a, 0x5b  }
1086
0
      },
1087
1088
0
      { "data-152 key-131",  /* Test 7  */
1089
        /* Test with a key and data that is larger than 128 bytes (=
1090
         * block-size of SHA-384 and SHA-512).  */
1091
0
        "This is a test using a larger than block-size key and a larger "
1092
0
        "than block-size data. The key needs to be hashed before being "
1093
0
        "used by the HMAC algorithm.",
1094
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1095
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1096
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1097
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1098
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1099
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1100
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1101
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1102
0
        "\xaa\xaa\xaa",
1103
1104
0
        { 0x05, 0xd8, 0xcd, 0x6d, 0x00, 0xfa, 0xea, 0x8d,
1105
0
          0x1e, 0xb6, 0x8a, 0xde, 0x28, 0x73, 0x0b, 0xbd,
1106
0
          0x3c, 0xba, 0xb6, 0x92, 0x9f, 0x0a, 0x08, 0x6b,
1107
0
          0x29, 0xcd, 0x62, 0xa0  },
1108
0
        { 0x65, 0xc5, 0xb0, 0x6d, 0x4c, 0x3d, 0xe3, 0x2a,
1109
0
          0x7a, 0xef, 0x87, 0x63, 0x26, 0x1e, 0x49, 0xad,
1110
0
          0xb6, 0xe2, 0x29, 0x3e, 0xc8, 0xe7, 0xc6, 0x1e,
1111
0
          0x8d, 0xe6, 0x17, 0x01, 0xfc, 0x63, 0xe1, 0x23  },
1112
0
        { 0x02, 0x6f, 0xdf, 0x6b, 0x50, 0x74, 0x1e, 0x37,
1113
0
          0x38, 0x99, 0xc9, 0xf7, 0xd5, 0x40, 0x6d, 0x4e,
1114
0
          0xb0, 0x9f, 0xc6, 0x66, 0x56, 0x36, 0xfc, 0x1a,
1115
0
          0x53, 0x00, 0x29, 0xdd, 0xf5, 0xcf, 0x3c, 0xa5,
1116
0
          0xa9, 0x00, 0xed, 0xce, 0x01, 0xf5, 0xf6, 0x1e,
1117
0
          0x2f, 0x40, 0x8c, 0xdf, 0x2f, 0xd3, 0xe7, 0xe8  },
1118
0
        { 0x38, 0xa4, 0x56, 0xa0, 0x04, 0xbd, 0x10, 0xd3,
1119
0
          0x2c, 0x9a, 0xb8, 0x33, 0x66, 0x84, 0x11, 0x28,
1120
0
          0x62, 0xc3, 0xdb, 0x61, 0xad, 0xcc, 0xa3, 0x18,
1121
0
          0x29, 0x35, 0x5e, 0xaf, 0x46, 0xfd, 0x5c, 0x73,
1122
0
          0xd0, 0x6a, 0x1f, 0x0d, 0x13, 0xfe, 0xc9, 0xa6,
1123
0
          0x52, 0xfb, 0x38, 0x11, 0xb5, 0x77, 0xb1, 0xb1,
1124
0
          0xd1, 0xb9, 0x78, 0x9f, 0x97, 0xae, 0x5b, 0x83,
1125
0
          0xc6, 0xf4, 0x4d, 0xfc, 0xf1, 0xd6, 0x7e, 0xba  }
1126
0
      },
1127
1128
0
      { "data-152 key-147",  /* Test 7a  */
1129
        /* Test with a key larger than 144 bytes (= block-size of
1130
         * SHA3-224). */
1131
0
        "This is a test using a larger than block-size key and a larger "
1132
0
        "than block-size data. The key needs to be hashed before being "
1133
0
        "used by the HMAC algorithm.",
1134
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1135
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1136
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1137
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1138
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1139
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1140
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1141
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1142
0
        "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1143
0
        "\xaa\xaa\xaa",
1144
1145
0
        { 0xc7, 0x9c, 0x9b, 0x09, 0x34, 0x24, 0xe5, 0x88,
1146
0
          0xa9, 0x87, 0x8b, 0xbc, 0xb0, 0x89, 0xe0, 0x18,
1147
0
          0x27, 0x00, 0x96, 0xe9, 0xb4, 0xb1, 0xa9, 0xe8,
1148
0
          0x22, 0x0c, 0x86, 0x6a  },
1149
0
        { 0xe6, 0xa3, 0x6d, 0x9b, 0x91, 0x5f, 0x86, 0xa0,
1150
0
          0x93, 0xca, 0xc7, 0xd1, 0x10, 0xe9, 0xe0, 0x4c,
1151
0
          0xf1, 0xd6, 0x10, 0x0d, 0x30, 0x47, 0x55, 0x09,
1152
0
          0xc2, 0x47, 0x5f, 0x57, 0x1b, 0x75, 0x8b, 0x5a  },
1153
0
        { 0xca, 0xd1, 0x8a, 0x8f, 0xf6, 0xc4, 0xcc, 0x3a,
1154
0
          0xd4, 0x87, 0xb9, 0x5f, 0x97, 0x69, 0xe9, 0xb6,
1155
0
          0x1c, 0x06, 0x2a, 0xef, 0xd6, 0x95, 0x25, 0x69,
1156
0
          0xe6, 0xe6, 0x42, 0x18, 0x97, 0x05, 0x4c, 0xfc,
1157
0
          0x70, 0xb5, 0xfd, 0xc6, 0x60, 0x5c, 0x18, 0x45,
1158
0
          0x71, 0x12, 0xfc, 0x6a, 0xaa, 0xd4, 0x55, 0x85  },
1159
0
        { 0xdc, 0x03, 0x0e, 0xe7, 0x88, 0x70, 0x34, 0xf3,
1160
0
          0x2c, 0xf4, 0x02, 0xdf, 0x34, 0x62, 0x2f, 0x31,
1161
0
          0x1f, 0x3e, 0x6c, 0xf0, 0x48, 0x60, 0xc6, 0xbb,
1162
0
          0xd7, 0xfa, 0x48, 0x86, 0x74, 0x78, 0x2b, 0x46,
1163
0
          0x59, 0xfd, 0xbd, 0xf3, 0xfd, 0x87, 0x78, 0x52,
1164
0
          0x88, 0x5c, 0xfe, 0x6e, 0x22, 0x18, 0x5f, 0xe7,
1165
0
          0xb2, 0xee, 0x95, 0x20, 0x43, 0x62, 0x9b, 0xc9,
1166
0
          0xd5, 0xf3, 0x29, 0x8a, 0x41, 0xd0, 0x2c, 0x66  }
1167
0
      }/*,*/
1168
1169
      /* Our API does not allow to specify a bit count and thus we
1170
       * can't use the following test.  */
1171
      /* { "data-5bit key-4",  /\* Test 8  *\/ */
1172
      /*   /\* Test with data bit size no multiple of 8, the data bits are */
1173
      /*    * '11001' from the NIST example using SHA-3 order (= 5 bits */
1174
      /*    * from LSB hex byte 13 or 5 bits from MSB hex byte c8).  *\/ */
1175
      /*   "\xc8", */
1176
      /*   "Jefe", */
1177
1178
      /*   { 0x5f, 0x8c, 0x0e, 0xa7, 0xfa, 0xfe, 0xcd, 0x0c, */
1179
      /*     0x34, 0x63, 0xaa, 0xd0, 0x97, 0x42, 0xce, 0xce, */
1180
      /*     0xb1, 0x42, 0xfe, 0x0a, 0xb6, 0xf4, 0x53, 0x94, */
1181
      /*     0x38, 0xc5, 0x9d, 0xe8  }, */
1182
      /*   { 0xec, 0x82, 0x22, 0x77, 0x3f, 0xac, 0x68, 0xb3, */
1183
      /*     0xd3, 0xdc, 0xb1, 0x82, 0xae, 0xc8, 0xb0, 0x50, */
1184
      /*     0x7a, 0xce, 0x44, 0x48, 0xd2, 0x0a, 0x11, 0x47, */
1185
      /*     0xe6, 0x82, 0x11, 0x8d, 0xa4, 0xe3, 0xf4, 0x4c  }, */
1186
      /*   { 0x21, 0xfb, 0xd3, 0xbf, 0x3e, 0xbb, 0xa3, 0xcf, */
1187
      /*     0xc9, 0xef, 0x64, 0xc0, 0x59, 0x1c, 0x92, 0xc5, */
1188
      /*     0xac, 0xb2, 0x65, 0xe9, 0x2d, 0x87, 0x61, 0xd1, */
1189
      /*     0xf9, 0x1a, 0x52, 0xa1, 0x03, 0xa6, 0xc7, 0x96, */
1190
      /*     0x94, 0xcf, 0xd6, 0x7a, 0x9a, 0x2a, 0xc1, 0x32, */
1191
      /*     0x4f, 0x02, 0xfe, 0xa6, 0x3b, 0x81, 0xef, 0xfc  }, */
1192
      /*   { 0x27, 0xf9, 0x38, 0x8c, 0x15, 0x67, 0xef, 0x4e, */
1193
      /*     0xf2, 0x00, 0x60, 0x2a, 0x6c, 0xf8, 0x71, 0xd6, */
1194
      /*     0x8a, 0x6f, 0xb0, 0x48, 0xd4, 0x73, 0x7a, 0xc4, */
1195
      /*     0x41, 0x8a, 0x2f, 0x02, 0x12, 0x89, 0xd1, 0x3d, */
1196
      /*     0x1f, 0xd1, 0x12, 0x0f, 0xec, 0xb9, 0xcf, 0x96, */
1197
      /*     0x4c, 0x5b, 0x11, 0x7a, 0xb5, 0xb1, 0x1c, 0x61, */
1198
      /*     0x4b, 0x2d, 0xa3, 0x9d, 0xad, 0xd5, 0x1f, 0x2f, */
1199
      /*     0x5e, 0x22, 0xaa, 0xcc, 0xec, 0x7d, 0x57, 0x6e  } */
1200
      /* } */
1201
1202
0
    };
1203
0
  const char *what;
1204
0
  const char *errtxt;
1205
0
  int tvidx;
1206
0
  const char *expect;
1207
0
  int nexpect;
1208
1209
0
  for (tvidx=0; tvidx < DIM(tv); tvidx++)
1210
0
    {
1211
0
      what = tv[tvidx].desc;
1212
0
      if (hashalgo == GCRY_MD_SHA3_224)
1213
0
        {
1214
0
          expect = tv[tvidx].expect_224;
1215
0
          nexpect = DIM (tv[tvidx].expect_224);
1216
0
        }
1217
0
      else if (hashalgo == GCRY_MD_SHA3_256)
1218
0
        {
1219
0
          expect = tv[tvidx].expect_256;
1220
0
          nexpect = DIM (tv[tvidx].expect_256);
1221
0
        }
1222
0
      else if (hashalgo == GCRY_MD_SHA3_384)
1223
0
        {
1224
0
          expect = tv[tvidx].expect_384;
1225
0
          nexpect = DIM (tv[tvidx].expect_384);
1226
0
        }
1227
0
      else if (hashalgo == GCRY_MD_SHA3_512)
1228
0
        {
1229
0
          expect = tv[tvidx].expect_512;
1230
0
          nexpect = DIM (tv[tvidx].expect_512);
1231
0
        }
1232
0
      else
1233
0
        BUG();
1234
1235
0
      if (tv[tvidx].trunc && tv[tvidx].trunc < nexpect)
1236
0
        nexpect = tv[tvidx].trunc;
1237
1238
0
      errtxt = check_one (hashalgo,
1239
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
1240
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
1241
0
                          expect, nexpect, !!tv[tvidx].trunc);
1242
0
      if (errtxt)
1243
0
        goto failed;
1244
0
      if (!extended)
1245
0
        break;
1246
0
    }
1247
1248
0
  return 0; /* Succeeded. */
1249
1250
0
 failed:
1251
0
  if (report)
1252
0
    report ("hmac", hashalgo, what, errtxt);
1253
0
  return GPG_ERR_SELFTEST_FAILED;
1254
0
}
1255
1256
1257
static gpg_err_code_t
1258
hmac_selftest (int algo, int extended, selftest_report_func_t report)
1259
0
{
1260
0
  gpg_err_code_t ec;
1261
1262
0
  switch (algo)
1263
0
    {
1264
0
    case GCRY_MAC_HMAC_SHA1:
1265
0
      ec = selftests_sha1 (extended, report);
1266
0
      break;
1267
0
    case GCRY_MAC_HMAC_SHA224:
1268
0
      ec = selftests_sha224 (extended, report);
1269
0
      break;
1270
0
    case GCRY_MAC_HMAC_SHA256:
1271
0
      ec = selftests_sha256 (extended, report);
1272
0
      break;
1273
0
    case GCRY_MAC_HMAC_SHA384:
1274
0
      ec = selftests_sha384 (extended, report);
1275
0
      break;
1276
0
    case GCRY_MAC_HMAC_SHA512:
1277
0
      ec = selftests_sha512 (extended, report);
1278
0
      break;
1279
1280
0
    case GCRY_MAC_HMAC_SHA3_224:
1281
0
    case GCRY_MAC_HMAC_SHA3_256:
1282
0
    case GCRY_MAC_HMAC_SHA3_384:
1283
0
    case GCRY_MAC_HMAC_SHA3_512:
1284
0
      {
1285
0
        int md_algo = map_mac_algo_to_md (algo);
1286
0
        ec = selftests_sha3 (md_algo, extended, report);
1287
0
      }
1288
0
      break;
1289
1290
0
    default:
1291
0
      ec = GPG_ERR_MAC_ALGO;
1292
0
      break;
1293
0
    }
1294
1295
0
  return ec;
1296
0
}
1297
1298
1299
static const gcry_mac_spec_ops_t hmac_ops = {
1300
  hmac_open,
1301
  hmac_close,
1302
  hmac_setkey,
1303
  NULL,
1304
  hmac_reset,
1305
  hmac_write,
1306
  hmac_read,
1307
  hmac_verify,
1308
  hmac_get_maclen,
1309
  hmac_get_keylen,
1310
  NULL,
1311
  hmac_selftest
1312
};
1313
1314
1315
#if USE_SHA1
1316
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha1 = {
1317
  GCRY_MAC_HMAC_SHA1, {0, 1}, "HMAC_SHA1",
1318
  &hmac_ops
1319
};
1320
#endif
1321
#if USE_SHA256
1322
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha256 = {
1323
  GCRY_MAC_HMAC_SHA256, {0, 1}, "HMAC_SHA256",
1324
  &hmac_ops
1325
};
1326
1327
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha224 = {
1328
  GCRY_MAC_HMAC_SHA224, {0, 1}, "HMAC_SHA224",
1329
  &hmac_ops
1330
};
1331
#endif
1332
#if USE_SHA512
1333
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha512 = {
1334
  GCRY_MAC_HMAC_SHA512, {0, 1}, "HMAC_SHA512",
1335
  &hmac_ops
1336
};
1337
1338
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha384 = {
1339
  GCRY_MAC_HMAC_SHA384, {0, 1}, "HMAC_SHA384",
1340
  &hmac_ops
1341
};
1342
1343
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha512_256 = {
1344
  GCRY_MAC_HMAC_SHA512_256, {0, 1}, "HMAC_SHA512_256",
1345
  &hmac_ops
1346
};
1347
1348
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha512_224 = {
1349
  GCRY_MAC_HMAC_SHA512_224, {0, 1}, "HMAC_SHA512_224",
1350
  &hmac_ops
1351
};
1352
1353
#endif
1354
#if USE_SHA3
1355
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha3_224 = {
1356
  GCRY_MAC_HMAC_SHA3_224, {0, 1}, "HMAC_SHA3_224",
1357
  &hmac_ops
1358
};
1359
1360
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha3_256 = {
1361
  GCRY_MAC_HMAC_SHA3_256, {0, 1}, "HMAC_SHA3_256",
1362
  &hmac_ops
1363
};
1364
1365
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha3_384 = {
1366
  GCRY_MAC_HMAC_SHA3_384, {0, 1}, "HMAC_SHA3_384",
1367
  &hmac_ops
1368
};
1369
1370
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sha3_512 = {
1371
  GCRY_MAC_HMAC_SHA3_512, {0, 1}, "HMAC_SHA3_512",
1372
  &hmac_ops
1373
};
1374
#endif
1375
#if USE_GOST_R_3411_94
1376
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_gost3411_94 = {
1377
  GCRY_MAC_HMAC_GOSTR3411_94, {0, 0}, "HMAC_GOSTR3411_94",
1378
  &hmac_ops
1379
};
1380
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_gost3411_cp = {
1381
  GCRY_MAC_HMAC_GOSTR3411_CP, {0, 0}, "HMAC_GOSTR3411_CP",
1382
  &hmac_ops
1383
};
1384
#endif
1385
#if USE_GOST_R_3411_12
1386
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_stribog256 = {
1387
  GCRY_MAC_HMAC_STRIBOG256, {0, 0}, "HMAC_STRIBOG256",
1388
  &hmac_ops
1389
};
1390
1391
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_stribog512 = {
1392
  GCRY_MAC_HMAC_STRIBOG512, {0, 0}, "HMAC_STRIBOG512",
1393
  &hmac_ops
1394
};
1395
#endif
1396
#if USE_WHIRLPOOL
1397
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_whirlpool = {
1398
  GCRY_MAC_HMAC_WHIRLPOOL, {0, 0}, "HMAC_WHIRLPOOL",
1399
  &hmac_ops
1400
};
1401
#endif
1402
#if USE_RMD160
1403
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_rmd160 = {
1404
  GCRY_MAC_HMAC_RMD160, {0, 0}, "HMAC_RIPEMD160",
1405
  &hmac_ops
1406
};
1407
#endif
1408
#if USE_TIGER
1409
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_tiger1 = {
1410
  GCRY_MAC_HMAC_TIGER1, {0, 0}, "HMAC_TIGER",
1411
  &hmac_ops
1412
};
1413
#endif
1414
#if USE_MD5
1415
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_md5 = {
1416
  GCRY_MAC_HMAC_MD5, {0, 0}, "HMAC_MD5",
1417
  &hmac_ops
1418
};
1419
#endif
1420
#if USE_MD4
1421
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_md4 = {
1422
  GCRY_MAC_HMAC_MD4, {0, 0}, "HMAC_MD4",
1423
  &hmac_ops
1424
};
1425
#endif
1426
#if USE_MD2
1427
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_md2 = {
1428
  GCRY_MAC_HMAC_MD2, {0, 0}, "HMAC_MD2",
1429
  &hmac_ops
1430
};
1431
#endif
1432
#if USE_BLAKE2
1433
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2b_512 = {
1434
  GCRY_MAC_HMAC_BLAKE2B_512, {0, 0}, "HMAC_BLAKE2B_512",
1435
  &hmac_ops
1436
};
1437
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2b_384 = {
1438
  GCRY_MAC_HMAC_BLAKE2B_384, {0, 0}, "HMAC_BLAKE2B_384",
1439
  &hmac_ops
1440
};
1441
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2b_256 = {
1442
  GCRY_MAC_HMAC_BLAKE2B_256, {0, 0}, "HMAC_BLAKE2B_256",
1443
  &hmac_ops
1444
};
1445
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2b_160 = {
1446
  GCRY_MAC_HMAC_BLAKE2B_160, {0, 0}, "HMAC_BLAKE2B_160",
1447
  &hmac_ops
1448
};
1449
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2s_256 = {
1450
  GCRY_MAC_HMAC_BLAKE2S_256, {0, 0}, "HMAC_BLAKE2S_256",
1451
  &hmac_ops
1452
};
1453
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2s_224 = {
1454
  GCRY_MAC_HMAC_BLAKE2S_224, {0, 0}, "HMAC_BLAKE2S_224",
1455
  &hmac_ops
1456
};
1457
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2s_160 = {
1458
  GCRY_MAC_HMAC_BLAKE2S_160, {0, 0}, "HMAC_BLAKE2S_160",
1459
  &hmac_ops
1460
};
1461
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_blake2s_128 = {
1462
  GCRY_MAC_HMAC_BLAKE2S_128, {0, 0}, "HMAC_BLAKE2S_128",
1463
  &hmac_ops
1464
};
1465
#endif
1466
#if USE_SM3
1467
const gcry_mac_spec_t _gcry_mac_type_spec_hmac_sm3 = {
1468
  GCRY_MAC_HMAC_SM3, {0, 0}, "HMAC_SM3",
1469
  &hmac_ops
1470
};
1471
#endif