fips.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* ====================================================================
  2. * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * 3. All advertising materials mentioning features or use of this
  17. * software must display the following acknowledgment:
  18. * "This product includes software developed by the OpenSSL Project
  19. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  20. *
  21. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  22. * endorse or promote products derived from this software without
  23. * prior written permission. For written permission, please contact
  24. * openssl-core@openssl.org.
  25. *
  26. * 5. Products derived from this software may not be called "OpenSSL"
  27. * nor may "OpenSSL" appear in their names without prior written
  28. * permission of the OpenSSL Project.
  29. *
  30. * 6. Redistributions of any form whatsoever must retain the following
  31. * acknowledgment:
  32. * "This product includes software developed by the OpenSSL Project
  33. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  36. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46. * OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. #include <openssl/opensslconf.h>
  50. #include <openssl/crypto.h>
  51. #include <stdarg.h>
  52. #ifndef OPENSSL_FIPS
  53. #error FIPS is disabled.
  54. #endif
  55. #ifdef OPENSSL_FIPS
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. struct dsa_st;
  60. struct rsa_st;
  61. struct evp_pkey_st;
  62. struct env_md_st;
  63. struct env_md_ctx_st;
  64. struct evp_cipher_st;
  65. struct evp_cipher_ctx_st;
  66. struct dh_method;
  67. struct CMAC_CTX_st;
  68. struct hmac_ctx_st;
  69. int FIPS_module_mode_set(int onoff, const char *auth);
  70. int FIPS_module_mode(void);
  71. int FIPS_module_installed(void);
  72. const void *FIPS_rand_check(void);
  73. int FIPS_selftest(void);
  74. int FIPS_selftest_failed(void);
  75. void FIPS_corrupt_sha1(void);
  76. int FIPS_selftest_sha1(void);
  77. int FIPS_selftest_sha2(void);
  78. void FIPS_corrupt_aes(void);
  79. int FIPS_selftest_aes_ccm(void);
  80. int FIPS_selftest_aes_gcm(void);
  81. int FIPS_selftest_aes_xts(void);
  82. int FIPS_selftest_aes(void);
  83. void FIPS_corrupt_des(void);
  84. int FIPS_selftest_des(void);
  85. void FIPS_corrupt_rsa(void);
  86. void FIPS_corrupt_rsa_keygen(void);
  87. int FIPS_selftest_rsa(void);
  88. void FIPS_corrupt_dsa(void);
  89. void FIPS_corrupt_dsa_keygen(void);
  90. int FIPS_selftest_dsa(void);
  91. int FIPS_selftest_ecdsa(void);
  92. int FIPS_selftest_ecdh(void);
  93. int FIPS_selftest_dh(void);
  94. void FIPS_corrupt_rng(void);
  95. void FIPS_rng_stick(void);
  96. void FIPS_x931_stick(int onoff);
  97. void FIPS_drbg_stick(int onoff);
  98. int FIPS_selftest_rng(void);
  99. int FIPS_selftest_x931(void);
  100. int FIPS_selftest_hmac(void);
  101. int FIPS_selftest_drbg(void);
  102. int FIPS_selftest_drbg_all(void);
  103. int FIPS_selftest_cmac(void);
  104. void FIPS_get_timevec(unsigned char *buf, unsigned long *pctr);
  105. #define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
  106. alg " previous FIPS forbidden algorithm error ignored");
  107. int fips_pkey_signature_test(struct evp_pkey_st *pkey,
  108. const unsigned char *tbs, int tbslen,
  109. const unsigned char *kat, unsigned int katlen,
  110. const struct env_md_st *digest, unsigned int md_flags,
  111. const char *fail_str);
  112. int fips_cipher_test(struct evp_cipher_ctx_st *ctx,
  113. const struct evp_cipher_st *cipher,
  114. const unsigned char *key,
  115. const unsigned char *iv,
  116. const unsigned char *plaintext,
  117. const unsigned char *ciphertext,
  118. int len);
  119. void fips_set_selftest_fail(void);
  120. const struct env_md_st *FIPS_get_digestbynid(int nid);
  121. const struct evp_cipher_st *FIPS_get_cipherbynid(int nid);
  122. /* BEGIN ERROR CODES */
  123. /* The following lines are auto generated by the script mkerr.pl. Any changes
  124. * made after this point may be overwritten when the script is next run.
  125. */
  126. void ERR_load_FIPS_strings(void);
  127. /* Error codes for the FIPS functions. */
  128. /* Function codes. */
  129. #define FIPS_F_DH_BUILTIN_GENPARAMS 100
  130. #define FIPS_F_DH_INIT 148
  131. #define FIPS_F_DRBG_RESEED 162
  132. #define FIPS_F_DSA_BUILTIN_PARAMGEN 101
  133. #define FIPS_F_DSA_BUILTIN_PARAMGEN2 107
  134. #define FIPS_F_DSA_DO_SIGN 102
  135. #define FIPS_F_DSA_DO_VERIFY 103
  136. #define FIPS_F_ECDH_COMPUTE_KEY 163
  137. #define FIPS_F_ECDSA_DO_SIGN 164
  138. #define FIPS_F_ECDSA_DO_VERIFY 165
  139. #define FIPS_F_EC_KEY_GENERATE_KEY 166
  140. #define FIPS_F_EVP_CIPHERINIT_EX 124
  141. #define FIPS_F_EVP_DIGESTINIT_EX 125
  142. #define FIPS_F_FIPS_CHECK_DSA 104
  143. #define FIPS_F_FIPS_CHECK_DSA_PRNG 151
  144. #define FIPS_F_FIPS_CHECK_EC 142
  145. #define FIPS_F_FIPS_CHECK_EC_PRNG 152
  146. #define FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT 105
  147. #define FIPS_F_FIPS_CHECK_RSA 106
  148. #define FIPS_F_FIPS_CHECK_RSA_PRNG 150
  149. #define FIPS_F_FIPS_CIPHER 160
  150. #define FIPS_F_FIPS_CIPHERINIT 143
  151. #define FIPS_F_FIPS_CIPHER_CTX_CTRL 161
  152. #define FIPS_F_FIPS_DIGESTFINAL 158
  153. #define FIPS_F_FIPS_DIGESTINIT 128
  154. #define FIPS_F_FIPS_DIGESTUPDATE 159
  155. #define FIPS_F_FIPS_DRBG_BYTES 131
  156. #define FIPS_F_FIPS_DRBG_CHECK 146
  157. #define FIPS_F_FIPS_DRBG_CPRNG_TEST 132
  158. #define FIPS_F_FIPS_DRBG_ERROR_CHECK 136
  159. #define FIPS_F_FIPS_DRBG_GENERATE 134
  160. #define FIPS_F_FIPS_DRBG_INIT 135
  161. #define FIPS_F_FIPS_DRBG_INSTANTIATE 138
  162. #define FIPS_F_FIPS_DRBG_NEW 139
  163. #define FIPS_F_FIPS_DRBG_RESEED 140
  164. #define FIPS_F_FIPS_DRBG_SINGLE_KAT 141
  165. #define FIPS_F_FIPS_DSA_CHECK /* unused */ 107
  166. #define FIPS_F_FIPS_DSA_SIGN_DIGEST 154
  167. #define FIPS_F_FIPS_DSA_VERIFY_DIGEST 155
  168. #define FIPS_F_FIPS_GET_ENTROPY 147
  169. #define FIPS_F_FIPS_MODE_SET /* unused */ 108
  170. #define FIPS_F_FIPS_MODULE_MODE_SET 108
  171. #define FIPS_F_FIPS_PKEY_SIGNATURE_TEST 109
  172. #define FIPS_F_FIPS_RAND_ADD 137
  173. #define FIPS_F_FIPS_RAND_BYTES 122
  174. #define FIPS_F_FIPS_RAND_PSEUDO_BYTES 167
  175. #define FIPS_F_FIPS_RAND_SEED 168
  176. #define FIPS_F_FIPS_RAND_SET_METHOD 126
  177. #define FIPS_F_FIPS_RAND_STATUS 127
  178. #define FIPS_F_FIPS_RSA_SIGN_DIGEST 156
  179. #define FIPS_F_FIPS_RSA_VERIFY_DIGEST 157
  180. #define FIPS_F_FIPS_SELFTEST_AES 110
  181. #define FIPS_F_FIPS_SELFTEST_AES_CCM 145
  182. #define FIPS_F_FIPS_SELFTEST_AES_GCM 129
  183. #define FIPS_F_FIPS_SELFTEST_AES_XTS 144
  184. #define FIPS_F_FIPS_SELFTEST_CMAC 130
  185. #define FIPS_F_FIPS_SELFTEST_DES 111
  186. #define FIPS_F_FIPS_SELFTEST_DSA 112
  187. #define FIPS_F_FIPS_SELFTEST_ECDSA 133
  188. #define FIPS_F_FIPS_SELFTEST_HMAC 113
  189. #define FIPS_F_FIPS_SELFTEST_RNG /* unused */ 114
  190. #define FIPS_F_FIPS_SELFTEST_SHA1 115
  191. #define FIPS_F_FIPS_SELFTEST_X931 114
  192. #define FIPS_F_FIPS_SET_PRNG_KEY 153
  193. #define FIPS_F_HASH_FINAL 123
  194. #define FIPS_F_RSA_BUILTIN_KEYGEN 116
  195. #define FIPS_F_RSA_EAY_INIT 149
  196. #define FIPS_F_RSA_EAY_PRIVATE_DECRYPT 117
  197. #define FIPS_F_RSA_EAY_PRIVATE_ENCRYPT 118
  198. #define FIPS_F_RSA_EAY_PUBLIC_DECRYPT 119
  199. #define FIPS_F_RSA_EAY_PUBLIC_ENCRYPT 120
  200. #define FIPS_F_RSA_X931_GENERATE_KEY_EX 121
  201. #define FIPS_F_SSLEAY_RAND_BYTES /* unused */ 122
  202. /* Reason codes. */
  203. #define FIPS_R_ADDITIONAL_INPUT_ERROR_UNDETECTED 150
  204. #define FIPS_R_ADDITIONAL_INPUT_TOO_LONG 125
  205. #define FIPS_R_ALREADY_INSTANTIATED 134
  206. #define FIPS_R_AUTHENTICATION_FAILURE 151
  207. #define FIPS_R_CANNOT_READ_EXE /* unused */ 103
  208. #define FIPS_R_CANNOT_READ_EXE_DIGEST /* unused */ 104
  209. #define FIPS_R_CONTRADICTING_EVIDENCE 114
  210. #define FIPS_R_DRBG_NOT_INITIALISED 152
  211. #define FIPS_R_DRBG_STUCK 103
  212. #define FIPS_R_ENTROPY_ERROR_UNDETECTED 104
  213. #define FIPS_R_ENTROPY_NOT_REQUESTED_FOR_RESEED 105
  214. #define FIPS_R_ENTROPY_SOURCE_STUCK 142
  215. #define FIPS_R_ERROR_INITIALISING_DRBG 115
  216. #define FIPS_R_ERROR_INSTANTIATING_DRBG 127
  217. #define FIPS_R_ERROR_RETRIEVING_ADDITIONAL_INPUT 124
  218. #define FIPS_R_ERROR_RETRIEVING_ENTROPY 122
  219. #define FIPS_R_ERROR_RETRIEVING_NONCE 140
  220. #define FIPS_R_EXE_DIGEST_DOES_NOT_MATCH /* unused */ 105
  221. #define FIPS_R_FINGERPRINT_DOES_NOT_MATCH 110
  222. #define FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED 111
  223. #define FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING 112
  224. #define FIPS_R_FIPS_MODE_ALREADY_SET 102
  225. #define FIPS_R_FIPS_SELFTEST_FAILED 106
  226. #define FIPS_R_FUNCTION_ERROR 116
  227. #define FIPS_R_GENERATE_ERROR 137
  228. #define FIPS_R_GENERATE_ERROR_UNDETECTED 118
  229. #define FIPS_R_INSTANTIATE_ERROR 119
  230. #define FIPS_R_INSUFFICIENT_SECURITY_STRENGTH 120
  231. #define FIPS_R_INTERNAL_ERROR 121
  232. #define FIPS_R_INVALID_KEY_LENGTH 109
  233. #define FIPS_R_INVALID_PARAMETERS 144
  234. #define FIPS_R_IN_ERROR_STATE 123
  235. #define FIPS_R_KEY_TOO_SHORT 108
  236. #define FIPS_R_NONCE_ERROR_UNDETECTED 149
  237. #define FIPS_R_NON_FIPS_METHOD 100
  238. #define FIPS_R_NOPR_TEST1_FAILURE 145
  239. #define FIPS_R_NOPR_TEST2_FAILURE 146
  240. #define FIPS_R_NOT_INSTANTIATED 126
  241. #define FIPS_R_PAIRWISE_TEST_FAILED 107
  242. #define FIPS_R_PERSONALISATION_ERROR_UNDETECTED 128
  243. #define FIPS_R_PERSONALISATION_STRING_TOO_LONG 129
  244. #define FIPS_R_PRNG_STRENGTH_TOO_LOW 143
  245. #define FIPS_R_PR_TEST1_FAILURE 147
  246. #define FIPS_R_PR_TEST2_FAILURE 148
  247. #define FIPS_R_REQUEST_LENGTH_ERROR_UNDETECTED 130
  248. #define FIPS_R_REQUEST_TOO_LARGE_FOR_DRBG 131
  249. #define FIPS_R_RESEED_COUNTER_ERROR 132
  250. #define FIPS_R_RESEED_ERROR 133
  251. #define FIPS_R_RSA_DECRYPT_ERROR /* unused */ 115
  252. #define FIPS_R_RSA_ENCRYPT_ERROR /* unused */ 116
  253. #define FIPS_R_SELFTEST_FAILED 101
  254. #define FIPS_R_SELFTEST_FAILURE 135
  255. #define FIPS_R_STRENGTH_ERROR_UNDETECTED 136
  256. #define FIPS_R_TEST_FAILURE 117
  257. #define FIPS_R_UNINSTANTIATE_ERROR 141
  258. #define FIPS_R_UNINSTANTIATE_ZEROISE_ERROR 138
  259. #define FIPS_R_UNSUPPORTED_DRBG_TYPE 139
  260. #define FIPS_R_UNSUPPORTED_PLATFORM 113
  261. #ifdef __cplusplus
  262. }
  263. #endif
  264. #endif