Skip to content

Commit b411d21

Browse files
committed
relax Sized requirements on the rng
1 parent bd20996 commit b411d21

File tree

11 files changed

+34
-23
lines changed

11 files changed

+34
-23
lines changed

Cargo.lock

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

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint.git" }
3131
ff = { git = "https://github.com/zkcrypto/ff.git", branch = "release-0.14.0" }
3232

3333
# https://github.com/zkcrypto/group/pull/56
34-
group = { git = "https://github.com/pinkforest/group.git", branch = "bump-rand-0.9" }
34+
# https://github.com/zkcrypto/group/pull/57
35+
group = { git = "https://github.com/baloo/group.git", branch = "baloo/relax-rng" }

aead/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait AeadCore {
130130
/// See [`AeadCore::generate_nonce`] documentation for requirements for
131131
/// random nonces.
132132
#[cfg(feature = "rand_core")]
133-
fn generate_nonce_with_rng<R: CryptoRng>(rng: &mut R) -> Nonce<Self> {
133+
fn generate_nonce_with_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Nonce<Self> {
134134
let mut nonce = Nonce::<Self>::default();
135135
rng.fill_bytes(&mut nonce);
136136
nonce
@@ -141,7 +141,7 @@ pub trait AeadCore {
141141
/// See [`AeadCore::generate_nonce`] documentation for requirements for
142142
/// random nonces.
143143
#[cfg(feature = "rand_core")]
144-
fn try_generate_nonce_with_rng<R: TryCryptoRng>(
144+
fn try_generate_nonce_with_rng<R: TryCryptoRng + ?Sized>(
145145
rng: &mut R,
146146
) -> core::result::Result<Nonce<Self>, R::Error> {
147147
let mut nonce = Nonce::<Self>::default();

crypto-common/src/lib.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub trait KeyInit: KeySizeUser + Sized {
196196
/// Generate random key using the provided [`CryptoRng`].
197197
#[cfg(feature = "rand_core")]
198198
#[inline]
199-
fn generate_key_with_rng<R: CryptoRng>(rng: &mut R) -> Key<Self> {
199+
fn generate_key_with_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Key<Self> {
200200
let mut key = Key::<Self>::default();
201201
rng.fill_bytes(&mut key);
202202
key
@@ -205,7 +205,9 @@ pub trait KeyInit: KeySizeUser + Sized {
205205
/// Generate random key using the provided [`TryCryptoRng`].
206206
#[cfg(feature = "rand_core")]
207207
#[inline]
208-
fn try_generate_key_with_rng<R: TryCryptoRng>(rng: &mut R) -> Result<Key<Self>, R::Error> {
208+
fn try_generate_key_with_rng<R: TryCryptoRng + ?Sized>(
209+
rng: &mut R,
210+
) -> Result<Key<Self>, R::Error> {
209211
let mut key = Key::<Self>::default();
210212
rng.try_fill_bytes(&mut key)?;
211213
Ok(key)
@@ -250,7 +252,7 @@ pub trait KeyIvInit: KeySizeUser + IvSizeUser + Sized {
250252
/// Generate random key using the provided [`CryptoRng`].
251253
#[cfg(feature = "rand_core")]
252254
#[inline]
253-
fn generate_key_with_rng<R: CryptoRng>(rng: &mut R) -> Key<Self> {
255+
fn generate_key_with_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Key<Self> {
254256
let mut key = Key::<Self>::default();
255257
rng.fill_bytes(&mut key);
256258
key
@@ -259,7 +261,9 @@ pub trait KeyIvInit: KeySizeUser + IvSizeUser + Sized {
259261
/// Generate random key using the provided [`TryCryptoRng`].
260262
#[cfg(feature = "rand_core")]
261263
#[inline]
262-
fn try_generate_key_with_rng<R: TryCryptoRng>(rng: &mut R) -> Result<Key<Self>, R::Error> {
264+
fn try_generate_key_with_rng<R: TryCryptoRng + ?Sized>(
265+
rng: &mut R,
266+
) -> Result<Key<Self>, R::Error> {
263267
let mut key = Key::<Self>::default();
264268
rng.try_fill_bytes(&mut key)?;
265269
Ok(key)
@@ -277,7 +281,7 @@ pub trait KeyIvInit: KeySizeUser + IvSizeUser + Sized {
277281
/// Generate random IV using the provided [`CryptoRng`].
278282
#[cfg(feature = "rand_core")]
279283
#[inline]
280-
fn generate_iv_with_rng<R: CryptoRng>(rng: &mut R) -> Iv<Self> {
284+
fn generate_iv_with_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Iv<Self> {
281285
let mut iv = Iv::<Self>::default();
282286
rng.fill_bytes(&mut iv);
283287
iv
@@ -286,7 +290,9 @@ pub trait KeyIvInit: KeySizeUser + IvSizeUser + Sized {
286290
/// Generate random IV using the provided [`TryCryptoRng`].
287291
#[cfg(feature = "rand_core")]
288292
#[inline]
289-
fn try_generate_iv_with_rng<R: TryCryptoRng>(rng: &mut R) -> Result<Iv<Self>, R::Error> {
293+
fn try_generate_iv_with_rng<R: TryCryptoRng + ?Sized>(
294+
rng: &mut R,
295+
) -> Result<Iv<Self>, R::Error> {
290296
let mut iv = Iv::<Self>::default();
291297
rng.try_fill_bytes(&mut iv)?;
292298
Ok(iv)
@@ -304,7 +310,7 @@ pub trait KeyIvInit: KeySizeUser + IvSizeUser + Sized {
304310
/// Generate random key and IV using the provided [`CryptoRng`].
305311
#[cfg(feature = "rand_core")]
306312
#[inline]
307-
fn generate_key_iv_with_rng<R: CryptoRng>(rng: &mut R) -> (Key<Self>, Iv<Self>) {
313+
fn generate_key_iv_with_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> (Key<Self>, Iv<Self>) {
308314
let key = Self::generate_key_with_rng(rng);
309315
let iv = Self::generate_iv_with_rng(rng);
310316
(key, iv)
@@ -313,7 +319,7 @@ pub trait KeyIvInit: KeySizeUser + IvSizeUser + Sized {
313319
/// Generate random key and IV using the provided [`TryCryptoRng`].
314320
#[cfg(feature = "rand_core")]
315321
#[inline]
316-
fn try_generate_key_iv_with_rng<R: TryCryptoRng>(
322+
fn try_generate_key_iv_with_rng<R: TryCryptoRng + ?Sized>(
317323
rng: &mut R,
318324
) -> Result<(Key<Self>, Iv<Self>), R::Error> {
319325
let key = Self::try_generate_key_with_rng(rng)?;
@@ -357,7 +363,7 @@ pub trait InnerIvInit: InnerUser + IvSizeUser + Sized {
357363
/// Generate random IV using the provided [`CryptoRng`].
358364
#[cfg(feature = "rand_core")]
359365
#[inline]
360-
fn generate_iv_with_rng<R: CryptoRng>(rng: &mut R) -> Iv<Self> {
366+
fn generate_iv_with_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Iv<Self> {
361367
let mut iv = Iv::<Self>::default();
362368
rng.fill_bytes(&mut iv);
363369
iv
@@ -366,7 +372,9 @@ pub trait InnerIvInit: InnerUser + IvSizeUser + Sized {
366372
/// Generate random IV using the provided [`TryCryptoRng`].
367373
#[cfg(feature = "rand_core")]
368374
#[inline]
369-
fn try_generate_iv_with_rng<R: TryCryptoRng>(rng: &mut R) -> Result<Iv<Self>, R::Error> {
375+
fn try_generate_iv_with_rng<R: TryCryptoRng + ?Sized>(
376+
rng: &mut R,
377+
) -> Result<Iv<Self>, R::Error> {
370378
let mut iv = Iv::<Self>::default();
371379
rng.try_fill_bytes(&mut iv)?;
372380
Ok(iv)

elliptic-curve/src/dev.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl ToEncodedPoint<MockCurve> for ProjectivePoint {
575575
impl group::Group for ProjectivePoint {
576576
type Scalar = Scalar;
577577

578-
fn random(_rng: impl RngCore) -> Self {
578+
fn random<R: RngCore + ?Sized>(_rng: &mut R) -> Self {
579579
unimplemented!();
580580
}
581581

elliptic-curve/src/ecdh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ where
108108
C: CurveArithmetic,
109109
{
110110
/// Generate a cryptographically random [`EphemeralSecret`].
111-
pub fn random<R: CryptoRng>(rng: &mut R) -> Self {
111+
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
112112
Self {
113113
scalar: NonZeroScalar::random(rng),
114114
}

elliptic-curve/src/point/non_identity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ where
5858
P: ConditionallySelectable + ConstantTimeEq + Curve + Default,
5959
{
6060
/// Generate a random `NonIdentity<ProjectivePoint>`.
61-
pub fn random<R: CryptoRng>(mut rng: R) -> Self {
61+
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
6262
loop {
63-
if let Some(point) = Self::new(P::random(&mut rng)).into() {
63+
if let Some(point) = Self::new(P::random(rng)).into() {
6464
break point;
6565
}
6666
}

elliptic-curve/src/scalar/blinded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
C: CurveArithmetic,
3939
{
4040
/// Create a new [`BlindedScalar`] from a scalar and a [`CryptoRng`].
41-
pub fn new<R: CryptoRng>(scalar: Scalar<C>, rng: &mut R) -> Self {
41+
pub fn new<R: CryptoRng + ?Sized>(scalar: Scalar<C>, rng: &mut R) -> Self {
4242
Self {
4343
scalar,
4444
mask: Scalar::<C>::random(rng),

elliptic-curve/src/scalar/primitive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
pub const MODULUS: C::Uint = C::ORDER;
6666

6767
/// Generate a random [`ScalarPrimitive`].
68-
pub fn random<R: CryptoRng>(rng: &mut R) -> Self {
68+
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
6969
Self {
7070
inner: C::Uint::random_mod(rng, &NonZero::new(Self::MODULUS).unwrap()),
7171
}

elliptic-curve/src/secret_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ where
9494

9595
/// Generate a random [`SecretKey`].
9696
#[cfg(feature = "arithmetic")]
97-
pub fn random<R: CryptoRng>(rng: &mut R) -> Self
97+
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self
9898
where
9999
C: CurveArithmetic,
100100
{

password-hash/src/salt.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,17 @@ pub struct SaltString {
203203
impl SaltString {
204204
/// Generate a random B64-encoded [`SaltString`] from [`CryptoRng`].
205205
#[cfg(feature = "rand_core")]
206-
pub fn from_rng<R: CryptoRng>(rng: &mut R) -> Self {
206+
pub fn from_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
207207
let mut bytes = [0u8; Salt::RECOMMENDED_LENGTH];
208208
rng.fill_bytes(&mut bytes);
209209
Self::encode_b64(&bytes).expect(INVARIANT_VIOLATED_MSG)
210210
}
211211

212212
/// Generate a random B64-encoded [`SaltString`] from [`TryCryptoRng`].
213213
#[cfg(feature = "rand_core")]
214-
pub fn try_from_rng<R: TryCryptoRng>(rng: &mut R) -> core::result::Result<Self, R::Error> {
214+
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(
215+
rng: &mut R,
216+
) -> core::result::Result<Self, R::Error> {
215217
let mut bytes = [0u8; Salt::RECOMMENDED_LENGTH];
216218
rng.try_fill_bytes(&mut bytes)?;
217219
let salt = Self::encode_b64(&bytes).expect(INVARIANT_VIOLATED_MSG);

0 commit comments

Comments
 (0)