-
Notifications
You must be signed in to change notification settings - Fork 8
Add CryptoRngProvider trait #4
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
Conversation
This commit defines an interface that allows an embedding application to set an extension trait which can process the functions that require a CryptoRng. It does this without infecting the type signature of essentially every part of sunset. The implementation is 100% safe when building with the default getrandom feature enabled, but when that feature is omitted and the new assignment interface is added, there is some unsafe code to manage replacing the pointer to that extension trait. This is not likely totally sound in every scenario, but it happens to work for me. There's probably some cribbing that could be done from the log::logger() and log::set_logger_racy() functions to make this more-safe.
It resolves to 'a anyway, so let's just set it to that
Thanks for the patch. I'm not quite sure whether it makes sense setting the RNG here or using sunset/embassy/demos/picow/src/main.rs Lines 69 to 71 in 5a91df0
Using [1] https://docs.rs/getrandom/0.3.2/getrandom/index.html#custom-backend |
Oh, I somehow missed that getrandom had its own extension mechanism. Yeah, I can hook that up. I'm running on an rp2350 which actually has hardware TRNG available. https://fosstodon.org/@wez/114325695508602149 shows sunset working on a picocalc on a pico 2w! |
Ah, the other issue is that getrandom 0.2 doesn't compile for this platform:
I think 0.3 gets further along, but there are some other dependencies to run down, and I'm not sure if those are solvable with the current version of embassy-rp. I'll dig in a bit more. |
Ah awesome with the picocalc. I'd been eyeing those off, maybe I should get one!
It works if you build with sunset/embassy/demos/picow/Cargo.toml Line 52 in 5a91df0
I'll have a look how 0.3 goes when I get a chance. |
I looked at 0.3, but it's blocked on dalek-cryptography/curve25519-dalek#729 which is incomplete right now; I tried using a git ref to that in sunset, but it's not quite there. I did confirm just now that 0.2 with the custom feature works! What I'll do is amend this PR to be just the elided lifetime warning, because the rest of this is redundant! |
Actually, let's just do a separate branch pr, that way I can keep the one around in my fork for posterity! |
This makes it a bit easier to plug in an RNG when not building on a platform that has an OsRng.