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