weidai11 / cryptopp

free C++ class library of cryptographic schemes
https://cryptopp.com
Other
4.83k stars 1.49k forks source link

Power-up self test failed and exception thrown with attached debugger #1153

Closed CSBVision closed 2 years ago

CSBVision commented 2 years ago

Hi all,

We are using a CryptoPP 64-bit Dll version 8.7.0 built with VS 2022.

The dll works fine in debug and release build as long as no debugger is attached. But with an debugger attached, during the DoDllPowerUpSelfTest() in fipstest.cpp the function bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac, unsigned long *pMacFileLocation) fails and as a result the exception Cryptographic algorithms are disabled after a power-up self test failed. is thrown when using a cryptographic function.

We guess that something similar to the lines 406 - 416 might solve the problem:

#if (_MSC_VER >= 1400 && _MSC_VER < 1920) && (defined(_M_IX86) || defined(_M_X64))
    // first byte of _CRT_DEBUGGER_HOOK gets modified in memory by the debugger invisibly, so read it from file
    if (IsDebuggerPresent())
    {
        if (subSectionMemStart <= (byte *)&_CRT_DEBUGGER_HOOK && (byte *)&_CRT_DEBUGGER_HOOK < subSectionMemStart + subSectionSize)
        {
            subSectionSize = (byte *)&_CRT_DEBUGGER_HOOK - subSectionMemStart;
            nextSubSectionStart = (byte *)&_CRT_DEBUGGER_HOOK - sectionMemStart + 1;
        }
    }
#endif

We circumvented the problem by changing the return value as follows without really solving the problem.

#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_IX86) || defined(_M_X64))
    if (IsDebuggerPresent())
    {
        OutputDebugStringA("Crypto++ DLL integrity check failure ignored due to attached debugger.\n");
        return true;
    }
#endif

We would appreciate if the problem could be solved. At least, if there is no better solution than our hack.

There is a wiki page with information on filing useful bug reports. If you have some time please visit http://www.cryptopp.com/wiki/Bug_Report on the wiki. The executive summary is:

noloader commented 2 years ago

The DLL is no longer an approved module. The project is deprecated, and it will be removed soon. You should not be using the DLL project.

If you need a DLL, then write a wrapper DLL.

Also see https://www.cryptopp.com/wiki/FIPS_DLL and https://www.cryptopp.com/wiki/Wrapper_DLL .