PROVIDER-MAC(7ossl)
π NAME
okay so provider-mac β it's literally the mac library <-> provider functions, the whole bridge between libcrypto and your provider's MAC implementation. welcome to the OpenSSL 7ossl corner of the manual, bestie, we're getting into it π«Ά
β¨ SYNOPSIS β¨
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
/*
* None of these are actual functions, but are displayed like this for
* the function signatures for functions that are offered as function
* pointers in OSSL_DISPATCH arrays.
*/
/* Context management */
void *OSSL_FUNC_mac_newctx(void *provctx);
void OSSL_FUNC_mac_freectx(void *mctx);
void *OSSL_FUNC_mac_dupctx(void *src);
/* Encryption/decryption */
int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen,
const OSSL_PARAM params[]);
int OSSL_FUNC_mac_init_skey(void *mctx, const void *key, const OSSL_PARAM params[]);
int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
/* MAC parameter descriptors */
const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
/* MAC parameters */
int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
heads up: none of these are actual functions β they're printed like this so you can see the function signatures for the function pointers you'll be stuffing into OSSL_DISPATCH arrays π
πΈ DESCRIPTION πΈ
so this doc is primarily aimed at provider authors, like you, writing an actual provider. if you need the general picture, go read provider(7) first, mwah π
The MAC operation is literally how providers get to implement mac algorithms and make them available to applications through the API functions EVP_MAC_init(3), EVP_MAC_update(3) and EVP_MAC_final(3). slay.
All the "functions" we're talking about here are passed as function pointers between libcrypto and the provider, inside OSSL_DISPATCH(3) arrays, which live in OSSL_ALGORITHM(3) arrays that get returned by the provider's provider_query_operation() function (peep "Provider Functions" in provider-base(7)). it's giving relay race but make it cryptographic πββοΈ
Every one of these "functions" has a matching function type definition named OSSL_FUNC_{name}_fn, plus a helper function that fetches the function pointer out of an OSSL_DISPATCH(3) element named OSSL_FUNC_{name}. like, for example, OSSL_FUNC_mac_newctx() gives you these cuties:
typedef void *(OSSL_FUNC_mac_newctx_fn)(void *provctx);
static ossl_inline OSSL_FUNC_mac_newctx_fn
OSSL_FUNC_mac_newctx(const OSSL_DISPATCH *opf);
OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as macros in openssl-core_dispatch.h(7), and here's the whole matching set, no cap:
OSSL_FUNC_mac_newctx OSSL_FUNC_MAC_NEWCTX
OSSL_FUNC_mac_freectx OSSL_FUNC_MAC_FREECTX
OSSL_FUNC_mac_dupctx OSSL_FUNC_MAC_DUPCTX
OSSL_FUNC_mac_init OSSL_FUNC_MAC_INIT
OSSL_FUNC_mac_init_skey OSSL_FUNC_MAC_INIT_SKEY
OSSL_FUNC_mac_update OSSL_FUNC_MAC_UPDATE
OSSL_FUNC_mac_final OSSL_FUNC_MAC_FINAL
OSSL_FUNC_mac_get_params OSSL_FUNC_MAC_GET_PARAMS
OSSL_FUNC_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS
OSSL_FUNC_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS
OSSL_FUNC_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS
OSSL_FUNC_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
OSSL_FUNC_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
A mac algorithm implementation may not implement all of these functions. but for a consistent set of functions you must implement at least these besties:
OSSL_FUNC_mac_newctx()OSSL_FUNC_mac_freectx()- at least one of
OSSL_FUNC_mac_init()orOSSL_FUNC_mac_init_skey() OSSL_FUNC_mac_update()OSSL_FUNC_mac_final()
everything else is optional, iykyk. the rest is just bonus content β¨
π§ Context Management Functions (the who's-who of your ctx)
OSSL_FUNC_mac_newctx()β should create and return a pointer to a provider side structure for holding context information during a mac operation. that pointer gets passed back into a bunch of the other mac operation function calls, so likeβ¦ keep track of it. the parameterprovctxis the provider context that got generated during provider initialisation (seeprovider(7)). πOSSL_FUNC_mac_freectx()β gets handed a pointer to the provider side mac context in themctxparameter. if it receivesNULLas themctxvalue, it should not do anything other than return, okay? just return, no dramatics. otherwise this function should free any resources associated with that context. cleanup era π§ΉOSSL_FUNC_mac_dupctx()β should duplicate the provider side mac context in themctxparameter and return the duplicate copy. twin moment π―ββοΈ
π₯ Encryption/Decryption Functions
OSSL_FUNC_mac_init()β initialises a mac operation given a newly created provider side mac context in themctxparameter. theparamsare set before setting the MAC key ofkeylenbytes. order matters, bestie π₯OSSL_FUNC_mac_init_skey()β similar vibe, but it uses an opaque provider-specific object to initialize the MAC context. mysterious. iconic. πΆοΈOSSL_FUNC_mac_update()β called to supply data for MAC computation of a previously initialised mac operation. themctxparameter contains a pointer to a previously initialised provider side context.OSSL_FUNC_mac_update()may be called multiple times for a single mac operation. feed it, feed it again πOSSL_FUNC_mac_final()β completes the MAC computation that was started through previousOSSL_FUNC_mac_init()andOSSL_FUNC_mac_update()calls. themctxparameter contains a pointer to the provider side context. the resulting MAC should be written toout, and the amount of data written to*outl, which should not exceedoutsizebytes. the same expectations apply tooutsizeas documented forEVP_MAC_final(3). no overflowing, we don't do that here π
π Mac Parameters
See OSSL_PARAM(3) for further details on the parameters structure used by these functions.
OSSL_FUNC_mac_get_params()β gets details of parameter values associated with the provider algorithm and stores them inparams.OSSL_FUNC_mac_set_ctx_params()β sets mac parameters associated with the given provider side mac contextmctxtoparams. any parameter settings are additional to any that were previously set. passingNULLforparamsshould return true. β¨OSSL_FUNC_mac_get_ctx_params()β gets details of currently set parameter values associated with the given provider side mac contextmctxand stores them inparams. passingNULLforparamsshould return true. β¨OSSL_FUNC_mac_gettable_params(),OSSL_FUNC_mac_gettable_ctx_params(), andOSSL_FUNC_mac_settable_ctx_params()β all return constantOSSL_PARAM(3)arrays as descriptors of the parameters thatOSSL_FUNC_mac_get_params(),OSSL_FUNC_mac_get_ctx_params(), andOSSL_FUNC_mac_set_ctx_params()can handle, respectively.OSSL_FUNC_mac_gettable_ctx_params()andOSSL_FUNC_mac_settable_ctx_params()will return the parameters associated with the provider side contextmctxin its current state if it is notNULL. otherwise, they return the parameters associated with the provider side algorithmprovctx. flexible queens π
All MAC implementations are expected to handle the following parameters:
with OSSL_FUNC_set_ctx_params():
"key"(OSSL_MAC_PARAM_KEY) <octet string> β sets the key in the associated MAC ctx. this is identical to passing akeyargument to theOSSL_FUNC_mac_init()function. π
with OSSL_FUNC_get_params():
"size"(OSSL_MAC_PARAM_SIZE) <integer> β can be used to get the default MAC size (which might be the only allowable MAC size for the implementation). note that some implementations allow setting the size that the resulting MAC should have as well β see the documentation of the implementation. π"size"(OSSL_MAC_PARAM_BLOCK_SIZE) <integer> β can be used to get the MAC block size (if supported by the algorithm).
The OpenSSL FIPS provider may support the following parameters:
"fips-indicator"(OSSL_MAC_PARAM_FIPS_APPROVED_INDICATOR) <int> β a getter that returns1if the operation is FIPS approved, or0otherwise. this may be used after calling the final function. it may return0if either"no-short-mac"or"key-check"are set to0. π"no-short-mac"(OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC) <integer> β if required, this parameter should be set early via an init function. the default value of1causes an error when too short MAC output is asked for. setting this to0will ignore the error and set the approved"fips-indicator"to0. this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. π¨"key-check"(OSSL_MAC_PARAM_FIPS_KEY_CHECK) <integer> β if required, this parameter should be set beforeOSSL_FUNC_mac_init. the default value of1causes an error when small key sizes are asked for. setting this to0will ignore the error and set the approved"fips-indicator"to0. this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. π¨
π¦ NOTES π¦
The MAC life-cycle is described in life_cycle-rand(7). providers should ensure that the various transitions listed there are supported, fr fr. at some point the EVP layer will begin enforcing the listed transitions β so like, don't be caught lacking π
π RETURN VALUES π
OSSL_FUNC_mac_newctx()andOSSL_FUNC_mac_dupctx()should return the newly created provider side mac context, orNULLon failure. πOSSL_FUNC_mac_init(),OSSL_FUNC_mac_init_skey(),OSSL_FUNC_mac_update(),OSSL_FUNC_mac_final(),OSSL_FUNC_mac_get_params(),OSSL_FUNC_mac_get_ctx_params()andOSSL_FUNC_mac_set_ctx_params()should return1for success or0on error. βOSSL_FUNC_mac_gettable_params(),OSSL_FUNC_mac_gettable_ctx_params()andOSSL_FUNC_mac_settable_ctx_params()should return a constantOSSL_PARAM(3)array, orNULLif none is offered. π
π SEE ALSO π
provider(7), EVP_MAC-BLAKE2(7), EVP_MAC-CMAC(7), EVP_MAC-GMAC(7), EVP_MAC-HMAC(7), EVP_MAC-KMAC(7), EVP_MAC-Poly1305(7), EVP_MAC-Siphash(7), life_cycle-mac(7), EVP_MAC(3)
like, the whole MAC cinematic universe, go read them all πΏ
π HISTORY π
The provider MAC interface was introduced in OpenSSL 3.0. the parameters "no-short-mac" and "fips-indicator" were added in OpenSSL 3.4. and the function OSSL_FUNC_mac_init_skey() was introduced in OpenSSL 3.5. glow-up timeline π
πΈ COPYRIGHT πΈ
Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved.
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 <https://www.openssl.org/source/license.html>.
okay that's the whole thing, bestie!! this page is from OpenSSL 3.5.6, dated 2026-04-07, and it's the PROVIDER-MAC(7ossl) manual page π«Ά go implement a mac algorithm, you're gonna ate π
β¨π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms