Fabcoin Core  0.16.2
P2P Digital Currency
fips140.cpp
Go to the documentation of this file.
1 // fips140.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 
5 #ifndef CRYPTOPP_IMPORTS
6 
7 #include "fips140.h"
8 #include "misc.h"
9 #include "trdlocal.h" // needs to be included last for cygwin
10 
12 
13 // Define this to 1 to turn on FIPS 140-2 compliance features, including additional tests during
14 // startup, random number generation, and key generation. These tests may affect performance.
15 #ifndef CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
16 #define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0
17 #endif
18 
19 #if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(THREADS_AVAILABLE))
20 #error FIPS 140-2 compliance requires the availability of thread local storage.
21 #endif
22 
23 #if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE))
24 #error FIPS 140-2 compliance requires the availability of OS provided RNG.
25 #endif
26 
28 
30 {
32 }
33 
35 {
36  g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED;
37 }
38 
40 {
42 }
43 
44 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
45 ThreadLocalStorage & AccessPowerUpSelfTestInProgress()
46 {
47  static ThreadLocalStorage selfTestInProgress;
48  return selfTestInProgress;
49 }
50 #endif
51 
53 {
54 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
55  return AccessPowerUpSelfTestInProgress().GetValue() != NULL;
56 #else
57  CRYPTOPP_ASSERT(false); // should not be called
58  return false;
59 #endif
60 }
61 
63 {
64  CRYPTOPP_UNUSED(inProgress);
65 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
66  AccessPowerUpSelfTestInProgress().SetValue((void *)inProgress);
67 #endif
68 }
69 
71 {
72  CRYPTOPP_UNUSED(encryptor), CRYPTOPP_UNUSED(decryptor);
73 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
74  EncryptionPairwiseConsistencyTest(encryptor, decryptor);
75 #endif
76 }
77 
79 {
80  CRYPTOPP_UNUSED(signer), CRYPTOPP_UNUSED(verifier);
81 #if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
82  SignaturePairwiseConsistencyTest(signer, verifier);
83 #endif
84 }
85 
87 
88 #endif
void SignaturePairwiseConsistencyTest(const PK_Signer &signer, const PK_Verifier &verifier)
Definition: fipstest.cpp:241
Utility functions for the Crypto++ library.
void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier)
Definition: fips140.cpp:78
PowerUpSelfTestStatus g_powerUpSelfTestStatus
Definition: fips140.cpp:27
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
bool FIPS_140_2_ComplianceEnabled()
Determines whether the library provides FIPS validated cryptography.
Definition: fips140.cpp:29
Interface for public-key signers.
Definition: cryptlib.h:2527
Interface for public-key encryptors.
Definition: cryptlib.h:2336
PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
Provides the current power-up self test status.
Definition: fips140.cpp:39
The self tests were executed via DoPowerUpSelfTest() or DoDllPowerUpSelfTest(), but the result was fa...
Definition: fips140.h:44
void EncryptionPairwiseConsistencyTest(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
Definition: fipstest.cpp:205
void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress)
Definition: fips140.cpp:62
#define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
Definition: fips140.cpp:16
Interface for public-key decryptors.
Definition: cryptlib.h:2372
void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
Definition: fips140.cpp:70
#define CRYPTOPP_API
Definition: config.h:705
void SimulatePowerUpSelfTestFailure()
Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED.
Definition: fips140.cpp:34
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
The self tests have not been performed.
Definition: fips140.h:41
Interface for public-key signature verifiers.
Definition: cryptlib.h:2592
Classes and functions for the FIPS 140-2 validated library.
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
PowerUpSelfTestStatus
Status of the power-up self test.
Definition: fips140.h:38
#define NAMESPACE_END
Definition: config.h:201
bool PowerUpSelfTestInProgressOnThisThread()
Definition: fips140.cpp:52