Skip to content
Snippets Groups Projects

Use a very cautious Rng for deriving longer-lived keys

Merged Nick Mathewson requested to merge nickm/arti:cautious_rng into main

This MR does several main things:

First, it introduces a "CautiousRng" which combines inputs from several sources, including OsRng, to minimize the likelihood of falling to a vulnerability in any particular one. (This is more than a bit paranoid, but it's what C Tor does.)

Second, it uses "CautiousRng" to generate any key that's going into a KeyMgr. (This is a close approximation to "any long- or medium-term key", though relays may want to consider some other keys "medium-term".)

(That part closes #1898 (closed).)

Third, it adds an "EntropicRng" marker trait to ensure that we don't accidentally use a weaker Rng when generating a managed key.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • gabi-250
  • gabi-250
    gabi-250 @gabi-250 started a thread on commit 53793d38
  • 44
    45 impl rand_core::RngCore for CautiousRng {
    46 fn next_u32(&mut self) -> u32 {
    47 let mut buf = Zeroizing::new([0_u8; 4]);
    48 self.fill_bytes(buf.as_mut());
    49 u32::from_le_bytes(*buf)
    50 }
    51
    52 fn next_u64(&mut self) -> u64 {
    53 let mut buf = Zeroizing::new([0_u8; 8]);
    54 self.fill_bytes(buf.as_mut());
    55 u64::from_le_bytes(*buf)
    56 }
    57
    58 fn fill_bytes(&mut self, dest: &mut [u8]) {
    59 let mut xof = Shake256::default();
  • gabi-250
  • gabi-250
  • gabi-250
    gabi-250 @gabi-250 started a thread on commit 75697f03
  • 20 21 period: TimePeriod,
    21 22 revision_counter: RevisionCounter,
    22 23 rng: &mut Rng,
    • Can we get rid of this rng now?

    • You mean, in favor of just having the method call rand::rng()? I don't have super strong feelings either way; I can include that in a ticket opened as followup.

      I would like to keep the Rng arguments in the hsdesc-encoding functions in tor-netdoc: those functions probably want to retain some determinism for testing.

    • Ahh, my bad, I thought it was unused. Yes, I agree it makes sense to keep it for the tor-netdoc functions.

    • That said, there's no real reason IMO that a funciton in hsservice still needs to take this argument: it could just call rand::rng() and pass that to the functions it calls in tor-netdoc.

    • Please register or sign in to reply
  • gabi-250
  • gabi-250
  • Thanks, the KeyMgr changes look good to me!

    I have a few questions and comments, but for the most part this LGTM.

  • gabi-250 left review comments

    left review comments

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading