Skip to content

Commit

Permalink
Make use of rand_core patch: TryCoreRng::unwrap_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Feb 16, 2025
1 parent 147808f commit e8d858e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 44 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint.git" }

# https://github.com/entropyxyz/crypto-primes/pull/74
crypto-primes = { git = "https://github.com/baloo/crypto-primes.git", branch = "baloo/rand_core-0.9" }

# https://github.com/rust-random/rand/pull/1589
rand_core = { git = "https://github.com/rust-random/rand.git" }
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ pub mod traits;
mod dummy_rng;
mod encoding;
mod key;
mod unwrap_rng;

pub use pkcs1;
pub use pkcs8;
Expand Down
6 changes: 3 additions & 3 deletions src/pkcs1v15/signing_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{oid, pkcs1v15_generate_prefix, sign, Signature, VerifyingKey};
use crate::{dummy_rng::DummyRng, unwrap_rng::UnwrapRng, Result, RsaPrivateKey};
use crate::{dummy_rng::DummyRng, Result, RsaPrivateKey};
use alloc::vec::Vec;
use core::marker::PhantomData;
use digest::Digest;
Expand Down Expand Up @@ -133,7 +133,7 @@ where
digest: D,
) -> signature::Result<Signature> {
sign(
Some(&mut UnwrapRng(rng)),
Some(&mut rng.unwrap_mut()),
&self.inner,
&self.prefix,
&digest.finalize(),
Expand All @@ -153,7 +153,7 @@ where
msg: &[u8],
) -> signature::Result<Signature> {
sign(
Some(&mut UnwrapRng(rng)),
Some(&mut rng.unwrap_mut()),
&self.inner,
&self.prefix,
&D::digest(msg),
Expand Down
8 changes: 4 additions & 4 deletions src/pss/blinded_signing_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{get_pss_signature_algo_id, sign_digest, Signature, VerifyingKey};
use crate::{unwrap_rng::UnwrapRng, Result, RsaPrivateKey};
use crate::{Result, RsaPrivateKey};
use const_oid::AssociatedOid;
use core::marker::PhantomData;
use digest::{Digest, FixedOutputReset};
Expand Down Expand Up @@ -94,7 +94,7 @@ where
msg: &[u8],
) -> signature::Result<Signature> {
sign_digest::<_, D>(
&mut UnwrapRng(rng),
&mut rng.unwrap_mut(),
true,
&self.inner,
&D::digest(msg),
Expand All @@ -115,7 +115,7 @@ where
digest: D,
) -> signature::Result<Signature> {
sign_digest::<_, D>(
&mut UnwrapRng(rng),
&mut rng.unwrap_mut(),
true,
&self.inner,
&digest.finalize(),
Expand All @@ -136,7 +136,7 @@ where
prehash: &[u8],
) -> signature::Result<Signature> {
sign_digest::<_, D>(
&mut UnwrapRng(rng),
&mut rng.unwrap_mut(),
true,
&self.inner,
prehash,
Expand Down
12 changes: 6 additions & 6 deletions src/pss/signing_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{get_pss_signature_algo_id, sign_digest, Signature, VerifyingKey};
use crate::encoding::verify_algorithm_id;
use crate::{unwrap_rng::UnwrapRng, Result, RsaPrivateKey};
use crate::{Result, RsaPrivateKey};
use const_oid::AssociatedOid;
use core::marker::PhantomData;
use digest::{Digest, FixedOutputReset};
Expand All @@ -24,7 +24,7 @@ use {

#[cfg(feature = "getrandom")]
use {
rand_core::{OsRng, UnwrapErr},
rand_core::{OsRng, TryRngCore},
signature::{hazmat::PrehashSigner, Signer},
};

Expand Down Expand Up @@ -100,7 +100,7 @@ where
digest: D,
) -> signature::Result<Signature> {
sign_digest::<_, D>(
&mut UnwrapRng(rng),
&mut rng.unwrap_mut(),
false,
&self.inner,
&digest.finalize(),
Expand Down Expand Up @@ -134,7 +134,7 @@ where
prehash: &[u8],
) -> signature::Result<Signature> {
sign_digest::<_, D>(
&mut UnwrapRng(rng),
&mut rng.unwrap_mut(),
false,
&self.inner,
prehash,
Expand All @@ -151,7 +151,7 @@ where
D: Digest + FixedOutputReset,
{
fn sign_prehash(&self, prehash: &[u8]) -> signature::Result<Signature> {
self.sign_prehash_with_rng(&mut UnwrapErr(OsRng), prehash)
self.sign_prehash_with_rng(&mut OsRng.unwrap_err(), prehash)
}
}

Expand All @@ -161,7 +161,7 @@ where
D: Digest + FixedOutputReset,
{
fn try_sign(&self, msg: &[u8]) -> signature::Result<Signature> {
self.try_sign_with_rng(&mut UnwrapErr(OsRng), msg)
self.try_sign_with_rng(&mut OsRng.unwrap_err(), msg)
}
}

Expand Down
28 changes: 0 additions & 28 deletions src/unwrap_rng.rs

This file was deleted.

0 comments on commit e8d858e

Please sign in to comment.