OSSL_PROVIDER-FIPS.pod 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. =pod
  2. =head1 NAME
  3. OSSL_PROVIDER-FIPS - OPENSSL FIPS provider
  4. =head1 DESCRIPTION
  5. The OPENSSL FIPS provider is a special provider that conforms to the Federal
  6. Information Processing Standards (FIPS) specified in FIPS 140-2. This 'module'
  7. contains an approved set of cryptographic algorithms that is validated by an
  8. accredited testing laboratory.
  9. =head1 SELF TESTING
  10. One of the requirements for the FIPS module is self testing. An optional callback
  11. mechanism is available to return information to the user using
  12. L<OSSL_SELF_TEST_set_callback(3)>.
  13. The OPENSSL FIPS module uses the following mechanism to provide information
  14. about the self tests as they run.
  15. This is useful for debugging if a self test is failing.
  16. The callback also allows forcing any self test to fail, in order to check that
  17. it operates correctly on failure.
  18. The 'args' parameter of B<OSSL_CALLBACK> contains the B<OPENSSL_CTX> associated
  19. with the provider that is triggering the self test. This may be useful if
  20. multiple fips providers are present.
  21. The OSSL_PARAM names used are:
  22. =over 4
  23. =item "st-phase" (B<OSSL_PROV_PARAM_SELF_TEST_PHASE>) <UTF8 string>
  24. Each self test calls the callback 3 times with the following string values
  25. for the phase.
  26. =over 4
  27. =item "Start" (B<OSSL_SELF_TEST_PHASE_START>)
  28. This is the initial phase before the self test has run.
  29. This is used for informational purposes only.
  30. The value returned by the callback is ignored.
  31. =item "Corrupt" (B<OSSL_SELF_TEST_PHASE_CORRUPT>)
  32. The corrupt phase is run after the self test has calculated its known value.
  33. The callback may be used to force the self test to fail by returning a value
  34. of 0 from the callback during this phase.
  35. Returning any other value from the callback causes the self test to run normally.
  36. =item "Pass" (B<OSSL_SELF_TEST_PHASE_PASS>)
  37. =item "Fail" (B<OSSL_SELF_TEST_PHASE_FAIL>)
  38. The final phase runs after the self test is complete and indicates if a self
  39. test passed or failed. This is used for informational purposes only.
  40. The value returned by the callback is ignored.
  41. "Fail" should normally only be returned if any self test was forced to fail
  42. during the "Corrupt" phase (or if there was an error such as the integrity
  43. check of the module failed).
  44. Note that all self tests run even if a self test failure occurs.
  45. =back
  46. =item "st-type" (B<OSSL_PROV_PARAM_SELF_TEST_TYPE>) <UTF8 string>
  47. Used as a category to identify the type of self test being run.
  48. It includes the following string values:
  49. =over 4
  50. =item "Module_Integrity" (B<OSSL_SELF_TEST_TYPE_MODULE_INTEGRITY>)
  51. Uses HMAC SHA256 on the module file to validate that the module has not been
  52. modified. The integrity value is compared to a value written to a configuration
  53. file during installation.
  54. =item "Install_Integrity" (B<OSSL_SELF_TEST_TYPE_INSTALL_INTEGRITY>)
  55. Uses HMAC SHA256 on a fixed string to validate that the installation process
  56. has already been performed and the self test KATS have already been tested,
  57. The integrity value is compared to a value written to a configuration
  58. file after successfully running the self tests during installation.
  59. =item "KAT_Cipher" (B<OSSL_SELF_TEST_TYPE_KAT_CIPHER>)
  60. Known answer test for a symmetric cipher.
  61. =item "KAT_Digest" (B<OSSL_SELF_TEST_TYPE_KAT_DIGEST>)
  62. Known answer test for a digest.
  63. =item "KAT_Signature" (B<OSSL_SELF_TEST_TYPE_KAT_SIGNATURE>)
  64. Known answer test for a signature.
  65. =item "KAT_KDF" (B<OSSL_SELF_TEST_TYPE_KAT_KDF>)
  66. Known answer test for a key derivation function.
  67. =item "KAT_KA" (B<OSSL_SELF_TEST_TYPE_KAT_KA>)
  68. Known answer test for key agreement.
  69. =item "DRBG" (B<OSSL_SELF_TEST_TYPE_DRBG>)
  70. Known answer test for a Deterministic Random Bit Generator.
  71. =item "Pairwise_Consistency_Test" (B<OSSL_SELF_TEST_TYPE_PCT>)
  72. Conditional test that is run during the generation of key pairs.
  73. =back
  74. The "Module_Integrity" self test is always run at startup.
  75. The "Install_Integrity" self test is used to check if the self tests have
  76. already been run at installation time. If they have already run then the
  77. self tests are not run on subsequent startups.
  78. All other self test categories are run once at installation time, except for the
  79. "Pairwise_Consistency_Test".
  80. There is only one instance of the "Module_Integrity" and "Install_Integrity"
  81. self tests. All other self tests may have multiple instances.
  82. =item "st-desc" (B<OSSL_PROV_PARAM_SELF_TEST_DESC>) <UTF8 string>
  83. Used as a sub category to identify an individual self test.
  84. The following description strings are used.
  85. =over 4
  86. =item "HMAC" (B<OSSL_SELF_TEST_DESC_INTEGRITY_HMAC>)
  87. "Module_Integrity" and "Install_Integrity" use this.
  88. =item "RSA" (B<OSSL_SELF_TEST_DESC_PCT_RSA_PKCS1>)
  89. =item "ECDSA" (B<OSSL_SELF_TEST_DESC_PCT_ECDSA>)
  90. =item "DSA" (B<OSSL_SELF_TEST_DESC_PCT_DSA>)
  91. Key generation tests used with the "Pairwise_Consistency_Test" type.
  92. =item "AES_GCM" (B<OSSL_SELF_TEST_DESC_CIPHER_AES_GCM>)
  93. =item "TDES" (B<OSSL_SELF_TEST_DESC_CIPHER_TDES>)
  94. Symmetric cipher tests used with the "KAT_Cipher" type.
  95. =item "SHA1" (B<OSSL_SELF_TEST_DESC_MD_SHA1>)
  96. =item "SHA2" (B<OSSL_SELF_TEST_DESC_MD_SHA2>)
  97. =item "SHA3" (B<OSSL_SELF_TEST_DESC_MD_SHA3>)
  98. Digest tests used with the "KAT_Digest" type.
  99. =item "DSA" (B<OSSL_SELF_TEST_DESC_SIGN_DSA>)
  100. =item "RSA" (B<OSSL_SELF_TEST_DESC_SIGN_RSA>)
  101. =item "ECDSA" (B<OSSL_SELF_TEST_DESC_SIGN_ECDSA>)
  102. Signature tests used with the "KAT_Signature" type.
  103. =item "ECDH" (B<OSSL_SELF_TEST_DESC_KA_ECDH>)
  104. =item "ECDSA" (B<OSSL_SELF_TEST_DESC_KA_ECDSA>)
  105. Key agreement tests used with the "KAT_KA" type.
  106. =item "HKDF" (B<OSSL_SELF_TEST_DESC_KDF_HKDF>)
  107. Key Derivation Function tests used with the "KAT_KDF" type.
  108. =item "CTR" (B<OSSL_SELF_TEST_DESC_DRBG_CTR>)
  109. =item "HASH" (B<OSSL_SELF_TEST_DESC_DRBG_HASH>)
  110. =item "HMAC" (B<OSSL_SELF_TEST_DESC_DRBG_HMAC>)
  111. DRBG tests used with the "DRBG" type.
  112. =back
  113. =back
  114. =head1 EXAMPLES
  115. A simple self test callback is shown below for illustrative purposes.
  116. #include <openssl/self_test.h>
  117. static OSSL_CALLBACK self_test_cb;
  118. static int self_test_cb(const OSSL_PARAM params[], void *arg)
  119. {
  120. int ret = 0;
  121. const OSSL_PARAM *p = NULL;
  122. const char *phase = NULL, *type = NULL, *desc = NULL;
  123. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_PHASE);
  124. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  125. goto err;
  126. phase = (const char *)p->data;
  127. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_DESC);
  128. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  129. goto err;
  130. desc = (const char *)p->data;
  131. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_TYPE);
  132. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  133. goto err;
  134. type = (const char *)p->data;
  135. /* Do some logging */
  136. if (strcmp(phase, OSSL_SELF_TEST_PHASE_START) == 0)
  137. BIO_printf(bio_out, "%s : (%s) : ", desc, type);
  138. if (strcmp(phase, OSSL_SELF_TEST_PHASE_PASS) == 0
  139. || strcmp(phase, OSSL_SELF_TEST_PHASE_FAIL) == 0)
  140. BIO_printf(bio_out, "%s\n", phase);
  141. /* Corrupt the SHA1 self test during the 'corrupt' phase by returning 0 */
  142. if (strcmp(phase, OSSL_SELF_TEST_PHASE_CORRUPT) == 0
  143. && strcmp(desc, OSSL_SELF_TEST_DESC_MD_SHA1) == 0) {
  144. BIO_printf(bio_out, "%s %s", phase, desc);
  145. return 0;
  146. }
  147. ret = 1;
  148. err:
  149. return ret;
  150. }
  151. =head1 SEE ALSO
  152. L<openssl-fipsinstall(1)>,
  153. L<fips_config(5)>,
  154. L<OSSL_SELF_TEST_set_callback(3)>,
  155. L<OSSL_PARAM(3)>,
  156. L<openssl-core.h(7)>
  157. =head1 HISTORY
  158. The type and functions described here were added in OpenSSL 3.0.
  159. =head1 COPYRIGHT
  160. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  161. Licensed under the Apache License 2.0 (the "License"). You may not use
  162. this file except in compliance with the License. You can obtain a copy
  163. in the file LICENSE in the source distribution or at
  164. L<https://www.openssl.org/source/license.html>.
  165. =cut