Current File : //usr/local/emps/share/doc/openssl/html/man7/EVP_MAC-KMAC.html |
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>EVP_MAC-KMAC</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a>
<ul>
<li><a href="#Identity">Identity</a></li>
<li><a href="#Supported-parameters">Supported parameters</a></li>
</ul>
</li>
<li><a href="#EXAMPLES">EXAMPLES</a></li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>EVP_MAC-KMAC, EVP_MAC-KMAC128, EVP_MAC-KMAC256 - The KMAC EVP_MAC implementations</p>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>Support for computing KMAC MACs through the <b>EVP_MAC</b> API.</p>
<h2 id="Identity">Identity</h2>
<p>These implementations are identified with one of these names and properties, to be used with EVP_MAC_fetch():</p>
<dl>
<dt id="KMAC-128-provider-default-or-provider-fips">"KMAC-128", "provider=default" or "provider=fips"</dt>
<dd>
</dd>
<dt id="KMAC-256-provider-default-or-provider-fips">"KMAC-256", "provider=default" or "provider=fips"</dt>
<dd>
</dd>
</dl>
<h2 id="Supported-parameters">Supported parameters</h2>
<p>The general description of these parameters can be found in <a href="../man3/EVP_MAC.html">"PARAMETERS" in EVP_MAC(3)</a>.</p>
<p>All these parameters can be set with EVP_MAC_CTX_set_params(). Furthermore, the "size" parameter can be retrieved with EVP_MAC_CTX_get_params(), or with EVP_MAC_CTX_get_mac_size(). The length of the "size" parameter should not exceed that of a <b>size_t</b>. Likewise, the "block-size" parameter can be retrieved with EVP_MAC_CTX_get_params(), or with EVP_MAC_CTX_get_block_size().</p>
<dl>
<dt id="key-OSSL_MAC_PARAM_KEY-octet-string">"key" (<b>OSSL_MAC_PARAM_KEY</b>) <octet string></dt>
<dd>
<p>Sets the MAC key. Setting this parameter is identical to passing a <i>key</i> to <a href="../man3/EVP_MAC_init.html">EVP_MAC_init(3)</a>.</p>
</dd>
<dt id="custom-OSSL_MAC_PARAM_CUSTOM-octet-string">"custom" (<b>OSSL_MAC_PARAM_CUSTOM</b>) <octet string></dt>
<dd>
<p>Sets the custom value. It is an optional value of at most 256 bytes, and is empty by default.</p>
</dd>
<dt id="size-OSSL_MAC_PARAM_SIZE-unsigned-integer">"size" (<b>OSSL_MAC_PARAM_SIZE</b>) <unsigned integer></dt>
<dd>
<p>Sets the MAC size. By default, it is 16 for <code>KMAC-128</code> and 32 for <code>KMAC-256</code>.</p>
</dd>
<dt id="block-size-OSSL_MAC_PARAM_SIZE-unsigned-integer">"block-size" (<b>OSSL_MAC_PARAM_SIZE</b>) <unsigned integer></dt>
<dd>
<p>Gets the MAC block size. By default, it is 168 for <code>KMAC-128</code> and 136 for <code>KMAC-256</code>.</p>
</dd>
<dt id="xof-OSSL_MAC_PARAM_XOF-integer">"xof" (<b>OSSL_MAC_PARAM_XOF</b>) <integer></dt>
<dd>
<p>The "xof" parameter value is expected to be 1 or 0. Use 1 to enable XOF mode. The default value is 0.</p>
</dd>
</dl>
<p>The "custom" parameter must be set as part of or before the EVP_MAC_init() call. The "xof" and "size" parameters can be set at any time before EVP_MAC_final(). The "key" parameter is set as part of the EVP_MAC_init() call, but can be set before it instead.</p>
<h1 id="EXAMPLES">EXAMPLES</h1>
<pre><code> #include <openssl/evp.h>
#include <openssl/params.h>
static int do_kmac(const unsigned char *in, size_t in_len,
const unsigned char *key, size_t key_len,
const unsigned char *custom, size_t custom_len,
int xof_enabled, unsigned char *out, int out_len)
{
EVP_MAC_CTX *ctx = NULL;
EVP_MAC *mac = NULL;
OSSL_PARAM params[4], *p;
int ret = 0;
size_t l = 0;
mac = EVP_MAC_fetch(NULL, "KMAC-128", NULL);
if (mac == NULL)
goto err;
ctx = EVP_MAC_CTX_new(mac);
/* The mac can be freed after it is used by EVP_MAC_CTX_new */
EVP_MAC_free(mac);
if (ctx == NULL)
goto err;
/*
* Setup parameters required before calling EVP_MAC_init()
* The parameters OSSL_MAC_PARAM_XOF and OSSL_MAC_PARAM_SIZE may also be
* used at this point.
*/
p = params;
*p++ = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
(void *)key, key_len);
if (custom != NULL && custom_len != 0)
*p++ = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM,
(void *)custom, custom_len);
*p = OSSL_PARAM_construct_end();
if (!EVP_MAC_CTX_set_params(ctx, params))
goto err;
if (!EVP_MAC_init(ctx))
goto err;
/*
* Note: the following optional parameters can be set any time
* before EVP_MAC_final().
*/
p = params;
*p++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_XOF, &xof_enabled);
*p++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_SIZE, &out_len);
*p = OSSL_PARAM_construct_end();
if (!EVP_MAC_CTX_set_params(ctx, params))
goto err;
/* The update may be called multiple times here for streamed input */
if (!EVP_MAC_update(ctx, in, in_len))
goto err;
if (!EVP_MAC_final(ctx, out, &l, out_len))
goto err;
ret = 1;
err:
EVP_MAC_CTX_free(ctx);
return ret;
}</code></pre>
<h1 id="SEE-ALSO">SEE ALSO</h1>
<p><a href="../man3/EVP_MAC_CTX_get_params.html">EVP_MAC_CTX_get_params(3)</a>, <a href="../man3/EVP_MAC_CTX_set_params.html">EVP_MAC_CTX_set_params(3)</a>, <a href="../man3/EVP_MAC.html">"PARAMETERS" in EVP_MAC(3)</a>, <a href="../man3/OSSL_PARAM.html">OSSL_PARAM(3)</a></p>
<h1 id="COPYRIGHT">COPYRIGHT</h1>
<p>Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.</p>
<p>Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
</body>
</html>