Coverage Report

Created: 2022-12-08 06:10

/src/libgcrypt/cipher/mac-cmac.c
Line
Count
Source (jump to first uncovered line)
1
/* mac-cmac.c  -  CMAC 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 "cipher.h"
29
#include "./mac-internal.h"
30
31
32
static int
33
map_mac_algo_to_cipher (int mac_algo)
34
0
{
35
0
  switch (mac_algo)
36
0
    {
37
0
    default:
38
0
      return GCRY_CIPHER_NONE;
39
0
    case GCRY_MAC_CMAC_AES:
40
0
      return GCRY_CIPHER_AES;
41
0
    case GCRY_MAC_CMAC_3DES:
42
0
      return GCRY_CIPHER_3DES;
43
0
    case GCRY_MAC_CMAC_CAMELLIA:
44
0
      return GCRY_CIPHER_CAMELLIA128;
45
0
    case GCRY_MAC_CMAC_IDEA:
46
0
      return GCRY_CIPHER_IDEA;
47
0
    case GCRY_MAC_CMAC_CAST5:
48
0
      return GCRY_CIPHER_CAST5;
49
0
    case GCRY_MAC_CMAC_BLOWFISH:
50
0
      return GCRY_CIPHER_BLOWFISH;
51
0
    case GCRY_MAC_CMAC_TWOFISH:
52
0
      return GCRY_CIPHER_TWOFISH;
53
0
    case GCRY_MAC_CMAC_SERPENT:
54
0
      return GCRY_CIPHER_SERPENT128;
55
0
    case GCRY_MAC_CMAC_SEED:
56
0
      return GCRY_CIPHER_SEED;
57
0
    case GCRY_MAC_CMAC_RFC2268:
58
0
      return GCRY_CIPHER_RFC2268_128;
59
0
    case GCRY_MAC_CMAC_GOST28147:
60
0
      return GCRY_CIPHER_GOST28147;
61
0
    case GCRY_MAC_CMAC_SM4:
62
0
      return GCRY_CIPHER_SM4;
63
0
    }
64
0
}
65
66
67
static gcry_err_code_t
68
cmac_open (gcry_mac_hd_t h)
69
0
{
70
0
  gcry_err_code_t err;
71
0
  gcry_cipher_hd_t hd;
72
0
  int secure = (h->magic == CTX_MAC_MAGIC_SECURE);
73
0
  int cipher_algo;
74
0
  unsigned int flags;
75
76
0
  cipher_algo = map_mac_algo_to_cipher (h->spec->algo);
77
0
  flags = (secure ? GCRY_CIPHER_SECURE : 0);
78
79
0
  err = _gcry_cipher_open_internal (&hd, cipher_algo, GCRY_CIPHER_MODE_CMAC,
80
0
                                    flags);
81
0
  if (err)
82
0
    return err;
83
84
0
  h->u.cmac.cipher_algo = cipher_algo;
85
0
  h->u.cmac.ctx = hd;
86
0
  h->u.cmac.blklen = _gcry_cipher_get_algo_blklen (cipher_algo);
87
0
  return 0;
88
0
}
89
90
91
static void
92
cmac_close (gcry_mac_hd_t h)
93
0
{
94
0
  _gcry_cipher_close (h->u.cmac.ctx);
95
0
  h->u.cmac.ctx = NULL;
96
0
}
97
98
99
static gcry_err_code_t
100
cmac_setkey (gcry_mac_hd_t h, const unsigned char *key, size_t keylen)
101
0
{
102
0
  return _gcry_cipher_setkey (h->u.cmac.ctx, key, keylen);
103
0
}
104
105
106
static gcry_err_code_t
107
cmac_reset (gcry_mac_hd_t h)
108
0
{
109
0
  return _gcry_cipher_reset (h->u.cmac.ctx);
110
0
}
111
112
113
static gcry_err_code_t
114
cmac_write (gcry_mac_hd_t h, const unsigned char *buf, size_t buflen)
115
0
{
116
0
  return _gcry_cipher_cmac_authenticate (h->u.cmac.ctx, buf, buflen);
117
0
}
118
119
120
static gcry_err_code_t
121
cmac_read (gcry_mac_hd_t h, unsigned char *outbuf, size_t * outlen)
122
0
{
123
0
  if (*outlen > h->u.cmac.blklen)
124
0
    *outlen = h->u.cmac.blklen;
125
0
  return _gcry_cipher_cmac_get_tag (h->u.cmac.ctx, outbuf, *outlen);
126
0
}
127
128
129
static gcry_err_code_t
130
cmac_verify (gcry_mac_hd_t h, const unsigned char *buf, size_t buflen)
131
0
{
132
0
  return _gcry_cipher_cmac_check_tag (h->u.cmac.ctx, buf, buflen);
133
0
}
134
135
136
static unsigned int
137
cmac_get_maclen (int algo)
138
0
{
139
0
  return _gcry_cipher_get_algo_blklen (map_mac_algo_to_cipher (algo));
140
0
}
141
142
143
static unsigned int
144
cmac_get_keylen (int algo)
145
0
{
146
0
  return _gcry_cipher_get_algo_keylen (map_mac_algo_to_cipher (algo));
147
0
}
148
149
150
/* Check one CMAC with MAC ALGO using the regular MAC
151
 * API. (DATA,DATALEN) is the data to be MACed, (KEY,KEYLEN) the key
152
 * and (EXPECT,EXPECTLEN) the expected result.  Returns NULL on
153
 * success or a string describing the failure.  */
