fips_test.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* fips_test.h
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLF_CRYPT_FIPS_TEST_H
  22. #define WOLF_CRYPT_FIPS_TEST_H
  23. #include <wolfssl/wolfcrypt/types.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Added for FIPS v5.3 or later */
  28. #if defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)
  29. /* Determine FIPS in core hash type and size */
  30. #ifndef NO_SHA256
  31. #define FIPS_IN_CORE_DIGEST_SIZE 32
  32. #define FIPS_IN_CORE_HASH_TYPE WC_SHA256
  33. #define FIPS_IN_CORE_KEY_SZ 32
  34. #define FIPS_IN_CORE_VERIFY_SZ FIPS_IN_CORE_KEY_SZ
  35. #elif defined(WOLFSSL_SHA384)
  36. #define FIPS_IN_CORE_DIGEST_SIZE 48
  37. #define FIPS_IN_CORE_HASH_TYPE WC_SHA384
  38. #define FIPS_IN_CORE_KEY_SZ 48
  39. #define FIPS_IN_CORE_VERIFY_SZ FIPS_IN_CORE_KEY_SZ
  40. #else
  41. #error No FIPS hash (SHA2-256 or SHA2-384)
  42. #endif
  43. #endif /* FIPS v5.3 or later */
  44. enum FipsCastId {
  45. FIPS_CAST_AES_CBC,
  46. FIPS_CAST_AES_GCM,
  47. FIPS_CAST_HMAC_SHA1,
  48. FIPS_CAST_HMAC_SHA2_256,
  49. FIPS_CAST_HMAC_SHA2_512,
  50. FIPS_CAST_HMAC_SHA3_256,
  51. FIPS_CAST_DRBG,
  52. FIPS_CAST_RSA_SIGN_PKCS1v15,
  53. FIPS_CAST_ECC_CDH,
  54. FIPS_CAST_ECC_PRIMITIVE_Z,
  55. FIPS_CAST_DH_PRIMITIVE_Z,
  56. FIPS_CAST_ECDSA,
  57. FIPS_CAST_KDF_TLS12,
  58. FIPS_CAST_KDF_TLS13,
  59. FIPS_CAST_KDF_SSH,
  60. FIPS_CAST_COUNT
  61. };
  62. enum FipsCastStateId {
  63. FIPS_CAST_STATE_INIT,
  64. FIPS_CAST_STATE_PROCESSING,
  65. FIPS_CAST_STATE_SUCCESS,
  66. FIPS_CAST_STATE_FAILURE
  67. };
  68. enum FipsModeId {
  69. FIPS_MODE_INIT,
  70. FIPS_MODE_NORMAL,
  71. FIPS_MODE_DEGRADED,
  72. FIPS_MODE_FAILED
  73. };
  74. /* FIPS failure callback */
  75. typedef void(*wolfCrypt_fips_cb)(int ok, int err, const char* hash);
  76. /* Public set function */
  77. WOLFSSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf);
  78. /* Public get status functions */
  79. WOLFSSL_API int wolfCrypt_GetStatus_fips(void);
  80. WOLFSSL_API const char* wolfCrypt_GetCoreHash_fips(void);
  81. #ifdef HAVE_FORCE_FIPS_FAILURE
  82. /* Public function to force failure mode for operational testing */
  83. WOLFSSL_API int wolfCrypt_SetStatus_fips(int status);
  84. #endif
  85. WOLFSSL_LOCAL int DoPOST(char* base16_hash, int base16_hashSz);
  86. WOLFSSL_LOCAL int DoCAST(int type);
  87. WOLFSSL_LOCAL int DoKnownAnswerTests(char* base16_hash, int base16_hashSz); /* FIPSv1 and FIPSv2 */
  88. WOLFSSL_API int wc_RunCast_fips(int type);
  89. WOLFSSL_API int wc_GetCastStatus_fips(int type);
  90. #ifdef __cplusplus
  91. } /* extern "C" */
  92. #endif
  93. #endif /* WOLF_CRYPT_FIPS_TEST_H */