chore: update more dependencies (#145)
* update more dependencies * cargo fmt * address review comments * fix format
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// of this source tree. You may select, at your option, one of the above-listed
|
||||
// licenses.
|
||||
|
||||
use core::num::NonZeroU32;
|
||||
use core::ops::Add;
|
||||
|
||||
use digest::core_api::BlockSizeUser;
|
||||
@@ -19,7 +20,7 @@ use elliptic_curve::{
|
||||
};
|
||||
use generic_array::typenum::{IsLess, IsLessOrEqual, Sum, U256};
|
||||
use generic_array::{ArrayLength, GenericArray};
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
use rand_core::{TryCryptoRng, TryRngCore};
|
||||
|
||||
use super::Group;
|
||||
use crate::{Error, InternalError, Result};
|
||||
@@ -93,8 +94,8 @@ where
|
||||
.map_err(|_| Error::Deserialization)
|
||||
}
|
||||
|
||||
fn random_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar {
|
||||
*SecretKey::<Self>::random(rng).to_nonzero_scalar()
|
||||
fn random_scalar<R: TryRngCore + TryCryptoRng>(rng: &mut R) -> Result<Self::Scalar> {
|
||||
Ok(*SecretKey::<Self>::random(&mut CompatRng(rng)).to_nonzero_scalar())
|
||||
}
|
||||
|
||||
fn invert_scalar(scalar: Self::Scalar) -> Self::Scalar {
|
||||
@@ -123,3 +124,42 @@ where
|
||||
.map_err(|_| Error::Deserialization)
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapter allowing `rand_core 0.9` RNGs to satisfy the `elliptic_curve` 0.13
|
||||
/// requirement for `rand_core 0.6` traits.
|
||||
///
|
||||
/// TODO #150: Remove this adapter when `elliptic_curve` migrates to `rand_core
|
||||
/// 0.9`.
|
||||
struct CompatRng<'a, R>(&'a mut R);
|
||||
|
||||
impl<'a, R> elliptic_curve::rand_core::RngCore for CompatRng<'a, R>
|
||||
where
|
||||
R: TryRngCore,
|
||||
{
|
||||
fn next_u32(&mut self) -> u32 {
|
||||
self.0.try_next_u32().expect("RNG failure")
|
||||
}
|
||||
|
||||
fn next_u64(&mut self) -> u64 {
|
||||
self.0.try_next_u64().expect("RNG failure")
|
||||
}
|
||||
|
||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
self.0
|
||||
.try_fill_bytes(dest)
|
||||
.expect("RNG failure while filling bytes");
|
||||
}
|
||||
|
||||
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), elliptic_curve::rand_core::Error> {
|
||||
self.0.try_fill_bytes(dest).map_err(|_| compat_error())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, R> elliptic_curve::rand_core::CryptoRng for CompatRng<'a, R> where R: TryCryptoRng {}
|
||||
|
||||
fn compat_error() -> elliptic_curve::rand_core::Error {
|
||||
let code = NonZeroU32::new(elliptic_curve::rand_core::Error::CUSTOM_START)
|
||||
.expect("CUSTOM_START must be non-zero");
|
||||
elliptic_curve::rand_core::Error::from(code)
|
||||
}
|
||||
|
||||
+6
-3
@@ -18,7 +18,7 @@ use digest::core_api::BlockSizeUser;
|
||||
use digest::{FixedOutput, HashMarker};
|
||||
use generic_array::typenum::{IsLess, IsLessOrEqual, Sum, U256};
|
||||
use generic_array::{ArrayLength, GenericArray};
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
use rand_core::{TryCryptoRng, TryRngCore};
|
||||
#[cfg(feature = "ristretto255")]
|
||||
pub use ristretto::Ristretto255;
|
||||
use subtle::{Choice, ConstantTimeEq};
|
||||
@@ -100,8 +100,11 @@ where
|
||||
/// is not a valid point on the group or the identity element.
|
||||
fn deserialize_elem(element_bits: &[u8]) -> Result<Self::Elem>;
|
||||
|
||||
/// picks a scalar at random
|
||||
fn random_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar;
|
||||
/// Picks a scalar at random.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`Error::Rng`](crate::Error::Rng) if the random number generator fails.
|
||||
fn random_scalar<R: TryRngCore + TryCryptoRng>(rng: &mut R) -> Result<Self::Scalar>;
|
||||
|
||||
/// The multiplicative inverse of this scalar
|
||||
fn invert_scalar(scalar: Self::Scalar) -> Self::Scalar;
|
||||
|
||||
@@ -15,7 +15,7 @@ use digest::{FixedOutput, HashMarker};
|
||||
use elliptic_curve::hash2curve::{ExpandMsg, ExpandMsgXmd, Expander};
|
||||
use generic_array::typenum::{IsLess, IsLessOrEqual, U256, U32, U64};
|
||||
use generic_array::GenericArray;
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
use rand_core::{TryCryptoRng, TryRngCore};
|
||||
use subtle::ConstantTimeEq;
|
||||
|
||||
use super::Group;
|
||||
@@ -94,13 +94,14 @@ impl Group for Ristretto255 {
|
||||
.ok_or(Error::Deserialization)
|
||||
}
|
||||
|
||||
fn random_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar {
|
||||
fn random_scalar<R: TryRngCore + TryCryptoRng>(rng: &mut R) -> Result<Self::Scalar> {
|
||||
loop {
|
||||
let mut scalar_bytes = [0u8; 32];
|
||||
rng.fill_bytes(&mut scalar_bytes);
|
||||
rng.try_fill_bytes(&mut scalar_bytes)
|
||||
.map_err(|_| Error::Rng)?;
|
||||
|
||||
if let Ok(scalar) = Self::deserialize_scalar(&scalar_bytes) {
|
||||
break scalar;
|
||||
break Ok(scalar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user