5 provider-mac - The mac library E<lt>-E<gt> provider functions
9 =for comment multiple includes
11 #include <openssl/core_numbers.h>
12 #include <openssl/core_names.h>
15 * None of these are actual functions, but are displayed like this for
16 * the function signatures for functions that are offered as function
17 * pointers in OSSL_DISPATCH arrays.
20 /* Context management */
21 void *OP_mac_newctx(void *provctx);
22 void OP_mac_freectx(void *mctx);
23 void *OP_mac_dupctx(void *src);
25 /* Encryption/decryption */
26 int OP_mac_init(void *mctx);
27 int OP_mac_update(void *mctx, const unsigned char *in, size_t inl);
28 int OP_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
30 /* MAC parameter descriptors */
31 const OSSL_PARAM *OP_mac_get_params(void);
32 const OSSL_PARAM *OP_mac_get_ctx_params(void);
33 const OSSL_PARAM *OP_mac_set_ctx_params(void);
36 int OP_mac_get_params(OSSL_PARAM params[]);
37 int OP_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
38 int OP_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
42 This documentation is primarily aimed at provider authors. See L<provider(7)>
43 for further information.
45 The MAC operation enables providers to implement mac algorithms and make
46 them available to applications via the API functions L<EVP_MAC_init(3)>,
47 L<EVP_MACM_update(3)> and L<EVP_MAC_final(3)>.
49 All "functions" mentioned here are passed as function pointers between
50 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
51 B<OSSL_ALGORITHM> arrays that are returned by the provider's
52 provider_query_operation() function
53 (see L<provider-base(7)/Provider Functions>).
55 All these "functions" have a corresponding function type definition
56 named B<OSSL_{name}_fn>, and a helper function to retrieve the
57 function pointer from an B<OSSL_DISPATCH> element named
59 For example, the "function" OP_mac_newctx() has these:
61 typedef void *(OSSL_OP_mac_newctx_fn)(void *provctx);
62 static ossl_inline OSSL_OP_mac_newctx_fn
63 OSSL_get_OP_mac_newctx(const OSSL_DISPATCH *opf);
65 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
66 macros in L<openssl-core_numbers.h(7)>, as follows:
68 OP_mac_newctx OSSL_FUNC_MAC_NEWCTX
69 OP_mac_freectx OSSL_FUNC_MAC_FREECTX
70 OP_mac_dupctx OSSL_FUNC_MAC_DUPCTX
72 OP_mac_init OSSL_FUNC_MAC_INIT
73 OP_mac_update OSSL_FUNC_MAC_UPDATE
74 OP_mac_final OSSL_FUNC_MAC_FINAL
76 OP_mac_get_params OSSL_FUNC_MAC_GET_PARAMS
77 OP_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS
78 OP_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS
80 OP_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS
81 OP_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
82 OP_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
84 A mac algorithm implementation may not implement all of these functions.
85 In order to be a consistent set of functions, at least the following functions
86 must be implemented: OP_mac_newctx(), OP_mac_freectx(), OP_mac_init(),
87 OP_mac_update(), OP_mac_final().
88 All other functions are optional.
90 =head2 Context Management Functions
92 OP_mac_newctx() should create and return a pointer to a provider side
93 structure for holding context information during a mac operation.
94 A pointer to this context will be passed back in a number of the other mac
95 operation function calls.
96 The paramater I<provctx> is the provider context generated during provider
97 initialisation (see L<provider(3)>).
99 OP_mac_freectx() is passed a pointer to the provider side mac context in
100 the I<mctx> parameter.
101 If it receives NULL as I<mctx> value, it should not do anything other than
103 This function should free any resources associated with that context.
105 OP_mac_dupctx() should duplicate the provider side mac context in the
106 I<mctx> parameter and return the duplicate copy.
108 =head2 Encryption/Decryption Functions
110 OP_mac_init() initialises a mac operation given a newly created provider
111 side mac context in the I<mctx> paramter.
113 OP_mac_update() is called to supply data for MAC computation of a previously
114 initialised mac operation.
115 The I<mctx> parameter contains a pointer to a previously initialised provider
117 OP_mac_update() may be called multiple times for a single mac operation.
119 OP_mac_final() completes the MAC computation started through previous
120 OP_mac_init() and OP_mac_update() calls.
121 The I<mctx> parameter contains a pointer to the provider side context.
122 The resulting MAC should be written to I<out> and the amount of data written
123 to I<*outl>, which should not exceed I<outsize> bytes.
124 The same expectations apply to I<outsize> as documented for
127 =head2 Mac Parameters
129 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
132 OP_mac_get_params() gets details of parameter values associated with the
133 provider algorithm and stores them in I<params>.
135 OP_mac_set_ctx_params() sets mac parameters associated with the given
136 provider side mac context I<mctx> to I<params>.
137 Any parameter settings are additional to any that were previously set.
139 OP_mac_get_ctx_params() gets details of currently set parameter values
140 associated with the given provider side mac context I<mctx> and stores them
143 OP_mac_gettable_params(), OP_mac_gettable_ctx_params(), and
144 OP_mac_settable_ctx_params() all return constant B<OSSL_PARAM> arrays
145 as descriptors of the parameters that OP_mac_get_params(),
146 OP_mac_get_ctx_params(), and OP_mac_set_ctx_params() can handle,
149 Parameters currently recognised by built-in macs are as follows. Not all
150 parameters are relevant to, or are understood by all macs:
154 =item B<OSSL_MAC_PARAM_KEY> (octet string)
156 Sets the key in the associated MAC ctx.
158 =item B<OSSL_MAC_PARAM_IV> (octet string)
160 Sets the IV of the underlying cipher, when applicable.
162 =item B<OSSL_MAC_PARAM_CUSTOM> (utf8 string)
164 Sets the custom string in the associated MAC ctx.
166 =item B<OSSL_MAC_PARAM_SALT> (octet string)
168 Sets the salt of the underlying cipher, when applicable.
170 =item B<OSSL_MAC_PARAM_BLOCK_XOF> (int)
172 Sets XOF mode in the associated MAC ctx.
173 0 means no XOF mode, 1 means XOF mode.
175 =item B<OSSL_MAC_PARAM_FLAGS> (int)
177 Gets flags associated with the MAC.
179 =for comment We need to investigate if this is the right approach
181 =item B<OSSL_MAC_PARAM_CIPHER> (utf8 string)
183 =item B<OSSL_MAC_PARAM_DIGEST> (utf8 string)
185 Sets the name of the underlying cipher or digest to be used.
186 It must name a suitable algorithm for the MAC that's being used.
188 =item B<OSSL_MAC_PARAM_PROPERTIES> (utf8 string)
190 Sets the properties to be queried when trying to fetch the underlying algorithm.
191 This must be given together with the algorithm naming parameter to be
194 =item B<OSSL_MAC_PARAM_SIZE> (int)
196 Can be used to get the resulting MAC size.
198 With some MAC algorithms, it can also be used to set the size that the
199 resulting MAC should have.
200 Allowable sizes are decided within each implementation.
206 OP_mac_newctx() and OP_mac_dupctx() should return the newly created
207 provider side mac context, or NULL on failure.
209 OP_mac_init(), OP_mac_update(), OP_mac_final(), OP_mac_get_params(),
210 OP_mac_get_ctx_params() and OP_mac_set_ctx_params() should return 1 for
211 success or 0 on error.
213 OP_mac_gettable_params(), OP_mac_gettable_ctx_params() and
214 OP_mac_settable_ctx_params() should return a constant B<OSSL_PARAM>
215 array, or NULL if none is offered.
223 The provider MAC interface was introduced in OpenSSL 3.0.
227 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
229 Licensed under the Apache License 2.0 (the "License"). You may not use
230 this file except in compliance with the License. You can obtain a copy
231 in the file LICENSE in the source distribution or at
232 L<https://www.openssl.org/source/license.html>.