| ▲ | alerighi an hour ago | |||||||
Depends in what trust do you have over your hardware/OS. If you assume the hardware is potentially backdoored, and the OS is proprietary, or even if open could have malware/rootkits that can thinker around the random number generator, the solution of using a sole implementation inside the program (assuming the sha256 function is inside the program itself) maybe better. Sure an infected system may as well fake time values, but that is much more difficult and it's possible to detect from a userspace program. For example you mention to use getentroy, but on a compromised system you know how easy it is to change something that is implemented in a system library (e.g. libc) or even if you read /dev/random directly without passing from the libc how easy it's to make it read whatever you want? To me that is not that bad implementation, in fact it's an implementation that is used in a lot of security software (including GPG, not as the sole source of course but as one of many). | ||||||||
| ▲ | sltkr 14 minutes ago | parent [-] | |||||||
If you cannot trust the platform you're running on, all bets are off. There is a reason so much effort is put in TPM and remote attestation and so on. A compromised kernel doesn't even have to fake any data. It can just read the generated seed directly from user space without the program ever knowing about it. > Sure an infected system may as well fake time values, but that is much more difficult clock_gettime() just reads a value that the kernel has set, so that's not particularly difficult to fake. If you're thinking of using RDTSC instructions directly, that's of course not portable, and at that point you might as well call RDRAND directly, which is at least designed to provide random data. > it's possible to detect from a userspace program. There is no detection that is guaranteed to work on a compromised system. And whatever detection you have in mind to make the algorithm resistant to tampering was _not_ part of the original for-loop. You cannot claim the for-loop is superior to just calling getentropy() because it "can detect" clock tampering, while handwaving away the actual code to detect this clock tampering. > it's an implementation that is used in a lot of security software (including GPG, not as the sole source of course but as one of many). It's fine if you use it as a strictly additional source of entropy, but then the whole argument that it is superior because it avoids syscalls goes out of the window, because you're doing strictly _more_ work. | ||||||||
| ||||||||