2018-10-13 04:27:18 +08:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
EVP: Add EVP_<TYPE>_description()
The following operation types are covered:
EVP_MD, EVP_CIPHER, EVP_MAC, EVP_RAND, EVP_KEYMGMT, EVP_SIGNATURE,
EVP_ASYM_CIPHER, EVP_KEM, EVP_KEYEXCH, EVP_KDF. Also EVP_PKEY.
For EVP_MD and EVP_CIPHER, OBJ_nid2ln() is used as a fallback for
legacy implementations.
For EVP_PKEY, the info field of the EVP_PKEY_ASN1_METHOD is used as a
fallback for legacy implementations.
Fixes #14514
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14656)
2021-03-16 21:23:54 +08:00
|
|
|
EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free, EVP_MAC_is_a,
|
|
|
|
EVP_MAC_number, EVP_MAC_name, EVP_MAC_names_do_all, EVP_MAC_description,
|
2019-06-05 00:14:38 +08:00
|
|
|
EVP_MAC_provider, EVP_MAC_get_params, EVP_MAC_gettable_params,
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX, EVP_MAC_CTX_new, EVP_MAC_CTX_free, EVP_MAC_CTX_dup,
|
|
|
|
EVP_MAC_CTX_mac, EVP_MAC_CTX_get_params, EVP_MAC_CTX_set_params,
|
2021-03-30 01:42:33 +08:00
|
|
|
EVP_MAC_CTX_get_mac_size, EVP_Q_mac,
|
|
|
|
EVP_MAC_init, EVP_MAC_update, EVP_MAC_final, EVP_MAC_finalXOF,
|
|
|
|
EVP_MAC_gettable_ctx_params, EVP_MAC_settable_ctx_params,
|
2021-02-23 09:03:31 +08:00
|
|
|
EVP_MAC_CTX_gettable_params, EVP_MAC_CTX_settable_params,
|
EVP: add missing common functionality
This adds the missing functions that should be common for all
fetchable EVP sub-APIs:
EVP_KEYMGMT_is_a(), EVP_KEYMGMT_do_all_provided(), EVP_KEYEXCH_is_a(),
EVP_KEYEXCH_do_all_provided(), EVP_KDF_is_a(), EVP_MD_is_a(),
EVP_SIGNATURE_do_all_provided(), EVP_SIGNATURE_is_a().
This also renames EVP_MD_do_all_ex(), EVP_CIPHER_do_all_ex(),
EVP_KDF_do_all_ex(), EVP_MAC_do_all_ex() to change '_ex'
to '_provided'.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9979)
2019-09-23 16:33:26 +08:00
|
|
|
EVP_MAC_do_all_provided - EVP MAC routines
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
|
|
|
|
typedef struct evp_mac_st EVP_MAC;
|
|
|
|
typedef struct evp_mac_ctx_st EVP_MAC_CTX;
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
EVP_MAC *EVP_MAC_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
|
2019-05-07 18:39:58 +08:00
|
|
|
const char *properties);
|
|
|
|
int EVP_MAC_up_ref(EVP_MAC *mac);
|
|
|
|
void EVP_MAC_free(EVP_MAC *mac);
|
2019-09-14 22:35:08 +08:00
|
|
|
int EVP_MAC_is_a(const EVP_MAC *mac, const char *name);
|
2019-09-23 17:16:21 +08:00
|
|
|
int EVP_MAC_number(const EVP_MAC *mac);
|
2020-09-22 07:25:35 +08:00
|
|
|
const char *EVP_MAC_name(const EVP_MAC *mac);
|
2021-02-20 01:03:43 +08:00
|
|
|
int EVP_MAC_names_do_all(const EVP_MAC *mac,
|
|
|
|
void (*fn)(const char *name, void *data),
|
|
|
|
void *data);
|
EVP: Add EVP_<TYPE>_description()
The following operation types are covered:
EVP_MD, EVP_CIPHER, EVP_MAC, EVP_RAND, EVP_KEYMGMT, EVP_SIGNATURE,
EVP_ASYM_CIPHER, EVP_KEM, EVP_KEYEXCH, EVP_KDF. Also EVP_PKEY.
For EVP_MD and EVP_CIPHER, OBJ_nid2ln() is used as a fallback for
legacy implementations.
For EVP_PKEY, the info field of the EVP_PKEY_ASN1_METHOD is used as a
fallback for legacy implementations.
Fixes #14514
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14656)
2021-03-16 21:23:54 +08:00
|
|
|
const char *EVP_MAC_description(const EVP_MAC *mac);
|
2019-06-05 00:14:38 +08:00
|
|
|
const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac);
|
2019-05-07 18:39:58 +08:00
|
|
|
int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]);
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac);
|
|
|
|
void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx);
|
|
|
|
EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src);
|
|
|
|
EVP_MAC *EVP_MAC_CTX_mac(EVP_MAC_CTX *ctx);
|
|
|
|
int EVP_MAC_CTX_get_params(EVP_MAC_CTX *ctx, OSSL_PARAM params[]);
|
|
|
|
int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[]);
|
2019-05-07 18:39:58 +08:00
|
|
|
|
2020-10-13 12:22:17 +08:00
|
|
|
size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx);
|
2021-03-30 01:42:33 +08:00
|
|
|
unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const char *propq,
|
|
|
|
const char *subalg, const OSSL_PARAM *params,
|
|
|
|
const void *key, size_t keylen,
|
|
|
|
const unsigned char *data, size_t datalen,
|
|
|
|
unsigned char *out, size_t outsize, unsigned int *outlen);
|
2021-02-25 12:03:09 +08:00
|
|
|
int EVP_MAC_init(EVP_MAC_CTX *ctx, const unsigned char *key, size_t keylen,
|
|
|
|
const OSSL_PARAM params[]);
|
2018-10-13 04:27:18 +08:00
|
|
|
int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen);
|
2019-05-07 18:39:58 +08:00
|
|
|
int EVP_MAC_final(EVP_MAC_CTX *ctx,
|
|
|
|
unsigned char *out, size_t *outl, size_t outsize);
|
2021-04-28 11:01:22 +08:00
|
|
|
int EVP_MAC_finalXOF(EVP_MAC_CTX *ctx, unsigned char *out, size_t outsize);
|
2019-05-07 18:39:58 +08:00
|
|
|
|
|
|
|
const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac);
|
2019-09-27 14:35:45 +08:00
|
|
|
const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac);
|
|
|
|
const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac);
|
2021-02-23 09:03:31 +08:00
|
|
|
const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx);
|
|
|
|
const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx);
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
void EVP_MAC_do_all_provided(OSSL_LIB_CTX *libctx,
|
EVP: add missing common functionality
This adds the missing functions that should be common for all
fetchable EVP sub-APIs:
EVP_KEYMGMT_is_a(), EVP_KEYMGMT_do_all_provided(), EVP_KEYEXCH_is_a(),
EVP_KEYEXCH_do_all_provided(), EVP_KDF_is_a(), EVP_MD_is_a(),
EVP_SIGNATURE_do_all_provided(), EVP_SIGNATURE_is_a().
This also renames EVP_MD_do_all_ex(), EVP_CIPHER_do_all_ex(),
EVP_KDF_do_all_ex(), EVP_MAC_do_all_ex() to change '_ex'
to '_provided'.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9979)
2019-09-23 16:33:26 +08:00
|
|
|
void (*fn)(EVP_MAC *mac, void *arg),
|
|
|
|
void *arg);
|
2019-06-05 00:17:49 +08:00
|
|
|
|
2018-10-13 04:27:18 +08:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
These types and functions help the application to calculate MACs of
|
|
|
|
different types and with different underlying algorithms if there are
|
|
|
|
any.
|
|
|
|
|
|
|
|
MACs are a bit complex insofar that some of them use other algorithms
|
|
|
|
for actual computation. HMAC uses a digest, and CMAC uses a cipher.
|
|
|
|
Therefore, there are sometimes two contexts to keep track of, one for
|
|
|
|
the MAC algorithm itself and one for the underlying computation
|
|
|
|
algorithm if there is one.
|
|
|
|
|
|
|
|
To make things less ambiguous, this manual talks about a "context" or
|
|
|
|
"MAC context", which is to denote the MAC level context, and about a
|
|
|
|
"underlying context", or "computation context", which is to denote the
|
|
|
|
context for the underlying computation algorithm if there is one.
|
|
|
|
|
|
|
|
=head2 Types
|
|
|
|
|
|
|
|
B<EVP_MAC> is a type that holds the implementation of a MAC.
|
|
|
|
|
|
|
|
B<EVP_MAC_CTX> is a context type that holds internal MAC information
|
|
|
|
as well as a reference to a computation context, for those MACs that
|
|
|
|
rely on an underlying computation algorithm.
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
=head2 Algorithm implementation fetching
|
|
|
|
|
|
|
|
EVP_MAC_fetch() fetches an implementation of a MAC I<algorithm>, given
|
|
|
|
a library context I<libctx> and a set of I<properties>.
|
2021-03-26 01:02:25 +08:00
|
|
|
See L<crypto(7)/ALGORITHM FETCHING> for further information.
|
2019-05-07 18:39:58 +08:00
|
|
|
|
2020-05-26 11:53:07 +08:00
|
|
|
See L<OSSL_PROVIDER-default(7)/Message Authentication Code (MAC)> for the list
|
|
|
|
of algorithms supported by the default provider.
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
The returned value must eventually be freed with
|
|
|
|
L<EVP_MAC_free(3)>.
|
|
|
|
|
|
|
|
EVP_MAC_up_ref() increments the reference count of an already fetched
|
|
|
|
MAC.
|
|
|
|
|
|
|
|
EVP_MAC_free() frees a fetched algorithm.
|
|
|
|
NULL is a valid parameter, for which this function is a no-op.
|
|
|
|
|
2018-10-13 04:27:18 +08:00
|
|
|
=head2 Context manipulation functions
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_new() creates a new context for the MAC type I<mac>.
|
2018-10-13 04:27:18 +08:00
|
|
|
The created context can then be used with most other functions
|
|
|
|
described here.
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_free() frees the contents of the context, including an
|
2018-10-13 04:27:18 +08:00
|
|
|
underlying context if there is one, as well as the context itself.
|
2019-05-07 18:39:58 +08:00
|
|
|
NULL is a valid parameter, for which this function is a no-op.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_dup() duplicates the I<src> context and returns a newly allocated
|
2018-11-05 02:16:20 +08:00
|
|
|
context.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_mac() returns the B<EVP_MAC> associated with the context
|
2019-05-07 18:39:58 +08:00
|
|
|
I<ctx>.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
=head2 Computing functions
|
|
|
|
|
2021-03-30 01:42:33 +08:00
|
|
|
EVP_Q_mac() computes the message authentication code
|
|
|
|
of I<data> with length I<datalen>
|
|
|
|
using the MAC algorithm I<name> and the key I<key> with length I<keylen>.
|
|
|
|
The MAC algorithm is fetched using any given I<libctx> and property query
|
|
|
|
string I<propq>. It takes parameters I<subalg> and further I<params>,
|
|
|
|
both of which may be NULL if not needed.
|
|
|
|
If I<out> is not NULL, it places the result in the memory pointed at by I<out>,
|
|
|
|
but only if I<outsize> is sufficient (otherwise no computation is made).
|
|
|
|
If I<out> is NULL, it allocates and uses a buffer of suitable length,
|
|
|
|
which will be returned on success and must be freed by the caller.
|
|
|
|
In either case, also on error,
|
|
|
|
it assigns the number of bytes written to I<*outlen> unless I<outlen> is NULL.
|
|
|
|
|
2021-04-20 14:30:47 +08:00
|
|
|
EVP_MAC_init() sets up the underlying context I<ctx> with information given
|
2021-02-25 12:03:09 +08:00
|
|
|
via the I<key> and I<params> arguments. The MAC I<key> has a length of
|
|
|
|
I<keylen> and the parameters in I<params> are processed before setting
|
2021-04-20 14:30:47 +08:00
|
|
|
the key. If I<key> is NULL, the key must be set via I<params> either
|
2021-02-25 12:03:09 +08:00
|
|
|
as part of this call or separately using EVP_MAC_CTX_set_params().
|
2021-04-20 14:30:47 +08:00
|
|
|
Providing non-NULL I<params> to this function is equivalent to calling
|
|
|
|
EVP_MAC_CTX_set_params() with those I<params> for the same I<ctx> beforehand.
|
|
|
|
|
|
|
|
EVP_MAC_init() should be called before EVP_MAC_update() and EVP_MAC_final().
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC_update() adds I<datalen> bytes from I<data> to the MAC input.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
EVP_MAC_final() does the final computation and stores the result in
|
2019-05-07 18:39:58 +08:00
|
|
|
the memory pointed at by I<out> of size I<outsize>, and sets the number
|
|
|
|
of bytes written in I<*outl> at.
|
2019-09-23 16:17:19 +08:00
|
|
|
If I<out> is NULL or I<outsize> is too small, then no computation
|
2019-05-07 18:39:58 +08:00
|
|
|
is made.
|
2018-10-13 04:27:18 +08:00
|
|
|
To figure out what the output length will be and allocate space for it
|
2019-09-23 16:17:19 +08:00
|
|
|
dynamically, simply call with I<out> being NULL and I<outl>
|
2018-10-13 04:27:18 +08:00
|
|
|
pointing at a valid location, then allocate space and make a second
|
2019-05-07 18:39:58 +08:00
|
|
|
call with I<out> pointing at the allocated space.
|
|
|
|
|
2021-04-28 11:01:22 +08:00
|
|
|
EVP_MAC_finalXOF() does the final computation for an XOF based MAC and stores
|
|
|
|
the result in the memory pointed at by I<out> of size I<outsize>.
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC_get_params() retrieves details about the implementation
|
|
|
|
I<mac>.
|
|
|
|
The set of parameters given with I<params> determine exactly what
|
|
|
|
parameters should be retrieved.
|
|
|
|
Note that a parameter that is unknown in the underlying context is
|
|
|
|
simply ignored.
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_get_params() retrieves chosen parameters, given the
|
2019-05-07 18:39:58 +08:00
|
|
|
context I<ctx> and its underlying context.
|
|
|
|
The set of parameters given with I<params> determine exactly what
|
|
|
|
parameters should be retrieved.
|
|
|
|
Note that a parameter that is unknown in the underlying context is
|
|
|
|
simply ignored.
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_set_params() passes chosen parameters to the underlying
|
2019-05-07 18:39:58 +08:00
|
|
|
context, given a context I<ctx>.
|
|
|
|
The set of parameters given with I<params> determine exactly what
|
|
|
|
parameters are passed down.
|
2021-03-30 01:42:33 +08:00
|
|
|
If I<params> are NULL, the unterlying context should do nothing and return 1.
|
2019-05-07 18:39:58 +08:00
|
|
|
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.
|
|
|
|
|
2021-02-23 09:03:31 +08:00
|
|
|
EVP_MAC_gettable_params() returns an B<OSSL_PARAM> array that describes
|
|
|
|
the retrievable and settable parameters. EVP_MAC_gettable_params()
|
|
|
|
returns parameters that can be used with EVP_MAC_get_params().
|
|
|
|
See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as a parameter descriptor.
|
|
|
|
|
|
|
|
EVP_MAC_gettable_ctx_params() and EVP_MAC_CTX_gettable_params()
|
|
|
|
return constant B<OSSL_PARAM> arrays that describe the retrievable
|
|
|
|
parameters that can be used with EVP_MAC_CTX_get_params().
|
|
|
|
EVP_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.
|
|
|
|
See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as a parameter descriptor.
|
|
|
|
|
|
|
|
EVP_MAC_settable_ctx_params() and EVP_MAC_CTX_settable_params() return
|
|
|
|
constant B<OSSL_PARAM> 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. See L<OSSL_PARAM(3)>
|
|
|
|
for the use of B<OSSL_PARAM> as a parameter descriptor.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
=head2 Information functions
|
|
|
|
|
2020-10-13 12:22:17 +08:00
|
|
|
EVP_MAC_CTX_get_mac_size() returns the MAC output size for the given context.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-09-14 22:35:08 +08:00
|
|
|
EVP_MAC_is_a() checks if the given I<mac> is an implementation of an
|
|
|
|
algorithm that's identifiable with I<name>.
|
|
|
|
|
2019-06-05 00:14:38 +08:00
|
|
|
EVP_MAC_provider() returns the provider that holds the implementation
|
|
|
|
of the given I<mac>.
|
|
|
|
|
EVP: add missing common functionality
This adds the missing functions that should be common for all
fetchable EVP sub-APIs:
EVP_KEYMGMT_is_a(), EVP_KEYMGMT_do_all_provided(), EVP_KEYEXCH_is_a(),
EVP_KEYEXCH_do_all_provided(), EVP_KDF_is_a(), EVP_MD_is_a(),
EVP_SIGNATURE_do_all_provided(), EVP_SIGNATURE_is_a().
This also renames EVP_MD_do_all_ex(), EVP_CIPHER_do_all_ex(),
EVP_KDF_do_all_ex(), EVP_MAC_do_all_ex() to change '_ex'
to '_provided'.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9979)
2019-09-23 16:33:26 +08:00
|
|
|
EVP_MAC_do_all_provided() traverses all MAC implemented by all activated
|
2019-06-05 00:17:49 +08:00
|
|
|
providers in the given library context I<libctx>, and for each of the
|
|
|
|
implementations, calls the given function I<fn> with the implementation method
|
|
|
|
and the given I<arg> as argument.
|
|
|
|
|
2019-09-23 17:16:21 +08:00
|
|
|
EVP_MAC_number() returns the internal dynamic number assigned to
|
|
|
|
I<mac>.
|
|
|
|
|
2020-09-22 07:25:35 +08:00
|
|
|
EVP_MAC_name() return the name of the given MAC. For fetched MACs
|
|
|
|
with multiple names, only one of them is returned; it's
|
|
|
|
recommended to use EVP_MAC_names_do_all() instead.
|
|
|
|
|
2019-09-23 16:56:13 +08:00
|
|
|
EVP_MAC_names_do_all() traverses all names for I<mac>, and calls
|
|
|
|
I<fn> with each name and I<data>.
|
|
|
|
|
EVP: Add EVP_<TYPE>_description()
The following operation types are covered:
EVP_MD, EVP_CIPHER, EVP_MAC, EVP_RAND, EVP_KEYMGMT, EVP_SIGNATURE,
EVP_ASYM_CIPHER, EVP_KEM, EVP_KEYEXCH, EVP_KDF. Also EVP_PKEY.
For EVP_MD and EVP_CIPHER, OBJ_nid2ln() is used as a fallback for
legacy implementations.
For EVP_PKEY, the info field of the EVP_PKEY_ASN1_METHOD is used as a
fallback for legacy implementations.
Fixes #14514
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14656)
2021-03-16 21:23:54 +08:00
|
|
|
EVP_MAC_description() returns a description of the I<mac>, meant for display
|
|
|
|
and human consumption. The description is at the discretion of the mac
|
|
|
|
implementation.
|
|
|
|
|
2019-09-17 06:45:38 +08:00
|
|
|
=head1 PARAMETERS
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-08-28 15:13:21 +08:00
|
|
|
Parameters are identified by name as strings, and have an expected
|
|
|
|
data type and maximum size.
|
|
|
|
OpenSSL has a set of macros for parameter names it expects to see in
|
|
|
|
its own MAC implementations.
|
|
|
|
Here, we show all three, the OpenSSL macro for the parameter name, the
|
|
|
|
name in string form, and a type description.
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
The standard parameter names are:
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
Its value is the MAC key as an array of bytes.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
For MACs that use an underlying computation algorithm, the algorithm
|
2019-05-07 18:39:58 +08:00
|
|
|
must be set first, see parameter names "algorithm" below.
|
2018-11-05 06:09:41 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "iv" (B<OSSL_MAC_PARAM_IV>) <octet string>
|
2018-11-05 06:09:41 +08:00
|
|
|
|
2021-05-12 10:26:24 +08:00
|
|
|
Some MAC implementations (GMAC) require an IV, this parameter sets the IV.
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "custom" (B<OSSL_MAC_PARAM_CUSTOM>) <octet string>
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2018-12-21 07:34:22 +08:00
|
|
|
Some MAC implementations (KMAC, BLAKE2) accept a Customization String,
|
2019-05-07 18:39:58 +08:00
|
|
|
this parameter sets the Customization String. The default value is the
|
|
|
|
empty string.
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "salt" (B<OSSL_MAC_PARAM_SALT>) <octet string>
|
2018-12-21 07:34:22 +08:00
|
|
|
|
|
|
|
This option is used by BLAKE2 MAC.
|
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "xof" (B<OSSL_MAC_PARAM_XOF>) <integer>
|
2018-11-09 12:00:05 +08:00
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
It's a simple flag, the value 0 or 1 are expected.
|
2018-11-09 12:00:05 +08:00
|
|
|
|
|
|
|
This option is used by KMAC.
|
|
|
|
|
2020-12-14 12:36:48 +08:00
|
|
|
=item "digest-noinit" (B<OSSL_MAC_PARAM_DIGEST_NOINIT>) <integer>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-12-14 12:36:48 +08:00
|
|
|
A simple flag to set the MAC digest to not initialise the
|
|
|
|
implementation specific data. The value 0 or 1 is expected.
|
|
|
|
|
|
|
|
This option is used by HMAC.
|
|
|
|
|
|
|
|
=item "digest-oneshot" (B<OSSL_MAC_PARAM_DIGEST_ONESHOT>) <integer>
|
|
|
|
|
|
|
|
A simple flag to set the MAC digest to be a oneshot operation.
|
|
|
|
The value 0 or 1 is expected.
|
|
|
|
|
|
|
|
This option is used by HMAC.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "digest" (B<OSSL_MAC_PARAM_DIGEST>) <UTF8 string>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "cipher" (B<OSSL_MAC_PARAM_CIPHER>) <UTF8 string>
|
2019-05-07 18:39:58 +08:00
|
|
|
|
2019-08-23 20:54:16 +08:00
|
|
|
For MAC implementations that use an underlying computation cipher or
|
2019-09-22 08:46:54 +08:00
|
|
|
digest, these parameters set what the algorithm should be.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-09-22 08:46:54 +08:00
|
|
|
The value is always the name of the intended algorithm,
|
2019-08-23 20:54:16 +08:00
|
|
|
or the properties.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
Note that not all algorithms may support all digests.
|
|
|
|
HMAC does not support variable output length digests such as SHAKE128
|
|
|
|
or SHAKE256.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-09-10 16:05:57 +08:00
|
|
|
=item "size" (B<OSSL_MAC_PARAM_SIZE>) <unsigned integer>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
For MAC implementations that support it, set the output size that
|
|
|
|
EVP_MAC_final() should produce.
|
2019-09-13 17:32:28 +08:00
|
|
|
The allowed sizes vary between MAC implementations, but must never exceed
|
|
|
|
what can be given with a B<size_t>.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-08-27 19:52:17 +08:00
|
|
|
=item "tls-data-size" (B<OSSL_MAC_PARAM_TLS_DATA_SIZE>) <unsigned integer>
|
|
|
|
|
|
|
|
This parameter is only supported by HMAC. If set then special handling is
|
|
|
|
activated for calculating the MAC of a received mac-then-encrypt TLS record
|
|
|
|
where variable length record padding has been used (as in the case of CBC mode
|
|
|
|
ciphersuites). The value represents the total length of the record that is
|
|
|
|
having the MAC calculated including the received MAC and the record padding.
|
|
|
|
|
|
|
|
When used EVP_MAC_update must be called precisely twice. The first time with
|
|
|
|
the 13 bytes of TLS "header" data, and the second time with the entire record
|
|
|
|
including the MAC itself and any padding. The entire record length must equal
|
|
|
|
the value passed in the "tls-data-size" parameter. The length passed in the
|
|
|
|
B<datalen> parameter to EVP_MAC_update() should be equal to the length of the
|
|
|
|
record after the MAC and any padding has been removed.
|
|
|
|
|
2018-10-13 04:27:18 +08:00
|
|
|
=back
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
All these parameters should be used before the calls to any of
|
2018-10-13 04:27:18 +08:00
|
|
|
EVP_MAC_init(), EVP_MAC_update() and EVP_MAC_final() for a full
|
|
|
|
computation.
|
|
|
|
Anything else may give undefined results.
|
|
|
|
|
2021-03-24 11:38:57 +08:00
|
|
|
=head1 NOTES
|
|
|
|
|
|
|
|
The MAC life-cycle is described in L<life_cycle-mac(7)>. In the future,
|
|
|
|
the transitions described there will be enforced. When this is done, it will
|
|
|
|
not be considered a breaking change to the API.
|
|
|
|
|
2021-05-12 10:26:24 +08:00
|
|
|
The usage of the parameter names "custom", "iv" and "salt" correspond to
|
|
|
|
the names used in the standard where the algorithm was defined.
|
2021-03-24 11:38:57 +08:00
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
=head1 RETURN VALUES
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2021-03-30 01:42:33 +08:00
|
|
|
EVP_MAC_fetch() returns a pointer to a newly fetched B<EVP_MAC>, or
|
2019-05-07 18:39:58 +08:00
|
|
|
NULL if allocation failed.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC_up_ref() returns 1 on success, 0 on error.
|
|
|
|
|
2021-02-20 01:03:43 +08:00
|
|
|
EVP_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.
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC_free() returns nothing at all.
|
|
|
|
|
2019-09-14 22:35:08 +08:00
|
|
|
EVP_MAC_is_a() returns 1 if the given method can be identified with
|
|
|
|
the given name, otherwise 0.
|
|
|
|
|
2020-09-22 07:25:35 +08:00
|
|
|
EVP_MAC_name() returns a name of the MAC, or NULL on error.
|
|
|
|
|
2019-06-05 00:14:38 +08:00
|
|
|
EVP_MAC_provider() returns a pointer to the provider for the MAC, or
|
|
|
|
NULL on error.
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_new() and EVP_MAC_CTX_dup() return a pointer to a newly
|
2019-05-07 18:39:58 +08:00
|
|
|
created EVP_MAC_CTX, or NULL if allocation failed.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_free() returns nothing at all.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_get_params() and EVP_MAC_CTX_set_params() return 1 on
|
2019-05-07 18:39:58 +08:00
|
|
|
success, 0 on error.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2021-03-30 01:42:33 +08:00
|
|
|
EVP_Q_mac() returns a pointer to the computed MAC value, or NULL on error.
|
|
|
|
|
|
|
|
EVP_MAC_init(), EVP_MAC_update(), EVP_MAC_final(), and EVP_MAC_finalXOF()
|
2021-04-28 11:01:22 +08:00
|
|
|
return 1 on success, 0 on error.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2020-10-13 12:22:17 +08:00
|
|
|
EVP_MAC_CTX_get_mac_size() returns the expected output size, or 0 if it isn't set.
|
2018-10-13 04:27:18 +08:00
|
|
|
If it isn't set, a call to EVP_MAC_init() should get it set.
|
|
|
|
|
EVP: add missing common functionality
This adds the missing functions that should be common for all
fetchable EVP sub-APIs:
EVP_KEYMGMT_is_a(), EVP_KEYMGMT_do_all_provided(), EVP_KEYEXCH_is_a(),
EVP_KEYEXCH_do_all_provided(), EVP_KDF_is_a(), EVP_MD_is_a(),
EVP_SIGNATURE_do_all_provided(), EVP_SIGNATURE_is_a().
This also renames EVP_MD_do_all_ex(), EVP_CIPHER_do_all_ex(),
EVP_KDF_do_all_ex(), EVP_MAC_do_all_ex() to change '_ex'
to '_provided'.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9979)
2019-09-23 16:33:26 +08:00
|
|
|
EVP_MAC_do_all_provided() returns nothing at all.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2019-08-16 02:26:08 +08:00
|
|
|
=head1 EXAMPLES
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/err.h>
|
2019-05-07 18:39:58 +08:00
|
|
|
#include <openssl/params.h>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
int main() {
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC *mac = EVP_MAC_fetch(NULL, getenv("MY_MAC"), NULL);
|
|
|
|
const char *cipher = getenv("MY_MAC_CIPHER");
|
|
|
|
const char *digest = getenv("MY_MAC_DIGEST");
|
2018-10-13 04:27:18 +08:00
|
|
|
const char *key = getenv("MY_KEY");
|
|
|
|
EVP_MAC_CTX *ctx = NULL;
|
|
|
|
|
|
|
|
unsigned char buf[4096];
|
2020-07-13 13:04:28 +08:00
|
|
|
size_t read_l;
|
2018-10-13 04:27:18 +08:00
|
|
|
size_t final_l;
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
|
2021-02-25 12:03:09 +08:00
|
|
|
OSSL_PARAM params[3];
|
2019-05-07 18:39:58 +08:00
|
|
|
size_t params_n = 0;
|
|
|
|
|
|
|
|
if (cipher != NULL)
|
|
|
|
params[params_n++] =
|
2020-07-13 13:04:28 +08:00
|
|
|
OSSL_PARAM_construct_utf8_string("cipher", (char*)cipher, 0);
|
2019-05-07 18:39:58 +08:00
|
|
|
if (digest != NULL)
|
|
|
|
params[params_n++] =
|
2020-07-13 13:04:28 +08:00
|
|
|
OSSL_PARAM_construct_utf8_string("digest", (char*)digest, 0);
|
2019-05-07 18:39:58 +08:00
|
|
|
params[params_n] = OSSL_PARAM_construct_end();
|
|
|
|
|
2018-10-13 04:27:18 +08:00
|
|
|
if (mac == NULL
|
|
|
|
|| key == NULL
|
2020-06-18 16:26:22 +08:00
|
|
|
|| (ctx = EVP_MAC_CTX_new(mac)) == NULL
|
2021-02-25 12:03:09 +08:00
|
|
|
|| !EVP_MAC_init(ctx, (const unsigned char *)key, strlen(key),
|
|
|
|
params))
|
2018-10-13 04:27:18 +08:00
|
|
|
goto err;
|
|
|
|
|
2020-02-21 15:41:29 +08:00
|
|
|
while ( (read_l = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
|
2018-10-13 04:27:18 +08:00
|
|
|
if (!EVP_MAC_update(ctx, buf, read_l))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2020-07-13 13:04:28 +08:00
|
|
|
if (!EVP_MAC_final(ctx, buf, &final_l, sizeof(buf)))
|
2018-10-13 04:27:18 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
printf("Result: ");
|
|
|
|
for (i = 0; i < final_l; i++)
|
|
|
|
printf("%02X", buf[i]);
|
|
|
|
printf("\n");
|
|
|
|
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_free(ctx);
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC_free(mac);
|
2018-10-13 04:27:18 +08:00
|
|
|
exit(0);
|
|
|
|
|
|
|
|
err:
|
2020-06-18 16:26:22 +08:00
|
|
|
EVP_MAC_CTX_free(ctx);
|
2019-05-07 18:39:58 +08:00
|
|
|
EVP_MAC_free(mac);
|
2018-10-13 04:27:18 +08:00
|
|
|
fprintf(stderr, "Something went wrong\n");
|
|
|
|
ERR_print_errors_fp(stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
A run of this program, called with correct environment variables, can
|
|
|
|
look like this:
|
|
|
|
|
|
|
|
$ MY_MAC=cmac MY_KEY=secret0123456789 MY_MAC_CIPHER=aes-128-cbc \
|
|
|
|
LD_LIBRARY_PATH=. ./foo < foo.c
|
2020-02-21 15:41:29 +08:00
|
|
|
Result: C5C06683CD9DDEF904D754505C560A4E
|
2018-10-13 04:27:18 +08:00
|
|
|
|
|
|
|
(in this example, that program was stored in F<foo.c> and compiled to
|
|
|
|
F<./foo>)
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2019-05-07 18:39:58 +08:00
|
|
|
L<property(7)>
|
|
|
|
L<OSSL_PARAM(3)>,
|
2019-08-22 13:21:25 +08:00
|
|
|
L<EVP_MAC-BLAKE2(7)>,
|
|
|
|
L<EVP_MAC-CMAC(7)>,
|
|
|
|
L<EVP_MAC-GMAC(7)>,
|
|
|
|
L<EVP_MAC-HMAC(7)>,
|
|
|
|
L<EVP_MAC-KMAC(7)>,
|
|
|
|
L<EVP_MAC-Siphash(7)>,
|
2021-03-24 11:38:57 +08:00
|
|
|
L<EVP_MAC-Poly1305(7)>,
|
|
|
|
L<provider-mac(7)>,
|
|
|
|
L<life_cycle-mac(7)>
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2018-11-05 02:16:20 +08:00
|
|
|
=head1 HISTORY
|
|
|
|
|
2019-07-15 21:03:44 +08:00
|
|
|
These functions were added in OpenSSL 3.0.
|
2018-11-05 02:16:20 +08:00
|
|
|
|
2018-10-13 04:27:18 +08:00
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
2021-02-18 22:57:13 +08:00
|
|
|
Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2018-10-13 04:27:18 +08:00
|
|
|
|
2018-12-06 21:04:44 +08:00
|
|
|
Licensed under the Apache License 2.0 (the "License"). You may not use
|
2018-10-13 04:27:18 +08:00
|
|
|
this file except in compliance with the License. You can obtain a copy
|
|
|
|
in the file LICENSE in the source distribution or at
|
|
|
|
L<https://www.openssl.org/source/license.html>.
|
|
|
|
|
|
|
|
=cut
|