Skip to content
Merged
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
73 changes: 37 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-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 }}
# 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
52 changes: 37 additions & 15 deletions Cargo.lock

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

13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ homepage = "https://github.com/RustCrypto/group"
repository = "https://github.com/RustCrypto/group"

[dependencies]
ff = { version = "=0.14.0-pre.0", package = "rustcrypto-ff", default-features = false }
chacha20 = { version = "0.10.0-rc.9", optional = true, default-features = false, features = ["rng"] }
ff = { version = "=0.14.0-pre.1", package = "rustcrypto-ff", default-features = false }
rand = { version = "0.10.0-rc.1", optional = true, default-features = false }
rand_core = { version = "0.10.0-rc-2", default-features = false }
rand_xorshift = { version = "0.5.0-rc.0", optional = true }
rand_core = { version = "0.10.0-rc-6", default-features = false }
#rand_xorshift = { version = "0.5.0-rc.0", optional = true }
subtle = { version = "2.2.1", default-features = false }

# Crate for exposing the dynamic memory usage of the w-NAF structs.
Expand All @@ -28,8 +29,12 @@ memuse = { version = "0.2", optional = true }
[features]
default = ["alloc"]
alloc = []
tests = ["alloc", "rand", "rand_xorshift"]
tests = ["alloc", "chacha20", "rand"] # "rand_xorshift"]
wnaf-memuse = ["alloc", "memuse"]

[badges]
maintenance = { status = "actively-developed" }

[patch.crates-io.rand]
git = "https://github.com/rust-random/rand"
branch = "rand_core/v0.10.0-rc-6"
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::fmt;
use core::iter::Sum;
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use ff::PrimeField;
use rand_core::{RngCore, TryRngCore};
use rand_core::{Rng, TryRng};
use subtle::{Choice, CtOption};

pub mod cofactor;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub trait Group:
/// this group.
///
/// This function is non-deterministic, and samples from the user-provided RNG.
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: Rng + ?Sized>(rng: &mut R) -> Self {
Self::try_from_rng(rng)
.map_err(|e: Infallible| e)
.expect("Infallible failed")
Expand All @@ -92,7 +92,7 @@ pub trait Group:
/// this group.
///
/// This function is non-deterministic, and samples from the user-provided RNG.
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error>;
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 Down
52 changes: 15 additions & 37 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use alloc::vec::Vec;
use chacha20::ChaCha8Rng;
use core::ops::{Mul, Neg};
use ff::{Field, PrimeField};
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;

use crate::{
prime::{PrimeCurve, PrimeCurveAffine},
wnaf::WnafGroup,
GroupEncoding, UncompressedEncoding,
};

const RNG_SEED: [u8; 32] = [
0x1f, 0x64, 0x25, 0xd1, 0x6c, 0xb5, 0xdf, 0x2, 0x6a, 0x72, 0xf6, 0x90, 0xa, 0x7a, 0xe1, 0x38,
0x22, 0xb7, 0xa8, 0x11, 0xb, 0xcf, 0xf4, 0x74, 0x25, 0xd, 0x63, 0x24, 0x17, 0x96, 0xc8, 0x58,
];

pub fn curve_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

// Negation edge case with identity.
{
Expand Down Expand Up @@ -72,10 +74,7 @@ pub fn curve_tests<G: PrimeCurve>() {
pub fn random_wnaf_tests<G: WnafGroup>() {
use crate::wnaf::*;

let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

{
let mut table = vec![];
Expand Down Expand Up @@ -189,10 +188,7 @@ pub fn random_wnaf_tests<G: WnafGroup>() {
}

fn random_negation_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

for _ in 0..1000 {
let r = G::random(&mut rng);
Expand All @@ -219,10 +215,7 @@ fn random_negation_tests<G: PrimeCurve>() {
}

fn random_doubling_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

for _ in 0..1000 {
let mut a = G::random(&mut rng);
Expand All @@ -247,10 +240,7 @@ fn random_doubling_tests<G: PrimeCurve>() {
}

fn random_multiplication_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

for _ in 0..1000 {
let mut a = G::random(&mut rng);
Expand Down Expand Up @@ -282,10 +272,7 @@ fn random_multiplication_tests<G: PrimeCurve>() {
}

fn random_addition_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

for _ in 0..1000 {
let a = G::random(&mut rng);
Expand Down Expand Up @@ -362,10 +349,7 @@ fn random_addition_tests<G: PrimeCurve>() {
}

fn random_transformation_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

for _ in 0..1000 {
let g = G::random(&mut rng);
Expand Down Expand Up @@ -399,10 +383,7 @@ fn random_transformation_tests<G: PrimeCurve>() {
}

fn random_compressed_encoding_tests<G: PrimeCurve>() {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

assert_eq!(
G::Affine::from_bytes(&G::Affine::identity().to_bytes()).unwrap(),
Expand All @@ -428,10 +409,7 @@ pub fn random_uncompressed_encoding_tests<G: PrimeCurve>()
where
<G as PrimeCurve>::Affine: UncompressedEncoding,
{
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let mut rng = ChaCha8Rng::from_seed(RNG_SEED);

assert_eq!(
G::Affine::from_uncompressed(&G::Affine::identity().to_uncompressed()).unwrap(),
Expand Down