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
48 changes: 13 additions & 35 deletions Cargo.lock

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

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

[dependencies]
chacha20 = { version = "0.10.0-rc.10", optional = true, default-features = false, features = ["rng"] }
ff = { version = "0.14.0-rc.0", package = "rustcrypto-ff", default-features = false }
rand = { version = "0.10.0-rc.8", optional = true, 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.0-rc.0", optional = true }
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 All @@ -29,11 +28,8 @@ memuse = { version = "0.2", optional = true }
[features]
default = ["alloc"]
alloc = []
tests = ["alloc", "chacha20", "rand"] # "rand_xorshift"]
tests = ["alloc", "rand", "rand_xorshift"]
wnaf-memuse = ["alloc", "memuse"]

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

[patch.crates-io.rand]
git = "https://github.com/rust-random/rand"
52 changes: 37 additions & 15 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
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 = ChaCha8Rng::from_seed(RNG_SEED);
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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