Skip to content
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

Allow for RNG propagation #86

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

lambdapioneer
Copy link

@lambdapioneer lambdapioneer commented Sep 24, 2022

Summary

Currently the Sphinx library is using OsRng (and sometimes ThreadRng) internally in some places that a caller cannot control. For example, inside the add_padding method which has non-public visibility. Hence, a caller who wants to use a different (P)RNG cannot easily do so.

This diff allows callers to provide a Rng for the top-level methods which is then passed through.

Following the existing pattern in EphemeralSecret::new_with_rng, I have added a new new_with_rng function in all places where necessary. We might want to consider to just change the existing new function instead, but that would be a breaking change of the public API.

See also this existing comment: https://github.com/lambdapioneer/nym-sphinx/blob/develop/src/crypto/keys.rs#L66-L67

    // honestly, this method shouldn't really exist, but right now we have no decent
    // rng propagation in the library

P.S. I enjoyed working in the code base :) well structured

Background

My personal motivation for this change is that we have an overlay protocol where multiple participants must generate the same SURB and then distribute it via secret shares. For this purpose I want to pass in a PRNG that's seeded with a nonce.

Test plan

I have added tests that verify that all output bytes rely on the passed-in RNG.

$ cargo test -q

running 80 tests
................................................................................
test result: ok. 80 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s


running 4 tests
....
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

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

Successfully merging this pull request may close these issues.

1 participant