simplify
This commit is contained in:
parent
fc51ea1057
commit
beead2b394
4 changed files with 21 additions and 45 deletions
|
|
@ -2,7 +2,7 @@ use crate::traits::{Curve, Point};
|
|||
use crypto_bigint::{AddMod, Encoding, NonZero, SubMod, U256};
|
||||
use crypto_bigint::{Integer, InvMod, MulMod};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::ops::{Div, Mul};
|
||||
use std::ops::{BitXor, Div, Mul};
|
||||
|
||||
/// A curve of the form `By^2 = x^3 + Ax^2 + x`
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
@ -162,24 +162,18 @@ ladder_impl!(MontgomeryPoint, swap_montgomery);
|
|||
|
||||
fn swap_montgomery<N>(a: &mut MontgomeryPoint<N>, b: &mut MontgomeryPoint<N>, c: u8, max: N)
|
||||
where
|
||||
N: AddMod + SubMod + MulMod + InvMod<Output = N> + Copy + Integer + std::ops::Div<Output = N>,
|
||||
N: BitXor + Copy + Mul<Output = N> + From<u8> + Div<Output = N> + Integer + InvMod<Output = N>,
|
||||
{
|
||||
let m = max * N::from(c);
|
||||
|
||||
let x = m & (a.x ^ b.x);
|
||||
let z = m & (a.z ^ b.z);
|
||||
|
||||
*a = MontgomeryPoint {
|
||||
x: a.x ^ x,
|
||||
z: a.z ^ z,
|
||||
curve: a.curve,
|
||||
};
|
||||
a.x ^= x;
|
||||
b.x ^= x;
|
||||
|
||||
*b = MontgomeryPoint {
|
||||
x: b.x ^ x,
|
||||
z: b.z ^ z,
|
||||
curve: b.curve,
|
||||
}
|
||||
a.z ^= z;
|
||||
b.z ^= z;
|
||||
}
|
||||
|
||||
impl<N> Display for MontgomeryPoint<N>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue