Skip to content

Commit 2100251

Browse files
authored
elliptic-curve: fixup rand_core API use (#2197)
This fixes changes made in #2195 This is due to the refactor made in rand_core in rust-random/rand_core#45 which dropped the "trait dependency" between CryptoRng and RngCore
1 parent 5d95f9f commit 2100251

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

elliptic-curve/src/point/non_identity.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use core::ops::{Deref, Mul};
66

77
use group::{Group, GroupEncoding, prime::PrimeCurveAffine};
8-
use rand_core::{CryptoRng, TryCryptoRng};
8+
use rand_core::{CryptoRng, RngCore, TryCryptoRng, TryRngCore};
99
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
1010

1111
#[cfg(feature = "alloc")]
@@ -88,16 +88,18 @@ where
8888
P: ConditionallySelectable + ConstantTimeEq + CurveGroup + Default,
8989
{
9090
/// Generate a random `NonIdentity<ProjectivePoint>`.
91-
pub fn random<R: CryptoRng + ?Sized>(mut rng: &mut R) -> Self {
91+
pub fn random<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
9292
loop {
93-
if let Some(point) = Self::new(P::random(&mut rng)).into() {
93+
if let Some(point) = Self::new(P::random(rng)).into() {
9494
break point;
9595
}
9696
}
9797
}
9898

9999
/// Generate a random `NonIdentity<ProjectivePoint>`.
100-
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
100+
pub fn try_from_rng<R: TryCryptoRng + TryRngCore + ?Sized>(
101+
rng: &mut R,
102+
) -> Result<Self, R::Error> {
101103
loop {
102104
if let Some(point) = Self::new(P::try_from_rng(rng)?).into() {
103105
break Ok(point);

elliptic-curve/src/scalar/blinded.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::Scalar;
44
use crate::{CurveArithmetic, ops::Invert};
55
use core::fmt;
66
use group::ff::Field;
7-
use rand_core::CryptoRng;
7+
use rand_core::{CryptoRng, RngCore};
88
use subtle::CtOption;
99
use zeroize::Zeroize;
1010

@@ -38,10 +38,10 @@ where
3838
C: CurveArithmetic,
3939
{
4040
/// Create a new [`BlindedScalar`] from a scalar and a [`CryptoRng`].
41-
pub fn new<R: CryptoRng + ?Sized>(scalar: Scalar<C>, mut rng: &mut R) -> Self {
41+
pub fn new<R: CryptoRng + RngCore + ?Sized>(scalar: Scalar<C>, rng: &mut R) -> Self {
4242
Self {
4343
scalar,
44-
mask: Scalar::<C>::random(&mut rng),
44+
mask: Scalar::<C>::random(rng),
4545
}
4646
}
4747
}

0 commit comments

Comments
 (0)