impl Mul<Fr> for [Extended|Affine]NielsPoint
This commit is contained in:
parent
a6afd81603
commit
e1193d2ae9
31
src/lib.rs
31
src/lib.rs
|
@ -252,6 +252,16 @@ impl AffineNielsPoint {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Mul<&'b Fr> for &'a AffineNielsPoint {
|
||||
type Output = ExtendedPoint;
|
||||
|
||||
fn mul(self, other: &'b Fr) -> ExtendedPoint {
|
||||
self.multiply(&other.into_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl_binops_multiplicative_mixed!(AffineNielsPoint, Fr, ExtendedPoint);
|
||||
|
||||
impl ConditionallySelectable for AffineNielsPoint {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
AffineNielsPoint {
|
||||
|
@ -326,6 +336,16 @@ impl ExtendedNielsPoint {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Mul<&'b Fr> for &'a ExtendedNielsPoint {
|
||||
type Output = ExtendedPoint;
|
||||
|
||||
fn mul(self, other: &'b Fr) -> ExtendedPoint {
|
||||
self.multiply(&other.into_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl_binops_multiplicative_mixed!(ExtendedNielsPoint, Fr, ExtendedPoint);
|
||||
|
||||
// `d = -(10240/10241)`
|
||||
const EDWARDS_D: Fq = Fq::from_raw([
|
||||
0x01065fd6d6343eb1,
|
||||
|
@ -1198,6 +1218,17 @@ fn test_mul_consistency() {
|
|||
]),
|
||||
}).mul_by_cofactor();
|
||||
assert_eq!(p * c, (p * a) * b);
|
||||
|
||||
// Test Mul implemented on ExtendedNielsPoint
|
||||
assert_eq!(p * c, (p.to_niels() * a) * b);
|
||||
assert_eq!(p.to_niels() * c, (p * a) * b);
|
||||
assert_eq!(p.to_niels() * c, (p.to_niels() * a) * b);
|
||||
|
||||
// Test Mul implemented on AffineNielsPoint
|
||||
let p_affine_niels = AffinePoint::from(p).to_niels();
|
||||
assert_eq!(p * c, (p_affine_niels * a) * b);
|
||||
assert_eq!(p_affine_niels * c, (p * a) * b);
|
||||
assert_eq!(p_affine_niels * c, (p_affine_niels * a) * b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
22
src/util.rs
22
src/util.rs
|
@ -105,34 +105,40 @@ macro_rules! impl_binops_additive {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_binops_multiplicative {
|
||||
($lhs:ident, $rhs:ident) => {
|
||||
macro_rules! impl_binops_multiplicative_mixed {
|
||||
($lhs:ident, $rhs:ident, $output:ident) => {
|
||||
impl<'b> Mul<&'b $rhs> for $lhs {
|
||||
type Output = $lhs;
|
||||
type Output = $output;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, rhs: &'b $rhs) -> $lhs {
|
||||
fn mul(self, rhs: &'b $rhs) -> $output {
|
||||
&self * rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Mul<$rhs> for &'a $lhs {
|
||||
type Output = $lhs;
|
||||
type Output = $output;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, rhs: $rhs) -> $lhs {
|
||||
fn mul(self, rhs: $rhs) -> $output {
|
||||
self * &rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<$rhs> for $lhs {
|
||||
type Output = $lhs;
|
||||
type Output = $output;
|
||||
|
||||
#[inline]
|
||||
fn mul(self, rhs: $rhs) -> $lhs {
|
||||
fn mul(self, rhs: $rhs) -> $output {
|
||||
&self * &rhs
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_binops_multiplicative {
|
||||
($lhs:ident, $rhs:ident) => {
|
||||
impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs);
|
||||
|
||||
impl MulAssign<$rhs> for $lhs {
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue