-
Notifications
You must be signed in to change notification settings - Fork 568
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
Add jitterentropy as RNG #4325
Add jitterentropy as RNG #4325
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So some significant skepticism here (ala #4309) but at least this is included in a few widely used Linux distros, so I'm relatively open to merging something that supports this source but I would be quite against doing so where the output of jitter is xored with the system RNG. This should either be its own RNG type, that is used if the application specifically wants to use it, or (I think much more appropriately) it should be an EntropySource
that is used to feed userspace RNGs.
1e9180c
to
d56064d
Compare
I rewrote this as an RNG and implemented all feedback points, plus a very basic test to make sure code gets executed. Please re-check and let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK looking better now, thanks for addressing the previous round. Some additional comments outside of the changed code so GH won’t let me comment
- It might be useful to (also) expose
Jitter_RNG
as an entropy source, in the similar way as we do forSystem_RNG
andProcessor_RNG
- Please also update the rng documentation
- Depending on your use case you may want to also expose this to the C wrapper in
botan_rng_init
I have addressed all issues except:
Will tackle those next. |
I have not figured out the formatting issue. If you have a script somewhere in the repo, please tell. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
c7cb815
to
d7754ed
Compare
Please (re-)review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's another round of polishing. Along with a few nits and style/consistency suggestions, I have a left an idea for compacting/improving the test code.
We should also enable this module in at least a few CI targets to ensure sustainability. Since it introduces a new (optional) dependency it'll require a bit of CI script mangling. No worries, I'll send you a patch for it next week.
Thank you very much for the great feedback, I have pushed a new update. Especially the declaration/definition of |
About the declaration/definition of Using anonymous namespace in headers is strongly discouraged. It generates a warning on my computer (Ubuntu x86_64 using GCC 13.2). I don't think it's harmful in this case because there's only a forward declaration in there but I don't see any benefits either. The default visibility is already hidden. Personally I think the best would be to just use an attribute to hide the nested internal class declaration, but this will probably not work on windows because there's no way to disable Considering this, the best compromise will probably be to just make the internal class a standalone declaration. It won't generate symbols and we'll have to deal with a bit of namespace pollution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more minor nits. Most notably, the BOTAN_ASSERT
suggestions are purely optional, in my opinion.
Also a suggestion for an implementation of RandomNumberGenerator::clear()
that might (or might not) make sense for this adapter.
Generally, I think this converged nicely! Thanks for your patience. :)
6aafa62
to
57ccd78
Compare
Again, thank you very much for your feedback. I have implemented all of it. Please re-check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This looks good now.
Still to do on our side:
- CI integration (probably for the coverage, valgrind and sanitizer builds ?)
On the note of CI: jitterentropy-library
(standalone, not the daemon) doesn't seem to exist as a package for ubuntu. Or am I missing something? For testing locally, I built it from source. This isn't a big deal as the library is small, but I'd like to omit this on CI if possible.
Regarding CI: Here a patch that enables running your test in (some) CI configurations: reneme@f22d6b8 @randombit I had to build jitterentropy from source, because Ubuntu doesn't provide a package for it. 😞 |
Currently Ubuntu does not ship with a package for the jitterentropy-library. Therefore, this pulls the sources from the maintainer's GitHub and builds/installs it from source. The library is tiny, so there's no significant overhead in time, but of course the additional build dependency on another repository is a bummer.
Rebased to current master and your CI change cherry-picked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@randombit Your call regarding merging before or after the 3.6.0 release. Given that this is entirely inside an optional module, there's probably little chance for general surprises here. |
Seems low risk to me so fine for 3.6 |
Add jitterentropy-library to Botan as a module. When enabled, the system RNG can use this additional entropy and depends on jitterentropy-library.
So far I have implemented this only for
BOTAN_TARGET_OS_HAS_CCRANDOM
for Botan 3, which got configured fairly automatically for my macOS machine.If this is something that is useful for Botan. I can easily provide implementation for other systems that I have access to, (windows and ubuntu, plus macOS/Android with arc4random). Plus port it to the Botan 2 branch.
I did not format
system_rng.cpp
yet because most changes would be in existing code (using vs code which should pick up.clang-format
).There is an integration project (using submodules for Botan and the jitter library), in case this is of use for someone. It probably works on linux too, but I'm not sure it the jitter will actually be used there because of the usage of
BOTAN_TARGET_OS_HAS_CCRANDOM
. At least with tests for Botan 2, a WSL ubuntu pickedBOTAN_TARGET_OS_HAS_GETRANDOM
here forSystem_RNG_Impl
.