diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-05-11 13:21:58 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-05-11 15:55:59 +0200 |
commit | 523cfd7845fd8141293b5dbe63e630428e9ac90d (patch) | |
tree | 2206da57847816dea89d0adfd1d7711ea854977e | |
parent | dfa22b657ba582cb03c0895d56b1513d4b9b8cd2 (diff) |
openpgp: Add explicit forwarder for crypto::random.
- This harmonizes the docstring across the different backends.
Also, it avoids monomorphization of the backend functions.
-rw-r--r-- | openpgp/src/crypto/backend/cng.rs | 4 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/nettle.rs | 12 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/rust.rs | 9 | ||||
-rw-r--r-- | openpgp/src/crypto/mod.rs | 14 |
4 files changed, 19 insertions, 20 deletions
diff --git a/openpgp/src/crypto/backend/cng.rs b/openpgp/src/crypto/backend/cng.rs index 8bf01b02..f964756a 100644 --- a/openpgp/src/crypto/backend/cng.rs +++ b/openpgp/src/crypto/backend/cng.rs @@ -11,9 +11,9 @@ pub mod hash; pub mod symmetric; /// Fills the given buffer with random data. -pub fn random<B: AsMut<[u8]>>(mut buf: B) { +pub fn random(buf: &mut [u8]) { RandomNumberGenerator::system_preferred() - .gen_random(buf.as_mut()) + .gen_random(buf) .expect("system-preferred RNG not to fail") } diff --git a/openpgp/src/crypto/backend/nettle.rs b/openpgp/src/crypto/backend/nettle.rs index 9bf737c0..79497a66 100644 --- a/openpgp/src/crypto/backend/nettle.rs +++ b/openpgp/src/crypto/backend/nettle.rs @@ -11,16 +11,8 @@ pub mod hash; pub mod symmetric; /// Fills the given buffer with random data. -/// -/// Fills the given buffer with random data produced by a -/// cryptographically secure pseudorandom number generator (CSPRNG). -/// The output may be used as session keys or to derive long-term -/// cryptographic keys from. However, to create session keys, -/// consider using [`SessionKey::new`]. -/// -/// [`SessionKey::new`]: crate::crypto::SessionKey::new() -pub fn random<B: AsMut<[u8]>>(mut buf: B) { - Yarrow::default().random(buf.as_mut()); +pub fn random(buf: &mut [u8]) { + Yarrow::default().random(buf); } impl PublicKeyAlgorithm { diff --git a/openpgp/src/crypto/backend/rust.rs b/openpgp/src/crypto/backend/rust.rs index 1bc6bf05..06b1da03 100644 --- a/openpgp/src/crypto/backend/rust.rs +++ b/openpgp/src/crypto/backend/rust.rs @@ -10,16 +10,11 @@ pub mod hash; pub mod symmetric; /// Fills the given buffer with random data. -/// -/// Fills the given buffer with random data produced by a -/// cryptographically secure pseudorandom number generator (CSPRNG). -/// The output may be used as session keys or to derive long-term -/// cryptographic keys from. -pub fn random<B: AsMut<[u8]>>(mut buf: B) { +pub fn random(buf: &mut [u8]) { use rand07::rngs::OsRng; use rand07::RngCore; - OsRng.fill_bytes(buf.as_mut()) + OsRng.fill_bytes(buf) } impl PublicKeyAlgorithm { diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs index 2e40451a..e3cfa197 100644 --- a/openpgp/src/crypto/mod.rs +++ b/openpgp/src/crypto/mod.rs @@ -32,7 +32,6 @@ pub(crate) mod aead; mod asymmetric; pub use self::asymmetric::{Signer, Decryptor, KeyPair}; mod backend; -pub use backend::random; pub mod ecdh; pub mod hash; pub mod mem; @@ -44,6 +43,19 @@ pub(crate) mod symmetric; #[cfg(test)] mod tests; +/// Fills the given buffer with random data. +/// +/// Fills the given buffer with random data produced by a +/// cryptographically secure pseudorandom number generator (CSPRNG). +/// The output may be used as session keys or to derive long-term +/// cryptographic keys from. However, to create session keys, +/// consider using [`SessionKey::new`]. +/// +/// [`SessionKey::new`]: crate::crypto::SessionKey::new() +pub fn random<B: AsMut<[u8]>>(mut buf: B) { + backend::random(buf.as_mut()); +} + /// Holds a session key. /// /// The session key is cleared when dropped. Sequoia uses this type |