Skip to content

Commit c3f377d

Browse files
committed
remove UnwrapRng
1 parent 6a07484 commit c3f377d

File tree

6 files changed

+14
-44
lines changed

6 files changed

+14
-44
lines changed

Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint.git" }
3838
ff = { git = "https://github.com/pinkforest/ff.git", branch = "bump-rand-core" }
3939
# https://github.com/zkcrypto/group/pull/56
4040
group = { git = "https://github.com/pinkforest/group.git", branch = "bump-rand-0.9" }
41+
42+
# https://github.com/RustCrypto/traits/pull/1752
43+
signature = { git = "https://github.com/baloo/traits.git", branch = "baloo/signature/prehash-TryCryptoRng" }

ecdsa/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ extern crate alloc;
5959

6060
mod recovery;
6161

62-
#[cfg(feature = "signing")]
63-
mod unwrap_rng;
64-
6562
#[cfg(feature = "der")]
6663
pub mod der;
6764
#[cfg(feature = "dev")]

ecdsa/src/recovery.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use crate::{Error, Result};
44

55
#[cfg(feature = "signing")]
66
use {
7-
crate::{hazmat::sign_prehashed_rfc6979, unwrap_rng::UnwrapRng, SigningKey},
7+
crate::{hazmat::sign_prehashed_rfc6979, SigningKey},
88
elliptic_curve::{subtle::CtOption, FieldBytes},
99
signature::{
1010
digest::FixedOutput,
1111
hazmat::{PrehashSigner, RandomizedPrehashSigner},
12-
rand_core::{CryptoRng, TryCryptoRng},
12+
rand_core::TryCryptoRng,
1313
DigestSigner, RandomizedDigestSigner, Signer,
1414
},
1515
};
@@ -185,14 +185,14 @@ where
185185
{
186186
/// Sign the given message prehash, using the given rng for the RFC6979 Section 3.6 "additional
187187
/// data", returning a signature and recovery ID.
188-
pub fn sign_prehash_recoverable_with_rng<R: CryptoRng>(
188+
pub fn sign_prehash_recoverable_with_rng<R: TryCryptoRng>(
189189
&self,
190190
rng: &mut R,
191191
prehash: &[u8],
192192
) -> Result<(Signature<C>, RecoveryId)> {
193193
let z = bits2field::<C>(prehash)?;
194194
let mut ad = FieldBytes::<C>::default();
195-
rng.fill_bytes(&mut ad);
195+
rng.try_fill_bytes(&mut ad).map_err(|_| Error::new())?;
196196
sign_prehashed_rfc6979::<C, C::Digest>(self.as_nonzero_scalar(), &z, &ad)
197197
}
198198

@@ -237,7 +237,7 @@ where
237237
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
238238
SignatureSize<C>: ArraySize,
239239
{
240-
fn sign_prehash_with_rng<R: CryptoRng>(
240+
fn sign_prehash_with_rng<R: TryCryptoRng>(
241241
&self,
242242
rng: &mut R,
243243
prehash: &[u8],
@@ -259,7 +259,7 @@ where
259259
rng: &mut R,
260260
msg_digest: D,
261261
) -> Result<(Signature<C>, RecoveryId)> {
262-
self.sign_prehash_with_rng(&mut UnwrapRng(rng), &msg_digest.finalize_fixed())
262+
self.sign_prehash_with_rng(rng, &msg_digest.finalize_fixed())
263263
}
264264
}
265265

ecdsa/src/signing.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use crate::{
44
ecdsa_oid_for_digest,
55
hazmat::{bits2field, sign_prehashed_rfc6979, DigestPrimitive},
6-
unwrap_rng::UnwrapRng,
76
EcdsaCurve, Error, Result, Signature, SignatureSize, SignatureWithOid,
87
};
98
use core::fmt::{self, Debug};
@@ -188,7 +187,7 @@ where
188187
rng: &mut R,
189188
msg_digest: D,
190189
) -> Result<Signature<C>> {
191-
self.sign_prehash_with_rng(&mut UnwrapRng(rng), &msg_digest.finalize_fixed())
190+
self.sign_prehash_with_rng(rng, &msg_digest.finalize_fixed())
192191
}
193192
}
194193

@@ -198,14 +197,14 @@ where
198197
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
199198
SignatureSize<C>: ArraySize,
200199
{
201-
fn sign_prehash_with_rng<R: CryptoRng>(
200+
fn sign_prehash_with_rng<R: TryCryptoRng>(
202201
&self,
203202
rng: &mut R,
204203
prehash: &[u8],
205204
) -> Result<Signature<C>> {
206205
let z = bits2field::<C>(prehash)?;
207206
let mut ad = FieldBytes::<C>::default();
208-
rng.fill_bytes(&mut ad);
207+
rng.try_fill_bytes(&mut ad).map_err(|_| Error::new())?;
209208
Ok(sign_prehashed_rfc6979::<C, C::Digest>(&self.secret_scalar, &z, &ad)?.0)
210209
}
211210
}
@@ -305,7 +304,7 @@ where
305304
der::MaxSize<C>: ArraySize,
306305
<FieldBytesSize<C> as Add>::Output: Add<der::MaxOverhead> + ArraySize,
307306
{
308-
fn sign_prehash_with_rng<R: CryptoRng>(
307+
fn sign_prehash_with_rng<R: TryCryptoRng>(
309308
&self,
310309
rng: &mut R,
311310
prehash: &[u8],

ecdsa/src/unwrap_rng.rs

-28
This file was deleted.

0 commit comments

Comments
 (0)