arnaucube
arnaucube/testudoPublic Self-hosted repository
testudo/src/group.rs
src/group.rsRaw
  1use lazy_static::lazy_static;
  2use super::scalar::{Scalar};
  3use core::borrow::Borrow;
  4use core::ops::{Mul, MulAssign};
  5use ark_ec::{ProjectiveCurve, AffineCurve};
  6
  7pub use ark_bls12_377::G1Projective as GroupElement;
  8pub use ark_bls12_377::G1Affine as AffineGroupElement;
  9
 10
 11
 12// pub type CompressedGroup = curve25519_dalek::ristretto::CompressedRistretto;
 13
 14// pub trait CompressedGroupExt {
 15//   type Group;
 16//   fn unpack(&self) -> Result<Self::Group, ProofVerifyError>;
 17// }
 18
 19
 20// what I should prolly do is implement compression and decompression operation on the GroupAffine
 21
 22// impl CompressedGroupExt for CompressedGroup {
 23//   type Group = curve25519_dalek::ristretto::RistrettoPoint;
 24//   fn unpack(&self) -> Result<Self::Group, ProofVerifyError> {
 25//     self
 26//       .decompress()
 27//       .ok_or_else(|| ProofVerifyError::DecompressionError(self.to_bytes()))
 28//   }
 29// }
 30
 31// ????
 32lazy_static! {
 33  pub static ref GROUP_BASEPOINT: GroupElement = GroupElement::prime_subgroup_generator();
 34}
 35
 36
 37// impl<'b> MulAssign<&'b Scalar> for GroupElement {
 38//   fn mul_assign(&mut self, scalar: &'b Scalar) {
 39//     let result = (self as &GroupElement).mul( scalar.into_repr());
 40//     *self = result;
 41//   }
 42// }
 43
 44// // This game happens because dalek works with scalars as bytes representation but we want people to have an easy life and not care about this
 45// impl<'a, 'b> Mul<&'b Scalar> for &'a GroupElement {
 46//   type Output = GroupElement;
 47//   fn mul(self, scalar: &'b Scalar) -> GroupElement {
 48//     self * Scalar::into_repr(scalar)
 49//   }
 50// }
 51
 52// impl<'a, 'b> Mul<&'b GroupElement> for &'a Scalar {
 53//   type Output = GroupElement;
 54
 55//   fn mul(self, point: &'b GroupElement) -> GroupElement {
 56//     Scalar::into_repr(self) * point
 57//   }
 58// }
 59
 60// macro_rules! define_mul_variants {
 61//   (LHS = $lhs:ty, RHS = $rhs:ty, Output = $out:ty) => {
 62//     impl<'b> Mul<&'b $rhs> for $lhs {
 63//       type Output = $out;
 64//       fn mul(self, rhs: &'b $rhs) -> $out {
 65//         &self * rhs
 66//       }
 67//     }
 68
 69//     impl<'a> Mul<$rhs> for &'a $lhs {
 70//       type Output = $out;
 71//       fn mul(self, rhs: $rhs) -> $out {
 72//         self * &rhs
 73//       }
 74//     }
 75
 76//     impl Mul<$rhs> for $lhs {
 77//       type Output = $out;
 78//       fn mul(self, rhs: $rhs) -> $out {
 79//         &self * &rhs
 80//       }
 81//     }
 82//   };
 83// }
 84
 85// macro_rules! define_mul_assign_variants {
 86//   (LHS = $lhs:ty, RHS = $rhs:ty) => {
 87//     impl MulAssign<$rhs> for $lhs {
 88//       fn mul_assign(&mut self, rhs: $rhs) {
 89//         *self *= &rhs;
 90//       }
 91//     }
 92//   };
 93// }
 94
 95// define_mul_assign_variants!(LHS = GroupElement, RHS = Scalar);
 96// define_mul_variants!(LHS = GroupElement, RHS = Scalar, Output = GroupElement);
 97// define_mul_variants!(LHS = Scalar, RHS = GroupElement, Output = GroupElement);
 98
 99
100// TODO
101// pub trait VartimeMultiscalarMul {
102//   type Scalar;
103//   fn vartime_multiscalar_mul<I, J>(scalars: I, points: J) -> Self
104//   where
105//     I: IntoIterator,
106//     I::Item: Borrow<Self::Scalar>,
107//     J: IntoIterator,
108//     J::Item: Borrow<Self>,
109//     Self: Clone;
110// }
111
112// impl VartimeMultiscalarMul for GroupElement {
113//   type Scalar = super::scalar::Scalar;
114//   fn vartime_multiscalar_mul<I, J>(scalars: I, points: J) -> Self
115//   where
116//     I: IntoIterator,
117//     I::Item: Borrow<Self::Scalar>,
118//     J: IntoIterator,
119//     J::Item: Borrow<Self>,
120//     Self: Clone,
121//   {
122//     // use curve25519_dalek::traits::VartimeMultiscalarMul;
123//     <Self as VartimeMultiscalarMul>::vartime_multiscalar_mul(
124//       scalars
125//         .into_iter()
126//         .map(|s| Scalar::into_repr(s.borrow()))
127//         .collect::<Vec<Scalar>>(),
128//       points,
129//     )
130//   }
131// }