154
static const char *
155
check_one (int algo, const char *data, size_t datalen,
156
           const char *key, size_t keylen,
157
           const char *expect, size_t expectlen)
158
0
{
159
0
  gcry_mac_hd_t hd;
160
0
  unsigned char mac[512]; /* hardcoded to avoid allocation */
161
0
  unsigned int maclen;
162
0
  size_t macoutlen;
163
0
  int i;
164
0
  gcry_error_t err = 0;
165
166
0
  err = _gcry_mac_open (&hd, algo, 0, NULL);
167
0
  if (err)
168
0
    return "gcry_mac_open failed";
169
170
0
  i = _gcry_mac_get_algo (hd);
171
0
  if (i != algo)
172
0
    return "gcry_mac_get_algo failed";
173
174
0
  maclen = _gcry_mac_get_algo_maclen (algo);
175
0
  if (maclen < 1 || maclen > 500)
176
0
    return "gcry_mac_get_algo_maclen failed";
177
178
0
  if (maclen != expectlen)
179
0
    return "invalid tests data";
180
181
0
  err = _gcry_mac_setkey (hd, key, keylen);
182
0
  if (err)
183
0
    {
184
0
      _gcry_mac_close (hd);
185
0
      return "gcry_mac_setkey failed";
186
0
    }
187
188
0
  err = _gcry_mac_write (hd, data, datalen);
189
0
  if (err)
190
0
    {
191
0
      _gcry_mac_close (hd);
192
0
      return "gcry_mac_write failed";
193
0
    }
194
195
0
  err = _gcry_mac_verify (hd, expect, maclen);
196
0
  if (err)
197
0
    {
198
0
      _gcry_mac_close (hd);
199
0
      return "gcry_mac_verify failed";
200
0
    }
201
202
0
  macoutlen = maclen;
203
0
  err = _gcry_mac_read (hd, mac, &macoutlen);
204
0
  _gcry_mac_close (hd);
205
0
  if (err)
206
0
    return "gcry_mac_read failed";
207
208
0
  if (memcmp (mac, expect, maclen))
209
0
    return "does not match";
210
211
0
  return NULL;
212
0
}
213
214
215
/*
216
 * CMAC AES and DES test vectors are from
217
 * http://web.archive.org/web/20130930212819/http://csrc.nist.gov/publica \
218
 * tions/nistpubs/800-38B/Updated_CMAC_Examples.pdf
219
 */
