monotone

monotone Mtn Source Tree

Root/cryptopp/fips140.cpp

1// fips140.cpp - written and placed in the public domain by Wei Dai
2
3#include "pch.h"
4#include "fips140.h"
5#include "trdlocal.h"// needs to be included last for cygwin
6
7NAMESPACE_BEGIN(CryptoPP)
8
9// Define this to 1 to turn on FIPS 140-2 compliance features, including additional tests during
10// startup, random number generation, and key generation. These tests may affect performance.
11#ifndef CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
12#define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0
13#endif
14
15#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(THREADS_AVAILABLE))
16#error FIPS 140-2 compliance requires the availability of thread local storage.
17#endif
18
19#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE))
20#error FIPS 140-2 compliance requires the availability of OS provided RNG.
21#endif
22
23PowerUpSelfTestStatus g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE;
24
25bool FIPS_140_2_ComplianceEnabled()
26{
27return CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2;
28}
29
30void SimulatePowerUpSelfTestFailure()
31{
32g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED;
33}
34
35PowerUpSelfTestStatus GetPowerUpSelfTestStatus()
36{
37return g_powerUpSelfTestStatus;
38}
39
40#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
41ThreadLocalStorage & AccessPowerUpSelfTestInProgress()
42{
43static ThreadLocalStorage selfTestInProgress;
44return selfTestInProgress;
45}
46#endif
47
48bool PowerUpSelfTestInProgressOnThisThread()
49{
50#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
51return AccessPowerUpSelfTestInProgress().GetValue() != NULL;
52#else
53assert(false);// should not be called
54return false;
55#endif
56}
57
58void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress)
59{
60#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
61AccessPowerUpSelfTestInProgress().SetValue((void *)inProgress);
62#endif
63}
64
65void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
66{
67#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
68EncryptionPairwiseConsistencyTest(encryptor, decryptor);
69#endif
70}
71
72void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier)
73{
74#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
75SignaturePairwiseConsistencyTest(signer, verifier);
76#endif
77}
78
79NAMESPACE_END

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status