Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.2 KiB

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