220
221
static gpg_err_code_t
222
selftests_cmac_3des (int extended, selftest_report_func_t report)
223
0
{
224
0
  static const struct
225
0
  {
226
0
    const char *desc;
227
0
    const char *data;
228
0
    const char *key;
229
0
    const char *expect;
230
0
  } tv[] =
231
0
    {
232
0
      { "Basic 3DES",
233
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
234
0
        "\xae\x2d\x8a\x57",
235
0
        "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
236
0
        "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
237
0
        "\x74\x3d\xdb\xe0\xce\x2d\xc2\xed" },
238
0
      { "Extended 3DES #1",
239
0
        "",
240
0
        "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
241
0
        "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
242
0
        "\xb7\xa6\x88\xe1\x22\xff\xaf\x95" },
243
0
      { "Extended 3DES #2",
244
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96",
245
0
        "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
246
0
        "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
247
0
        "\x8e\x8f\x29\x31\x36\x28\x37\x97" },
248
0
      { "Extended 3DES #3",
249
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
250
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
251
0
        "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
252
0
        "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
253
0
        "\x33\xe6\xb1\x09\x24\x00\xea\xe5" },
254
0
      { "Extended 3DES #4",
255
0
        "",
256
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
257
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
258
0
        "\xbd\x2e\xbf\x9a\x3b\xa0\x03\x61" },
259
0
      { "Extended 3DES #5",
260
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96",
261
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
262
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
263
0
        "\x4f\xf2\xab\x81\x3c\x53\xce\x83" },
264
0
      { "Extended 3DES #6",
265
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
266
0
        "\xae\x2d\x8a\x57",
267
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
268
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
269
0
        "\x62\xdd\x1b\x47\x19\x02\xbd\x4e" },
270
0
      { "Extended 3DES #7",
271
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
272
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
273
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
274
0
        "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
275
0
        "\x31\xb1\xe4\x31\xda\xbc\x4e\xb8" },
276
0
      { NULL }
277
0
    };
278
0
  const char *what;
279
0
  const char *errtxt;
280
0
  int tvidx;
281
282
0
  for (tvidx=0; tv[tvidx].desc; tvidx++)
283
0
    {
284
0
      what = tv[tvidx].desc;
285
0
      errtxt = check_one (GCRY_MAC_CMAC_3DES,
286
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
287
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
288
0
                          tv[tvidx].expect, 8);
289
0
      if (errtxt)
290
0
        goto failed;
291
0
      if (!extended)
292
0
        break;
293
0
    }
294
295
0
  return 0; /* Succeeded. */
296
297
0
 failed:
298
0
  if (report)
299
0
    report ("cmac", GCRY_MAC_CMAC_3DES, what, errtxt);
300
0
  return GPG_ERR_SELFTEST_FAILED;
301
0
}
302
303
304
305
static gpg_err_code_t
306
selftests_cmac_aes (int extended, selftest_report_func_t report)
307
0
{
308
0
  static const struct
309
0
  {
310
0
    const char *desc;
311
0
    const char *data;
312
0
    const char *key;
313
0
    const char *expect;
314
0
  } tv[] =
315
0
    {
316
0
      { "Basic AES128",
317
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
318
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
319
0
        "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
320
0
        "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
321
0
        "\xdf\xa6\x67\x47\xde\x9a\xe6\x30\x30\xca\x32\x61\x14\x97\xc8\x27" },
322
0
      { "Basic AES192",
323
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
324
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
325
0
        "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
326
0
        "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
327
0
        "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
328
0
        "\x8a\x1d\xe5\xbe\x2e\xb3\x1a\xad\x08\x9a\x82\xe6\xee\x90\x8b\x0e" },
329
0
      { "Basic AES256",
330
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
331
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
332
0
        "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
333
0
        "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
334
0
        "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
335
0
        "\xaa\xf3\xd8\xf1\xde\x56\x40\xc2\x32\xf5\xb1\x69\xb9\xc9\x11\xe6" },
336
0
      { "Extended AES #1",
337
0
        "",
338
0
        "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
339
0
        "\xbb\x1d\x69\x29\xe9\x59\x37\x28\x7f\xa3\x7d\x12\x9b\x75\x67\x46" },
340
0
      { "Extended AES #2",
341
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
342
0
        "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
343
0
        "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
344
0
        "\x9e\x99\xa7\xbf\x31\xe7\x10\x90\x06\x62\xf6\x5e\x61\x7c\x51\x84" },
345
0
      { "Extended AES #3",
346
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
347
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
348
0
        "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
349
0
        "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
350
0
        "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
351
0
        "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
352
0
        "\xe1\x99\x21\x90\x54\x9f\x6e\xd5\x69\x6a\x2c\x05\x6c\x31\x54\x10" },
353
0
      { "Extended AES #4",
354
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
355
0
        "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
356
0
        "\x07\x0a\x16\xb4\x6b\x4d\x41\x44\xf7\x9b\xdd\x9d\xd0\x4a\x28\x7c" },
357
0
      { "Extended AES #5",
358
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
359
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
360
0
        "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
361
0
        "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
362
0
        "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
363
0
        "\x51\xf0\xbe\xbf\x7e\x3b\x9d\x92\xfc\x49\x74\x17\x79\x36\x3c\xfe" },
364
0
      { "Extended AES #6",
365
0
        "",
366
0
        "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
367
0
        "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
368
0
        "\xd1\x7d\xdf\x46\xad\xaa\xcd\xe5\x31\xca\xc4\x83\xde\x7a\x93\x67" },
369
0
      { "Extended AES #7",
370
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
371
0
        "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
372
0
        "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
373
0
        "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
374
0
        "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
375
0
        "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
376
0
        "\xa1\xd5\xdf\x0e\xed\x79\x0f\x79\x4d\x77\x58\x96\x59\xf3\x9a\x11" },
377
0
      { "Extended AES #8",
378
0
        "",
379
0
        "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
380
0
        "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
381
0
        "\x02\x89\x62\xf6\x1b\x7b\xf8\x9e\xfc\x6b\x55\x1f\x46\x67\xd9\x83" },
382
0
      { "Extended AES #9",
383
0
        "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
384
0
        "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
385
0
        "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
386
0
        "\x28\xa7\x02\x3f\x45\x2e\x8f\x82\xbd\x4b\xf2\x8d\x8c\x37\xc3\x5c" },
387
0
      { NULL }
388
0
    };
389
0
  const char *what;
390
0
  const char *errtxt;
391
0
  int tvidx;
392
393
0
  for (tvidx=0; tv[tvidx].desc; tvidx++)
394
0
    {
395
0
      what = tv[tvidx].desc;
396
0
      errtxt = check_one (GCRY_MAC_CMAC_AES,
397
0
                          tv[tvidx].data, strlen (tv[tvidx].data),
398
0
                          tv[tvidx].key, strlen (tv[tvidx].key),
399
0
                          tv[tvidx].expect, strlen (tv[tvidx].expect));
400
0
      if (errtxt)
401
0
        goto failed;
402
0
      if (tvidx >= 2 && !extended)
403
0
        break;
404
0
    }
405
406
0
  return 0; /* Succeeded. */
407
408
0
 failed:
409
0
  if (report)
410
0
    report ("cmac", GCRY_MAC_CMAC_AES, what, errtxt);
411
0
  return GPG_ERR_SELFTEST_FAILED;
412
0
}
413
414
static gpg_err_code_t
415
cmac_selftest (int algo, int extended, selftest_report_func_t report)
416
0
{
417
0
  gpg_err_code_t ec;
418
419
0
  switch (algo)
420
0
    {
421
0
    case GCRY_MAC_CMAC_3DES:
422
0
      ec = selftests_cmac_3des (extended, report);
423
0
      break;
424
0
    case GCRY_MAC_CMAC_AES:
425
0
      ec = selftests_cmac_aes (extended, report);
426
0
      break;
427
428
0
    default:
429
0
      ec = GPG_ERR_MAC_ALGO;
430
0
      break;
431
0
    }
432
433
0
  return ec;
434
0
}
435
436
437
static gcry_mac_spec_ops_t cmac_ops = {
438
  cmac_open,
439
  cmac_close,
440
  cmac_setkey,
441
  NULL,
442
  cmac_reset,
443
  cmac_write,
444
  cmac_read,
445
  cmac_verify,
446
  cmac_get_maclen,
447
  cmac_get_keylen,
448
  NULL,
449
  cmac_selftest
450
};
451
452
453
#if USE_BLOWFISH
454
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_blowfish = {
455
  GCRY_MAC_CMAC_BLOWFISH, {0, 0}, "CMAC_BLOWFISH",
456
  &cmac_ops
457
};
458
#endif
459
#if USE_DES
460
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_tripledes = {
461
  GCRY_MAC_CMAC_3DES, {0, 0}, "CMAC_3DES",
462
  &cmac_ops
463
};
464
#endif
465
#if USE_CAST5
466
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_cast5 = {
467
  GCRY_MAC_CMAC_CAST5, {0, 0}, "CMAC_CAST5",
468
  &cmac_ops
469
};
470
#endif
471
#if USE_AES
472
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_aes = {
473
  GCRY_MAC_CMAC_AES, {0, 1}, "CMAC_AES",
474
  &cmac_ops
475
};
476
#endif
477
#if USE_TWOFISH
478
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_twofish = {
479
  GCRY_MAC_CMAC_TWOFISH, {0, 0}, "CMAC_TWOFISH",
480
  &cmac_ops
481
};
482
#endif
483
#if USE_SERPENT
484
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_serpent = {
485
  GCRY_MAC_CMAC_SERPENT, {0, 0}, "CMAC_SERPENT",
486
  &cmac_ops
487
};
488
#endif
489
#if USE_RFC2268
490
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_rfc2268 = {
491
  GCRY_MAC_CMAC_RFC2268, {0, 0}, "CMAC_RFC2268",
492
  &cmac_ops
493
};
494
#endif
495
#if USE_SEED
496
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_seed = {
497
  GCRY_MAC_CMAC_SEED, {0, 0}, "CMAC_SEED",
498
  &cmac_ops
499
};
500
#endif
501
#if USE_CAMELLIA
502
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_camellia = {
503
  GCRY_MAC_CMAC_CAMELLIA, {0, 0}, "CMAC_CAMELLIA",
504
  &cmac_ops
505
};
506
#endif
507
#if USE_IDEA
508
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_idea = {
509
  GCRY_MAC_CMAC_IDEA, {0, 0}, "CMAC_IDEA",
510
  &cmac_ops
511
};
512
#endif
513
#if USE_GOST28147
514
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_gost28147 = {
515
  GCRY_MAC_CMAC_GOST28147, {0, 0}, "CMAC_GOST28147",
516
  &cmac_ops
517
};
518
#endif
519
#if USE_SM4
520
const gcry_mac_spec_t _gcry_mac_type_spec_cmac_sm4 = {
521
  GCRY_MAC_CMAC_SM4, {0, 0}, "CMAC_SM4",
522
  &cmac_ops
523
};
524
#endif