Standard preamble:
========================================================================
..
.... Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF
Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================
Title "EVP_MAC 3"
way too many mistakes in technical documents.
MACs are a bit complex insofar that some of them use other algorithms for actual computation. \s-1HMAC\s0 uses a digest, and \s-1CMAC\s0 uses a cipher. Therefore, there are sometimes two contexts to keep track of, one for the \s-1MAC\s0 algorithm itself and one for the underlying computation algorithm if there is one.
To make things less ambiguous, this manual talks about a \*(L"context\*(R" or \*(L"\s-1MAC\s0 context\*(R", which is to denote the \s-1MAC\s0 level context, and about a \*(L"underlying context\*(R", or \*(L"computation context\*(R", which is to denote the context for the underlying computation algorithm if there is one.
\fB\s-1EVP_MAC_CTX\s0 is a context type that holds internal \s-1MAC\s0 information as well as a reference to a computation context, for those MACs that rely on an underlying computation algorithm.
See \*(L"Message Authentication Code (\s-1MAC\s0)\*(R" in OSSL_PROVIDER-default\|(7) for the list of algorithms supported by the default provider.
The returned value must eventually be freed with \fBEVP_MAC_free\|(3).
\fBEVP_MAC_up_ref() increments the reference count of an already fetched \s-1MAC.\s0
\fBEVP_MAC_free() frees a fetched algorithm. \s-1NULL\s0 is a valid parameter, for which this function is a no-op.
\fBEVP_MAC_CTX_free() frees the contents of the context, including an underlying context if there is one, as well as the context itself. \s-1NULL\s0 is a valid parameter, for which this function is a no-op.
\fBEVP_MAC_CTX_dup() duplicates the src context and returns a newly allocated context.
\fBEVP_MAC_CTX_get0_mac() returns the \s-1EVP_MAC\s0 associated with the context \fIctx.
\fBEVP_MAC_init() sets up the underlying context ctx with information given via the key and params arguments. The \s-1MAC\s0 key has a length of \fIkeylen and the parameters in params are processed before setting the key. If key is \s-1NULL,\s0 the key must be set via params either as part of this call or separately using EVP_MAC_CTX_set_params(). Providing non-NULL params to this function is equivalent to calling \fBEVP_MAC_CTX_set_params() with those params for the same ctx beforehand.
\fBEVP_MAC_init() should be called before EVP_MAC_update() and EVP_MAC_final().
\fBEVP_MAC_update() adds datalen bytes from data to the \s-1MAC\s0 input.
\fBEVP_MAC_final() does the final computation and stores the result in the memory pointed at by out of size outsize, and sets the number of bytes written in *outl at. If out is \s-1NULL\s0 or outsize is too small, then no computation is made. To figure out what the output length will be and allocate space for it dynamically, simply call with out being \s-1NULL\s0 and outl pointing at a valid location, then allocate space and make a second call with out pointing at the allocated space.
\fBEVP_MAC_finalXOF() does the final computation for an \s-1XOF\s0 based \s-1MAC\s0 and stores the result in the memory pointed at by out of size outsize.
\fBEVP_MAC_get_params() retrieves details about the implementation \fImac. The set of parameters given with params determine exactly what parameters should be retrieved. Note that a parameter that is unknown in the underlying context is simply ignored.
\fBEVP_MAC_CTX_get_params() retrieves chosen parameters, given the context ctx and its underlying context. The set of parameters given with params determine exactly what parameters should be retrieved. Note that a parameter that is unknown in the underlying context is simply ignored.
\fBEVP_MAC_CTX_set_params() passes chosen parameters to the underlying context, given a context ctx. The set of parameters given with params determine exactly what parameters are passed down. If params are \s-1NULL,\s0 the unterlying context should do nothing and return 1. Note that a parameter that is unknown in the underlying context is simply ignored. Also, what happens when a needed parameter isn't passed down is defined by the implementation.
\fBEVP_MAC_gettable_params() returns an \s-1OSSL_PARAM\s0\|(3) array that describes the retrievable and settable parameters. EVP_MAC_gettable_params() returns parameters that can be used with EVP_MAC_get_params().
\fBEVP_MAC_gettable_ctx_params() and EVP_MAC_CTX_gettable_params() return constant \s-1OSSL_PARAM\s0\|(3) arrays that describe the retrievable parameters that can be used with EVP_MAC_CTX_get_params(). \fBEVP_MAC_gettable_ctx_params() returns the parameters that can be retrieved from the algorithm, whereas EVP_MAC_CTX_gettable_params() returns the parameters that can be retrieved in the context's current state.
\fBEVP_MAC_settable_ctx_params() and EVP_MAC_CTX_settable_params() return constant \s-1OSSL_PARAM\s0\|(3) arrays that describe the settable parameters that can be used with EVP_MAC_CTX_set_params(). EVP_MAC_settable_ctx_params() returns the parameters that can be retrieved from the algorithm, whereas EVP_MAC_CTX_settable_params() returns the parameters that can be retrieved in the context's current state.
\fBEVP_MAC_CTX_get_block_size() returns the \s-1MAC\s0 block size for the given context. Not all \s-1MAC\s0 algorithms support this.
\fBEVP_MAC_is_a() checks if the given mac is an implementation of an algorithm that's identifiable with name.
\fBEVP_MAC_get0_provider() returns the provider that holds the implementation of the given mac.
\fBEVP_MAC_do_all_provided() traverses all \s-1MAC\s0 implemented by all activated providers in the given library context libctx, and for each of the implementations, calls the given function fn with the implementation method and the given arg as argument.
\fBEVP_MAC_get0_name() return the name of the given \s-1MAC.\s0 For fetched MACs with multiple names, only one of them is returned; it's recommended to use EVP_MAC_names_do_all() instead.
\fBEVP_MAC_names_do_all() traverses all names for mac, and calls \fIfn with each name and data.
\fBEVP_MAC_get0_description() returns a description of the mac, meant for display and human consumption. The description is at the discretion of the mac implementation.
The standard parameter names are: Item "key (OSSL_MAC_PARAM_KEY) <octet string>" Its value is the \s-1MAC\s0 key as an array of bytes. .Sp For MACs that use an underlying computation algorithm, the algorithm must be set first, see parameter names \*(L"algorithm\*(R" below. Item "iv (OSSL_MAC_PARAM_IV) <octet string>" Some \s-1MAC\s0 implementations (\s-1GMAC\s0) require an \s-1IV,\s0 this parameter sets the \s-1IV.\s0 Item "custom (OSSL_MAC_PARAM_CUSTOM) <octet string>" Some \s-1MAC\s0 implementations (\s-1KMAC, BLAKE2\s0) accept a Customization String, this parameter sets the Customization String. The default value is the empty string. Item "salt (OSSL_MAC_PARAM_SALT) <octet string>" This option is used by \s-1BLAKE2 MAC.\s0 Item "xof (OSSL_MAC_PARAM_XOF) <integer>" It's a simple flag, the value 0 or 1 are expected. .Sp This option is used by \s-1KMAC.\s0 Item "digest-noinit (OSSL_MAC_PARAM_DIGEST_NOINIT) <integer>" A simple flag to set the \s-1MAC\s0 digest to not initialise the implementation specific data. The value 0 or 1 is expected. .Sp This option is used by \s-1HMAC.\s0 Item "digest-oneshot (OSSL_MAC_PARAM_DIGEST_ONESHOT) <integer>" A simple flag to set the \s-1MAC\s0 digest to be a oneshot operation. The value 0 or 1 is expected. .Sp This option is used by \s-1HMAC.\s0 Item "properties (OSSL_MAC_PARAM_PROPERTIES) <UTF8 string>"
0 Item "digest (OSSL_MAC_PARAM_DIGEST) <UTF8 string>" Item "cipher (OSSL_MAC_PARAM_CIPHER) <UTF8 string>"
For \s-1MAC\s0 implementations that use an underlying computation cipher or digest, these parameters set what the algorithm should be. .Sp The value is always the name of the intended algorithm, or the properties. .Sp Note that not all algorithms may support all digests. \s-1HMAC\s0 does not support variable output length digests such as \s-1SHAKE128\s0 or \s-1SHAKE256.\s0 Item "size (OSSL_MAC_PARAM_SIZE) <unsigned integer>" For \s-1MAC\s0 implementations that support it, set the output size that \fBEVP_MAC_final() should produce. The allowed sizes vary between \s-1MAC\s0 implementations, but must never exceed what can be given with a size_t. Item "tls-data-size (OSSL_MAC_PARAM_TLS_DATA_SIZE) <unsigned integer>" This parameter is only supported by \s-1HMAC.\s0 If set then special handling is activated for calculating the \s-1MAC\s0 of a received mac-then-encrypt \s-1TLS\s0 record where variable length record padding has been used (as in the case of \s-1CBC\s0 mode ciphersuites). The value represents the total length of the record that is having the \s-1MAC\s0 calculated including the received \s-1MAC\s0 and the record padding. .Sp When used EVP_MAC_update must be called precisely twice. The first time with the 13 bytes of \s-1TLS\s0 \*(L"header\*(R" data, and the second time with the entire record including the \s-1MAC\s0 itself and any padding. The entire record length must equal the value passed in the \*(L"tls-data-size\*(R" parameter. The length passed in the \fBdatalen parameter to EVP_MAC_update() should be equal to the length of the record after the \s-1MAC\s0 and any padding has been removed.
All these parameters should be used before the calls to any of \fBEVP_MAC_init(), EVP_MAC_update() and EVP_MAC_final() for a full computation. Anything else may give undefined results.
The usage of the parameter names \*(L"custom\*(R", \*(L"iv\*(R" and \*(L"salt\*(R" correspond to the names used in the standard where the algorithm was defined.
\fBEVP_MAC_up_ref() returns 1 on success, 0 on error.
\fBEVP_MAC_names_do_all() returns 1 if the callback was called for all names. A return value of 0 means that the callback was not called for any names.
\fBEVP_MAC_free() returns nothing at all.
\fBEVP_MAC_is_a() returns 1 if the given method can be identified with the given name, otherwise 0.
\fBEVP_MAC_get0_name() returns a name of the \s-1MAC,\s0 or \s-1NULL\s0 on error.
\fBEVP_MAC_get0_provider() returns a pointer to the provider for the \s-1MAC,\s0 or \s-1NULL\s0 on error.
\fBEVP_MAC_CTX_new() and EVP_MAC_CTX_dup() return a pointer to a newly created \s-1EVP_MAC_CTX,\s0 or \s-1NULL\s0 if allocation failed.
\fBEVP_MAC_CTX_free() returns nothing at all.
\fBEVP_MAC_CTX_get_params() and EVP_MAC_CTX_set_params() return 1 on success, 0 on error.
\fBEVP_Q_mac() returns a pointer to the computed \s-1MAC\s0 value, or \s-1NULL\s0 on error.
\fBEVP_MAC_init(), EVP_MAC_update(), EVP_MAC_final(), and EVP_MAC_finalXOF() return 1 on success, 0 on error.
\fBEVP_MAC_CTX_get_mac_size() returns the expected output size, or 0 if it isn't set. If it isn't set, a call to EVP_MAC_init() will set it.
\fBEVP_MAC_CTX_get_block_size() returns the block size, or 0 if it isn't set. If it isn't set, a call to EVP_MAC_init() will set it.
\fBEVP_MAC_do_all_provided() returns nothing at all.
A run of this program, called with correct environment variables, can look like this:
.Vb 3 $ MY_MAC=cmac MY_KEY=secret0123456789 MY_MAC_CIPHER=aes-128-cbc \e LD_LIBRARY_PATH=. ./foo < foo.c Result: C5C06683CD9DDEF904D754505C560A4E .Ve
(in this example, that program was stored in foo.c and compiled to \fI./foo)
Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.