Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:03

0001 // fips140.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file fips140.h

0004 /// \brief Classes and functions for the FIPS 140-2 validated library

0005 /// \details The FIPS validated library is only available on Windows as a DLL. Once compiled,

0006 ///   the library is always in FIPS mode contingent upon successful execution of

0007 ///   DoPowerUpSelfTest() or DoDllPowerUpSelfTest().

0008 /// \sa <A HREF="http://cryptopp.com/wiki/Visual_Studio">Visual Studio</A> and

0009 ///   <A HREF="http://cryptopp.com/wiki/config.h">config.h</A> on the Crypto++ wiki.

0010 
0011 #ifndef CRYPTOPP_FIPS140_H
0012 #define CRYPTOPP_FIPS140_H
0013 
0014 #include "cryptlib.h"
0015 #include "secblock.h"
0016 
0017 NAMESPACE_BEGIN(CryptoPP)
0018 
0019 /// Exception thrown when a crypto algorithm is used after a self test fails

0020 /// \details The self tests for an algorithm are performed by Algorithm class

0021 ///   when CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 is defined.

0022 class CRYPTOPP_DLL SelfTestFailure : public Exception
0023 {
0024 public:
0025     explicit SelfTestFailure(const std::string &s) : Exception(OTHER_ERROR, s) {}
0026 };
0027 
0028 /// \brief Determines whether the library provides FIPS validated cryptography

0029 /// \return true if FIPS 140-2 validated features were enabled at compile time.

0030 /// \details true if FIPS 140-2 validated features were enabled at compile time,

0031 ///   false otherwise.

0032 /// \note FIPS mode is enabled at compile time. A program or other module cannot

0033 ///   arbitrarily enter or exit the mode.

0034 CRYPTOPP_DLL bool CRYPTOPP_API FIPS_140_2_ComplianceEnabled();
0035 
0036 /// \brief Status of the power-up self test

0037 enum PowerUpSelfTestStatus {
0038 
0039     /// \brief The self tests have not been performed.

0040     POWER_UP_SELF_TEST_NOT_DONE,
0041     /// \brief The self tests were executed via DoPowerUpSelfTest() or

0042     ///   DoDllPowerUpSelfTest(), but the result was failure.

0043     POWER_UP_SELF_TEST_FAILED,
0044     /// \brief The self tests were executed via DoPowerUpSelfTest() or

0045     ///   DoDllPowerUpSelfTest(), and the result was success.

0046     POWER_UP_SELF_TEST_PASSED
0047 };
0048 
0049 /// \brief Performs the power-up self test

0050 /// \param moduleFilename the fully qualified name of the module

0051 /// \param expectedModuleMac the expected MAC of the components protected by the integrity check

0052 /// \details Performs the power-up self test, and sets the self test status to

0053 ///   POWER_UP_SELF_TEST_PASSED or POWER_UP_SELF_TEST_FAILED.

0054 /// \details The self tests for an algorithm are performed by the Algorithm class

0055 ///   when CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 is defined.

0056 CRYPTOPP_DLL void CRYPTOPP_API DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleMac);
0057 
0058 /// \brief Performs the power-up self test on the DLL

0059 /// \details Performs the power-up self test using the filename of this DLL and the

0060 ///   embedded module MAC, and sets the self test status to POWER_UP_SELF_TEST_PASSED or

0061 ///   POWER_UP_SELF_TEST_FAILED.

0062 /// \details The self tests for an algorithm are performed by the Algorithm class

0063 ///   when CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 is defined.

0064 CRYPTOPP_DLL void CRYPTOPP_API DoDllPowerUpSelfTest();
0065 
0066 /// \brief Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED

0067 /// \details Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED to simulate failure.

0068 CRYPTOPP_DLL void CRYPTOPP_API SimulatePowerUpSelfTestFailure();
0069 
0070 /// \brief Provides the current power-up self test status

0071 /// \return the current power-up self test status

0072 CRYPTOPP_DLL PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus();
0073 
0074 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
0075 typedef PowerUpSelfTestStatus (CRYPTOPP_API * PGetPowerUpSelfTestStatus)();
0076 #endif
0077 
0078 /// \brief Class object that calculates the MAC on the module

0079 /// \return the MAC for the module

0080 CRYPTOPP_DLL MessageAuthenticationCode * CRYPTOPP_API NewIntegrityCheckingMAC();
0081 
0082 /// \brief Verifies the MAC on the module

0083 /// \param moduleFilename the fully qualified name of the module

0084 /// \param expectedModuleMac the expected MAC of the components protected by the integrity check

0085 /// \param pActualMac the actual MAC of the components calculated by the integrity check

0086 /// \param pMacFileLocation the offset of the MAC in the PE/PE+ module

0087 /// \return true if the MAC is valid, false otherwise

0088 CRYPTOPP_DLL bool CRYPTOPP_API IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac = NULLPTR, unsigned long *pMacFileLocation = NULLPTR);
0089 
0090 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
0091 // this is used by Algorithm constructor to allow Algorithm objects to be constructed for the self test

0092 bool PowerUpSelfTestInProgressOnThisThread();
0093 
0094 void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress);
0095 
0096 void SignaturePairwiseConsistencyTest(const PK_Signer &signer, const PK_Verifier &verifier);
0097 void EncryptionPairwiseConsistencyTest(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor);
0098 
0099 void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier);
0100 void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor);
0101 #endif
0102 
0103 /// \brief The placeholder used prior to embedding the actual MAC in the module.

0104 /// \details After the DLL is built but before it is MAC'd, the string CRYPTOPP_DUMMY_DLL_MAC

0105 ///   is used as a placeholder for the actual MAC. A post-build step is performed which calculates

0106 ///   the MAC of the DLL and embeds it in the module. The actual MAC is written by the

0107 ///   <tt>cryptest.exe</tt> program using the <tt>mac_dll</tt> subcommand.

0108 #define CRYPTOPP_DUMMY_DLL_MAC "MAC_51f34b8db820ae8"
0109 
0110 NAMESPACE_END
0111 
0112 #endif