prng: support getrandom & getentropy#1367
Conversation
|
What platforms have arc4random but not getrandom? I'd rather not add support for arc4 which has known weaknesses |
|
WASI (standardized WASM interface) doesn't have getrandom() unfortunately. it has getentropy(). i can swap the define preference so getrandom() comes first. |
|
Preferring getrandom over arc4random sounds like a good move -- how does that help with getentropy, though? |
done
it's orthogonal of course. I was just noting that WASI supports arc4random & getentropy, but not getrandom. I can drop arc4random & add getentropy if you want as it still makes things work for me (just tested). |
|
If that works, that sounds preferable. getrandom and getentropy are both reasonable modern APIs. |
|
ok, it'll take me a little bit to adjust to getentropy in the general case. the documented API says it operates on max size of 256, and while all the calls in mosh production code are well below that, src/tests/encrypt-decrypt.cc grabs a couple KB :). |
|
okidoki, this version supports getrandom first, then getentropy, then /dev/urandom. while the getentropy code is annoying due to the loop, a spot check on x86_64 shows it's only a few bytes larger than getrandom when compiled with -O2. |
|
If you rebase this we should be able to run CI on it and get this merged. |
|
Can you please apply the clang-format fixes from https://github.com/mobile-shell/mosh/actions/runs/22505470885/job/65202884828?pr=1367 |
If the C library supports these random functions, use them directly instead of reading the /dev/urandom file. This makes life easier on platforms that don't have /dev/urandom (like WASM).
|
ran |
If the C library supports these random functions, use them directly instead of reading the /dev/urandom file. This makes life easier on platforms that don't have /dev/urandom (like WASM).