diff --git a/src/fp.rs b/src/fp.rs new file mode 100644 index 000000000..c91a9190e --- /dev/null +++ b/src/fp.rs @@ -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; diff --git a/src/fp2.rs b/src/fp2.rs new file mode 100644 index 000000000..848fc472c --- /dev/null +++ b/src/fp2.rs @@ -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, +} diff --git a/src/g1.rs b/src/g1.rs new file mode 100644 index 000000000..607cf2739 --- /dev/null +++ b/src/g1.rs @@ -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, +} diff --git a/src/g2.rs b/src/g2.rs new file mode 100644 index 000000000..018f54ea3 --- /dev/null +++ b/src/g2.rs @@ -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, +} diff --git a/src/lib.rs b/src/lib.rs index e0c6e2a11..d73c8f66a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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};