Add selftest callback to CRNG output test
[openssl.git] / doc / man7 / OSSL_PROVIDER-FIPS.pod
1 =pod
2
3 =head1 NAME
4
5 OSSL_PROVIDER-FIPS - OpenSSL FIPS provider
6
7 =head1 DESCRIPTION
8
9 The OpenSSL FIPS provider is a special provider that conforms to the Federal 
10 Information Processing Standards (FIPS) specified in FIPS 140-2. This 'module'
11 contains an approved set of cryptographic algorithms that is validated by an
12 accredited testing laboratory.
13
14 =head2 Properties
15
16 The implementations in this provider specifically have these properties
17 defined:
18
19 =over 4
20
21 =item "provider=default"
22
23 =item "fips=yes"
24
25 =back
26
27 It may be used in a property query string with fetching functions such as
28 L<EVP_MD_fetch(3)> or L<EVP_CIPHER_fetch(3)>, as well as with other
29 functions that take a property query string, such as
30 L<EVP_PKEY_CTX_new_from_name(3)>.
31
32 It isn't mandatory to query for any of these properties, except to
33 make sure to get implementations of this provider and none other.
34
35 The "fips=yes" property can be use to make sure only FIPS approved
36 implementations are used for crypto operations.  This may also include
37 other non-crypto support operations that are not in the fips provider,
38 such as asymmetric key encoders,
39 see L<OSSL_PROVIDER-default(7)/Asymmetric Key Management>.
40
41 =head1 OPERATIONS AND ALGORITHMS
42
43 The OpenSSL FIPS provider supports these operations and algorithms:
44
45 =head2 Hashing Algorithms / Message Digests
46
47 =over 4
48
49 =item SHA1, see L<EVP_MD-SHA1(7)>
50
51 =item SHA2, see L<EVP_MD-SHA2(7)>
52
53 =item SHA3, see L<EVP_MD-SHA3(7)>
54
55 =item KECCAK-KMAC, see L<EVP_MD-KECCAK-KMAC(7)>
56
57 =back
58
59 =head2 Symmetric Ciphers
60
61 =over 4
62
63 =item AES, see L<EVP_CIPHER-AES(7)>
64
65 =item DES-EDE3 (TrippleDES), see L<EVP_CIPHER-DES(7)>
66
67 =back
68
69 =head2 Message Authentication Code (MAC)
70
71 =over 4
72
73 =item CMAC, see L<EVP_MAC-CMAC(7)>
74
75 =item GMAC, see L<EVP_MAC-GMAC(7)>
76
77 =item HMAC, see L<EVP_MAC-HMAC(7)>
78
79 =item KMAC, see L<EVP_MAC-KMAC(7)>
80
81 =back
82
83 =head2 Key Derivation Function (KDF)
84
85 =over 4
86
87 =item HKDF, see L<EVP_KDF-HKDF(7)>
88
89 =item SSKDF, see L<EVP_KDF-SSKDF(7)>
90
91 =item PBKDF2, see L<EVP_KDF-PBKDF2(7)>
92
93 =item TLS1-PRF, see L<EVP_KDF-TLS1-PRF(7)>
94
95 =item KBKDF, see L<EVP_KDF-KBKDF(7)>
96
97 =back
98
99 =head2 Key Exchange
100
101 =over 4
102
103 =item DH, see L<EVP_KEYEXCH-DH(7)>
104
105 =item ECDH, see L<EVP_KEYEXCH-ECDH(7)>
106
107 =item X25519, see L<EVP_KEYEXCH-X25519(7)>
108
109 This has the property "provider=fips,fips=no"
110
111 =item X448, see L<EVP_KEYEXCH-X448(7)>
112
113 This has the property "provider=fips,fips=no"
114
115 =back
116
117 =head2 Asymmetric Signature
118
119 =over 4
120
121 =item DSA, see L<EVP_KEYEXCH-DSA(7)>
122
123 =item RSA, see L<EVP_SIGNATURE-RSA(7)>
124
125 =item HMAC, see L<EVP_SIGNATURE-HMAC(7)>
126
127 =item CMAC, see L<EVP_SIGNATURE-CMAC(7)>
128
129 =back
130
131 =head2 Asymmetric Cipher
132
133 =over 4
134
135 =item RSA, see L<EVP_KEYEXCH-RSA(7)>
136
137 =back
138
139 =head2 Asymmetric Key Management
140
141 =over 4
142
143 =item DH, see L<EVP_KEYMGMT-DH(7)>
144
145 =item DSA, see L<EVP_KEYMGMT-DSA(7)>
146
147 =item RSA, see L<EVP_KEYMGMT-RSA(7)>
148
149 =back
150
151 =head1 SELF TESTING
152
153 One of the requirements for the FIPS module is self testing. An optional callback
154 mechanism is available to return information to the user using
155 L<OSSL_SELF_TEST_set_callback(3)>.
156
157 The parameters passed to the callback are described in L<OSSL_SELF_TEST_new(3)>
158
159 The OpenSSL FIPS module uses the following mechanism to provide information
160 about the self tests as they run.
161 This is useful for debugging if a self test is failing.
162 The callback also allows forcing any self test to fail, in order to check that
163 it operates correctly on failure.
164 Note that all self tests run even if a self test failure occurs.
165
166 The FIPS module passes the following type(s) to OSSL_SELF_TEST_onbegin().
167
168 =over 4
169
170 =item "Module_Integrity" (B<OSSL_SELF_TEST_TYPE_MODULE_INTEGRITY>)
171
172 Uses HMAC SHA256 on the module file to validate that the module has not been
173 modified. The integrity value is compared to a value written to a configuration
174 file during installation.
175
176 =item "Install_Integrity" (B<OSSL_SELF_TEST_TYPE_INSTALL_INTEGRITY>)
177
178 Uses HMAC SHA256 on a fixed string to validate that the installation process
179 has already been performed and the self test KATS have already been tested,
180 The integrity value is compared to a value written to a configuration
181 file after successfully running the self tests during installation.
182
183 =item "KAT_Cipher" (B<OSSL_SELF_TEST_TYPE_KAT_CIPHER>)
184
185 Known answer test for a symmetric cipher.
186
187 =item "KAT_AsymmetricCipher" (B<OSSL_SELF_TEST_TYPE_KAT_ASYM_CIPHER>)
188
189 Known answer test for a asymmetric cipher.
190
191 =item "KAT_Digest" (B<OSSL_SELF_TEST_TYPE_KAT_DIGEST>)
192
193 Known answer test for a digest.
194
195 =item "KAT_Signature" (B<OSSL_SELF_TEST_TYPE_KAT_SIGNATURE>)
196
197 Known answer test for a signature.
198
199 =item "KAT_KDF" (B<OSSL_SELF_TEST_TYPE_KAT_KDF>)
200
201 Known answer test for a key derivation function.
202
203 =item "KAT_KA" (B<OSSL_SELF_TEST_TYPE_KAT_KA>)
204
205 Known answer test for key agreement.
206
207 =item "DRBG" (B<OSSL_SELF_TEST_TYPE_DRBG>)
208
209 Known answer test for a Deterministic Random Bit Generator.
210
211 =item "Pairwise_Consistency_Test" (B<OSSL_SELF_TEST_TYPE_PCT>)
212
213 Conditional test that is run during the generation of key pairs.
214
215 =item "Continuous_RNG_Test" (B<OSSL_SELF_TEST_TYPE_CRNG>)
216
217 Continuous random number generator test.
218
219 =back
220
221 The "Module_Integrity" self test is always run at startup.
222 The "Install_Integrity" self test is used to check if the self tests have
223 already been run at installation time. If they have already run then the
224 self tests are not run on subsequent startups.
225 All other self test categories are run once at installation time, except for the
226 "Pairwise_Consistency_Test".
227
228 There is only one instance of the "Module_Integrity" and "Install_Integrity"
229 self tests. All other self tests may have multiple instances.
230
231
232 The FIPS module passes the following descriptions(s) to OSSL_SELF_TEST_onbegin().
233
234 =over 4
235
236 =item "HMAC" (B<OSSL_SELF_TEST_DESC_INTEGRITY_HMAC>)
237
238 "Module_Integrity" and "Install_Integrity" use this.
239
240 =item "RSA" (B<OSSL_SELF_TEST_DESC_PCT_RSA_PKCS1>)
241
242 =item "ECDSA" (B<OSSL_SELF_TEST_DESC_PCT_ECDSA>)
243
244 =item "DSA" (B<OSSL_SELF_TEST_DESC_PCT_DSA>)
245
246 Key generation tests used with the "Pairwise_Consistency_Test" type.
247
248 =item "RSA_Encrypt" (B<OSSL_SELF_TEST_DESC_ASYM_RSA_ENC>)
249
250 =item "RSA_Decrypt" (B<OSSL_SELF_TEST_DESC_ASYM_RSA_DEC>)
251
252 "KAT_AsymmetricCipher" uses this to indicate an encrypt or decrypt KAT.
253
254 =item "AES_GCM" (B<OSSL_SELF_TEST_DESC_CIPHER_AES_GCM>)
255
256 =item "TDES" (B<OSSL_SELF_TEST_DESC_CIPHER_TDES>)
257
258 Symmetric cipher tests used with the "KAT_Cipher" type.
259
260 =item "SHA1" (B<OSSL_SELF_TEST_DESC_MD_SHA1>)
261
262 =item "SHA2" (B<OSSL_SELF_TEST_DESC_MD_SHA2>)
263
264 =item "SHA3" (B<OSSL_SELF_TEST_DESC_MD_SHA3>)
265
266 Digest tests used with the "KAT_Digest" type.
267
268 =item "DSA" (B<OSSL_SELF_TEST_DESC_SIGN_DSA>)
269
270 =item "RSA" (B<OSSL_SELF_TEST_DESC_SIGN_RSA>)
271
272 =item "ECDSA" (B<OSSL_SELF_TEST_DESC_SIGN_ECDSA>)
273
274 Signature tests used with the "KAT_Signature" type.
275
276 =item "ECDH" (B<OSSL_SELF_TEST_DESC_KA_ECDH>)
277
278 =item "DH" (B<OSSL_SELF_TEST_DESC_KA_DH>)
279
280 Key agreement tests used with the "KAT_KA" type.
281
282 =item "HKDF" (B<OSSL_SELF_TEST_DESC_KDF_HKDF>)
283
284 =item "SSKDF" (B<OSSL_SELF_TEST_DESC_KDF_SSKDF>)
285
286 Key Derivation Function tests used with the "KAT_KDF" type.
287
288 =item "CTR" (B<OSSL_SELF_TEST_DESC_DRBG_CTR>)
289
290 =item "HASH" (B<OSSL_SELF_TEST_DESC_DRBG_HASH>)
291
292 =item "HMAC" (B<OSSL_SELF_TEST_DESC_DRBG_HMAC>)
293
294 DRBG tests used with the "DRBG" type.
295
296 = item "RNG" (B<OSSL_SELF_TEST_DESC_RNG>)
297
298 "Continuous_RNG_Test" uses this.
299
300 =back
301
302 =head1 EXAMPLES
303
304 A simple self test callback is shown below for illustrative purposes.
305
306   #include <openssl/self_test.h>
307
308   static OSSL_CALLBACK self_test_cb;
309
310   static int self_test_cb(const OSSL_PARAM params[], void *arg)
311   {
312     int ret = 0;
313     const OSSL_PARAM *p = NULL;
314     const char *phase = NULL, *type = NULL, *desc = NULL;
315
316     p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_PHASE);
317     if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
318         goto err;
319     phase = (const char *)p->data;
320
321     p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_DESC);
322     if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
323         goto err;
324     desc = (const char *)p->data;
325
326     p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_TYPE);
327     if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
328         goto err;
329     type = (const char *)p->data;
330
331     /* Do some logging */
332     if (strcmp(phase, OSSL_SELF_TEST_PHASE_START) == 0)
333         BIO_printf(bio_out, "%s : (%s) : ", desc, type);
334     if (strcmp(phase, OSSL_SELF_TEST_PHASE_PASS) == 0
335             || strcmp(phase, OSSL_SELF_TEST_PHASE_FAIL) == 0)
336         BIO_printf(bio_out, "%s\n", phase);
337
338     /* Corrupt the SHA1 self test during the 'corrupt' phase by returning 0 */
339     if (strcmp(phase, OSSL_SELF_TEST_PHASE_CORRUPT) == 0
340             && strcmp(desc, OSSL_SELF_TEST_DESC_MD_SHA1) == 0) {
341         BIO_printf(bio_out, "%s %s", phase, desc);
342         return 0;
343     }
344     ret = 1;
345   err:
346     return ret;
347   }
348
349 =head1 SEE ALSO
350
351 L<openssl-fipsinstall(1)>,
352 L<fips_config(5)>,
353 L<OSSL_SELF_TEST_set_callback(3)>,
354 L<OSSL_SELF_TEST_new(3)>,
355 L<OSSL_PARAM(3)>,
356 L<openssl-core.h(7)>,
357 L<openssl-core_dispatch.h(7)>,
358 L<provider(7)>
359
360 =head1 HISTORY
361
362 The type and functions described here were added in OpenSSL 3.0.
363
364 =head1 COPYRIGHT
365
366 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
367
368 Licensed under the Apache License 2.0 (the "License").  You may not use
369 this file except in compliance with the License.  You can obtain a copy
370 in the file LICENSE in the source distribution or at
371 L<https://www.openssl.org/source/license.html>.
372
373 =cut