1 | =pod
|
---|
2 |
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | provider-mac - The mac library E<lt>-E<gt> provider functions
|
---|
6 |
|
---|
7 | =head1 SYNOPSIS
|
---|
8 |
|
---|
9 | =for openssl multiple includes
|
---|
10 |
|
---|
11 | #include <openssl/core_dispatch.h>
|
---|
12 | #include <openssl/core_names.h>
|
---|
13 |
|
---|
14 | /*
|
---|
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.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Context management */
|
---|
21 | void *OSSL_FUNC_mac_newctx(void *provctx);
|
---|
22 | void OSSL_FUNC_mac_freectx(void *mctx);
|
---|
23 | void *OSSL_FUNC_mac_dupctx(void *src);
|
---|
24 |
|
---|
25 | /* Encryption/decryption */
|
---|
26 | int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen,
|
---|
27 | const OSSL_PARAM params[]);
|
---|
28 | int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
|
---|
29 | int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
|
---|
30 |
|
---|
31 | /* MAC parameter descriptors */
|
---|
32 | const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
|
---|
33 | const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
|
---|
34 | const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
|
---|
35 |
|
---|
36 | /* MAC parameters */
|
---|
37 | int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
|
---|
38 | int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
|
---|
39 | int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
|
---|
40 |
|
---|
41 | =head1 DESCRIPTION
|
---|
42 |
|
---|
43 | This documentation is primarily aimed at provider authors. See L<provider(7)>
|
---|
44 | for further information.
|
---|
45 |
|
---|
46 | The MAC operation enables providers to implement mac algorithms and make
|
---|
47 | them available to applications via the API functions L<EVP_MAC_init(3)>,
|
---|
48 | L<EVP_MAC_update(3)> and L<EVP_MAC_final(3)>.
|
---|
49 |
|
---|
50 | All "functions" mentioned here are passed as function pointers between
|
---|
51 | F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
|
---|
52 | L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
|
---|
53 | provider_query_operation() function
|
---|
54 | (see L<provider-base(7)/Provider Functions>).
|
---|
55 |
|
---|
56 | All these "functions" have a corresponding function type definition
|
---|
57 | named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
|
---|
58 | function pointer from an L<OSSL_DISPATCH(3)> element named
|
---|
59 | B<OSSL_FUNC_{name}>.
|
---|
60 | For example, the "function" OSSL_FUNC_mac_newctx() has these:
|
---|
61 |
|
---|
62 | typedef void *(OSSL_FUNC_mac_newctx_fn)(void *provctx);
|
---|
63 | static ossl_inline OSSL_FUNC_mac_newctx_fn
|
---|
64 | OSSL_FUNC_mac_newctx(const OSSL_DISPATCH *opf);
|
---|
65 |
|
---|
66 | L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
|
---|
67 | macros in L<openssl-core_dispatch.h(7)>, as follows:
|
---|
68 |
|
---|
69 | OSSL_FUNC_mac_newctx OSSL_FUNC_MAC_NEWCTX
|
---|
70 | OSSL_FUNC_mac_freectx OSSL_FUNC_MAC_FREECTX
|
---|
71 | OSSL_FUNC_mac_dupctx OSSL_FUNC_MAC_DUPCTX
|
---|
72 |
|
---|
73 | OSSL_FUNC_mac_init OSSL_FUNC_MAC_INIT
|
---|
74 | OSSL_FUNC_mac_update OSSL_FUNC_MAC_UPDATE
|
---|
75 | OSSL_FUNC_mac_final OSSL_FUNC_MAC_FINAL
|
---|
76 |
|
---|
77 | OSSL_FUNC_mac_get_params OSSL_FUNC_MAC_GET_PARAMS
|
---|
78 | OSSL_FUNC_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS
|
---|
79 | OSSL_FUNC_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS
|
---|
80 |
|
---|
81 | OSSL_FUNC_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS
|
---|
82 | OSSL_FUNC_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
|
---|
83 | OSSL_FUNC_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
|
---|
84 |
|
---|
85 | A mac algorithm implementation may not implement all of these functions.
|
---|
86 | In order to be a consistent set of functions, at least the following functions
|
---|
87 | must be implemented: OSSL_FUNC_mac_newctx(), OSSL_FUNC_mac_freectx(), OSSL_FUNC_mac_init(),
|
---|
88 | OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final().
|
---|
89 | All other functions are optional.
|
---|
90 |
|
---|
91 | =head2 Context Management Functions
|
---|
92 |
|
---|
93 | OSSL_FUNC_mac_newctx() should create and return a pointer to a provider side
|
---|
94 | structure for holding context information during a mac operation.
|
---|
95 | A pointer to this context will be passed back in a number of the other mac
|
---|
96 | operation function calls.
|
---|
97 | The parameter I<provctx> is the provider context generated during provider
|
---|
98 | initialisation (see L<provider(7)>).
|
---|
99 |
|
---|
100 | OSSL_FUNC_mac_freectx() is passed a pointer to the provider side mac context in
|
---|
101 | the I<mctx> parameter.
|
---|
102 | If it receives NULL as I<mctx> value, it should not do anything other than
|
---|
103 | return.
|
---|
104 | This function should free any resources associated with that context.
|
---|
105 |
|
---|
106 | OSSL_FUNC_mac_dupctx() should duplicate the provider side mac context in the
|
---|
107 | I<mctx> parameter and return the duplicate copy.
|
---|
108 |
|
---|
109 | =head2 Encryption/Decryption Functions
|
---|
110 |
|
---|
111 | OSSL_FUNC_mac_init() initialises a mac operation given a newly created provider
|
---|
112 | side mac context in the I<mctx> parameter. The I<params> are set before setting
|
---|
113 | the MAC I<key> of I<keylen> bytes.
|
---|
114 |
|
---|
115 | OSSL_FUNC_mac_update() is called to supply data for MAC computation of a previously
|
---|
116 | initialised mac operation.
|
---|
117 | The I<mctx> parameter contains a pointer to a previously initialised provider
|
---|
118 | side context.
|
---|
119 | OSSL_FUNC_mac_update() may be called multiple times for a single mac operation.
|
---|
120 |
|
---|
121 | OSSL_FUNC_mac_final() completes the MAC computation started through previous
|
---|
122 | OSSL_FUNC_mac_init() and OSSL_FUNC_mac_update() calls.
|
---|
123 | The I<mctx> parameter contains a pointer to the provider side context.
|
---|
124 | The resulting MAC should be written to I<out> and the amount of data written
|
---|
125 | to I<*outl>, which should not exceed I<outsize> bytes.
|
---|
126 | The same expectations apply to I<outsize> as documented for
|
---|
127 | L<EVP_MAC_final(3)>.
|
---|
128 |
|
---|
129 | =head2 Mac Parameters
|
---|
130 |
|
---|
131 | See L<OSSL_PARAM(3)> for further details on the parameters structure used by
|
---|
132 | these functions.
|
---|
133 |
|
---|
134 | OSSL_FUNC_mac_get_params() gets details of parameter values associated with the
|
---|
135 | provider algorithm and stores them in I<params>.
|
---|
136 |
|
---|
137 | OSSL_FUNC_mac_set_ctx_params() sets mac parameters associated with the given
|
---|
138 | provider side mac context I<mctx> to I<params>.
|
---|
139 | Any parameter settings are additional to any that were previously set.
|
---|
140 | Passing NULL for I<params> should return true.
|
---|
141 |
|
---|
142 | OSSL_FUNC_mac_get_ctx_params() gets details of currently set parameter values
|
---|
143 | associated with the given provider side mac context I<mctx> and stores them
|
---|
144 | in I<params>.
|
---|
145 | Passing NULL for I<params> should return true.
|
---|
146 |
|
---|
147 | OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params(),
|
---|
148 | and OSSL_FUNC_mac_settable_ctx_params() all return constant L<OSSL_PARAM(3)>
|
---|
149 | arrays as descriptors of the parameters that OSSL_FUNC_mac_get_params(),
|
---|
150 | OSSL_FUNC_mac_get_ctx_params(), and OSSL_FUNC_mac_set_ctx_params()
|
---|
151 | can handle, respectively. OSSL_FUNC_mac_gettable_ctx_params() and
|
---|
152 | OSSL_FUNC_mac_settable_ctx_params() will return the parameters associated
|
---|
153 | with the provider side context I<mctx> in its current state if it is
|
---|
154 | not NULL. Otherwise, they return the parameters associated with the
|
---|
155 | provider side algorithm I<provctx>.
|
---|
156 |
|
---|
157 | All MAC implementations are expected to handle the following parameters:
|
---|
158 |
|
---|
159 | =over 4
|
---|
160 |
|
---|
161 | =item with OSSL_FUNC_set_ctx_params():
|
---|
162 |
|
---|
163 | =over 4
|
---|
164 |
|
---|
165 | =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
|
---|
166 |
|
---|
167 | Sets the key in the associated MAC ctx. This is identical to passing a I<key>
|
---|
168 | argument to the OSSL_FUNC_mac_init() function.
|
---|
169 |
|
---|
170 | =back
|
---|
171 |
|
---|
172 | =item with OSSL_FUNC_get_params():
|
---|
173 |
|
---|
174 | =over 4
|
---|
175 |
|
---|
176 | =item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer>
|
---|
177 |
|
---|
178 | Can be used to get the default MAC size (which might be the only allowable
|
---|
179 | MAC size for the implementation).
|
---|
180 |
|
---|
181 | Note that some implementations allow setting the size that the resulting MAC
|
---|
182 | should have as well, see the documentation of the implementation.
|
---|
183 |
|
---|
184 | =back
|
---|
185 |
|
---|
186 | =over 4
|
---|
187 |
|
---|
188 | =item "size" (B<OSSL_MAC_PARAM_BLOCK_SIZE>) <integer>
|
---|
189 |
|
---|
190 | Can be used to get the MAC block size (if supported by the algorithm).
|
---|
191 |
|
---|
192 | =back
|
---|
193 |
|
---|
194 | =back
|
---|
195 |
|
---|
196 | =head1 NOTES
|
---|
197 |
|
---|
198 | The MAC life-cycle is described in L<life_cycle-rand(7)>. Providers should
|
---|
199 | ensure that the various transitions listed there are supported. At some point
|
---|
200 | the EVP layer will begin enforcing the listed transitions.
|
---|
201 |
|
---|
202 | =head1 RETURN VALUES
|
---|
203 |
|
---|
204 | OSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created
|
---|
205 | provider side mac context, or NULL on failure.
|
---|
206 |
|
---|
207 | OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(),
|
---|
208 | OSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for
|
---|
209 | success or 0 on error.
|
---|
210 |
|
---|
211 | OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and
|
---|
212 | OSSL_FUNC_mac_settable_ctx_params() should return a constant L<OSSL_PARAM(3)>
|
---|
213 | array, or NULL if none is offered.
|
---|
214 |
|
---|
215 | =head1 SEE ALSO
|
---|
216 |
|
---|
217 | L<provider(7)>,
|
---|
218 | L<EVP_MAC-BLAKE2(7)>, L<EVP_MAC-CMAC(7)>, L<EVP_MAC-GMAC(7)>,
|
---|
219 | L<EVP_MAC-HMAC(7)>, L<EVP_MAC-KMAC(7)>, L<EVP_MAC-Poly1305(7)>,
|
---|
220 | L<EVP_MAC-Siphash(7)>,
|
---|
221 | L<life_cycle-mac(7)>, L<EVP_MAC(3)>
|
---|
222 |
|
---|
223 | =head1 HISTORY
|
---|
224 |
|
---|
225 | The provider MAC interface was introduced in OpenSSL 3.0.
|
---|
226 |
|
---|
227 | =head1 COPYRIGHT
|
---|
228 |
|
---|
229 | Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
|
---|
230 |
|
---|
231 | Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
232 | this file except in compliance with the License. You can obtain a copy
|
---|
233 | in the file LICENSE in the source distribution or at
|
---|
234 | L<https://www.openssl.org/source/license.html>.
|
---|
235 |
|
---|
236 | =cut
|
---|