Skip to content

Consier speeding up get_secure_random_bytes #1958

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

Closed
TheBlueMatt opened this issue Jan 16, 2023 · 4 comments
Closed

Consier speeding up get_secure_random_bytes #1958

TheBlueMatt opened this issue Jan 16, 2023 · 4 comments
Labels
good first issue Good for newcomers

Comments

@TheBlueMatt
Copy link
Collaborator

We really should swap out for a "real" CSPRNG, not because it'll be more secure, but because it'll be way faster than deriving a new HD key and hashing it. Preferrably something chacha-based given we already have chacha in-tree.

@TheBlueMatt TheBlueMatt added the good first issue Good for newcomers label Jan 16, 2023
@danielgranhao
Copy link
Contributor

danielgranhao commented Jan 17, 2023

I can take this up if no one has started yet.

I've done an initial experiment, and it seems that using chacha can get the execution time of get_secure_random_bytes from ~235 ns down to just ~4 ns on my machine.

Some of the tests broke, but I think it's due to them relying on the values that the original method generated using the same starting_time_nanos and starting_time_secs. Looking into it.

@TheBlueMatt
Copy link
Collaborator Author

Nice! Thanks.

@danielgranhao
Copy link
Contributor

I think I need some help here. I opened a draft PR with the current state of my attempt -> #1974.

One unit test fails because 2 Outpoints are equal when they should be different. I'm not sure if this shows a problem with the get_secure_random_bytes() method or if it's something that must be changed in the tests. I've already spent some time trying to figure it out but to no avail...

Also, I'm not sure of the safety of the RNG implementation. Some thoughts on that would also be appreciated 🙂

@TheBlueMatt
Copy link
Collaborator Author

Let's continue the discussion on the PR, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants