mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-08 15:01:29 +01:00
Replace rand with ark_std::rand (#42)
* replace rand * update CHANGELOG * fmt * fix * fix
This commit is contained in:
@@ -7,8 +7,8 @@ use ark_serialize::CanonicalSerialize;
|
||||
use ark_std::test_rng;
|
||||
|
||||
use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine, ProjectiveCurve};
|
||||
use ark_std::rand::Rng;
|
||||
use core::ops::{AddAssign, MulAssign};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{g1, g2, Bls12_377, Fq, Fq12, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ use ark_ff::{
|
||||
One, UniformRand, Zero,
|
||||
};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::rand::Rng;
|
||||
use ark_std::test_rng;
|
||||
use core::{
|
||||
cmp::Ordering,
|
||||
ops::{AddAssign, MulAssign, SubAssign},
|
||||
};
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
use crate::{Fq, Fq12, Fq2, Fq2Parameters, Fq6, Fq6Parameters, FqParameters, Fr};
|
||||
|
||||
@@ -135,7 +134,7 @@ fn test_fq_repr_num_bits() {
|
||||
fn test_fq_add_assign() {
|
||||
// Test associativity
|
||||
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
// Generate a, b, c and ensure (a + b) + c == a + (b + c).
|
||||
@@ -157,7 +156,7 @@ fn test_fq_add_assign() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_sub_assign() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
// Ensure that (a - b) + (b - a) = 0.
|
||||
@@ -177,7 +176,7 @@ fn test_fq_sub_assign() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_mul_assign() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000000 {
|
||||
// Ensure that (a * b) * c = a * (b * c)
|
||||
@@ -222,7 +221,7 @@ fn test_fq_mul_assign() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_squaring() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000000 {
|
||||
// Ensure that (a * a) = a^2
|
||||
@@ -242,7 +241,7 @@ fn test_fq_squaring() {
|
||||
fn test_fq_inverse() {
|
||||
assert!(Fq::zero().inverse().is_none());
|
||||
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
let one = Fq::one();
|
||||
|
||||
@@ -257,7 +256,7 @@ fn test_fq_inverse() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_double_in_place() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
// Ensure doubling a is equivalent to adding a to itself.
|
||||
@@ -277,7 +276,7 @@ fn test_fq_negate() {
|
||||
assert!(a.is_zero());
|
||||
}
|
||||
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
// Ensure (a - (-a)) = 0.
|
||||
@@ -291,7 +290,7 @@ fn test_fq_negate() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_pow() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for i in 0..1000 {
|
||||
// Exponentiate by various small numbers and ensure it consists with repeated
|
||||
@@ -315,7 +314,7 @@ fn test_fq_pow() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_sqrt() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
assert_eq!(Fq::zero().sqrt().unwrap(), Fq::zero());
|
||||
|
||||
@@ -438,7 +437,7 @@ fn test_fq2_legendre() {
|
||||
|
||||
#[test]
|
||||
fn test_fq2_mul_nonresidue() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
let nqr = Fq2::new(Fq::zero(), Fq::one());
|
||||
|
||||
@@ -458,7 +457,7 @@ fn test_fq2_mul_nonresidue() {
|
||||
|
||||
#[test]
|
||||
fn test_fq6_mul_by_1() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
let c1 = Fq2::rand(&mut rng);
|
||||
@@ -474,7 +473,7 @@ fn test_fq6_mul_by_1() {
|
||||
|
||||
#[test]
|
||||
fn test_fq6_mul_by_01() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
let c0 = Fq2::rand(&mut rng);
|
||||
@@ -491,7 +490,7 @@ fn test_fq6_mul_by_01() {
|
||||
|
||||
#[test]
|
||||
fn test_fq12_mul_by_014() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
let c0 = Fq2::rand(&mut rng);
|
||||
@@ -512,7 +511,7 @@ fn test_fq12_mul_by_014() {
|
||||
|
||||
#[test]
|
||||
fn test_fq12_mul_by_034() {
|
||||
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
|
||||
let mut rng = test_rng();
|
||||
|
||||
for _ in 0..1000 {
|
||||
let c0 = Fq2::rand(&mut rng);
|
||||
|
||||
Reference in New Issue
Block a user