1EVP_MAC-KMAC(7ossl)                 OpenSSL                EVP_MAC-KMAC(7ossl)
2
3
4

NAME

6       EVP_MAC-KMAC, EVP_MAC-KMAC128, EVP_MAC-KMAC256 - The KMAC EVP_MAC
7       implementations
8

DESCRIPTION

10       Support for computing KMAC MACs through the EVP_MAC API.
11
12   Identity
13       These implementations are identified with one of these names and
14       properties, to be used with EVP_MAC_fetch():
15
16       "KMAC-128", "provider=default" or "provider=fips"
17       "KMAC-256", "provider=default" or "provider=fips"
18
19   Supported parameters
20       The general description of these parameters can be found in
21       "PARAMETERS" in EVP_MAC(3).
22
23       All these parameters can be set with EVP_MAC_CTX_set_params().
24       Furthermore, the "size" parameter can be retrieved with
25       EVP_MAC_CTX_get_params(), or with EVP_MAC_CTX_get_mac_size().  The
26       length of the "size" parameter should not exceed that of a size_t.
27       Likewise, the "block-size" parameter can be retrieved with
28       EVP_MAC_CTX_get_params(), or with EVP_MAC_CTX_get_block_size().
29
30       "key" (OSSL_MAC_PARAM_KEY) <octet string>
31           Sets the MAC key.  Setting this parameter is identical to passing a
32           key to EVP_MAC_init(3).
33
34       "custom" (OSSL_MAC_PARAM_CUSTOM) <octet string>
35           Sets the custom value.  It is an optional value of at most 256
36           bytes, and is empty by default.
37
38       "size" (OSSL_MAC_PARAM_SIZE) <unsigned integer>
39           Sets the MAC size.  By default, it is 16 for "KMAC-128" and 32 for
40           "KMAC-256".
41
42       "block-size" (OSSL_MAC_PARAM_SIZE) <unsigned integer>
43           Gets the MAC block size.  By default, it is 168 for "KMAC-128" and
44           136 for "KMAC-256".
45
46       "xof" (OSSL_MAC_PARAM_XOF) <integer>
47           The "xof" parameter value is expected to be 1 or 0. Use 1 to enable
48           XOF mode.  The default value is 0.
49
50       The "custom" parameter must be set as part of or before the
51       EVP_MAC_init() call.  The "xof" and "size" parameters can be set at any
52       time before EVP_MAC_final().  The "key" parameter is set as part of the
53       EVP_MAC_init() call, but can be set before it instead.
54

EXAMPLES

56         #include <openssl/evp.h>
57         #include <openssl/params.h>
58
59         static int do_kmac(const unsigned char *in, size_t in_len,
60                            const unsigned char *key, size_t key_len,
61                            const unsigned char *custom, size_t custom_len,
62                            int xof_enabled, unsigned char *out, int out_len)
63         {
64             EVP_MAC_CTX *ctx = NULL;
65             EVP_MAC *mac = NULL;
66             OSSL_PARAM params[4], *p;
67             int ret = 0;
68             size_t l = 0;
69
70             mac = EVP_MAC_fetch(NULL, "KMAC-128", NULL);
71             if (mac == NULL)
72                 goto err;
73             ctx = EVP_MAC_CTX_new(mac);
74             /* The mac can be freed after it is used by EVP_MAC_CTX_new */
75             EVP_MAC_free(mac);
76             if (ctx == NULL)
77                 goto err;
78
79             /*
80              * Setup parameters required before calling EVP_MAC_init()
81              * The parameters OSSL_MAC_PARAM_XOF and OSSL_MAC_PARAM_SIZE may also be
82              * used at this point.
83              */
84             p = params;
85             *p++ = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
86                                                      (void *)key, key_len);
87             if (custom != NULL && custom_len != 0)
88               *p++ = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM,
89                                                        (void *)custom, custom_len);
90             *p = OSSL_PARAM_construct_end();
91             if (!EVP_MAC_CTX_set_params(ctx, params))
92                 goto err;
93
94             if (!EVP_MAC_init(ctx))
95                 goto err;
96
97             /*
98              * Note: the following optional parameters can be set any time
99              * before EVP_MAC_final().
100              */
101             p = params;
102             *p++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_XOF, &xof_enabled);
103             *p++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_SIZE, &out_len);
104             *p = OSSL_PARAM_construct_end();
105             if (!EVP_MAC_CTX_set_params(ctx, params))
106                 goto err;
107
108             /* The update may be called multiple times here for streamed input */
109             if (!EVP_MAC_update(ctx, in, in_len))
110                 goto err;
111             if (!EVP_MAC_final(ctx, out, &l, out_len))
112                 goto err;
113             ret = 1;
114         err:
115             EVP_MAC_CTX_free(ctx);
116             return ret;
117         }
118

SEE ALSO

120       EVP_MAC_CTX_get_params(3), EVP_MAC_CTX_set_params(3), "PARAMETERS" in
121       EVP_MAC(3), OSSL_PARAM(3)
122
124       Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
125
126       Licensed under the Apache License 2.0 (the "License").  You may not use
127       this file except in compliance with the License.  You can obtain a copy
128       in the file LICENSE in the source distribution or at
129       <https://www.openssl.org/source/license.html>.
130
131
132
1333.0.5                             2022-07-05               EVP_MAC-KMAC(7ossl)
Impressum