From d887f79b62c86cf7a29ecc206c5755ff56879713 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 2 Jul 2019 19:00:41 +0200 Subject: openpgp: New function crypto::random. - Add and use a function that fills a buffer with a thread-local random number generator. --- openpgp/src/crypto/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'openpgp/src/crypto/mod.rs') diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs index 5a6b06c0..6645ecdc 100644 --- a/openpgp/src/crypto/mod.rs +++ b/openpgp/src/crypto/mod.rs @@ -27,6 +27,13 @@ pub use self::asymmetric::{ KeyPair, }; +/// Fills the given buffer with random data. +pub fn random>(mut buf: B) { + use std::cell::RefCell; + thread_local!(static RNG: RefCell = Default::default()); + RNG.with(|rng| rng.borrow_mut().random(buf.as_mut())); +} + /// Holds a session key. /// /// The session key is cleared when dropped. @@ -37,7 +44,7 @@ impl SessionKey { /// Creates a new session key. pub fn new(size: usize) -> Self { let mut sk: mem::Protected = vec![0; size].into(); - Yarrow::default().random(&mut sk); + random(&mut sk); Self(sk) } -- cgit v1.2.3