source: trunk/src-cryptopp/fips140.cpp

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 2.5 KB
Line 
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
11NAMESPACE_BEGIN(CryptoPP)
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
27PowerUpSelfTestStatus g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE;
28
29bool FIPS_140_2_ComplianceEnabled()
30{
31        return CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2;
32}
33
34void SimulatePowerUpSelfTestFailure()
35{
36        g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED;
37}
38
39PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
40{
41        return g_powerUpSelfTestStatus;
42}
43
44#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
45ThreadLocalStorage & AccessPowerUpSelfTestInProgress()
46{
47        static ThreadLocalStorage selfTestInProgress;
48        return selfTestInProgress;
49}
50#endif
51
52bool PowerUpSelfTestInProgressOnThisThread()
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
62void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress)
63{
64        CRYPTOPP_UNUSED(inProgress);
65#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
66        AccessPowerUpSelfTestInProgress().SetValue((void *)inProgress);
67#endif
68}
69
70void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
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
78void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier)
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
86NAMESPACE_END
87
88#endif
Note: See TracBrowser for help on using the repository browser.