group: Introduce Group and PrimeGroup traits

Group represents a cryptographic group with a large prime-order subgroup
and a small cofactor. PrimeGroup further constrains the group to have a
cofactor of one.
This commit is contained in:
Jack Grigg 2020-05-14 18:10:06 +12:00
parent e75b850fe5
commit 78db26b713
3 changed files with 12 additions and 7 deletions

View File

@ -3,7 +3,7 @@ use std::ops::{AddAssign, MulAssign};
use std::sync::Arc;
use ff::Field;
use group::{CurveAffine, CurveProjective, Wnaf};
use group::{CurveAffine, CurveProjective, Group, Wnaf};
use pairing::Engine;
use super::{Parameters, VerifyingKey};

View File

@ -1,5 +1,5 @@
use ff::{Field, PrimeField, ScalarEngine};
use group::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError};
use group::{CurveAffine, CurveProjective, EncodedPoint, Group, GroupDecodingError, PrimeGroup};
use pairing::{Engine, PairingCurveAffine};
use rand_core::RngCore;
@ -352,11 +352,7 @@ impl Engine for DummyEngine {
}
}
impl CurveProjective for Fr {
type Affine = Fr;
type Base = Fr;
type Scalar = Fr;
impl Group for Fr {
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
<Fr as Field>::random(rng)
}
@ -372,6 +368,14 @@ impl CurveProjective for Fr {
fn is_identity(&self) -> bool {
<Fr as Field>::is_zero(self)
}
}
impl PrimeGroup for Fr {}
impl CurveProjective for Fr {
type Affine = Fr;
type Base = Fr;
type Scalar = Fr;
fn batch_normalization(_: &mut [Self]) {}

View File

@ -314,6 +314,7 @@ fn test_with_bls12() {
acc
}
use group::Group;
use pairing::{bls12_381::Bls12, Engine};
use rand;