fips_module.7ossl 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "FIPS_MODULE 7ossl"
  136. .TH FIPS_MODULE 7ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. fips_module \- OpenSSL fips module guide
  143. .SH "SYNOPSIS"
  144. .IX Header "SYNOPSIS"
  145. See the individual manual pages for details.
  146. .SH "DESCRIPTION"
  147. .IX Header "DESCRIPTION"
  148. This guide details different ways that OpenSSL can be used in conjunction
  149. with the \s-1FIPS\s0 module. Which is the correct approach to use will depend on your
  150. own specific circumstances and what you are attempting to achieve.
  151. .PP
  152. For information related to installing the \s-1FIPS\s0 module see
  153. <https://github.com/openssl/openssl/blob/master/README\-FIPS.md>.
  154. .PP
  155. Note that the old functions \fBFIPS_mode()\fR and \fBFIPS_mode_set()\fR are no longer
  156. present so you must remove them from your application if you use them.
  157. .PP
  158. Applications written to use the OpenSSL 3.0 \s-1FIPS\s0 module should not use any
  159. legacy APIs or features that avoid the \s-1FIPS\s0 module. Specifically this includes:
  160. .IP "\(bu" 4
  161. Low level cryptographic APIs (use the high level APIs, such as \s-1EVP,\s0 instead)
  162. .IP "\(bu" 4
  163. Engines
  164. .IP "\(bu" 4
  165. Any functions that create or modify custom \*(L"\s-1METHODS\*(R"\s0 (for example
  166. \&\fBEVP_MD_meth_new()\fR, \fBEVP_CIPHER_meth_new()\fR, \fBEVP_PKEY_meth_new()\fR, \fBRSA_meth_new()\fR,
  167. \&\fBEC_KEY_METHOD_new()\fR, etc.)
  168. .PP
  169. All of the above APIs are deprecated in OpenSSL 3.0 \- so a simple rule is to
  170. avoid using all deprecated functions. See \fBossl\-guide\-migration\fR\|(7) for a list of
  171. deprecated functions.
  172. .SS "Making all applications use the \s-1FIPS\s0 module by default"
  173. .IX Subsection "Making all applications use the FIPS module by default"
  174. One simple approach is to cause all applications that are using OpenSSL to only
  175. use the \s-1FIPS\s0 module for cryptographic algorithms by default.
  176. .PP
  177. This approach can be done purely via configuration. As long as applications are
  178. built and linked against OpenSSL 3.0 and do not override the loading of the
  179. default config file or its settings then they can automatically start using the
  180. \&\s-1FIPS\s0 module without the need for any further code changes.
  181. .PP
  182. To do this the default OpenSSL config file will have to be modified. The
  183. location of this config file will depend on the platform, and any options that
  184. were given during the build process. You can check the location of the config
  185. file by running this command:
  186. .PP
  187. .Vb 2
  188. \& $ openssl version \-d
  189. \& OPENSSLDIR: "/usr/local/ssl"
  190. .Ve
  191. .PP
  192. Caution: Many Operating Systems install OpenSSL by default. It is a common error
  193. to not have the correct version of OpenSSL in your \f(CW$PATH\fR. Check that you are
  194. running an OpenSSL 3.0 version like this:
  195. .PP
  196. .Vb 2
  197. \& $ openssl version \-v
  198. \& OpenSSL 3.0.0\-dev xx XXX xxxx (Library: OpenSSL 3.0.0\-dev xx XXX xxxx)
  199. .Ve
  200. .PP
  201. The \fB\s-1OPENSSLDIR\s0\fR value above gives the directory name for where the default
  202. config file is stored. So in this case the default config file will be called
  203. \&\fI/usr/local/ssl/openssl.cnf\fR.
  204. .PP
  205. Edit the config file to add the following lines near the beginning:
  206. .PP
  207. .Vb 2
  208. \& config_diagnostics = 1
  209. \& openssl_conf = openssl_init
  210. \&
  211. \& .include /usr/local/ssl/fipsmodule.cnf
  212. \&
  213. \& [openssl_init]
  214. \& providers = provider_sect
  215. \& alg_section = algorithm_sect
  216. \&
  217. \& [provider_sect]
  218. \& fips = fips_sect
  219. \& base = base_sect
  220. \&
  221. \& [base_sect]
  222. \& activate = 1
  223. \&
  224. \& [algorithm_sect]
  225. \& default_properties = fips=yes
  226. .Ve
  227. .PP
  228. Obviously the include file location above should match the path and name of the
  229. \&\s-1FIPS\s0 module config file that you installed earlier.
  230. See <https://github.com/openssl/openssl/blob/master/README\-FIPS.md>.
  231. .PP
  232. For \s-1FIPS\s0 usage, it is recommended that the \fBconfig_diagnostics\fR option is
  233. enabled to prevent accidental use of non-FIPS validated algorithms via broken
  234. or mistaken configuration. See \fBconfig\fR\|(5).
  235. .PP
  236. Any applications that use OpenSSL 3.0 and are started after these changes are
  237. made will start using only the \s-1FIPS\s0 module unless those applications take
  238. explicit steps to avoid this default behaviour. Note that this configuration
  239. also activates the \*(L"base\*(R" provider. The base provider does not include any
  240. cryptographic algorithms (and therefore does not impact the validation status of
  241. any cryptographic operations), but does include other supporting algorithms that
  242. may be required. It is designed to be used in conjunction with the \s-1FIPS\s0 module.
  243. .PP
  244. This approach has the primary advantage that it is simple, and no code changes
  245. are required in applications in order to benefit from the \s-1FIPS\s0 module. There are
  246. some disadvantages to this approach:
  247. .IP "\(bu" 4
  248. You may not want all applications to use the \s-1FIPS\s0 module.
  249. .Sp
  250. It may be the case that some applications should and some should not use the
  251. \&\s-1FIPS\s0 module.
  252. .IP "\(bu" 4
  253. If applications take explicit steps to not load the default config file or
  254. set different settings.
  255. .Sp
  256. This method will not work for these cases.
  257. .IP "\(bu" 4
  258. The algorithms available in the \s-1FIPS\s0 module are a subset of the algorithms
  259. that are available in the default OpenSSL Provider.
  260. .Sp
  261. If any applications attempt to use any algorithms that are not present,
  262. then they will fail.
  263. .IP "\(bu" 4
  264. Usage of certain deprecated APIs avoids the use of the \s-1FIPS\s0 module.
  265. .Sp
  266. If any applications use those APIs then the \s-1FIPS\s0 module will not be used.
  267. .SS "Selectively making applications use the \s-1FIPS\s0 module by default"
  268. .IX Subsection "Selectively making applications use the FIPS module by default"
  269. A variation on the above approach is to do the same thing on an individual
  270. application basis. The default OpenSSL config file depends on the compiled in
  271. value for \fB\s-1OPENSSLDIR\s0\fR as described in the section above. However it is also
  272. possible to override the config file to be used via the \fB\s-1OPENSSL_CONF\s0\fR
  273. environment variable. For example the following, on Unix, will cause the
  274. application to be executed with a non-standard config file location:
  275. .PP
  276. .Vb 1
  277. \& $ OPENSSL_CONF=/my/nondefault/openssl.cnf myapplication
  278. .Ve
  279. .PP
  280. Using this mechanism you can control which config file is loaded (and hence
  281. whether the \s-1FIPS\s0 module is loaded) on an application by application basis.
  282. .PP
  283. This removes the disadvantage listed above that you may not want all
  284. applications to use the \s-1FIPS\s0 module. All the other advantages and disadvantages
  285. still apply.
  286. .SS "Programmatically loading the \s-1FIPS\s0 module (default library context)"
  287. .IX Subsection "Programmatically loading the FIPS module (default library context)"
  288. Applications may choose to load the \s-1FIPS\s0 provider explicitly rather than relying
  289. on config to do this. The config file is still necessary in order to hold the
  290. \&\s-1FIPS\s0 module config data (such as its self test status and integrity data). But
  291. in this case we do not automatically activate the \s-1FIPS\s0 provider via that config
  292. file.
  293. .PP
  294. To do things this way configure as per
  295. \&\*(L"Making all applications use the \s-1FIPS\s0 module by default\*(R" above, but edit the
  296. \&\fIfipsmodule.cnf\fR file to remove or comment out the line which says
  297. \&\f(CW\*(C`activate = 1\*(C'\fR (note that setting this value to 0 is \fInot\fR sufficient).
  298. This means all the required config information will be available to load the
  299. \&\s-1FIPS\s0 module, but it is not automatically loaded when the application starts. The
  300. \&\s-1FIPS\s0 provider can then be loaded programmatically like this:
  301. .PP
  302. .Vb 1
  303. \& #include <openssl/provider.h>
  304. \&
  305. \& int main(void)
  306. \& {
  307. \& OSSL_PROVIDER *fips;
  308. \& OSSL_PROVIDER *base;
  309. \&
  310. \& fips = OSSL_PROVIDER_load(NULL, "fips");
  311. \& if (fips == NULL) {
  312. \& printf("Failed to load FIPS provider\en");
  313. \& exit(EXIT_FAILURE);
  314. \& }
  315. \& base = OSSL_PROVIDER_load(NULL, "base");
  316. \& if (base == NULL) {
  317. \& OSSL_PROVIDER_unload(fips);
  318. \& printf("Failed to load base provider\en");
  319. \& exit(EXIT_FAILURE);
  320. \& }
  321. \&
  322. \& /* Rest of application */
  323. \&
  324. \& OSSL_PROVIDER_unload(base);
  325. \& OSSL_PROVIDER_unload(fips);
  326. \& exit(EXIT_SUCCESS);
  327. \& }
  328. .Ve
  329. .PP
  330. Note that this should be one of the first things that you do in your
  331. application. If any OpenSSL functions get called that require the use of
  332. cryptographic functions before this occurs then, if no provider has yet been
  333. loaded, then the default provider will be automatically loaded. If you then
  334. later explicitly load the \s-1FIPS\s0 provider then you will have both the \s-1FIPS\s0 and the
  335. default provider loaded at the same time. It is undefined which implementation
  336. of an algorithm will be used if multiple implementations are available and you
  337. have not explicitly specified via a property query (see below) which one should
  338. be used.
  339. .PP
  340. Also note that in this example we have additionally loaded the \*(L"base\*(R" provider.
  341. This loads a sub-set of algorithms that are also available in the default
  342. provider \- specifically non cryptographic ones which may be used in conjunction
  343. with the \s-1FIPS\s0 provider. For example this contains algorithms for encoding and
  344. decoding keys. If you decide not to load the default provider then you
  345. will usually want to load the base provider instead.
  346. .PP
  347. In this example we are using the \*(L"default\*(R" library context. OpenSSL functions
  348. operate within the scope of a library context. If no library context is
  349. explicitly specified then the default library context is used. For further
  350. details about library contexts see the \s-1\fBOSSL_LIB_CTX\s0\fR\|(3) man page.
  351. .SS "Loading the \s-1FIPS\s0 module at the same time as other providers"
  352. .IX Subsection "Loading the FIPS module at the same time as other providers"
  353. It is possible to have the \s-1FIPS\s0 provider and other providers (such as the
  354. default provider) all loaded at the same time into the same library context. You
  355. can use a property query string during algorithm fetches to specify which
  356. implementation you would like to use.
  357. .PP
  358. For example to fetch an implementation of \s-1SHA256\s0 which conforms to \s-1FIPS\s0
  359. standards you can specify the property query \f(CW\*(C`fips=yes\*(C'\fR like this:
  360. .PP
  361. .Vb 1
  362. \& EVP_MD *sha256;
  363. \&
  364. \& sha256 = EVP_MD_fetch(NULL, "SHA2\-256", "fips=yes");
  365. .Ve
  366. .PP
  367. If no property query is specified, or more than one implementation matches the
  368. property query then it is undefined which implementation of a particular
  369. algorithm will be returned.
  370. .PP
  371. This example shows an explicit request for an implementation of \s-1SHA256\s0 from the
  372. default provider:
  373. .PP
  374. .Vb 1
  375. \& EVP_MD *sha256;
  376. \&
  377. \& sha256 = EVP_MD_fetch(NULL, "SHA2\-256", "provider=default");
  378. .Ve
  379. .PP
  380. It is also possible to set a default property query string. The following
  381. example sets the default property query of \f(CW\*(C`fips=yes\*(C'\fR for all fetches within
  382. the default library context:
  383. .PP
  384. .Vb 1
  385. \& EVP_set_default_properties(NULL, "fips=yes");
  386. .Ve
  387. .PP
  388. If a fetch function has both an explicit property query specified, and a
  389. default property query is defined then the two queries are merged together and
  390. both apply. The local property query overrides the default properties if the
  391. same property name is specified in both.
  392. .PP
  393. There are two important built-in properties that you should be aware of:
  394. .PP
  395. The \*(L"provider\*(R" property enables you to specify which provider you want an
  396. implementation to be fetched from, e.g. \f(CW\*(C`provider=default\*(C'\fR or \f(CW\*(C`provider=fips\*(C'\fR.
  397. All algorithms implemented in a provider have this property set on them.
  398. .PP
  399. There is also the \f(CW\*(C`fips\*(C'\fR property. All \s-1FIPS\s0 algorithms match against the
  400. property query \f(CW\*(C`fips=yes\*(C'\fR. There are also some non-cryptographic algorithms
  401. available in the default and base providers that also have the \f(CW\*(C`fips=yes\*(C'\fR
  402. property defined for them. These are the encoder and decoder algorithms that
  403. can (for example) be used to write out a key generated in the \s-1FIPS\s0 provider to a
  404. file. The encoder and decoder algorithms are not in the \s-1FIPS\s0 module itself but
  405. are allowed to be used in conjunction with the \s-1FIPS\s0 algorithms.
  406. .PP
  407. It is possible to specify default properties within a config file. For example
  408. the following config file automatically loads the default and \s-1FIPS\s0 providers and
  409. sets the default property value to be \f(CW\*(C`fips=yes\*(C'\fR. Note that this config file
  410. does not load the \*(L"base\*(R" provider. All supporting algorithms that are in \*(L"base\*(R"
  411. are also in \*(L"default\*(R", so it is unnecessary in this case:
  412. .PP
  413. .Vb 2
  414. \& config_diagnostics = 1
  415. \& openssl_conf = openssl_init
  416. \&
  417. \& .include /usr/local/ssl/fipsmodule.cnf
  418. \&
  419. \& [openssl_init]
  420. \& providers = provider_sect
  421. \& alg_section = algorithm_sect
  422. \&
  423. \& [provider_sect]
  424. \& fips = fips_sect
  425. \& default = default_sect
  426. \&
  427. \& [default_sect]
  428. \& activate = 1
  429. \&
  430. \& [algorithm_sect]
  431. \& default_properties = fips=yes
  432. .Ve
  433. .SS "Programmatically loading the \s-1FIPS\s0 module (nondefault library context)"
  434. .IX Subsection "Programmatically loading the FIPS module (nondefault library context)"
  435. In addition to using properties to separate usage of the \s-1FIPS\s0 module from other
  436. usages this can also be achieved using library contexts. In this example we
  437. create two library contexts. In one we assume the existence of a config file
  438. called \fIopenssl\-fips.cnf\fR that automatically loads and configures the \s-1FIPS\s0 and
  439. base providers. The other library context will just use the default provider.
  440. .PP
  441. .Vb 4
  442. \& OSSL_LIB_CTX *fips_libctx, *nonfips_libctx;
  443. \& OSSL_PROVIDER *defctxnull = NULL;
  444. \& EVP_MD *fipssha256 = NULL, *nonfipssha256 = NULL;
  445. \& int ret = 1;
  446. \&
  447. \& /*
  448. \& * Create two nondefault library contexts. One for fips usage and
  449. \& * one for non\-fips usage
  450. \& */
  451. \& fips_libctx = OSSL_LIB_CTX_new();
  452. \& nonfips_libctx = OSSL_LIB_CTX_new();
  453. \& if (fips_libctx == NULL || nonfips_libctx == NULL)
  454. \& goto err;
  455. \&
  456. \& /* Prevent anything from using the default library context */
  457. \& defctxnull = OSSL_PROVIDER_load(NULL, "null");
  458. \&
  459. \& /*
  460. \& * Load config file for the FIPS library context. We assume that
  461. \& * this config file will automatically activate the FIPS and base
  462. \& * providers so we don\*(Aqt need to explicitly load them here.
  463. \& */
  464. \& if (!OSSL_LIB_CTX_load_config(fips_libctx, "openssl\-fips.cnf"))
  465. \& goto err;
  466. \&
  467. \& /*
  468. \& * Set the default property query on the FIPS library context to
  469. \& * ensure that only FIPS algorithms can be used. There are a few non\-FIPS
  470. \& * approved algorithms in the FIPS provider for backward compatibility reasons.
  471. \& */
  472. \& if (!EVP_set_default_properties(fips_libctx, "fips=yes"))
  473. \& goto err;
  474. \&
  475. \& /*
  476. \& * We don\*(Aqt need to do anything special to load the default
  477. \& * provider into nonfips_libctx. This happens automatically if no
  478. \& * other providers are loaded.
  479. \& * Because we don\*(Aqt call OSSL_LIB_CTX_load_config() explicitly for
  480. \& * nonfips_libctx it will just use the default config file.
  481. \& */
  482. \&
  483. \& /* As an example get some digests */
  484. \&
  485. \& /* Get a FIPS validated digest */
  486. \& fipssha256 = EVP_MD_fetch(fips_libctx, "SHA2\-256", NULL);
  487. \& if (fipssha256 == NULL)
  488. \& goto err;
  489. \&
  490. \& /* Get a non\-FIPS validated digest */
  491. \& nonfipssha256 = EVP_MD_fetch(nonfips_libctx, "SHA2\-256", NULL);
  492. \& if (nonfipssha256 == NULL)
  493. \& goto err;
  494. \&
  495. \& /* Use the digests */
  496. \&
  497. \& printf("Success\en");
  498. \& ret = 0;
  499. \&
  500. \& err:
  501. \& EVP_MD_free(fipssha256);
  502. \& EVP_MD_free(nonfipssha256);
  503. \& OSSL_LIB_CTX_free(fips_libctx);
  504. \& OSSL_LIB_CTX_free(nonfips_libctx);
  505. \& OSSL_PROVIDER_unload(defctxnull);
  506. \&
  507. \& return ret;
  508. .Ve
  509. .PP
  510. Note that we have made use of the special \*(L"null\*(R" provider here which we load
  511. into the default library context. We could have chosen to use the default
  512. library context for \s-1FIPS\s0 usage, and just create one additional library context
  513. for other usages \- or vice versa. However if code has not been converted to use
  514. library contexts then the default library context will be automatically used.
  515. This could be the case for your own existing applications as well as certain
  516. parts of OpenSSL itself. Not all parts of OpenSSL are library context aware. If
  517. this happens then you could \*(L"accidentally\*(R" use the wrong library context for a
  518. particular operation. To be sure this doesn't happen you can load the \*(L"null\*(R"
  519. provider into the default library context. Because a provider has been
  520. explicitly loaded, the default provider will not automatically load. This means
  521. code using the default context by accident will fail because no algorithms will
  522. be available.
  523. .PP
  524. See \*(L"Library Context\*(R" in \fBossl\-guide\-migration\fR\|(7) for additional information about the
  525. Library Context.
  526. .SS "Using Encoders and Decoders with the \s-1FIPS\s0 module"
  527. .IX Subsection "Using Encoders and Decoders with the FIPS module"
  528. Encoders and decoders are used to read and write keys or parameters from or to
  529. some external format (for example a \s-1PEM\s0 file). If your application generates
  530. keys or parameters that then need to be written into \s-1PEM\s0 or \s-1DER\s0 format
  531. then it is likely that you will need to use an encoder to do this. Similarly
  532. you need a decoder to read previously saved keys and parameters. In most cases
  533. this will be invisible to you if you are using APIs that existed in
  534. OpenSSL 1.1.1 or earlier such as \fBi2d_PrivateKey\fR\|(3). However the appropriate
  535. encoder/decoder will need to be available in the library context associated with
  536. the key or parameter object. The built-in OpenSSL encoders and decoders are
  537. implemented in both the default and base providers and are not in the \s-1FIPS\s0
  538. module boundary. However since they are not cryptographic algorithms themselves
  539. it is still possible to use them in conjunction with the \s-1FIPS\s0 module, and
  540. therefore these encoders/decoders have the \f(CW\*(C`fips=yes\*(C'\fR property against them.
  541. You should ensure that either the default or base provider is loaded into the
  542. library context in this case.
  543. .SS "Using the \s-1FIPS\s0 module in \s-1SSL/TLS\s0"
  544. .IX Subsection "Using the FIPS module in SSL/TLS"
  545. Writing an application that uses libssl in conjunction with the \s-1FIPS\s0 module is
  546. much the same as writing a normal libssl application. If you are using global
  547. properties and the default library context to specify usage of \s-1FIPS\s0 validated
  548. algorithms then this will happen automatically for all cryptographic algorithms
  549. in libssl. If you are using a nondefault library context to load the \s-1FIPS\s0
  550. provider then you can supply this to libssl using the function
  551. \&\fBSSL_CTX_new_ex\fR\|(3). This works as a drop in replacement for the function
  552. \&\fBSSL_CTX_new\fR\|(3) except it provides you with the capability to specify the
  553. library context to be used. You can also use the same function to specify
  554. libssl specific properties to use.
  555. .PP
  556. In this first example we create two \s-1SSL_CTX\s0 objects using two different library
  557. contexts.
  558. .PP
  559. .Vb 11
  560. \& /*
  561. \& * We assume that a nondefault library context with the FIPS
  562. \& * provider loaded has been created called fips_libctx.
  563. \& */
  564. \& SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(fips_libctx, "fips=yes", TLS_method());
  565. \& /*
  566. \& * We assume that a nondefault library context with the default
  567. \& * provider loaded has been created called non_fips_libctx.
  568. \& */
  569. \& SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(non_fips_libctx, NULL,
  570. \& TLS_method());
  571. .Ve
  572. .PP
  573. In this second example we create two \s-1SSL_CTX\s0 objects using different properties
  574. to specify \s-1FIPS\s0 usage:
  575. .PP
  576. .Vb 10
  577. \& /*
  578. \& * The "fips=yes" property includes all FIPS approved algorithms
  579. \& * as well as encoders from the default provider that are allowed
  580. \& * to be used. The NULL below indicates that we are using the
  581. \& * default library context.
  582. \& */
  583. \& SSL_CTX *fips_ssl_ctx = SSL_CTX_new_ex(NULL, "fips=yes", TLS_method());
  584. \& /*
  585. \& * The "provider!=fips" property allows algorithms from any
  586. \& * provider except the FIPS provider
  587. \& */
  588. \& SSL_CTX *non_fips_ssl_ctx = SSL_CTX_new_ex(NULL, "provider!=fips",
  589. \& TLS_method());
  590. .Ve
  591. .SS "Confirming that an algorithm is being provided by the \s-1FIPS\s0 module"
  592. .IX Subsection "Confirming that an algorithm is being provided by the FIPS module"
  593. A chain of links needs to be followed to go from an algorithm instance to the
  594. provider that implements it. The process is similar for all algorithms. Here the
  595. example of a digest is used.
  596. .PP
  597. To go from an \fB\s-1EVP_MD_CTX\s0\fR to an \fB\s-1EVP_MD\s0\fR, use \fBEVP_MD_CTX_md\fR\|(3) .
  598. To go from the \fB\s-1EVP_MD\s0\fR to its \fB\s-1OSSL_PROVIDER\s0\fR,
  599. use \fBEVP_MD_get0_provider\fR\|(3).
  600. To extract the name from the \fB\s-1OSSL_PROVIDER\s0\fR, use
  601. \&\fBOSSL_PROVIDER_get0_name\fR\|(3).
  602. .SH "NOTES"
  603. .IX Header "NOTES"
  604. Some released versions of OpenSSL do not include a validated
  605. \&\s-1FIPS\s0 provider. To determine which versions have undergone
  606. the validation process, please refer to the
  607. OpenSSL Downloads page <https://www.openssl.org/source/>. If you
  608. require FIPS-approved functionality, it is essential to build your \s-1FIPS\s0
  609. provider using one of the validated versions listed there. Normally,
  610. it is possible to utilize a \s-1FIPS\s0 provider constructed from one of the
  611. validated versions alongside \fIlibcrypto\fR and \fIlibssl\fR compiled from any
  612. release within the same major release series. This flexibility enables
  613. you to address bug fixes and CVEs that fall outside the \s-1FIPS\s0 boundary.
  614. .PP
  615. The \s-1FIPS\s0 provider in OpenSSL 3.1 includes some non-FIPS validated algorithms,
  616. consequently the property query \f(CW\*(C`fips=yes\*(C'\fR is mandatory for applications that
  617. want to operate in a \s-1FIPS\s0 approved manner. The algorithms are:
  618. .IP "Triple \s-1DES ECB\s0" 4
  619. .IX Item "Triple DES ECB"
  620. .PD 0
  621. .IP "Triple \s-1DES CBC\s0" 4
  622. .IX Item "Triple DES CBC"
  623. .IP "EdDSA" 4
  624. .IX Item "EdDSA"
  625. .PD
  626. .SH "SEE ALSO"
  627. .IX Header "SEE ALSO"
  628. \&\fBossl\-guide\-migration\fR\|(7), \fBcrypto\fR\|(7), \fBfips_config\fR\|(5),
  629. <https://www.openssl.org/source/>
  630. .SH "HISTORY"
  631. .IX Header "HISTORY"
  632. The \s-1FIPS\s0 module guide was created for use with the new \s-1FIPS\s0 provider
  633. in OpenSSL 3.0.
  634. .SH "COPYRIGHT"
  635. .IX Header "COPYRIGHT"
  636. Copyright 2021\-2023 The OpenSSL Project Authors. All Rights Reserved.
  637. .PP
  638. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  639. this file except in compliance with the License. You can obtain a copy
  640. in the file \s-1LICENSE\s0 in the source distribution or at
  641. <https://www.openssl.org/source/license.html>.