Refactor algebra API, split into algebra and algebra-core. (#100)

This commit is contained in:
Pratyush Mishra
2020-02-26 21:42:04 -08:00
committed by GitHub
parent d4896ade47
commit 8bf042a029
68 changed files with 417 additions and 572 deletions

View File

@@ -1,4 +1,4 @@
use algebra::Field;
use algebra_core::Field;
use r1cs_core::{ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;

View File

@@ -1,5 +1,5 @@
use crate::Error;
use algebra::bytes::ToBytes;
use algebra_core::bytes::ToBytes;
use core::hash::Hash;
use rand::Rng;
@@ -54,8 +54,7 @@ pub trait SignatureScheme {
mod test {
use crate::{signature::schnorr::SchnorrSignature, SignatureScheme};
use algebra::{
curves::edwards_sw6::EdwardsAffine as Edwards, groups::Group, test_rng, to_bytes, ToBytes,
UniformRand,
groups::Group, jubjub::JubJubAffine as JubJub, test_rng, to_bytes, ToBytes, UniformRand,
};
use blake2::Blake2s;
@@ -90,13 +89,13 @@ mod test {
fn schnorr_signature_test() {
let message = "Hi, I am a Schnorr signature!";
let rng = &mut test_rng();
sign_and_verify::<SchnorrSignature<Edwards, Blake2s>>(message.as_bytes());
failed_verification::<SchnorrSignature<Edwards, Blake2s>>(
sign_and_verify::<SchnorrSignature<JubJub, Blake2s>>(message.as_bytes());
failed_verification::<SchnorrSignature<JubJub, Blake2s>>(
message.as_bytes(),
"Bad message".as_bytes(),
);
let random_scalar = to_bytes!(<Edwards as Group>::ScalarField::rand(rng)).unwrap();
randomize_and_verify::<SchnorrSignature<Edwards, Blake2s>>(
let random_scalar = to_bytes!(<JubJub as Group>::ScalarField::rand(rng)).unwrap();
randomize_and_verify::<SchnorrSignature<JubJub, Blake2s>>(
message.as_bytes(),
&random_scalar.as_slice(),
);

View File

@@ -1,4 +1,4 @@
use algebra::{groups::Group, Field};
use algebra_core::{groups::Group, Field};
use r1cs_core::{ConstraintSystem, SynthesisError};
use r1cs_std::prelude::*;

View File

@@ -1,5 +1,5 @@
use crate::{Error, SignatureScheme, Vec};
use algebra::{
use algebra_core::{
bytes::ToBytes,
fields::{Field, PrimeField},
groups::Group,