phobos
phobos copied to clipboard
`unpredictableSeed` doesn't work with ASAN
import std.random;
void main()
{
auto n = unpredictableSeed!ulong;
}
Fails when compiling with ldc2 -fsanitize=address %s.
Even though -fsanitize=address is specific to LDC, this is mainly a problem with the current Phobos implementation, assuming that the compiler wont poison the assembly block. In the current form, the assembly block should be marked as naked and optimally, be on a separate function to completely avoid conflicting registers.
Also, compare and jump instructions shouldn't really be in an inline assembly block, but rather, on readable D code.
CC @JohanEngelen
I’d go as far as to say that this function should probably just call the system’s CSPRNG – instead of executing RDRAND by itself (assuming that’s available on the respective platform).
I’d go as far as to say that this function should probably just call the system’s CSPRNG – instead of executing
RDRANDby itself (assuming that’s available on the respective platform).
Arguably, but I wouldn't, unless its vDSO-based (if that is even possible to implement securely and fast enough), but mostly for performance reasons, although I can totally see a point security-wise, but if that's the argument, don't use unpredictableSeed at all. Accessing the random device with enough entropy is not strictly required here, and I think this function has a balanced trade-off of not calling a syscall, being reasonably random and being fast.
On a side note, specifically to LLVM, this should be probably an intrinsic.
https://d.godbolt.org/z/3ej5G6Mf7