prepare for gpu integration
This commit is contained in:
parent
74f0a18f31
commit
9228d20862
@ -15,12 +15,14 @@ description = "Pairing-friendly elliptic curve library"
|
||||
documentation = "https://docs.rs/pairing/"
|
||||
homepage = "https://github.com/matter-labs/pairing"
|
||||
repository = "https://github.com/matter-labs/pairing"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.4"
|
||||
byteorder = "1"
|
||||
ff_ce = {version = "0.6", features = ["derive"] }
|
||||
#ff = { git = 'https://github.com/matterinc/ff', features = ["derive"], tag = "0.5"}
|
||||
#ff_ce = {version = "0.6", features = ["derive"] }
|
||||
#ff_ce = { git = 'https://github.com/matter-labs/ff', features = ["derive"], branch = "gpu"}
|
||||
ff_ce = { path = '../ff', features = ["derive", "derive_serde"]}
|
||||
serde = "1.0.80"
|
||||
serde_derive = "1.0.80"
|
||||
serde_json = "1.0.33"
|
||||
|
@ -626,7 +626,7 @@ pub mod g1 {
|
||||
use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField};
|
||||
use rand::{Rand, Rng};
|
||||
use std::fmt;
|
||||
use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
use crate::{RawEncodable, CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
|
||||
curve_impl!(
|
||||
"G1",
|
||||
@ -750,6 +750,18 @@ pub mod g1 {
|
||||
}
|
||||
}
|
||||
|
||||
impl RawEncodable for G1Affine {
|
||||
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed {
|
||||
let mut res = Self::Uncompressed::empty();
|
||||
let mut writer = &mut res.0[..];
|
||||
|
||||
self.x.into_raw_repr().write_le(&mut writer).unwrap();
|
||||
self.y.into_raw_repr().write_le(&mut writer).unwrap();
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct G1Compressed([u8; 48]);
|
||||
|
||||
@ -1272,7 +1284,7 @@ pub mod g2 {
|
||||
use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField};
|
||||
use rand::{Rand, Rng};
|
||||
use std::fmt;
|
||||
use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
use crate::{CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
|
||||
curve_impl!(
|
||||
"G2",
|
||||
|
@ -190,9 +190,7 @@ macro_rules! curve_impl {
|
||||
fn into_projective(&self) -> $projective {
|
||||
(*self).into()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// impl Rand for $projective {
|
||||
// fn rand<R: Rng>(rng: &mut R) -> Self {
|
||||
// loop {
|
||||
@ -630,7 +628,7 @@ pub mod g1 {
|
||||
use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField};
|
||||
use rand::{Rand, Rng};
|
||||
use std::fmt;
|
||||
use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
use crate::{RawEncodable, CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
|
||||
curve_impl!(
|
||||
"G1",
|
||||
@ -644,6 +642,18 @@ pub mod g1 {
|
||||
G2Affine
|
||||
);
|
||||
|
||||
impl RawEncodable for G1Affine {
|
||||
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed {
|
||||
let mut res = Self::Uncompressed::empty();
|
||||
let mut writer = &mut res.0[..];
|
||||
|
||||
self.x.into_raw_repr().write_le(&mut writer).unwrap();
|
||||
self.y.into_raw_repr().write_le(&mut writer).unwrap();
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct G1Uncompressed([u8; 64]);
|
||||
|
||||
@ -1013,7 +1023,7 @@ pub mod g2 {
|
||||
use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField};
|
||||
use rand::{Rand, Rng};
|
||||
use std::fmt;
|
||||
use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
use crate::{CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError};
|
||||
|
||||
curve_impl!(
|
||||
"G2",
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -22,11 +22,13 @@ extern crate serde_derive;
|
||||
#[cfg(test)]
|
||||
pub mod tests;
|
||||
|
||||
extern crate ff_ce as imported_ff;
|
||||
pub extern crate ff_ce as ff;
|
||||
|
||||
pub mod ff {
|
||||
pub use imported_ff::*;
|
||||
}
|
||||
pub use ff::*;
|
||||
|
||||
// pub mod ff {
|
||||
// pub use ff::*;
|
||||
// }
|
||||
|
||||
pub mod bls12_381;
|
||||
pub mod bn256;
|
||||
@ -60,7 +62,7 @@ pub trait Engine: ScalarEngine {
|
||||
Pair = Self::G2Affine,
|
||||
PairingResult = Self::Fqk,
|
||||
>
|
||||
+ From<Self::G1>;
|
||||
+ From<Self::G1> + RawEncodable;
|
||||
|
||||
/// The projective representation of an element in G2.
|
||||
type G2: CurveProjective<
|
||||
@ -102,7 +104,7 @@ pub trait Engine: ScalarEngine {
|
||||
>;
|
||||
|
||||
/// Perform final exponentiation of the result of a miller loop.
|
||||
fn final_exponentiation(&Self::Fqk) -> Option<Self::Fqk>;
|
||||
fn final_exponentiation(r: &Self::Fqk) -> Option<Self::Fqk>;
|
||||
|
||||
/// Performs a complete pairing operation `(p, q)`.
|
||||
fn pairing<G1, G2>(p: G1, q: G2) -> Self::Fqk
|
||||
@ -240,6 +242,12 @@ pub trait CurveAffine:
|
||||
}
|
||||
}
|
||||
|
||||
pub trait RawEncodable: CurveAffine {
|
||||
/// Converts this element into its uncompressed encoding, so long as it's not
|
||||
/// the point at infinity. Leaves coordinates in Montgommery form
|
||||
fn into_raw_uncompressed_le(&self) -> Self::Uncompressed;
|
||||
}
|
||||
|
||||
/// An encoded elliptic curve point, which should essentially wrap a `[u8; N]`.
|
||||
pub trait EncodedPoint:
|
||||
Sized + Send + Sync + AsRef<[u8]> + AsMut<[u8]> + Clone + Copy + 'static
|
||||
|
Loading…
Reference in New Issue
Block a user