Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b4e8749
Add `Group::mul_by_generator`
tarcieri Dec 30, 2022
6ab641f
Raise MSRV to 1.63
str4d Apr 16, 2025
8240c17
Update lockfile to latest MSRV-compatible dependencies
str4d Apr 16, 2025
8534991
Merge pull request #62 from zkcrypto/msrv-1.63
str4d Apr 16, 2025
055cc14
Bump to rust-random 0.9
pinkforest Jan 26, 2025
42e0ad5
Merge pull request #56 from pinkforest/bump-rand-0.9
str4d Apr 16, 2025
f3537bc
Relax `Sized` requirements on the rng
baloo Mar 3, 2025
430e26a
Merge pull request #57 from baloo/baloo/relax-rng
str4d Apr 16, 2025
4456de8
Provide a `Group::try_from_rng`
baloo Mar 3, 2025
94b7e74
Merge pull request #59 from baloo/baloo/try_from_rng
str4d Apr 16, 2025
6636782
Merge pull request #44 from tarcieri/mul_by_generator
str4d Apr 16, 2025
a260479
Preview 0.14.0-pre.0
str4d Apr 17, 2025
31e349d
Merge pull request #64 from zkcrypto/preview-0.14.0-pre.0
str4d Apr 17, 2025
3cbf67f
Merge pull request #1 from RustCrypto/release-0.14.0
tarcieri Nov 21, 2025
b1e0777
Fork `group` as `rustcrypto-group` (#2)
tarcieri Nov 21, 2025
e143fee
Bump `rand_core` dependency to v0.10.0-rc-2 (#3)
tarcieri Nov 22, 2025
dbd8e6c
v0.14.0-pre.0 (#4)
tarcieri Nov 22, 2025
82ce1a7
Bump `rand_core` to v0.10.0-rc-6 (#5)
tarcieri Jan 24, 2026
1be1a55
v0.14.0-pre.1 (#6)
tarcieri Jan 24, 2026
dfc8081
Bump `rand_core` dependency to v0.10 (#7)
tarcieri Feb 2, 2026
5203ec9
v0.14.0-rc.0 (#8)
tarcieri Feb 2, 2026
50ad1c4
Bump `rand` dependency to v0.10 (#11)
tarcieri Mar 31, 2026
1de70ab
Have wNAF use `PrimeField::to_le_repr` for scalars (#12)
tarcieri Mar 31, 2026
04930ff
v0.14.0-rc.1
tarcieri Mar 31, 2026
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
77 changes: 39 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ ubuntu-latest, windows-latest, macOS-latest ]
steps:
- uses: actions/checkout@v4
- name: Run tests
Expand All @@ -24,7 +24,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ ubuntu-latest, windows-latest, macOS-latest ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -37,42 +37,43 @@ jobs:
- name: Verify working directory is clean (excluding lockfile)
run: git diff --exit-code ':!Cargo.lock'

build-nodefault:
name: Build target ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- wasm32-wasi
- thumbv6m-none-eabi
- thumbv7em-none-eabihf
steps:
- uses: actions/checkout@v4
with:
path: crate_root
# We use a synthetic crate to ensure no dev-dependencies are enabled, which can
# be incompatible with some of these targets.
- name: Create synthetic crate for testing
run: cargo init --edition 2021 --lib ci-build
- name: Copy Rust version into synthetic crate
run: cp crate_root/rust-toolchain.toml ci-build/
- name: Copy patch directives into synthetic crate
run: |
echo "[patch.crates-io]" >> ./ci-build/Cargo.toml
cat ./crate_root/Cargo.toml | sed "0,/.\+\(patch.crates.\+\)/d" >> ./ci-build/Cargo.toml
- name: Add no_std pragma to lib.rs
run: |
echo "#![no_std]" > ./ci-build/src/lib.rs
- name: Add group as a dependency of the synthetic crate
working-directory: ./ci-build
# run: cargo add --no-default-features --path ../crate_root
run: sed -i 's;\[dependencies\];\[dependencies\]\ngroup = { path = "../crate_root", default-features = false };g' ./Cargo.toml
- name: Add target
working-directory: ./ci-build
run: rustup target add ${{ matrix.target }}
- name: Build for target
working-directory: ./ci-build
run: cargo build --verbose --target ${{ matrix.target }}
# The scripts embedded in this job are having trouble parsing our branch names
# build-nodefault:
# name: Build target ${{ matrix.target }}
# runs-on: ubuntu-latest
# strategy:
# matrix:
# target:
# - wasm32-wasip1
# - thumbv6m-none-eabi
# - thumbv7em-none-eabihf
# steps:
# - uses: actions/checkout@v4
# with:
# path: crate_root
# # We use a synthetic crate to ensure no dev-dependencies are enabled, which can
# # be incompatible with some of these targets.
# - name: Create synthetic crate for testing
# run: cargo init --edition 2021 --lib ci-build
# - name: Copy Rust version into synthetic crate
# run: cp crate_root/rust-toolchain.toml ci-build/
# - name: Copy patch directives into synthetic crate
# run: |
# echo "[patch.crates-io]" >> ./ci-build/Cargo.toml
# cat ./crate_root/Cargo.toml | sed "0,/.\+\(patch.crates.\+\)/d" >> ./ci-build/Cargo.toml
# - name: Add no_std pragma to lib.rs
# run: |
# echo "#![no_std]" > ./ci-build/src/lib.rs
# - name: Add group as a dependency of the synthetic crate
# working-directory: ./ci-build
# # run: cargo add --no-default-features --path ../crate_root
# run: sed -i 's;\[dependencies\];\[dependencies\]\nrustcrypto-group = { path = "../crate_root", default-features = false };g' ./Cargo.toml
# - name: Add target
# working-directory: ./ci-build
# run: rustup target add ${{ matrix.target }}
# - name: Build for target
# working-directory: ./ci-build
# run: cargo build --verbose --target ${{ matrix.target }}

doc-links:
name: Intra-doc links
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this library adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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

## [0.13.0] - 2022-12-06
### Changed
Expand Down
60 changes: 30 additions & 30 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "group"
version = "0.13.0"
name = "rustcrypto-group"
version = "0.14.0-rc.1"
authors = [
"Sean Bowe <ewillbefull@gmail.com>",
"Jack Grigg <jack@z.cash>",
]
edition = "2021"
rust-version = "1.56"
rust-version = "1.85"
readme = "README.md"
license = "MIT/Apache-2.0"

description = "Elliptic curve group traits and utilities"
documentation = "https://docs.rs/group/"
homepage = "https://github.com/zkcrypto/group"
repository = "https://github.com/zkcrypto/group"
documentation = "https://docs.rs/rustcrypto-group/"
homepage = "https://github.com/RustCrypto/group"
repository = "https://github.com/RustCrypto/group"

[dependencies]
ff = { version = "0.13", default-features = false }
rand = { version = "0.8", optional = true, default-features = false }
rand_core = { version = "0.6", default-features = false }
rand_xorshift = { version = "0.3", optional = true }
ff = { version = "0.14.0-rc.1", package = "rustcrypto-ff", default-features = false }
rand = { version = "0.10", optional = true, default-features = false }
rand_core = { version = "0.10", default-features = false }
rand_xorshift = { version = "0.5", optional = true }
subtle = { version = "2.2.1", default-features = false }

# Crate for exposing the dynamic memory usage of the w-NAF structs.
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# group [![Crates.io](https://img.shields.io/crates/v/group.svg)](https://crates.io/crates/group) #
# [RustCrypto]: group [![Crates.io](https://img.shields.io/crates/v/group.svg)](https://crates.io/crates/group) #

`group` is a crate for working with groups over elliptic curves.

This is a fork of: https://github.com/zkcrypto/group

## RFC process

This crate follows the [zkcrypto RFC process](https://zkcrypto.github.io/rfcs/).
Expand All @@ -11,7 +13,7 @@ wider discussion.

## Minimum Supported Rust Version

Requires Rust **1.56** or higher.
Requires Rust **1.85** or higher.

Minimum supported Rust version can be changed in the future, but it will be done with a
minor version bump.
Expand All @@ -32,3 +34,5 @@ Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.

[RustCrypto]: https://github.com/rustcrypto/
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.56.0"
components = [ "clippy", "rustfmt" ]
channel = "1.85.0"
components = ["clippy", "rustfmt"]
28 changes: 25 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ extern crate alloc;
// Re-export ff to make version-matching easier.
pub use ff;

use core::convert::Infallible;
use core::fmt;
use core::iter::Sum;
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use ff::PrimeField;
use rand_core::RngCore;
use rand_core::{Rng, TryRng};
use subtle::{Choice, CtOption};

pub mod cofactor;
Expand Down Expand Up @@ -76,7 +77,22 @@ pub trait Group:
/// this group.
///
/// This function is non-deterministic, and samples from the user-provided RNG.
fn random(rng: impl RngCore) -> Self;
fn random<R: Rng + ?Sized>(rng: &mut R) -> Self {
Self::try_from_rng(rng)
.map_err(|e: Infallible| e)
.expect("Infallible failed")

// NOTE: once MSRV gets to 1.82 remove the map_err/expect and use
// let Ok(out) = Self::try_from_rng(rng);
// out
// See: https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#omitting-empty-types-in-pattern-matching
}

/// Returns an element chosen uniformly at random from the non-identity elements of
/// this group.
///
/// This function is non-deterministic, and samples from the user-provided RNG.
fn try_from_rng<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error>;

/// Returns the additive identity, also known as the "neutral element".
fn identity() -> Self;
Expand All @@ -90,6 +106,12 @@ pub trait Group:
/// Doubles this element.
#[must_use]
fn double(&self) -> Self;

/// Multiply by the generator of the prime-order subgroup.
#[must_use]
fn mul_by_generator(scalar: &Self::Scalar) -> Self {
Self::generator() * scalar
}
}

/// Efficient representation of an elliptic curve point guaranteed.
Expand Down Expand Up @@ -119,7 +141,7 @@ pub trait GroupEncoding: Sized {
/// The `Default` implementation is not required to return a valid point encoding. The
/// bound is present to enable encodings to be constructed generically:
/// ```
/// # use group::GroupEncoding;
/// # use rustcrypto_group::GroupEncoding;
/// # use subtle::CtOption;
/// # struct G;
/// # impl GroupEncoding for G {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ fn random_transformation_tests<G: PrimeCurve>() {
for _ in 0..10 {
let mut v = (0..1000).map(|_| G::random(&mut rng)).collect::<Vec<_>>();

use rand::distributions::{Distribution, Uniform};
let between = Uniform::new(0, 1000);
use rand::distr::{Distribution, Uniform};
let between = Uniform::new(0, 1000).unwrap();
// Sprinkle in some normalized points
for _ in 0..5 {
v[between.sample(&mut rng)] = G::identity();
Expand Down
19 changes: 16 additions & 3 deletions src/wnaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ pub(crate) fn wnaf_form<S: AsRef<[u8]>>(wnaf: &mut Vec<i64>, c: S, window: usize
pos += window;
}
}

// If there is a remaining carry (the scalar used all `bit_len` bits
// and the last wNAF digit was negative), emit it so the
// representation is exact.
if carry != 0 {
wnaf.push(carry as i64);
}
}

/// Performs w-NAF exponentiation with the provided window table and w-NAF form scalar.
Expand Down Expand Up @@ -255,6 +262,12 @@ pub struct Wnaf<W, B, S> {
window_size: W,
}

impl<G: Group> Default for Wnaf<(), Vec<G>, Vec<i64>> {
fn default() -> Self {
Self::new()
}
}

impl<G: Group> Wnaf<(), Vec<G>, Vec<i64>> {
/// Construct a new wNAF context without allocating.
pub fn new() -> Self {
Expand Down Expand Up @@ -309,7 +322,7 @@ impl<G: WnafGroup> Wnaf<(), Vec<G>, Vec<i64>> {
let window_size = 4;

// Compute the wNAF form of the scalar.
wnaf_form(&mut self.scalar, scalar.to_repr(), window_size);
wnaf_form(&mut self.scalar, scalar.to_le_repr(), window_size);

// Return a Wnaf object that mutably borrows the base storage location, but
// immutably borrows the computed wNAF form scalar location.
Expand Down Expand Up @@ -387,7 +400,7 @@ impl<B, S: AsMut<Vec<i64>>> Wnaf<usize, B, S> {
where
B: AsRef<[G]>,
{
wnaf_form(self.scalar.as_mut(), scalar.to_repr(), self.window_size);
wnaf_form(self.scalar.as_mut(), scalar.to_le_repr(), self.window_size);
wnaf_exp(self.base.as_ref(), self.scalar.as_mut())
}
}
Expand Down Expand Up @@ -422,7 +435,7 @@ impl<F: PrimeField, const WINDOW_SIZE: usize> WnafScalar<F, WINDOW_SIZE> {
let mut wnaf = vec![];

// Compute the w-NAF form of the scalar.
wnaf_form(&mut wnaf, scalar.to_repr(), WINDOW_SIZE);
wnaf_form(&mut wnaf, scalar.to_le_repr(), WINDOW_SIZE);

WnafScalar {
wnaf,
Expand Down
Loading