OK.  I have done some more research and testing.  Here's what I found out 
so far:

On our build server (where the tests do not crash), the test logs tell me:

  hasRDRAND == 0, hasRDSEED == 0

and because of that, apparently the tests are skipped, because in the logs I
have:

  Testing RDSEED generator...

  RDSEED generator not available, skipping test.

On my laptop, it seems like I have RDRAND and RDSEED available, because in 
the
logs I see:

  hasRDRAND == 1, hasRDSEED == 1

and so the test is started:

  Testing RDSEED generator...

but that is the last line in the output, the test crashes somewhere.

Using the VS2015 debugger, i found that the call stack at the moment of the 
crash is:

  cryptest.exe!017e9c80() Unknown
  cryptest.exe!CryptoPP::RDSEED::GenerateBlock(unsigned char * output, 
unsigned int size) Line 249 C++
  
cryptest.exe!CryptoPP::RandomNumberGenerator::GenerateIntoBufferedTransformation(CryptoPP::BufferedTransformation
 
& target, const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
channel, unsigned __int64 length) Line 330 C++
  
cryptest.exe!CryptoPP::RandomNumberStore::TransferTo2(CryptoPP::BufferedTransformation
 
& target, unsigned __int64 & transferBytes, const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
channel, bool blocking) Line 1227 C++
  
cryptest.exe!CryptoPP::BufferedTransformation::TransferMessagesTo2(CryptoPP::BufferedTransformation
 
& target, unsigned int & messageCount, const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
channel, bool blocking) Line 650 C++
  
cryptest.exe!CryptoPP::BufferedTransformation::TransferAllTo2(CryptoPP::BufferedTransformation
 
& target, const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
channel, bool blocking) Line 696 C++
  
cryptest.exe!CryptoPP::SourceTemplate<CryptoPP::RandomNumberStore>::PumpAll2(bool
 
blocking) Line 1378 C++
  cryptest.exe!CryptoPP::Source::PumpAll() Line 1319 C++
  cryptest.exe!CryptoPP::Source::SourceInitialize(bool pumpAll, const 
CryptoPP::NameValuePairs & parameters) Line 1355 C++
  
cryptest.exe!CryptoPP::RandomNumberSource::RandomNumberSource(CryptoPP::RandomNumberGenerator
 
& rng, int length, bool pumpAll, CryptoPP::BufferedTransformation * 
attachment) Line 1454 C++
  
cryptest.exe!CryptoPP::Test::Test_RandomNumberGenerator(CryptoPP::RandomNumberGenerator
 
& prng, bool drain) Line 431 C++
  cryptest.exe!CryptoPP::Test::TestRDSEED() Line 866 C++
  cryptest.exe!CryptoPP::Test::ValidateAll(bool thorough) Line 56 C++
  cryptest.exe!CryptoPP::Test::Validate(int alg, bool thorough, const char 
* seedInput) Line 915 C++
  cryptest.exe!CryptoPP::Test::scoped_main(int argc, char * * argv) Line 396 
C++
  cryptest.exe!main(int argc, char * * argv) Line 1058 C++
  cryptest.exe!invoke_main() Line 64 C++
  cryptest.exe!__scrt_common_main_seh() Line 253 C++
  cryptest.exe!__scrt_common_main() Line 296 C++
  cryptest.exe!mainCRTStartup() Line 17 C++
  kernel32.dll!76ea6359() Unknown
  [Frames below may be incorrect and/or missing, no symbols loaded for 
kernel32.dll] 
  ntdll.dll!77407c14() Unknown
  ntdll.dll!77407be4() Unknown

more specifically inside the function RDSEED::GenerateBlock where we have 
the
statement

  MASM_RDSEED_GenerateBlock(output, size);

And in rdrand.cpp we have

  #if MASM_RDSEED_ASM_AVAILABLE
  extern "C" void CRYPTOPP_FASTCALL MASM_RDSEED_GenerateBlock(byte*, 
size_t);
  #endif

Searching the Visual Studio cryptest solution for 
'MASM_RDSEED_GenerateBlock'
tells me that this is a function written in assembler and defined in the 
file
rdrand.asm.

My main question remains why I have the crash when this 
MASM_RDSEED_GenerateBlock
assembler function is called.  Could it be that I am not using the right
compiler flags when building Crypto++?  Because at the top of rdrand.asm I 
see
the comment:

  ;; This ASM file provides RDRAND and RDSEED to downlevel Microsoft tool 
chains.
  ;; Everything "just works" under Visual Studio. Other platforms will have 
to
  ;; run MASM/MASM-64 and then link to the object files.
  
  ;; set ASFLAGS=/nologo /D_M_X86 /W3 /Cx /Zi /safeseh
  ;; set ASFLAGS64=/nologo /D_M_X64 /W3 /Cx /Zi
  ;; "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\ml.exe" 
%ASFLAGS% /Fo rdrand-x86.obj /c rdrand.asm
  ;; "C:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\bin\amd64\ml64.exe" %ASFLAGS64% /Fo rdrand-x64.obj /c rdrand.asm

If anybody has an idea on why MASM_RDSEED_GenerateBlock(output, size) 
crashes
and what I can do to avoid it, it would be highly appreciated :-)

Kind regards,
Bart

On Thursday, March 18, 2021 at 5:33:18 PM UTC+1 Jeffrey Walton wrote:

> On Thu, Mar 18, 2021 at 12:24 PM Bart Vandewoestyne 
> <bart.vand...@gmail.com> wrote: 
> > 
> > OK... and it seems like MASM_RDSEED_GenerateBlock is a function written 
> in assembler in rdrand.asm. 
> > 
> > Since my assembler knowledge is very limited, I'm lost here. So it looks 
> like the fact that I'm running this using VS2019 causes that assembler code 
> to throw an exception or something? 
>
> There's not much too the assembly instructions. Also see 
> https://www.cryptopp.com/wiki/RDRAND_and_RDSEED. 
>
> Jeff 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/76ed28a9-7aee-4697-8478-34ffcdd97f6fn%40googlegroups.com.

Reply via email to