-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Use libsodium's CSPRNG interface #2622
Conversation
Hmm, apparently it's less trivial than |
cb74b61
to
d3dafd3
Compare
I'm not a Monero developer but as a cryptographer, this looks good to me (modulo the build error of course). I strongly endorse the use of libsodium's default RNG; its choices of what to do on each platform are well-motivated. It's what we use in Zcash (see zcash/zcash#2299 for our notes on the blocking issue, which concluded that libsodium does get that right). |
And to address the points raised on the preceding PR, using the libsodium user space PRNG without a specific reason is a downgrade in quality versus the kernel one.
|
As I've said elsewhere: I'm not super fluent in C/C++. I know how to read/write it (the easy part), but getting the compiler to cooperate isn't something I've had much luck with. Anyone have any clues as to what the missing piece is to make |
What is the error ? |
|
Alternative to monero-project#2621, uses libsodium's randombytes_buf() instead.
d3dafd3
to
86201b2
Compare
Spoke too soon.
|
Is it installed (sorry to ask) ? |
Ah okay, I'll double-check that, then. |
Alternatively, we could use Bitcoin's RNG: https://github.com/moneromooo-monero/bitmonero/tree/wipe This doesn't seed with /dev/random at startup though. (don't mind the HAVE_xxx defines, it's still missing some cmake detection) |
Crypto++'s CSPRNG is more than fine... and will be available to monero via kovri... |
@anonimal Is it possible to PR the Crypto++ CSPRNG prior to Kovri completion? |
@NanoAkron sure, and AFAICT is less brittle than #2731 (also includes RDRAND support, a secure wipe impl, doesn't require openssl, and more). But do you want to pull in the whole library (it's not large) or hack a branch together for just these various parts? It seems easier to just pull in the whole lib. |
@anonimal Afraid I don't personally have the requisite skills. Was more an observation that including all the right hooks just this one time would prevent more work in the future to:
So doing it now could save months in the future. |
I briefly reviewed the Crypto++ RNG code and maybe it is a documentation issue but I don't really see where it has a complete packaged solution that is comparable to the Bitcoin code or even libsodium. There are various pieces that support OS entropy sources, CPU hardware, a mixing pool, etc. and makes all of these available to user code, but I don't see any single clearly-defined API that handles managing the available sources, proper seeding, etc. into a CSPRNG in a reasonably safe way. However, as I said it is possible I just missed it given the limited documentation (that I found). Also, it doesn't appear to have support for getrandom, which is a significant omission when it comes to safe and well-behaved seeding. (libsodium appears to get seeding somewhat wrong without getrandom but does support getrandom so this issue is largely moot.) |
Giving someone an API doesn't make something reasonably safe. Certain aspects of crypto should be sandboxed; otherwise, you're homebrewing yourself. Also, there is a clearly-defined API: to start, look at classes
??? Here's the implementation, there's not much to it as far as userland is concerned. I've also seen #2731 (comment) but I'm not convinced that getrandom is a requisite. We can definitely PR the addition to crypto++ or open the issue as a topic of discussion (they've merged my PRs in the past, still waiting on this one though weidai11/cryptopp#668). #2731 treads on the question of to homegrow or not homegrow. I'd personally prefer that we don't and instead shift responsibility to a library. |
There is documentation at RandomNumberGenerator on the Crypto++ wiki. There's also the manual and the RandomNumberGenerator interface (just check what is derived from it). They may not be that useful for those who are new to the Crypto++ library. If I am parsing things correctly, I think you only need to use There are some other details, like how does the generator seed itself using OS. That comes from In nearly all situations it is hard to shoot yourself in the foot with If you don't like the auto-seeded pool then you can use And you have the other generator available, like the Bitcoin generators and the libsodium generators. All of them do the same thing and all of them should be production quality. I would not lament over the details. Find one you like and use it. |
We are now linking with libsodium via 0mq, so: #4159 |
There's a PR with this in that builds, so I'll close this as a dupe. +duplicate |
Supersedes #2621.