Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 45 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkcs5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ aes = { version = "=0.9.0-pre.2", optional = true, default-features = false }
aes-gcm = { version = "=0.11.0-pre.2", optional = true, default-features = false, features = ["aes"] }
des = { version = "=0.9.0-pre.2", optional = true, default-features = false }
pbkdf2 = { version = "=0.13.0-pre.1", optional = true, default-features = false, features = ["hmac"] }
rand_core = { version = "0.6.4", optional = true, default-features = false }
rand_core = { version = "0.9.0", optional = true, default-features = false }
scrypt = { version = "=0.12.0-pre.2", optional = true, default-features = false }
sha1 = { version = "=0.11.0-pre.4", optional = true, default-features = false }
sha2 = { version = "=0.11.0-pre.4", optional = true, default-features = false }
Expand All @@ -39,7 +39,7 @@ std = []

3des = ["dep:des", "pbes2"]
des-insecure = ["dep:des", "pbes2"]
getrandom = ["rand_core/getrandom"]
getrandom = ["rand_core/os_rng"]
pbes2 = ["dep:aes", "dep:cbc", "dep:pbkdf2", "dep:scrypt", "dep:sha2", "dep:aes-gcm"]
sha1-insecure = ["dep:sha1", "pbes2"]

Expand Down
8 changes: 4 additions & 4 deletions pkcs5/src/pbes2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use der::{
};

#[cfg(feature = "rand_core")]
use rand_core::CryptoRngCore;
use rand_core::CryptoRng;

#[cfg(all(feature = "alloc", feature = "pbes2"))]
use alloc::vec::Vec;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Parameters {
/// This is currently an alias for [`Parameters::scrypt`]. See that method
/// for more information.
#[cfg(all(feature = "pbes2", feature = "rand_core"))]
pub fn recommended(rng: &mut impl CryptoRngCore) -> Self {
pub fn recommended<R: CryptoRng>(rng: &mut R) -> Self {
Self::scrypt(rng)
}

Expand All @@ -118,7 +118,7 @@ impl Parameters {
/// This will use AES-256-CBC as the encryption algorithm and SHA-256 as
/// the hash function for PBKDF2.
#[cfg(feature = "rand_core")]
pub fn pbkdf2(rng: &mut impl CryptoRngCore) -> Self {
pub fn pbkdf2<R: CryptoRng>(rng: &mut R) -> Self {
let mut iv = [0u8; Self::DEFAULT_IV_LEN];
rng.fill_bytes(&mut iv);

Expand Down Expand Up @@ -169,7 +169,7 @@ impl Parameters {
///
/// [RustCrypto/formats#1205]: https://github.com/RustCrypto/formats/issues/1205
#[cfg(all(feature = "pbes2", feature = "rand_core"))]
pub fn scrypt(rng: &mut impl CryptoRngCore) -> Self {
pub fn scrypt<R: CryptoRng>(rng: &mut R) -> Self {
let mut iv = [0u8; Self::DEFAULT_IV_LEN];
rng.fill_bytes(&mut iv);

Expand Down
4 changes: 2 additions & 2 deletions pkcs8/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ der = { version = "0.8.0-rc.0", features = ["oid"] }
spki = { version = "0.8.0-rc.0" }

# optional dependencies
rand_core = { version = "0.6", optional = true, default-features = false }
rand_core = { version = "0.9.0", optional = true, default-features = false }
pkcs5 = { version = "0.8.0-rc.0", optional = true, features = ["rand_core"] }
subtle = { version = "2", optional = true, default-features = false }

Expand All @@ -36,7 +36,7 @@ std = ["alloc", "der/std", "spki/std"]
3des = ["encryption", "pkcs5/3des"]
des-insecure = ["encryption", "pkcs5/des-insecure"]
encryption = ["alloc", "pkcs5/alloc", "pkcs5/pbes2", "rand_core"]
getrandom = ["rand_core/getrandom"]
getrandom = ["rand_core/os_rng"]
pem = ["alloc", "der/pem", "spki/pem"]
sha1-insecure = ["encryption", "pkcs5/sha1-insecure"]

Expand Down
6 changes: 3 additions & 3 deletions pkcs8/src/encrypted_private_key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pkcs5::EncryptionScheme;
use der::{asn1::OctetString, SecretDocument};

#[cfg(feature = "encryption")]
use {pkcs5::pbes2, rand_core::CryptoRngCore};
use {pkcs5::pbes2, rand_core::CryptoRng};

#[cfg(feature = "pem")]
use der::pem::PemLabel;
Expand Down Expand Up @@ -64,8 +64,8 @@ where
/// Encrypt the given ASN.1 DER document using a symmetric encryption key
/// derived from the provided password.
#[cfg(feature = "encryption")]
pub(crate) fn encrypt(
rng: &mut impl CryptoRngCore,
pub(crate) fn encrypt<R: CryptoRng>(
rng: &mut R,
password: impl AsRef<[u8]>,
doc: &[u8],
) -> Result<SecretDocument> {
Expand Down
7 changes: 3 additions & 4 deletions pkcs8/src/private_key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use der::{

#[cfg(feature = "encryption")]
use {
crate::EncryptedPrivateKeyInfoRef, der::zeroize::Zeroizing, pkcs5::pbes2,
rand_core::CryptoRngCore,
crate::EncryptedPrivateKeyInfoRef, der::zeroize::Zeroizing, pkcs5::pbes2, rand_core::CryptoRng,
};

#[cfg(feature = "pem")]
Expand Down Expand Up @@ -146,9 +145,9 @@ where
/// - p: 1
/// - Cipher: AES-256-CBC (best available option for PKCS#5 encryption)
#[cfg(feature = "encryption")]
pub fn encrypt(
pub fn encrypt<R: CryptoRng>(
&self,
rng: &mut impl CryptoRngCore,
rng: &mut R,
password: impl AsRef<[u8]>,
) -> Result<SecretDocument> {
let der = Zeroizing::new(self.to_der()?);
Expand Down
10 changes: 5 additions & 5 deletions pkcs8/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{Error, PrivateKeyInfoRef, Result};
use der::SecretDocument;

#[cfg(feature = "encryption")]
use {crate::EncryptedPrivateKeyInfoRef, rand_core::CryptoRngCore};
use {crate::EncryptedPrivateKeyInfoRef, rand_core::CryptoRng};

#[cfg(feature = "pem")]
use {
Expand Down Expand Up @@ -101,9 +101,9 @@ pub trait EncodePrivateKey {
/// Create an [`SecretDocument`] containing the ciphertext of
/// a PKCS#8 encoded private key encrypted under the given `password`.
#[cfg(feature = "encryption")]
fn to_pkcs8_encrypted_der(
fn to_pkcs8_encrypted_der<R: CryptoRng>(
&self,
rng: &mut impl CryptoRngCore,
rng: &mut R,
password: impl AsRef<[u8]>,
) -> Result<SecretDocument> {
EncryptedPrivateKeyInfoRef::encrypt(rng, password, self.to_pkcs8_der()?.as_bytes())
Expand All @@ -119,9 +119,9 @@ pub trait EncodePrivateKey {
/// Serialize this private key as an encrypted PEM-encoded PKCS#8 private
/// key using the `provided` to derive an encryption key.
#[cfg(all(feature = "encryption", feature = "pem"))]
fn to_pkcs8_encrypted_pem(
fn to_pkcs8_encrypted_pem<R: CryptoRng>(
&self,
rng: &mut impl CryptoRngCore,
rng: &mut R,
password: impl AsRef<[u8]>,
line_ending: LineEnding,
) -> Result<Zeroizing<String>> {
Expand Down