group: Remove EncodedPoint::from_affine
The EncodedPoint trait is replaced by explicit bounds on the CurveAffine::{Uncompressed, Compressed} associated types.
This commit is contained in:
parent
b77f8dddda
commit
ceecd32ac4
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! [Groth16]: https://eprint.iacr.org/2016/260
|
//! [Groth16]: https://eprint.iacr.org/2016/260
|
||||||
|
|
||||||
use group::{CurveAffine, EncodedPoint};
|
use group::CurveAffine;
|
||||||
use pairing::{Engine, PairingCurveAffine};
|
use pairing::{Engine, PairingCurveAffine};
|
||||||
|
|
||||||
use crate::SynthesisError;
|
use crate::SynthesisError;
|
||||||
|
@ -47,7 +47,7 @@ impl<E: Engine> Proof<E> {
|
||||||
|
|
||||||
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||||
let read_g1 = |reader: &mut R| -> io::Result<E::G1Affine> {
|
let read_g1 = |reader: &mut R| -> io::Result<E::G1Affine> {
|
||||||
let mut g1_repr = <E::G1Affine as CurveAffine>::Compressed::empty();
|
let mut g1_repr = <E::G1Affine as CurveAffine>::Compressed::default();
|
||||||
reader.read_exact(g1_repr.as_mut())?;
|
reader.read_exact(g1_repr.as_mut())?;
|
||||||
|
|
||||||
let affine = E::G1Affine::from_compressed(&g1_repr);
|
let affine = E::G1Affine::from_compressed(&g1_repr);
|
||||||
|
@ -70,7 +70,7 @@ impl<E: Engine> Proof<E> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_g2 = |reader: &mut R| -> io::Result<E::G2Affine> {
|
let read_g2 = |reader: &mut R| -> io::Result<E::G2Affine> {
|
||||||
let mut g2_repr = <E::G2Affine as CurveAffine>::Compressed::empty();
|
let mut g2_repr = <E::G2Affine as CurveAffine>::Compressed::default();
|
||||||
reader.read_exact(g2_repr.as_mut())?;
|
reader.read_exact(g2_repr.as_mut())?;
|
||||||
|
|
||||||
let affine = E::G2Affine::from_compressed(&g2_repr);
|
let affine = E::G2Affine::from_compressed(&g2_repr);
|
||||||
|
@ -158,7 +158,7 @@ impl<E: Engine> VerifyingKey<E> {
|
||||||
|
|
||||||
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||||
let read_g1 = |reader: &mut R| -> io::Result<E::G1Affine> {
|
let read_g1 = |reader: &mut R| -> io::Result<E::G1Affine> {
|
||||||
let mut g1_repr = <E::G1Affine as CurveAffine>::Uncompressed::empty();
|
let mut g1_repr = <E::G1Affine as CurveAffine>::Uncompressed::default();
|
||||||
reader.read_exact(g1_repr.as_mut())?;
|
reader.read_exact(g1_repr.as_mut())?;
|
||||||
|
|
||||||
let affine = E::G1Affine::from_uncompressed(&g1_repr);
|
let affine = E::G1Affine::from_uncompressed(&g1_repr);
|
||||||
|
@ -170,7 +170,7 @@ impl<E: Engine> VerifyingKey<E> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_g2 = |reader: &mut R| -> io::Result<E::G2Affine> {
|
let read_g2 = |reader: &mut R| -> io::Result<E::G2Affine> {
|
||||||
let mut g2_repr = <E::G2Affine as CurveAffine>::Uncompressed::empty();
|
let mut g2_repr = <E::G2Affine as CurveAffine>::Uncompressed::default();
|
||||||
reader.read_exact(g2_repr.as_mut())?;
|
reader.read_exact(g2_repr.as_mut())?;
|
||||||
|
|
||||||
let affine = E::G2Affine::from_uncompressed(&g2_repr);
|
let affine = E::G2Affine::from_uncompressed(&g2_repr);
|
||||||
|
@ -289,7 +289,7 @@ impl<E: Engine> Parameters<E> {
|
||||||
|
|
||||||
pub fn read<R: Read>(mut reader: R, checked: bool) -> io::Result<Self> {
|
pub fn read<R: Read>(mut reader: R, checked: bool) -> io::Result<Self> {
|
||||||
let read_g1 = |reader: &mut R| -> io::Result<E::G1Affine> {
|
let read_g1 = |reader: &mut R| -> io::Result<E::G1Affine> {
|
||||||
let mut repr = <E::G1Affine as CurveAffine>::Uncompressed::empty();
|
let mut repr = <E::G1Affine as CurveAffine>::Uncompressed::default();
|
||||||
reader.read_exact(repr.as_mut())?;
|
reader.read_exact(repr.as_mut())?;
|
||||||
|
|
||||||
let affine = if checked {
|
let affine = if checked {
|
||||||
|
@ -317,7 +317,7 @@ impl<E: Engine> Parameters<E> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_g2 = |reader: &mut R| -> io::Result<E::G2Affine> {
|
let read_g2 = |reader: &mut R| -> io::Result<E::G2Affine> {
|
||||||
let mut repr = <E::G2Affine as CurveAffine>::Uncompressed::empty();
|
let mut repr = <E::G2Affine as CurveAffine>::Uncompressed::default();
|
||||||
reader.read_exact(repr.as_mut())?;
|
reader.read_exact(repr.as_mut())?;
|
||||||
|
|
||||||
let affine = if checked {
|
let affine = if checked {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use ff::{Field, PrimeField, ScalarEngine};
|
use ff::{Field, PrimeField, ScalarEngine};
|
||||||
use group::{CurveAffine, CurveProjective, EncodedPoint, Group, PrimeGroup};
|
use group::{CurveAffine, CurveProjective, Group, PrimeGroup};
|
||||||
use pairing::{Engine, PairingCurveAffine};
|
use pairing::{Engine, PairingCurveAffine};
|
||||||
|
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
|
@ -417,7 +417,7 @@ impl CurveProjective for Fr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone, Default)]
|
||||||
pub struct FakePoint;
|
pub struct FakePoint;
|
||||||
|
|
||||||
impl AsMut<[u8]> for FakePoint {
|
impl AsMut<[u8]> for FakePoint {
|
||||||
|
@ -432,22 +432,6 @@ impl AsRef<[u8]> for FakePoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncodedPoint for FakePoint {
|
|
||||||
type Affine = Fr;
|
|
||||||
|
|
||||||
fn empty() -> Self {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size() -> usize {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_affine(_: Self::Affine) -> Self {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CurveAffine for Fr {
|
impl CurveAffine for Fr {
|
||||||
type Compressed = FakePoint;
|
type Compressed = FakePoint;
|
||||||
type Uncompressed = FakePoint;
|
type Uncompressed = FakePoint;
|
||||||
|
@ -479,6 +463,10 @@ impl CurveAffine for Fr {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn into_compressed(&self) -> Self::Compressed {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
fn from_uncompressed(_bytes: &Self::Uncompressed) -> CtOption<Self> {
|
fn from_uncompressed(_bytes: &Self::Uncompressed) -> CtOption<Self> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
@ -486,6 +474,10 @@ impl CurveAffine for Fr {
|
||||||
fn from_uncompressed_unchecked(_bytes: &Self::Uncompressed) -> CtOption<Self> {
|
fn from_uncompressed_unchecked(_bytes: &Self::Uncompressed) -> CtOption<Self> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn into_uncompressed(&self) -> Self::Uncompressed {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PairingCurveAffine for Fr {
|
impl PairingCurveAffine for Fr {
|
||||||
|
|
|
@ -138,8 +138,8 @@ pub trait CurveAffine:
|
||||||
type Scalar: PrimeField;
|
type Scalar: PrimeField;
|
||||||
type Base: Field;
|
type Base: Field;
|
||||||
type Projective: CurveProjective<Affine = Self, Scalar = Self::Scalar>;
|
type Projective: CurveProjective<Affine = Self, Scalar = Self::Scalar>;
|
||||||
type Uncompressed: EncodedPoint<Affine = Self>;
|
type Uncompressed: Default + AsRef<[u8]> + AsMut<[u8]>;
|
||||||
type Compressed: EncodedPoint<Affine = Self>;
|
type Compressed: Default + AsRef<[u8]> + AsMut<[u8]>;
|
||||||
|
|
||||||
/// Returns the additive identity.
|
/// Returns the additive identity.
|
||||||
fn identity() -> Self;
|
fn identity() -> Self;
|
||||||
|
@ -167,9 +167,7 @@ pub trait CurveAffine:
|
||||||
|
|
||||||
/// Converts this element into its compressed encoding, so long as it's not
|
/// Converts this element into its compressed encoding, so long as it's not
|
||||||
/// the point at infinity.
|
/// the point at infinity.
|
||||||
fn into_compressed(&self) -> Self::Compressed {
|
fn into_compressed(&self) -> Self::Compressed;
|
||||||
<Self::Compressed as EncodedPoint>::from_affine(*self)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Attempts to deserialize an element from its uncompressed encoding.
|
/// Attempts to deserialize an element from its uncompressed encoding.
|
||||||
fn from_uncompressed(bytes: &Self::Uncompressed) -> CtOption<Self>;
|
fn from_uncompressed(bytes: &Self::Uncompressed) -> CtOption<Self>;
|
||||||
|
@ -184,24 +182,5 @@ pub trait CurveAffine:
|
||||||
|
|
||||||
/// Converts this element into its uncompressed encoding, so long as it's not
|
/// Converts this element into its uncompressed encoding, so long as it's not
|
||||||
/// the point at infinity.
|
/// the point at infinity.
|
||||||
fn into_uncompressed(&self) -> Self::Uncompressed {
|
fn into_uncompressed(&self) -> Self::Uncompressed;
|
||||||
<Self::Uncompressed as EncodedPoint>::from_affine(*self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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
|
|
||||||
{
|
|
||||||
type Affine: CurveAffine;
|
|
||||||
|
|
||||||
/// Creates an empty representation.
|
|
||||||
fn empty() -> Self;
|
|
||||||
|
|
||||||
/// Returns the number of bytes consumed by this representation.
|
|
||||||
fn size() -> usize;
|
|
||||||
|
|
||||||
/// Creates an `EncodedPoint` from an affine point, as long as the
|
|
||||||
/// point is not the point at infinity.
|
|
||||||
fn from_affine(affine: Self::Affine) -> Self;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,6 +247,10 @@ macro_rules! curve_impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn into_compressed(&self) -> Self::Compressed {
|
||||||
|
$compressed::from_affine(*self)
|
||||||
|
}
|
||||||
|
|
||||||
fn from_uncompressed(bytes: &Self::Uncompressed) -> CtOption<Self> {
|
fn from_uncompressed(bytes: &Self::Uncompressed) -> CtOption<Self> {
|
||||||
Self::from_uncompressed_unchecked(bytes).and_then(|affine| {
|
Self::from_uncompressed_unchecked(bytes).and_then(|affine| {
|
||||||
CtOption::new(
|
CtOption::new(
|
||||||
|
@ -271,6 +275,10 @@ macro_rules! curve_impl {
|
||||||
CtOption::new(Self::identity(), Choice::from(0))
|
CtOption::new(Self::identity(), Choice::from(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn into_uncompressed(&self) -> Self::Uncompressed {
|
||||||
|
$uncompressed::from_affine(*self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PairingCurveAffine for $affine {
|
impl PairingCurveAffine for $affine {
|
||||||
|
@ -901,7 +909,7 @@ pub mod g1 {
|
||||||
use super::{g2::G2Affine, GroupDecodingError};
|
use super::{g2::G2Affine, GroupDecodingError};
|
||||||
use crate::{Engine, PairingCurveAffine};
|
use crate::{Engine, PairingCurveAffine};
|
||||||
use ff::{BitIterator, Field, PrimeField};
|
use ff::{BitIterator, Field, PrimeField};
|
||||||
use group::{CurveAffine, CurveProjective, EncodedPoint, Group, PrimeGroup};
|
use group::{CurveAffine, CurveProjective, Group, PrimeGroup};
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
||||||
|
@ -922,6 +930,12 @@ pub mod g1 {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct G1Uncompressed([u8; 96]);
|
pub struct G1Uncompressed([u8; 96]);
|
||||||
|
|
||||||
|
impl Default for G1Uncompressed {
|
||||||
|
fn default() -> Self {
|
||||||
|
G1Uncompressed([0; 96])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<[u8]> for G1Uncompressed {
|
impl AsRef<[u8]> for G1Uncompressed {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -941,6 +955,10 @@ pub mod g1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl G1Uncompressed {
|
impl G1Uncompressed {
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn size() -> usize {
|
||||||
|
96
|
||||||
|
}
|
||||||
fn into_affine_unchecked(&self) -> Result<G1Affine, GroupDecodingError> {
|
fn into_affine_unchecked(&self) -> Result<G1Affine, GroupDecodingError> {
|
||||||
// Create a copy of this representation.
|
// Create a copy of this representation.
|
||||||
let mut copy = self.0;
|
let mut copy = self.0;
|
||||||
|
@ -991,19 +1009,8 @@ pub mod g1 {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl EncodedPoint for G1Uncompressed {
|
|
||||||
type Affine = G1Affine;
|
|
||||||
|
|
||||||
fn empty() -> Self {
|
|
||||||
G1Uncompressed([0; 96])
|
|
||||||
}
|
|
||||||
fn size() -> usize {
|
|
||||||
96
|
|
||||||
}
|
|
||||||
fn from_affine(affine: G1Affine) -> Self {
|
fn from_affine(affine: G1Affine) -> Self {
|
||||||
let mut res = Self::empty();
|
let mut res = Self::default();
|
||||||
|
|
||||||
if affine.is_identity().into() {
|
if affine.is_identity().into() {
|
||||||
// Set the second-most significant bit to indicate this point
|
// Set the second-most significant bit to indicate this point
|
||||||
|
@ -1021,6 +1028,12 @@ pub mod g1 {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct G1Compressed([u8; 48]);
|
pub struct G1Compressed([u8; 48]);
|
||||||
|
|
||||||
|
impl Default for G1Compressed {
|
||||||
|
fn default() -> Self {
|
||||||
|
G1Compressed([0; 48])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<[u8]> for G1Compressed {
|
impl AsRef<[u8]> for G1Compressed {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -1040,6 +1053,10 @@ pub mod g1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl G1Compressed {
|
impl G1Compressed {
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn size() -> usize {
|
||||||
|
48
|
||||||
|
}
|
||||||
fn into_affine_unchecked(&self) -> Result<G1Affine, GroupDecodingError> {
|
fn into_affine_unchecked(&self) -> Result<G1Affine, GroupDecodingError> {
|
||||||
// Create a copy of this representation.
|
// Create a copy of this representation.
|
||||||
let mut copy = self.0;
|
let mut copy = self.0;
|
||||||
|
@ -1080,19 +1097,8 @@ pub mod g1 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl EncodedPoint for G1Compressed {
|
|
||||||
type Affine = G1Affine;
|
|
||||||
|
|
||||||
fn empty() -> Self {
|
|
||||||
G1Compressed([0; 48])
|
|
||||||
}
|
|
||||||
fn size() -> usize {
|
|
||||||
48
|
|
||||||
}
|
|
||||||
fn from_affine(affine: G1Affine) -> Self {
|
fn from_affine(affine: G1Affine) -> Self {
|
||||||
let mut res = Self::empty();
|
let mut res = Self::default();
|
||||||
|
|
||||||
if affine.is_identity().into() {
|
if affine.is_identity().into() {
|
||||||
// Set the second-most significant bit to indicate this point
|
// Set the second-most significant bit to indicate this point
|
||||||
|
@ -1493,7 +1499,7 @@ pub mod g2 {
|
||||||
use super::{g1::G1Affine, GroupDecodingError};
|
use super::{g1::G1Affine, GroupDecodingError};
|
||||||
use crate::{Engine, PairingCurveAffine};
|
use crate::{Engine, PairingCurveAffine};
|
||||||
use ff::{BitIterator, Field, PrimeField};
|
use ff::{BitIterator, Field, PrimeField};
|
||||||
use group::{CurveAffine, CurveProjective, EncodedPoint, Group, PrimeGroup};
|
use group::{CurveAffine, CurveProjective, Group, PrimeGroup};
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
||||||
|
@ -1514,6 +1520,12 @@ pub mod g2 {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct G2Uncompressed([u8; 192]);
|
pub struct G2Uncompressed([u8; 192]);
|
||||||
|
|
||||||
|
impl Default for G2Uncompressed {
|
||||||
|
fn default() -> Self {
|
||||||
|
G2Uncompressed([0; 192])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<[u8]> for G2Uncompressed {
|
impl AsRef<[u8]> for G2Uncompressed {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -1533,6 +1545,10 @@ pub mod g2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl G2Uncompressed {
|
impl G2Uncompressed {
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn size() -> usize {
|
||||||
|
192
|
||||||
|
}
|
||||||
fn into_affine_unchecked(&self) -> Result<G2Affine, GroupDecodingError> {
|
fn into_affine_unchecked(&self) -> Result<G2Affine, GroupDecodingError> {
|
||||||
// Create a copy of this representation.
|
// Create a copy of this representation.
|
||||||
let mut copy = self.0;
|
let mut copy = self.0;
|
||||||
|
@ -1595,19 +1611,8 @@ pub mod g2 {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl EncodedPoint for G2Uncompressed {
|
|
||||||
type Affine = G2Affine;
|
|
||||||
|
|
||||||
fn empty() -> Self {
|
|
||||||
G2Uncompressed([0; 192])
|
|
||||||
}
|
|
||||||
fn size() -> usize {
|
|
||||||
192
|
|
||||||
}
|
|
||||||
fn from_affine(affine: G2Affine) -> Self {
|
fn from_affine(affine: G2Affine) -> Self {
|
||||||
let mut res = Self::empty();
|
let mut res = Self::default();
|
||||||
|
|
||||||
if affine.is_identity().into() {
|
if affine.is_identity().into() {
|
||||||
// Set the second-most significant bit to indicate this point
|
// Set the second-most significant bit to indicate this point
|
||||||
|
@ -1627,6 +1632,12 @@ pub mod g2 {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct G2Compressed([u8; 96]);
|
pub struct G2Compressed([u8; 96]);
|
||||||
|
|
||||||
|
impl Default for G2Compressed {
|
||||||
|
fn default() -> Self {
|
||||||
|
G2Compressed([0; 96])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<[u8]> for G2Compressed {
|
impl AsRef<[u8]> for G2Compressed {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -1646,6 +1657,10 @@ pub mod g2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl G2Compressed {
|
impl G2Compressed {
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn size() -> usize {
|
||||||
|
96
|
||||||
|
}
|
||||||
fn into_affine_unchecked(&self) -> Result<G2Affine, GroupDecodingError> {
|
fn into_affine_unchecked(&self) -> Result<G2Affine, GroupDecodingError> {
|
||||||
// Create a copy of this representation.
|
// Create a copy of this representation.
|
||||||
let mut copy = self.0;
|
let mut copy = self.0;
|
||||||
|
@ -1701,19 +1716,8 @@ pub mod g2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl EncodedPoint for G2Compressed {
|
|
||||||
type Affine = G2Affine;
|
|
||||||
|
|
||||||
fn empty() -> Self {
|
|
||||||
G2Compressed([0; 96])
|
|
||||||
}
|
|
||||||
fn size() -> usize {
|
|
||||||
96
|
|
||||||
}
|
|
||||||
fn from_affine(affine: G2Affine) -> Self {
|
fn from_affine(affine: G2Affine) -> Self {
|
||||||
let mut res = Self::empty();
|
let mut res = Self::default();
|
||||||
|
|
||||||
if affine.is_identity().into() {
|
if affine.is_identity().into() {
|
||||||
// Set the second-most significant bit to indicate this point
|
// Set the second-most significant bit to indicate this point
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use ff::PrimeField;
|
use ff::PrimeField;
|
||||||
use group::{CurveAffine, CurveProjective, EncodedPoint, Group};
|
use group::{CurveAffine, CurveProjective, Group};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
@ -57,20 +57,21 @@ fn test_pairing_result_against_relic() {
|
||||||
|
|
||||||
fn uncompressed_test_vectors<G: CurveProjective>(expected: &[u8]) {
|
fn uncompressed_test_vectors<G: CurveProjective>(expected: &[u8]) {
|
||||||
let mut e = G::identity();
|
let mut e = G::identity();
|
||||||
|
let encoded_len = <G::Affine as CurveAffine>::Uncompressed::default()
|
||||||
|
.as_ref()
|
||||||
|
.len();
|
||||||
|
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
{
|
{
|
||||||
let mut expected = expected;
|
let mut expected = expected;
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
let e_affine = e.into_affine();
|
let e_affine = e.into_affine();
|
||||||
let encoded = <G::Affine as CurveAffine>::Uncompressed::from_affine(e_affine);
|
let encoded = e_affine.into_uncompressed();
|
||||||
v.extend_from_slice(encoded.as_ref());
|
v.extend_from_slice(encoded.as_ref());
|
||||||
|
|
||||||
let mut decoded = <G::Affine as CurveAffine>::Uncompressed::empty();
|
let mut decoded = <G::Affine as CurveAffine>::Uncompressed::default();
|
||||||
decoded
|
decoded.as_mut().copy_from_slice(&expected[0..encoded_len]);
|
||||||
.as_mut()
|
expected = &expected[encoded_len..];
|
||||||
.copy_from_slice(&expected[0..<G::Affine as CurveAffine>::Uncompressed::size()]);
|
|
||||||
expected = &expected[<G::Affine as CurveAffine>::Uncompressed::size()..];
|
|
||||||
let decoded = G::Affine::from_uncompressed(&decoded).unwrap();
|
let decoded = G::Affine::from_uncompressed(&decoded).unwrap();
|
||||||
assert_eq!(e_affine, decoded);
|
assert_eq!(e_affine, decoded);
|
||||||
|
|
||||||
|
@ -83,20 +84,21 @@ fn uncompressed_test_vectors<G: CurveProjective>(expected: &[u8]) {
|
||||||
|
|
||||||
fn compressed_test_vectors<G: CurveProjective>(expected: &[u8]) {
|
fn compressed_test_vectors<G: CurveProjective>(expected: &[u8]) {
|
||||||
let mut e = G::identity();
|
let mut e = G::identity();
|
||||||
|
let encoded_len = <G::Affine as CurveAffine>::Compressed::default()
|
||||||
|
.as_ref()
|
||||||
|
.len();
|
||||||
|
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
{
|
{
|
||||||
let mut expected = expected;
|
let mut expected = expected;
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
let e_affine = e.into_affine();
|
let e_affine = e.into_affine();
|
||||||
let encoded = <G::Affine as CurveAffine>::Compressed::from_affine(e_affine);
|
let encoded = e_affine.into_compressed();
|
||||||
v.extend_from_slice(encoded.as_ref());
|
v.extend_from_slice(encoded.as_ref());
|
||||||
|
|
||||||
let mut decoded = <G::Affine as CurveAffine>::Compressed::empty();
|
let mut decoded = <G::Affine as CurveAffine>::Compressed::default();
|
||||||
decoded
|
decoded.as_mut().copy_from_slice(&expected[0..encoded_len]);
|
||||||
.as_mut()
|
expected = &expected[encoded_len..];
|
||||||
.copy_from_slice(&expected[0..<G::Affine as CurveAffine>::Compressed::size()]);
|
|
||||||
expected = &expected[<G::Affine as CurveAffine>::Compressed::size()..];
|
|
||||||
let decoded = G::Affine::from_compressed(&decoded).unwrap();
|
let decoded = G::Affine::from_compressed(&decoded).unwrap();
|
||||||
assert_eq!(e_affine, decoded);
|
assert_eq!(e_affine, decoded);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue