Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 92 additions & 13 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]
[dev-dependencies]
bincode = "1.3"
criterion = "0.4"
rand_xorshift = "0.3"
rand_xorshift = "0.4"
serde_json = "1.0"

[[bench]]
Expand All @@ -44,9 +44,9 @@ harness = false
required-features = ["alloc"]

[dependencies]
ff = { version = "0.13", default-features = false }
group = { version = "0.13", default-features = false }
rand = { version = "0.8", default-features = false }
ff = { version = "=0.14.0-pre.0", default-features = false }
group = { version = "=0.14.0-pre.0", default-features = false }
rand = { version = "0.9", default-features = false }
static_assertions = "1.1.0"
subtle = { version = "2.3", default-features = false }

Expand Down
10 changes: 5 additions & 5 deletions src/curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use group::{
prime::{PrimeCurve, PrimeCurveAffine, PrimeGroup},
Curve as _, Group as _, GroupEncoding,
};
use rand::RngCore;
use rand::TryRngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -70,10 +70,10 @@ macro_rules! new_curve_impl {
impl group::Group for $name {
type Scalar = $scalar;

fn random(mut rng: impl RngCore) -> Self {
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
loop {
let x = $base::random(&mut rng);
let ysign = (rng.next_u32() % 2) as u8;
let x = $base::try_from_rng(rng)?;
let ysign = (rng.try_next_u32()? % 2) as u8;

let x3 = x.square() * x;
let y = (x3 + $name::curve_constant_b()).sqrt();
Expand All @@ -85,7 +85,7 @@ macro_rules! new_curve_impl {
x,
y,
};
break p.to_curve();
break Ok(p.to_curve());
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt;
use core::ops::{Add, Mul, Neg, Sub};

use ff::{Field, FromUniformBytes, PrimeField, WithSmallOrderMulGroup};
use rand::RngCore;
use rand::TryRngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "sqrt-table")]
Expand Down Expand Up @@ -479,17 +479,17 @@ impl ff::Field for Fp {
const ZERO: Self = Self::zero();
const ONE: Self = Self::one();

fn random(mut rng: impl RngCore) -> Self {
Self::from_u512([
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
])
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
Ok(Self::from_u512([
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
]))
}

fn double(&self) -> Self {
Expand Down
24 changes: 12 additions & 12 deletions src/fields/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt;
use core::ops::{Add, Mul, Neg, Sub};

use ff::{Field, FromUniformBytes, PrimeField, WithSmallOrderMulGroup};
use rand::RngCore;
use rand::TryRngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "sqrt-table")]
Expand Down Expand Up @@ -479,17 +479,17 @@ impl ff::Field for Fq {
const ZERO: Self = Self::zero();
const ONE: Self = Self::one();

fn random(mut rng: impl RngCore) -> Self {
Self::from_u512([
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
])
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
Ok(Self::from_u512([
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
rng.try_next_u64()?,
]))
}

fn double(&self) -> Self {
Expand Down