Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
5.5 KiB

  1. // fips140.h - written and placed in the public domain by Wei Dai
  2. //! \file fips140.h
  3. //! \brief Classes and functions for the FIPS 140-2 validated library
  4. //! \details The FIPS validated library is only available on Windows as a DLL. Once compiled,
  5. //! the library is always in FIPS mode contingent upon successful execution of
  6. //! DoPowerUpSelfTest() or DoDllPowerUpSelfTest().
  7. //! \sa <A HREF="http://cryptopp.com/wiki/Visual_Studio">Visual Studio</A> and
  8. //! <A HREF="http://cryptopp.com/wiki/config.h">config.h</A> on the Crypto++ wiki.
  9. #ifndef CRYPTOPP_FIPS140_H
  10. #define CRYPTOPP_FIPS140_H
  11. #include "cryptlib.h"
  12. #include "secblock.h"
  13. NAMESPACE_BEGIN(CryptoPP)
  14. //! \class SelfTestFailure
  15. //! Exception thrown when a crypto algorithm is used after a self test fails
  16. //! \details The self tests for an algorithm are performed by Algortihm class
  17. //! when CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 is defined.
  18. class CRYPTOPP_DLL SelfTestFailure : public Exception
  19. {
  20. public:
  21. explicit SelfTestFailure(const std::string &s) : Exception(OTHER_ERROR, s) {}
  22. };
  23. //! \brief Determines whether the library provides FIPS validated cryptography
  24. //! \returns true if FIPS 140-2 validated features were enabled at compile time.
  25. //! \details true if FIPS 140-2 validated features were enabled at compile time,
  26. //! false otherwise.
  27. //! \note FIPS mode is enabled at compile time. A program or other module cannot
  28. //! arbitrarily enter or exit the mode.
  29. CRYPTOPP_DLL bool CRYPTOPP_API FIPS_140_2_ComplianceEnabled();
  30. //! \brief Status of the power-up self test
  31. enum PowerUpSelfTestStatus {
  32. //! \brief The self tests have not been performed.
  33. POWER_UP_SELF_TEST_NOT_DONE,
  34. //! \brief The self tests were executed via DoPowerUpSelfTest() or
  35. //! DoDllPowerUpSelfTest(), but the result was failure.
  36. POWER_UP_SELF_TEST_FAILED,
  37. //! \brief The self tests were executed via DoPowerUpSelfTest() or
  38. //! DoDllPowerUpSelfTest(), and the result was success.
  39. POWER_UP_SELF_TEST_PASSED
  40. };
  41. //! \brief Performs the power-up self test
  42. //! \param moduleFilename the fully qualified name of the module
  43. //! \param expectedModuleMac the expected MAC of the components protected by the integrity check
  44. //! \details Performs the power-up self test, and sets the self test status to
  45. //! POWER_UP_SELF_TEST_PASSED or POWER_UP_SELF_TEST_FAILED.
  46. //! \details The self tests for an algorithm are performed by the Algortihm class
  47. //! when CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 is defined.
  48. CRYPTOPP_DLL void CRYPTOPP_API DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleMac);
  49. //! \brief Performs the power-up self test on the DLL
  50. //! \details Performs the power-up self test using the filename of this DLL and the
  51. //! embedded module MAC, and sets the self test status to POWER_UP_SELF_TEST_PASSED or
  52. //! POWER_UP_SELF_TEST_FAILED.
  53. //! \details The self tests for an algorithm are performed by the Algortihm class
  54. //! when CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 is defined.
  55. CRYPTOPP_DLL void CRYPTOPP_API DoDllPowerUpSelfTest();
  56. //! \brief Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED
  57. //! \details Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED to simulate failure.
  58. CRYPTOPP_DLL void CRYPTOPP_API SimulatePowerUpSelfTestFailure();
  59. //! \brief Provides the current power-up self test status
  60. //! \returns the current power-up self test status
  61. CRYPTOPP_DLL PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus();
  62. #ifndef CRYPTOPP_DOXYGEN_PROCESSING
  63. typedef PowerUpSelfTestStatus (CRYPTOPP_API * PGetPowerUpSelfTestStatus)();
  64. #endif
  65. //! \brief Class object that calculates the MAC on the module
  66. //! \returns the MAC for the module
  67. CRYPTOPP_DLL MessageAuthenticationCode * CRYPTOPP_API NewIntegrityCheckingMAC();
  68. //! \brief Verifies the MAC on the module
  69. //! \param moduleFilename the fully qualified name of the module
  70. //! \param expectedModuleMac the expected MAC of the components protected by the integrity check
  71. //! \param pActualMac the actual MAC of the components calculated by the integrity check
  72. //! \param pMacFileLocation the offest of the MAC in the PE/PE+ module
  73. //! \returns true if the MAC is valid, false otherwise
  74. CRYPTOPP_DLL bool CRYPTOPP_API IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac = NULL, unsigned long *pMacFileLocation = NULL);
  75. #ifndef CRYPTOPP_DOXYGEN_PROCESSING
  76. // this is used by Algorithm constructor to allow Algorithm objects to be constructed for the self test
  77. bool PowerUpSelfTestInProgressOnThisThread();
  78. void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress);
  79. void SignaturePairwiseConsistencyTest(const PK_Signer &signer, const PK_Verifier &verifier);
  80. void EncryptionPairwiseConsistencyTest(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor);
  81. void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier);
  82. void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor);
  83. #endif
  84. //! \brief The placeholder used prior to embedding the actual MAC in the module.
  85. //! \details After the DLL is built but before it is MAC'd, the string CRYPTOPP_DUMMY_DLL_MAC
  86. //! is used as a placeholder for the actual MAC. A post-build step is performed which calculates
  87. //! the MAC of the DLL and embeds it in the module. The actual MAC is written by the
  88. //! <tt>cryptest.exe</tt> program using the <tt>mac_dll</tt> subcommand.
  89. #define CRYPTOPP_DUMMY_DLL_MAC "MAC_51f34b8db820ae8"
  90. NAMESPACE_END
  91. #endif