1FIPS_MODULE(7ossl) OpenSSL FIPS_MODULE(7ossl)
2
3
4
6 fips_module - OpenSSL fips module guide
7
9 See the individual manual pages for details.
10
12 This guide details different ways that OpenSSL can be used in
13 conjunction with the FIPS module. Which is the correct approach to use
14 will depend on your own specific circumstances and what you are
15 attempting to achieve.
16
17 Note that the old functions FIPS_mode() and FIPS_mode_set() are no
18 longer present so you must remove them from your application if you use
19 them.
20
21 Applications written to use the OpenSSL 3.0 FIPS module should not use
22 any legacy APIs or features that avoid the FIPS module. Specifically
23 this includes:
24
25 • Low level cryptographic APIs (use the high level APIs, such as EVP,
26 instead)
27
28 • Engines
29
30 • Any functions that create or modify custom "METHODS" (for example
31 EVP_MD_meth_new(), EVP_CIPHER_meth_new(), EVP_PKEY_meth_new(),
32 RSA_meth_new(), EC_KEY_METHOD_new(), etc.)
33
34 All of the above APIs are deprecated in OpenSSL 3.0 - so a simple rule
35 is to avoid using all deprecated functions. See migration_guide(7) for
36 a list of deprecated functions.
37
38 Making all applications use the FIPS module by default
39 One simple approach is to cause all applications that are using OpenSSL
40 to only use the FIPS module for cryptographic algorithms by default.
41
42 This approach can be done purely via configuration. As long as
43 applications are built and linked against OpenSSL 3.0 and do not
44 override the loading of the default config file or its settings then
45 they can automatically start using the FIPS module without the need for
46 any further code changes.
47
48 To do this the default OpenSSL config file will have to be modified.
49 The location of this config file will depend on the platform, and any
50 options that were given during the build process. You can check the
51 location of the config file by running this command:
52
53 $ openssl version -d
54 OPENSSLDIR: "/usr/local/ssl"
55
56 Caution: Many Operating Systems install OpenSSL by default. It is a
57 common error to not have the correct version of OpenSSL in your $PATH.
58 Check that you are running an OpenSSL 3.0 version like this:
59
60 $ openssl version -v
61 OpenSSL 3.0.0-dev xx XXX xxxx (Library: OpenSSL 3.0.0-dev xx XXX xxxx)
62
63 The OPENSSLDIR value above gives the directory name for where the
64 default config file is stored. So in this case the default config file
65 will be called /usr/local/ssl/openssl.cnf.
66
67 Edit the config file to add the following lines near the beginning:
68
69 config_diagnostics = 1
70 openssl_conf = openssl_init
71
72 .include /usr/local/ssl/fipsmodule.cnf
73
74 [openssl_init]
75 providers = provider_sect
76 alg_section = algorithm_sect
77
78 [provider_sect]
79 fips = fips_sect
80 base = base_sect
81
82 [base_sect]
83 activate = 1
84
85 [algorithm_sect]
86 default_properties = fips=yes
87
88 Obviously the include file location above should match the path and
89 name of the FIPS module config file that you installed earlier. See
90 <https://github.com/openssl/openssl/blob/master/README-FIPS.md>.
91
92 For FIPS usage, it is recommended that the config_diagnostics option is
93 enabled to prevent accidental use of non-FIPS validated algorithms via
94 broken or mistaken configuration. See config(5).
95
96 Any applications that use OpenSSL 3.0 and are started after these
97 changes are made will start using only the FIPS module unless those
98 applications take explicit steps to avoid this default behaviour. Note
99 that this configuration also activates the "base" provider. The base
100 provider does not include any cryptographic algorithms (and therefore
101 does not impact the validation status of any cryptographic operations),
102 but does include other supporting algorithms that may be required. It
103 is designed to be used in conjunction with the FIPS module.
104
105 This approach has the primary advantage that it is simple, and no code
106 changes are required in applications in order to benefit from the FIPS
107 module. There are some disadvantages to this approach:
108
109 • You may not want all applications to use the FIPS module.
110
111 It may be the case that some applications should and some should
112 not use the FIPS module.
113
114 • If applications take explicit steps to not load the default config
115 file or set different settings.
116
117 This method will not work for these cases.
118
119 • The algorithms available in the FIPS module are a subset of the
120 algorithms that are available in the default OpenSSL Provider.
121
122 If any applications attempt to use any algorithms that are not
123 present, then they will fail.
124
125 • Usage of certain deprecated APIs avoids the use of the FIPS module.
126
127 If any applications use those APIs then the FIPS module will not be
128 used.
129
130 Selectively making applications use the FIPS module by default
131 A variation on the above approach is to do the same thing on an
132 individual application basis. The default OpenSSL config file depends
133 on the compiled in value for OPENSSLDIR as described in the section
134 above. However it is also possible to override the config file to be
135 used via the OPENSSL_CONF environment variable. For example the
136 following, on Unix, will cause the application to be executed with a
137 non-standard config file location:
138
139 $ OPENSSL_CONF=/my/nondefault/openssl.cnf myapplication
140
141 Using this mechanism you can control which config file is loaded (and
142 hence whether the FIPS module is loaded) on an application by
143 application basis.
144
145 This removes the disadvantage listed above that you may not want all
146 applications to use the FIPS module. All the other advantages and
147 disadvantages still apply.
148
149 Programmatically loading the FIPS module (default library context)
150 Applications may choose to load the FIPS provider explicitly rather
151 than relying on config to do this. The config file is still necessary
152 in order to hold the FIPS module config data (such as its self test
153 status and integrity data). But in this case we do not automatically
154 activate the FIPS provider via that config file.
155
156 To do things this way configure as per "Making all applications use the
157 FIPS module by default" above, but edit the fipsmodule.cnf file to
158 remove or comment out the line which says "activate = 1" (note that
159 setting this value to 0 is not sufficient). This means all the
160 required config information will be available to load the FIPS module,
161 but it is not automatically loaded when the application starts. The
162 FIPS provider can then be loaded programmatically like this:
163
164 #include <openssl/provider.h>
165
166 int main(void)
167 {
168 OSSL_PROVIDER *fips;
169 OSSL_PROVIDER *base;
170
171 fips = OSSL_PROVIDER_load(NULL, "fips");
172 if (fips == NULL) {
173 printf("Failed to load FIPS provider\n");
174 exit(EXIT_FAILURE);
175 }
176 base = OSSL_PROVIDER_load(NULL, "base");
177 if (base == NULL) {
178 OSSL_PROVIDER_unload(fips);
179 printf("Failed to load base provider\n");
180 exit(EXIT_FAILURE);
181 }
182
183 /* Rest of application */
184
185 OSSL_PROVIDER_unload(base);
186 OSSL_PROVIDER_unload(fips);
187 exit(EXIT_SUCCESS);
188 }
189
190 Note that this should be one of the first things that you do in your
191 application. If any OpenSSL functions get called that require the use
192 of cryptographic functions before this occurs then, if no provider has
193 yet been loaded, then the default provider will be automatically
194 loaded. If you then later explicitly load the FIPS provider then you
195 will have both the FIPS and the default provider loaded at the same
196 time. It is undefined which implementation of an algorithm will be used
197 if multiple implementations are available and you have not explicitly
198 specified via a property query (see below) which one should be used.
199
200 Also note that in this example we have additionally loaded the "base"
201 provider. This loads a sub-set of algorithms that are also available
202 in the default provider - specifically non cryptographic ones which may
203 be used in conjunction with the FIPS provider. For example this
204 contains algorithms for encoding and decoding keys. If you decide not
205 to load the default provider then you will usually want to load the
206 base provider instead.
207
208 In this example we are using the "default" library context. OpenSSL
209 functions operate within the scope of a library context. If no library
210 context is explicitly specified then the default library context is
211 used. For further details about library contexts see the
212 OSSL_LIB_CTX(3) man page.
213
214 Loading the FIPS module at the same time as other providers
215 It is possible to have the FIPS provider and other providers (such as
216 the default provider) all loaded at the same time into the same library
217 context. You can use a property query string during algorithm fetches
218 to specify which implementation you would like to use.
219
220 For example to fetch an implementation of SHA256 which conforms to FIPS
221 standards you can specify the property query "fips=yes" like this:
222
223 EVP_MD *sha256;
224
225 sha256 = EVP_MD_fetch(NULL, "SHA2-256", "fips=yes");
226
227 If no property query is specified, or more than one implementation
228 matches the property query then it is undefined which implementation of
229 a particular algorithm will be returned.
230
231 This example shows an explicit request for an implementation of SHA256
232 from the default provider:
233
234 EVP_MD *sha256;
235
236 sha256 = EVP_MD_fetch(NULL, "SHA2-256", "provider=default");
237
238 It is also possible to set a default property query string. The
239 following example sets the default property query of "fips=yes" for all
240 fetches within the default library context:
241
242 EVP_set_default_properties(NULL, "fips=yes");
243
244 If a fetch function has both an explicit property query specified, and
245 a default property query is defined then the two queries are merged
246 together and both apply. The local property query overrides the default
247 properties if the same property name is specified in both.
248
249 There are two important built-in properties that you should be aware
250 of:
251
252 The "provider" property enables you to specify which provider you want
253 an implementation to be fetched from, e.g. "provider=default" or
254 "provider=fips". All algorithms implemented in a provider have this
255 property set on them.
256
257 There is also the "fips" property. All FIPS algorithms match against
258 the property query "fips=yes". There are also some non-cryptographic
259 algorithms available in the default and base providers that also have
260 the "fips=yes" property defined for them. These are the encoder and
261 decoder algorithms that can (for example) be used to write out a key
262 generated in the FIPS provider to a file. The encoder and decoder
263 algorithms are not in the FIPS module itself but are allowed to be used
264 in conjunction with the FIPS algorithms.
265
266 It is possible to specify default properties within a config file. For
267 example the following config file automatically loads the default and
268 FIPS providers and sets the default property value to be "fips=yes".
269 Note that this config file does not load the "base" provider. All
270 supporting algorithms that are in "base" are also in "default", so it
271 is unnecessary in this case:
272
273 config_diagnostics = 1
274 openssl_conf = openssl_init
275
276 .include /usr/local/ssl/fipsmodule.cnf
277
278 [openssl_init]
279 providers = provider_sect
280 alg_section = algorithm_sect
281
282 [provider_sect]
283 fips = fips_sect
284 default = default_sect
285
286 [default_sect]
287 activate = 1
288
289 [algorithm_sect]
290 default_properties = fips=yes
291
292 Programmatically loading the FIPS module (nondefault library context)
293 In addition to using properties to separate usage of the FIPS module
294 from other usages this can also be achieved using library contexts. In
295 this example we create two library contexts. In one we assume the
296 existence of a config file called openssl-fips.cnf that automatically
297 loads and configures the FIPS and base providers. The other library
298 context will just use the default provider.
299
300 OSSL_LIB_CTX *fips_libctx, *nonfips_libctx;
301 OSSL_PROVIDER *defctxnull = NULL;
302 EVP_MD *fipssha256 = NULL, *nonfipssha256 = NULL;
303 int ret = 1;
304
305 /*
306 * Create two nondefault library contexts. One for fips usage and
307 * one for non-fips usage
308 */
309 fips_libctx = OSSL_LIB_CTX_new();
310 nonfips_libctx = OSSL_LIB_CTX_new();
311 if (fips_libctx == NULL || nonfips_libctx == NULL)
312 goto err;
313
314 /* Prevent anything from using the default library context */
315 defctxnull = OSSL_PROVIDER_load(NULL, "null");
316
317 /*
318 * Load config file for the FIPS library context. We assume that
319 * this config file will automatically activate the FIPS and base
320 * providers so we don't need to explicitly load them here.
321 */
322 if (!OSSL_LIB_CTX_load_config(fips_libctx, "openssl-fips.cnf"))
323 goto err;
324
325 /*
326 * Set the default property query on the FIPS library context to
327 * ensure that only FIPS algorithms can be used. There are a few non-FIPS
328 * approved algorithms in the FIPS provider for backward compatibility reasons.
329 */
330 if (!EVP_set_default_properties(fips_libctx, "fips=yes"))
331 goto err;
332
333 /*
334 * We don't need to do anything special to load the default
335 * provider into nonfips_libctx. This happens automatically if no
336 * other providers are loaded.
337 * Because we don't call OSSL_LIB_CTX_load_config() explicitly for
338 * nonfips_libctx it will just use the default config file.
339 */
340
341 /* As an example get some digests */
342
343 /* Get a FIPS validated digest */
344 fipssha256 = EVP_MD_fetch(fips_libctx, "SHA2-256", NULL);
345 if (fipssha256 == NULL)
346 goto err;
347
348 /* Get a non-FIPS validated digest */
349 nonfipssha256 = EVP_MD_fetch(nonfips_libctx, "SHA2-256", NULL);
350 if (nonfipssha256 == NULL)
351 goto err;
352
353 /* Use the digests */
354
355 printf("Success\n");
356 ret = 0;
357
358 err:
359 EVP_MD_free(fipssha256);
360 EVP_MD_free(nonfipssha256);
361 OSSL_LIB_CTX_free(fips_libctx);
362 OSSL_LIB_CTX_free(nonfips_libctx);
363 OSSL_PROVIDER_unload(defctxnull);
364
365 return ret;
366
367 Note that we have made use of the special "null" provider here which we
368 load into the default library context. We could have chosen to use the
369 default library context for FIPS usage, and just create one additional
370 library context for other usages - or vice versa. However if code has
371 not been converted to use library contexts then the default library
372 context will be automatically used. This could be the case for your
373 own existing applications as well as certain parts of OpenSSL itself.
374 Not all parts of OpenSSL are library context aware. If this happens
375 then you could "accidentally" use the wrong library context for a
376 particular operation. To be sure this doesn't happen you can load the
377 "null" provider into the default library context. Because a provider
378 has been explicitly loaded, the default provider will not automatically
379 load. This means code using the default context by accident will fail
380 because no algorithms will be available.
381
382 See "Library Context" in migration_guide(7) for additional information
383 about the Library Context.
384
385 Using Encoders and Decoders with the FIPS module
386 Encoders and decoders are used to read and write keys or parameters
387 from or to some external format (for example a PEM file). If your
388 application generates keys or parameters that then need to be written
389 into PEM or DER format then it is likely that you will need to use an
390 encoder to do this. Similarly you need a decoder to read previously
391 saved keys and parameters. In most cases this will be invisible to you
392 if you are using APIs that existed in OpenSSL 1.1.1 or earlier such as
393 i2d_PrivateKey(3). However the appropriate encoder/decoder will need to
394 be available in the library context associated with the key or
395 parameter object. The built-in OpenSSL encoders and decoders are
396 implemented in both the default and base providers and are not in the
397 FIPS module boundary. However since they are not cryptographic
398 algorithms themselves it is still possible to use them in conjunction
399 with the FIPS module, and therefore these encoders/decoders have the
400 "fips=yes" property against them. You should ensure that either the
401 default or base provider is loaded into the library context in this
402 case.
403
404 Using the FIPS module in SSL/TLS
405 Writing an application that uses libssl in conjunction with the FIPS
406 module is much the same as writing a normal libssl application. If you
407 are using global properties and the default library context to specify
408 usage of FIPS validated algorithms then this will happen automatically
409 for all cryptographic algorithms in libssl. If you are using a
410 nondefault library context to load the FIPS provider then you can
411 supply this to libssl using the function SSL_CTX_new_ex(3). This works
412 as a drop in replacement for the function SSL_CTX_new(3) except it
413 provides you with the capability to specify the library context to be
414 used. You can also use the same function to specify libssl specific
415 properties to use.
416
417 In this first example we create two SSL_CTX objects using two different
418 library contexts.
419
420 /*
421 * We assume that a nondefault library context with the FIPS
422 * provider loaded has been created called fips_libctx.
423 */
424 SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(fips_libctx, "fips=yes", TLS_method());
425 /*
426 * We assume that a nondefault library context with the default
427 * provider loaded has been created called non_fips_libctx.
428 */
429 SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(non_fips_libctx, NULL,
430 TLS_method());
431
432 In this second example we create two SSL_CTX objects using different
433 properties to specify FIPS usage:
434
435 /*
436 * The "fips=yes" property includes all FIPS approved algorithms
437 * as well as encoders from the default provider that are allowed
438 * to be used. The NULL below indicates that we are using the
439 * default library context.
440 */
441 SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(NULL, "fips=yes", TLS_method());
442 /*
443 * The "provider!=fips" property allows algorithms from any
444 * provider except the FIPS provider
445 */
446 SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(NULL, "provider!=fips",
447 TLS_method());
448
449 Confirming that an algorithm is being provided by the FIPS module
450 A chain of links needs to be followed to go from an algorithm instance
451 to the provider that implements it. The process is similar for all
452 algorithms. Here the example of a digest is used.
453
454 To go from an EVP_MD_CTX to an EVP_MD, use EVP_MD_CTX_md(3) . To go
455 from the EVP_MD to its OSSL_PROVIDER, use EVP_MD_get0_provider(3). To
456 extract the name from the OSSL_PROVIDER, use
457 OSSL_PROVIDER_get0_name(3).
458
460 The FIPS provider in OpenSSL 3.1 includes some non-FIPS validated
461 algorithms, consequently the property query "fips=yes" is mandatory for
462 applications that want to operate in a FIPS approved manner. The
463 algorithms are:
464
465 Triple DES ECB
466 Triple DES CBC
467 EdDSA
468
470 migration_guide(7), crypto(7), fips_config(5)
471
473 The FIPS module guide was created for use with the new FIPS provider in
474 OpenSSL 3.0.
475
476 OpenSSL 3.0 includes a FIPS 140-2 approved FIPS provider.
477
478 OpenSSL 3.1 includes a FIPS 140-3 approved FIPS provider.
479
481 Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.
482
483 Licensed under the Apache License 2.0 (the "License"). You may not use
484 this file except in compliance with the License. You can obtain a copy
485 in the file LICENSE in the source distribution or at
486 <https://www.openssl.org/source/license.html>.
487
488
489
4903.1.1 2023-08-31 FIPS_MODULE(7ossl)