fips140.cpp
// fips140.cpp - originally written and placed in the public domain by Wei Dai
#include "pch.h"
#ifndef CRYPTOPP_IMPORTS
#include "fips140.h"
#include "misc.h"
NAMESPACE_BEGIN(CryptoPP)
// Define this to 1 to turn on FIPS 140-2 compliance features, including additional tests during
// startup, random number generation, and key generation. These tests may affect performance.
#ifndef CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
#define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0
#endif
#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE))
#error FIPS 140-2 compliance requires the availability of OS provided RNG.
#endif
PowerUpSelfTestStatus g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE;
bool FIPS_140_2_ComplianceEnabled()
{
return CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2;
}
void SimulatePowerUpSelfTestFailure()
{
g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED;
}
PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
{
return g_powerUpSelfTestStatus;
}
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
// One variable for all threads for compatibility. Previously this
// was a ThreadLocalStorage variable, which is per-thread. Also see
// https://github.com/weidai11/cryptopp/issues/208
static bool s_inProgress = false;
#endif
bool PowerUpSelfTestInProgressOnThisThread()
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
return s_inProgress;
#else
return false;
#endif
}
void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress)
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
s_inProgress = inProgress;
#else
CRYPTOPP_UNUSED(inProgress);
#endif
}
void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
EncryptionPairwiseConsistencyTest(encryptor, decryptor);
#else
CRYPTOPP_UNUSED(encryptor), CRYPTOPP_UNUSED(decryptor);
#endif
}
void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier)
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
SignaturePairwiseConsistencyTest(signer, verifier);
#else
CRYPTOPP_UNUSED(signer), CRYPTOPP_UNUSED(verifier);
#endif
}
NAMESPACE_END
#endif
PK_Decryptor
Interface for public-key decryptors.
Definition cryptlib.h:2738
PK_Encryptor
Interface for public-key encryptors.
Definition cryptlib.h:2703
PK_Signer
Interface for public-key signers.
Definition cryptlib.h:2882
PK_Verifier
Interface for public-key signature verifiers.
Definition cryptlib.h:2946
CRYPTOPP_API
#define CRYPTOPP_API
Win32 calling convention.
Definition config_dll.h:119
fips140.h
Classes and functions for the FIPS 140-2 validated library.
FIPS_140_2_ComplianceEnabled
CRYPTOPP_DLL bool FIPS_140_2_ComplianceEnabled()
Determines whether the library provides FIPS validated cryptography.
GetPowerUpSelfTestStatus
CRYPTOPP_DLL PowerUpSelfTestStatus GetPowerUpSelfTestStatus()
Provides the current power-up self test status.
PowerUpSelfTestStatus
PowerUpSelfTestStatus
Status of the power-up self test.
Definition fips140.h:37
POWER_UP_SELF_TEST_NOT_DONE
@ POWER_UP_SELF_TEST_NOT_DONE
The self tests have not been performed.
Definition fips140.h:40
POWER_UP_SELF_TEST_FAILED
@ POWER_UP_SELF_TEST_FAILED
The self tests were executed via DoPowerUpSelfTest() or DoDllPowerUpSelfTest(), but the result was fa...
Definition fips140.h:43
SimulatePowerUpSelfTestFailure
CRYPTOPP_DLL void SimulatePowerUpSelfTestFailure()
Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED.
misc.h
Utility functions for the Crypto++ library.
CryptoPP
Crypto++ library namespace.
pch.h
Precompiled header file.