Add scaffolding for G1 and G2 data structures.

This commit is contained in:
Sean Bowe 2019-08-10 00:20:47 -06:00
parent 479b151075
commit 419c62536c
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
5 changed files with 78 additions and 0 deletions

5
src/fp.rs Normal file
View File

@ -0,0 +1,5 @@
//! This module provides an implementation of the BLS12-381 base field `GF(p)`
//! where `p = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab`
#[derive(Copy, Clone, Debug)]
pub struct Fp;

9
src/fp2.rs Normal file
View File

@ -0,0 +1,9 @@
//! This module implements arithmetic over the quadratic extension field Fp2.
use crate::fp::Fp;
#[derive(Copy, Clone, Debug)]
pub struct Fp2 {
pub c0: Fp,
pub c1: Fp,
}

25
src/g1.rs Normal file
View File

@ -0,0 +1,25 @@
//! This module provides an implementation of the G1 group of BLS12-381.
use crate::fp::Fp;
use subtle::Choice;
/// This is an element of G1 represented in the affine (x, y) coordinate space. It
/// is ideal to keep elements in this representation to reduce memory usage and
/// improve performance through the use of mixed curve model arithmetic.
///
/// Values of `G1Affine` are guaranteed to be in the q-order subgroup unless an
/// "unchecked" API was misused.
#[derive(Copy, Clone, Debug)]
pub struct G1Affine {
x: Fp,
y: Fp,
infinity: Choice,
}
/// This is an element of G1 represented in the projective (X, Y, Z) coordinate space.
#[derive(Copy, Clone, Debug)]
pub struct G1Projective {
x: Fp,
y: Fp,
z: Fp,
}

25
src/g2.rs Normal file
View File

@ -0,0 +1,25 @@
//! This module provides an implementation of the G2 group of BLS12-381.
use crate::fp2::Fp2;
use subtle::Choice;
/// This is an element of G2 represented in the affine (x, y) coordinate space. It
/// is ideal to keep elements in this representation to reduce memory usage and
/// improve performance through the use of mixed curve model arithmetic.
///
/// Values of `G2Affine` are guaranteed to be in the q-order subgroup unless an
/// "unchecked" API was misused.
#[derive(Copy, Clone, Debug)]
pub struct G2Affine {
x: Fp2,
y: Fp2,
infinity: Choice,
}
/// This is an element of G2 represented in the projective (X, Y, Z) coordinate space.
#[derive(Copy, Clone, Debug)]
pub struct G2Projective {
x: Fp2,
y: Fp2,
z: Fp2,
}

View File

@ -29,3 +29,17 @@ mod util;
mod scalar;
pub use scalar::Scalar;
#[cfg(feature = "groups")]
mod fp;
#[cfg(feature = "groups")]
mod fp2;
#[cfg(feature = "groups")]
mod g1;
#[cfg(feature = "groups")]
mod g2;
#[cfg(feature = "groups")]
pub use g1::{G1Affine, G1Projective};
#[cfg(feature = "groups")]
pub use g2::{G2Affine, G2Projective};