Skip to content

Consier speeding up get_secure_random_bytes #1958

Closed

Description

@TheBlueMatt

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.

Activity

  1. danielgranhao commented on Jan 17, 2023

    @danielgranhao
    Contributor

    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.

  2. TheBlueMatt commented on Jan 17, 2023

    @TheBlueMatt
    CollaboratorAuthor

    Nice! Thanks.

  3. danielgranhao commented on Jan 20, 2023

    @danielgranhao
    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 🙂

  4. TheBlueMatt commented on Jan 25, 2023

    @TheBlueMatt
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions