Home | History | Annotate | Line # | Download | only in man7
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 EVP_MAC-KMAC, EVP_MAC-KMAC128, EVP_MAC-KMAC256
      6 - The KMAC EVP_MAC implementations
      7 
      8 =head1 DESCRIPTION
      9 
     10 Support for computing KMAC MACs through the B<EVP_MAC> API.
     11 
     12 =head2 Identity
     13 
     14 These implementations are identified with one of these names and
     15 properties, to be used with EVP_MAC_fetch():
     16 
     17 =over 4
     18 
     19 =item "KMAC-128", "provider=default" or "provider=fips"
     20 
     21 =item "KMAC-256", "provider=default" or "provider=fips"
     22 
     23 =back
     24 
     25 =head2 Supported parameters
     26 
     27 The general description of these parameters can be found in
     28 L<EVP_MAC(3)/PARAMETERS>.
     29 
     30 All these parameters (except for "block-size") can be set with
     31 EVP_MAC_CTX_set_params().
     32 Furthermore, the "size" parameter can be retrieved with
     33 EVP_MAC_CTX_get_params(), or with EVP_MAC_CTX_get_mac_size().
     34 The length of the "size" parameter should not exceed that of a B<size_t>.
     35 Likewise, the "block-size" parameter can be retrieved with
     36 EVP_MAC_CTX_get_params(), or with EVP_MAC_CTX_get_block_size().
     37 
     38 =over 4
     39 
     40 =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
     41 
     42 Sets the MAC key.
     43 Setting this parameter is identical to passing a I<key> to L<EVP_MAC_init(3)>.
     44 The length of the key (in bytes) must be in the range 4...512.
     45 
     46 =item "custom" (B<OSSL_MAC_PARAM_CUSTOM>) <octet string>
     47 
     48 Sets the customization string.
     49 It is an optional value with a length of at most 512 bytes, and is
     50 empty by default.
     51 
     52 =item "size" (B<OSSL_MAC_PARAM_SIZE>) <unsigned integer>
     53 
     54 Sets the MAC size.
     55 By default, it is 32 for C<KMAC-128> and 64 for C<KMAC-256>.
     56 
     57 =item "block-size" (B<OSSL_MAC_PARAM_BLOCK_SIZE>) <unsigned integer>
     58 
     59 Gets the MAC block size.
     60 It is 168 for C<KMAC-128> and 136 for C<KMAC-256>.
     61 
     62 =item "xof" (B<OSSL_MAC_PARAM_XOF>) <integer>
     63 
     64 The "xof" parameter value is expected to be 1 or 0. Use 1 to enable XOF mode.
     65 The default value is 0.
     66 
     67 =item "fips-indicator" (B<OSSL_MAC_PARAM_FIPS_APPROVED_INDICATOR>) <int>
     68 
     69 This settable parameter is described in L<provider-mac(7)>.
     70 
     71 =item "no-short-mac" (B<OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC>) <integer>
     72 
     73 This settable parameter is described in L<provider-mac(7)>.  It is used by
     74 the OpenSSL FIPS provider and the minimum length output for KMAC
     75 is defined by NIST's SP 800-185 8.4.2.
     76 
     77 =item "key-check" (B<OSSL_MAC_PARAM_FIPS_KEY_CHECK>) <integer>
     78 
     79 This settable parameter is described in L<provider-mac(7)>.
     80 
     81 =back
     82 
     83 The "custom" and "no-short-mac" parameters must be set as part of or before
     84 the EVP_MAC_init() call.
     85 The "xof" and "size" parameters can be set at any time before EVP_MAC_final().
     86 The "key" parameter is set as part of the EVP_MAC_init() call, but can be
     87 set before it instead.
     88 
     89 =head1 EXAMPLES
     90 
     91   #include <openssl/evp.h>
     92   #include <openssl/params.h>
     93 
     94   static int do_kmac(const unsigned char *in, size_t in_len,
     95                      const unsigned char *key, size_t key_len,
     96                      const unsigned char *custom, size_t custom_len,
     97                      int xof_enabled, unsigned char *out, int out_len)
     98   {
     99       EVP_MAC_CTX *ctx = NULL;
    100       EVP_MAC *mac = NULL;
    101       OSSL_PARAM params[4], *p;
    102       int ret = 0;
    103       size_t l = 0;
    104 
    105       mac = EVP_MAC_fetch(NULL, "KMAC-128", NULL);
    106       if (mac == NULL)
    107           goto err;
    108       ctx = EVP_MAC_CTX_new(mac);
    109       /* The mac can be freed after it is used by EVP_MAC_CTX_new */
    110       EVP_MAC_free(mac);
    111       if (ctx == NULL)
    112           goto err;
    113 
    114       /*
    115        * Setup parameters required before calling EVP_MAC_init()
    116        * The parameters OSSL_MAC_PARAM_XOF and OSSL_MAC_PARAM_SIZE may also be
    117        * used at this point.
    118        */
    119       p = params;
    120       *p++ = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
    121                                                (void *)key, key_len);
    122       if (custom != NULL && custom_len != 0)
    123         *p++ = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM,
    124                                                  (void *)custom, custom_len);
    125       *p = OSSL_PARAM_construct_end();
    126       if (!EVP_MAC_CTX_set_params(ctx, params))
    127           goto err;
    128 
    129       if (!EVP_MAC_init(ctx))
    130           goto err;
    131 
    132       /*
    133        * Note: the following optional parameters can be set any time
    134        * before EVP_MAC_final().
    135        */
    136       p = params;
    137       *p++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_XOF, &xof_enabled);
    138       *p++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_SIZE, &out_len);
    139       *p = OSSL_PARAM_construct_end();
    140       if (!EVP_MAC_CTX_set_params(ctx, params))
    141           goto err;
    142 
    143       /* The update may be called multiple times here for streamed input */
    144       if (!EVP_MAC_update(ctx, in, in_len))
    145           goto err;
    146       if (!EVP_MAC_final(ctx, out, &l, out_len))
    147           goto err;
    148       ret = 1;
    149   err:
    150       EVP_MAC_CTX_free(ctx);
    151       return ret;
    152   }
    153 
    154 =head1 SEE ALSO
    155 
    156 L<EVP_MAC_CTX_get_params(3)>, L<EVP_MAC_CTX_set_params(3)>,
    157 L<EVP_MAC(3)/PARAMETERS>, L<OSSL_PARAM(3)>,
    158 L<SP 800-185 8.4.2|https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf>
    159 
    160 =head1 COPYRIGHT
    161 
    162 Copyright 2018-2024 The OpenSSL Project Authors. All Rights Reserved.
    163 
    164 Licensed under the Apache License 2.0 (the "License").  You may not use
    165 this file except in compliance with the License.  You can obtain a copy
    166 in the file LICENSE in the source distribution or at
    167 L<https://www.openssl.org/source/license.html>.
    168 
    169 =cut
    170