Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arc4random #1343

Open
patricus3 opened this issue Dec 27, 2024 · 5 comments
Open

arc4random #1343

patricus3 opened this issue Dec 27, 2024 · 5 comments
Assignees
Labels
accepted We intend to address this issue.

Comments

@patricus3
Copy link

Hi.
I have two questions, why you didn't inplement arc4random?
and an other, the discord drama all was a big misunderstanding, check the new issue at superconfigure repo, and see what I actually meant.

@jart jart changed the title arc4random, why it isn't inplemented? arc4random Dec 27, 2024
@jart
Copy link
Owner

jart commented Dec 27, 2024

Cosmopolitan provides a variety of ways to generate random numbers, such as getrandom() and getentropy() which are both recommended for all use cases. No one's found need of arc4random yet, which is why we don't have it. I'm perfectly happy to include that too, if someone wants to copy over the FreeBSD or OpenBSD implementation per the CONTRIBUTING.md process.

@jart jart added the contributions welcome We'll commit to review and maintenance if the people who need it write the changes. label Dec 27, 2024
Repository owner deleted a comment from patricus3 Dec 27, 2024
@jart jart added accepted We intend to address this issue. and removed contributions welcome We'll commit to review and maintenance if the people who need it write the changes. labels Jan 6, 2025
@mrdomino
Copy link
Collaborator

mrdomino commented Jan 6, 2025

Some resources:

@mrdomino
Copy link
Collaborator

mrdomino commented Jan 6, 2025

TLDR on Fenestras X + the Windows 10 RNG is:

  • The kernel maintains one root randomness pool per logical core so that no synchronization is needed
  • Random numbers are generated via AES-CTR, which directly services large requests or else fills up a 128-byte buffer that is pulled from for small requests (to amortize the cost of the AES key expansion.)
  • The libc arc4random calls use MAP_INHERIT_ZERO (spelled INHERIT_ZERO in FreeBSD) to reset the buffer state on forks.

There are lots more subtleties in the whitepaper, and also some interesting design choices in Fenestras X in FreeBSD.

However, I think the arc4random family of syscalls might actually be implemented on all the platforms we care about (in Windows it's just spelled ProcessPrng) so at least the initial implementation of this might be pretty boring.

@mrdomino
Copy link
Collaborator

mrdomino commented Jan 6, 2025

Okay, right, they're not syscalls, they're in libc. So there's at least some porting work to be done.

@jart
Copy link
Owner

jart commented Jan 6, 2025

The libc arc4random calls use MAP_INHERIT_ZERO (spelled INHERIT_ZERO in FreeBSD) to reset the buffer state on forks.

That would be a good feature for cosmo's memory manager.
We could easily polyfill it in the fork() libc wrapper on platforms that don't support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted We intend to address this issue.
Projects
None yet
Development

No branches or pull requests

3 participants