Windows 上有哪些可用的熵源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4955527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What entropy sources are available on Windows?
提问by soid
I want to produce a random cryptographic key on Windows. Where can I obtain entropy?
我想在 Windows 上生成一个随机加密密钥。我在哪里可以获得熵?
I would like my entropy function to work without a network connection and to be reliable on Windows 2000 and upwards. Even sources which may or may not provide a small amount of entropy could be useful as all the sources will be pooled.
我希望我的熵函数在没有网络连接的情况下工作,并且在 Windows 2000 及更高版本上可靠。即使可能提供或可能不提供少量熵的来源也可能有用,因为所有来源都将被汇集。
This is my initial list of functions:
这是我最初的函数列表:
GetCurrentProcessID, GetCurrentThreadID, GetTickCount, GetLocalTime, QueryPerformanceCounter, GlobalMemoryStatus, GetDiskFreeSpace, GetComputerName, GetUserName, GetCursorPos, GetMessageTime, GetSystemInfo, CryptGenRandom, GetProcessHandleCount, GetProcessMemoryInfo.
GetCurrentProcessID、 GetCurrentThreadID、 GetTickCount、 GetLocalTime、 QueryPerformanceCounter、 GlobalMemoryStatus、 GetDiskFreeSpace、 GetComputerName、 GetUserName、 GetCursorPos、 GetMessageTime、 GetSystemInfo、 CryptGenRandom、 GetProcessHandleCount、 GetProcessMemoryInfo。
回答by soid
Although early versions of the CryptGenRandomfunction may contain weaknesseslater versions follow secure standards (see remarks on the CrypGenRandom page.)
尽管CryptGenRandom函数的早期版本可能包含弱点,但后续版本遵循安全标准(请参阅 CrypGenRandom 页面上的备注。)
It is weak to just use time as your seed. There is an answer under What is the most secure seed for random number generation?which explains that the unpredictable random seed may only need 128 bits to produce a secure PRNG. It is therefore probably unnecessary to find more sources than those listed in the question, and normally the CryptGenRandom function will already contain and generate enough entropy for itself that the caller does not need to do any of this.
仅以时间为种子是很弱的。在什么是最安全的随机数生成种子下有答案?这解释了不可预测的随机种子可能只需要 128 位就可以生成安全的 PRNG。因此,可能没有必要找到比问题中列出的更多的源,并且通常 CryptGenRandom 函数已经包含并为其自身生成足够的熵,调用者不需要执行任何这些操作。
CryptGenRandom and the function CryptAcquireContextwhich must preceed it can be called from Delphi like this.
CryptGenRandom 和必须在它之前的函数CryptAcquireContext可以像这样从 Delphi 中调用。
回答by greg
If its an option you can ask user to move mouse pointer for a while.
如果它是一个选项,您可以要求用户移动鼠标指针一段时间。
回答by Anders
The only external source that most machines have is Mic In/Line In, call waveInOpen+waveInPrepareHeader+waveInAddBuffer+waveInStart. How random that is probably depends on the hardware...
大多数机器唯一的外部源是Mic In/Line In,调用waveInOpen+waveInPrepareHeader+waveInAddBuffer+waveInStart。随机性可能取决于硬件......