Skip to content

Commit 3cbf67f

Browse files
authored
Merge pull request #1 from RustCrypto/release-0.14.0
Merge `release-0.14.0` into `main`
2 parents 1d32e5f + 31e349d commit 3cbf67f

File tree

8 files changed

+117
-25
lines changed

8 files changed

+117
-25
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this library adheres to Rust's notion of
66
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Changed
10+
- MSRV is now 1.63.0.
11+
- Migrated to `ff 0.14`, `rand_core 0.9`.
12+
- `group::Group::random(rng: impl RngCore) -> Self` has been changed to
13+
`Group::random<R: RngCore + ?Sized>(rng: &mut R) -> Self`, to enable passing a
14+
trait object as the RNG.
15+
- `group::Group::try_from_rng` is a new trait method that must be implemented by
16+
downstreams. `Group::random` now has a default implementation that calls it.
917

1018
## [0.13.0] - 2022-12-06
1119
### Changed

Cargo.lock

Lines changed: 69 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "group"
3-
version = "0.13.0"
3+
version = "0.14.0-pre.0"
44
authors = [
55
"Sean Bowe <[email protected]>",
66
"Jack Grigg <[email protected]>",
77
]
88
edition = "2021"
9-
rust-version = "1.56"
9+
rust-version = "1.63"
1010
readme = "README.md"
1111
license = "MIT/Apache-2.0"
1212

@@ -16,10 +16,10 @@ homepage = "https://github.com/zkcrypto/group"
1616
repository = "https://github.com/zkcrypto/group"
1717

1818
[dependencies]
19-
ff = { version = "0.13", default-features = false }
20-
rand = { version = "0.8", optional = true, default-features = false }
21-
rand_core = { version = "0.6", default-features = false }
22-
rand_xorshift = { version = "0.3", optional = true }
19+
ff = { version = "=0.14.0-pre.0", default-features = false }
20+
rand = { version = "0.9", optional = true, default-features = false }
21+
rand_core = { version = "0.9", default-features = false }
22+
rand_xorshift = { version = "0.4", optional = true }
2323
subtle = { version = "2.2.1", default-features = false }
2424

2525
# Crate for exposing the dynamic memory usage of the w-NAF structs.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ wider discussion.
1111

1212
## Minimum Supported Rust Version
1313

14-
Requires Rust **1.56** or higher.
14+
Requires Rust **1.63** or higher.
1515

1616
Minimum supported Rust version can be changed in the future, but it will be done with a
1717
minor version bump.

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.56.0"
2+
channel = "1.63.0"
33
components = [ "clippy", "rustfmt" ]

src/lib.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ extern crate alloc;
99
// Re-export ff to make version-matching easier.
1010
pub use ff;
1111

12+
use core::convert::Infallible;
1213
use core::fmt;
1314
use core::iter::Sum;
1415
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
1516
use ff::PrimeField;
16-
use rand_core::RngCore;
17+
use rand_core::{RngCore, TryRngCore};
1718
use subtle::{Choice, CtOption};
1819

1920
pub mod cofactor;
@@ -76,7 +77,22 @@ pub trait Group:
7677
/// this group.
7778
///
7879
/// This function is non-deterministic, and samples from the user-provided RNG.
79-
fn random(rng: impl RngCore) -> Self;
80+
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
81+
Self::try_from_rng(rng)
82+
.map_err(|e: Infallible| e)
83+
.expect("Infallible failed")
84+
85+
// NOTE: once MSRV gets to 1.82 remove the map_err/expect and use
86+
// let Ok(out) = Self::try_from_rng(rng);
87+
// out
88+
// See: https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#omitting-empty-types-in-pattern-matching
89+
}
90+
91+
/// Returns an element chosen uniformly at random from the non-identity elements of
92+
/// this group.
93+
///
94+
/// This function is non-deterministic, and samples from the user-provided RNG.
95+
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error>;
8096

8197
/// Returns the additive identity, also known as the "neutral element".
8298
fn identity() -> Self;
@@ -90,6 +106,12 @@ pub trait Group:
90106
/// Doubles this element.
91107
#[must_use]
92108
fn double(&self) -> Self;
109+
110+
/// Multiply by the generator of the prime-order subgroup.
111+
#[must_use]
112+
fn mul_by_generator(scalar: &Self::Scalar) -> Self {
113+
Self::generator() * scalar
114+
}
93115
}
94116

95117
/// Efficient representation of an elliptic curve point guaranteed.

src/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ fn random_transformation_tests<G: PrimeCurve>() {
378378
for _ in 0..10 {
379379
let mut v = (0..1000).map(|_| G::random(&mut rng)).collect::<Vec<_>>();
380380

381-
use rand::distributions::{Distribution, Uniform};
382-
let between = Uniform::new(0, 1000);
381+
use rand::distr::{Distribution, Uniform};
382+
let between = Uniform::new(0, 1000).unwrap();
383383
// Sprinkle in some normalized points
384384
for _ in 0..5 {
385385
v[between.sample(&mut rng)] = G::identity();

src/wnaf.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ pub struct Wnaf<W, B, S> {
255255
window_size: W,
256256
}
257257

258+
impl<G: Group> Default for Wnaf<(), Vec<G>, Vec<i64>> {
259+
fn default() -> Self {
260+
Self::new()
261+
}
262+
}
263+
258264
impl<G: Group> Wnaf<(), Vec<G>, Vec<i64>> {
259265
/// Construct a new wNAF context without allocating.
260266
pub fn new() -> Self {

0 commit comments

Comments
 (0)