可以在多线程中调用 RtlGenRandom (SystemFunction036) 检索重复的字节吗?
can calling RtlGenRandom (SystemFunction036) in multi threads retrieve duplicate bytes?
我将在多线程应用程序中生成 RSA 密钥。我使用 RtlGenRandom 作为 RNG。
我知道我可以在有 hanging/crash 或错误的情况下调用多线程。
我的问题是:
在多个线程中调用 RtlGenRandom 是否会在每个线程上给我重复的字节?
请不要提醒我使用 CNG 或 cryptgenrandom,因为 说它们最终都在 bcryptPrimitives!AesRNG*
。
只有 Microsoft 可以肯定地告诉您,或者该功能背后的合同到底是什么,但 Microsoft 基本上说您应该 get away from this function。
The RtlGenRandom function is available for use in the operating
systems specified in the Requirements section. It may be altered or
unavailable in subsequent versions. Instead, use the CryptGenRandom
function
反正你拆开就发现了
ProcessPrng -> AesRNGState_generate -> SymCryptRngAesGenerate
函数调用链,并且沿途还有 EnterCriticalSection 调用,所以我“想象”它是线程安全的。
PS: 最后一个SymCryptRngAesGenerate
function is open source.
另请参阅有关该主题的 crypto/rand: Currently using deprecated API for random number generation on Windows github 讨论。
我将在多线程应用程序中生成 RSA 密钥。我使用 RtlGenRandom 作为 RNG。
我知道我可以在有 hanging/crash 或错误的情况下调用多线程。
我的问题是:
在多个线程中调用 RtlGenRandom 是否会在每个线程上给我重复的字节?
请不要提醒我使用 CNG 或 cryptgenrandom,因为 bcryptPrimitives!AesRNG*
。
只有 Microsoft 可以肯定地告诉您,或者该功能背后的合同到底是什么,但 Microsoft 基本上说您应该 get away from this function。
The RtlGenRandom function is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use the CryptGenRandom function
反正你拆开就发现了
ProcessPrng -> AesRNGState_generate -> SymCryptRngAesGenerate
函数调用链,并且沿途还有 EnterCriticalSection 调用,所以我“想象”它是线程安全的。
PS: 最后一个SymCryptRngAesGenerate
function is open source.
另请参阅有关该主题的 crypto/rand: Currently using deprecated API for random number generation on Windows github 讨论。