Fix up path generation to use OPENSSL_MODULES
[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_get_params(void *provctx);
32  const OSSL_PARAM *OSSL_FUNC_mac_get_ctx_params(void *provctx);
33  const OSSL_PARAM *OSSL_FUNC_mac_set_ctx_params(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(), and
144 OSSL_FUNC_mac_settable_ctx_params() all return constant B<OSSL_PARAM> arrays
145 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() can handle,
147 respectively.
148
149 Parameters currently recognised by built-in macs are as follows. Not all
150 parameters are relevant to, or are understood by all macs:
151
152 =over 4
153
154 =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
155
156 Sets the key in the associated MAC ctx.
157
158 =item "iv" (B<OSSL_MAC_PARAM_IV>) <octet string>
159
160 Sets the IV of the underlying cipher, when applicable.
161
162 =item "custom" (B<OSSL_MAC_PARAM_CUSTOM>) <UTF8 string>
163
164 Sets the custom string in the associated MAC ctx.
165
166 =item "salt" (B<OSSL_MAC_PARAM_SALT>) <octet string>
167
168 Sets the salt of the underlying cipher, when applicable.
169
170 =item "xof" (B<OSSL_MAC_PARAM_BLOCK_XOF>) <integer>
171
172 Sets XOF mode in the associated MAC ctx.
173 0 means no XOF mode, 1 means XOF mode.
174
175 =item "flags" (B<OSSL_MAC_PARAM_FLAGS>) <integer>
176
177 Gets flags associated with the MAC.
178
179 =for comment We need to investigate if this is the right approach
180
181 =item "cipher" (B<OSSL_MAC_PARAM_CIPHER>) <UTF8 string>
182
183 =item "digest" (B<OSSL_MAC_PARAM_DIGEST>) <UTF8 string>
184
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.
187
188 =item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string>
189
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
192 considered valid.
193
194 =item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer>
195
196 Can be used to get the resulting MAC size.
197
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.
201
202 =back
203
204 =head1 RETURN VALUES
205
206 OSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created
207 provider side mac context, or NULL on failure.
208
209 OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(),
210 OSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for
211 success or 0 on error.
212
213 OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and
214 OSSL_FUNC_mac_settable_ctx_params() should return a constant B<OSSL_PARAM>
215 array, or NULL if none is offered.
216
217 =head1 SEE ALSO
218
219 L<provider(7)>
220
221 =head1 HISTORY
222
223 The provider MAC interface was introduced in OpenSSL 3.0.
224
225 =head1 COPYRIGHT
226
227 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
228
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>.
233
234 =cut