doc: changes to match the updated context gettable/settable calls for MACs
[openssl.git] / doc / man7 / provider-mac.pod
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);
27  int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
28  int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
29
30  /* MAC parameter descriptors */
31  const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
32  const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
33  const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
34
35  /* MAC parameters */
36  int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
37  int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
38  int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
39
40 =head1 DESCRIPTION
41
42 This documentation is primarily aimed at provider authors. See L<provider(7)>
43 for further information.
44
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_MAC_update(3)> and L<EVP_MAC_final(3)>.
48
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>).
54
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
58 B<OSSL_FUNC_{name}>.
59 For example, the "function" OSSL_FUNC_mac_newctx() has these:
60
61  typedef void *(OSSL_OSSL_FUNC_mac_newctx_fn)(void *provctx);
62  static ossl_inline OSSL_OSSL_FUNC_mac_newctx_fn
63      OSSL_FUNC_mac_newctx(const OSSL_DISPATCH *opf);
64
65 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
66 macros in L<openssl-core_dispatch.h(7)>, as follows:
67
68  OSSL_FUNC_mac_newctx               OSSL_FUNC_MAC_NEWCTX
69  OSSL_FUNC_mac_freectx              OSSL_FUNC_MAC_FREECTX
70  OSSL_FUNC_mac_dupctx               OSSL_FUNC_MAC_DUPCTX
71
72  OSSL_FUNC_mac_init                 OSSL_FUNC_MAC_INIT
73  OSSL_FUNC_mac_update               OSSL_FUNC_MAC_UPDATE
74  OSSL_FUNC_mac_final                OSSL_FUNC_MAC_FINAL
75
76  OSSL_FUNC_mac_get_params           OSSL_FUNC_MAC_GET_PARAMS
77  OSSL_FUNC_mac_get_ctx_params       OSSL_FUNC_MAC_GET_CTX_PARAMS
78  OSSL_FUNC_mac_set_ctx_params       OSSL_FUNC_MAC_SET_CTX_PARAMS
79
80  OSSL_FUNC_mac_gettable_params      OSSL_FUNC_MAC_GETTABLE_PARAMS
81  OSSL_FUNC_mac_gettable_ctx_params  OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
82  OSSL_FUNC_mac_settable_ctx_params  OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
83
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: OSSL_FUNC_mac_newctx(), OSSL_FUNC_mac_freectx(), OSSL_FUNC_mac_init(),
87 OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final().
88 All other functions are optional.
89
90 =head2 Context Management Functions
91
92 OSSL_FUNC_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 parameter I<provctx> is the provider context generated during provider
97 initialisation (see L<provider(7)>).
98
99 OSSL_FUNC_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
102 return.
103 This function should free any resources associated with that context.
104
105 OSSL_FUNC_mac_dupctx() should duplicate the provider side mac context in the
106 I<mctx> parameter and return the duplicate copy.
107
108 =head2 Encryption/Decryption Functions
109
110 OSSL_FUNC_mac_init() initialises a mac operation given a newly created provider
111 side mac context in the I<mctx> parameter.
112
113 OSSL_FUNC_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
116 side context.
117 OSSL_FUNC_mac_update() may be called multiple times for a single mac operation.
118
119 OSSL_FUNC_mac_final() completes the MAC computation started through previous
120 OSSL_FUNC_mac_init() and OSSL_FUNC_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
125 L<EVP_MAC_final(3)>.
126
127 =head2 Mac Parameters
128
129 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
130 these functions.
131
132 OSSL_FUNC_mac_get_params() gets details of parameter values associated with the
133 provider algorithm and stores them in I<params>.
134
135 OSSL_FUNC_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.
138
139 OSSL_FUNC_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
141 in I<params>.
142
143 OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params(),
144 and OSSL_FUNC_mac_settable_ctx_params() all return constant B<OSSL_PARAM>
145 arrays as descriptors of the parameters that OSSL_FUNC_mac_get_params(),
146 OSSL_FUNC_mac_get_ctx_params(), and OSSL_FUNC_mac_set_ctx_params()
147 can handle, respectively.  OSSL_FUNC_mac_gettable_ctx_params() and
148 OSSL_FUNC_mac_settable_ctx_params() will return the parameters associated
149 with the provider side context I<mctx> in its current state if it is
150 not NULL.  Otherwise, they return the parameters associated with the
151 provider side algorithm I<provctx>.
152
153
154 Parameters currently recognised by built-in macs are as follows. Not all
155 parameters are relevant to, or are understood by all macs:
156
157 =over 4
158
159 =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
160
161 Sets the key in the associated MAC ctx.
162
163 =item "iv" (B<OSSL_MAC_PARAM_IV>) <octet string>
164
165 Sets the IV of the underlying cipher, when applicable.
166
167 =item "custom" (B<OSSL_MAC_PARAM_CUSTOM>) <UTF8 string>
168
169 Sets the custom string in the associated MAC ctx.
170
171 =item "salt" (B<OSSL_MAC_PARAM_SALT>) <octet string>
172
173 Sets the salt of the underlying cipher, when applicable.
174
175 =item "xof" (B<OSSL_MAC_PARAM_BLOCK_XOF>) <integer>
176
177 Sets XOF mode in the associated MAC ctx.
178 0 means no XOF mode, 1 means XOF mode.
179
180 =item "digest-noinit" (B<OSSL_MAC_PARAM_DIGEST_NOINIT>) <integer>
181
182 A simple flag to set the MAC digest to not initialise the
183 implementation specific data. The value 0 or 1 is expected.
184
185 =item "digest-oneshot" (B<OSSL_MAC_PARAM_DIGEST_ONESHOT>) <integer>
186
187 A simple flag to set the MAC digest to be a oneshot operation.
188 The value 0 or 1 is expected.
189
190
191 =for comment We need to investigate if this is the right approach
192
193 =item "cipher" (B<OSSL_MAC_PARAM_CIPHER>) <UTF8 string>
194
195 =item "digest" (B<OSSL_MAC_PARAM_DIGEST>) <UTF8 string>
196
197 Sets the name of the underlying cipher or digest to be used.
198 It must name a suitable algorithm for the MAC that's being used.
199
200 =item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string>
201
202 Sets the properties to be queried when trying to fetch the underlying algorithm.
203 This must be given together with the algorithm naming parameter to be
204 considered valid.
205
206 =item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer>
207
208 Can be used to get the resulting MAC size.
209
210 With some MAC algorithms, it can also be used to set the size that the
211 resulting MAC should have.
212 Allowable sizes are decided within each implementation.
213
214 =back
215
216 =head1 RETURN VALUES
217
218 OSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created
219 provider side mac context, or NULL on failure.
220
221 OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(),
222 OSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for
223 success or 0 on error.
224
225 OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and
226 OSSL_FUNC_mac_settable_ctx_params() should return a constant B<OSSL_PARAM>
227 array, or NULL if none is offered.
228
229 =head1 SEE ALSO
230
231 L<provider(7)>
232
233 =head1 HISTORY
234
235 The provider MAC interface was introduced in OpenSSL 3.0.
236
237 =head1 COPYRIGHT
238
239 Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
240
241 Licensed under the Apache License 2.0 (the "License").  You may not use
242 this file except in compliance with the License.  You can obtain a copy
243 in the file LICENSE in the source distribution or at
244 L<https://www.openssl.org/source/license.html>.
245
246 =cut