mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
Rust fixes for some clippy warnings
Clippy lints with instances in the project but NOT applied here, since they seem consistently at odds with the projects' style: - [unreadable literal](https://rust-lang.github.io/rust-clippy/master/#unreadable_literal) - [cast lossless](https://rust-lang.github.io/rust-clippy/master/#cast_lossless) - [assign op pattern](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern)
This commit is contained in:
parent
023fdf2a2c
commit
9785f56c0f
5 changed files with 26 additions and 28 deletions
|
|
@ -20,7 +20,7 @@ static MULTISCALAR_SIZES: [usize; 13] = [1, 2, 4, 8, 16, 32, 64, 128, 256, 384,
|
||||||
|
|
||||||
mod edwards_benches {
|
mod edwards_benches {
|
||||||
use super::*;
|
use super::*;
|
||||||
use curve25519_dalek::edwards;
|
|
||||||
use curve25519_dalek::edwards::EdwardsPoint;
|
use curve25519_dalek::edwards::EdwardsPoint;
|
||||||
|
|
||||||
fn compress(c: &mut Criterion) {
|
fn compress(c: &mut Criterion) {
|
||||||
|
|
@ -47,7 +47,7 @@ mod edwards_benches {
|
||||||
let B = &constants::ED25519_BASEPOINT_POINT;
|
let B = &constants::ED25519_BASEPOINT_POINT;
|
||||||
let s = Scalar::from(897987897u64).invert();
|
let s = Scalar::from(897987897u64).invert();
|
||||||
c.bench_function("Constant-time variable-base scalar mul", move |b| {
|
c.bench_function("Constant-time variable-base scalar mul", move |b| {
|
||||||
b.iter(|| B * &s)
|
b.iter(|| B * s)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ mod edwards_benches {
|
||||||
|
|
||||||
mod multiscalar_benches {
|
mod multiscalar_benches {
|
||||||
use super::*;
|
use super::*;
|
||||||
use curve25519_dalek::edwards;
|
|
||||||
use curve25519_dalek::edwards::EdwardsPoint;
|
use curve25519_dalek::edwards::EdwardsPoint;
|
||||||
use curve25519_dalek::edwards::VartimeEdwardsPrecomputation;
|
use curve25519_dalek::edwards::VartimeEdwardsPrecomputation;
|
||||||
use curve25519_dalek::traits::MultiscalarMul;
|
use curve25519_dalek::traits::MultiscalarMul;
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,6 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
// Collect optimized scalars and points in buffers for repeated access
|
// Collect optimized scalars and points in buffers for repeated access
|
||||||
// (scanning the whole set per digit position).
|
// (scanning the whole set per digit position).
|
||||||
let scalars = scalars
|
let scalars = scalars
|
||||||
.into_iter()
|
|
||||||
.map(|s| s.borrow().to_radix_2w(w));
|
.map(|s| s.borrow().to_radix_2w(w));
|
||||||
|
|
||||||
let points = points
|
let points = points
|
||||||
|
|
@ -158,8 +157,7 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
columns
|
columns
|
||||||
.fold(hi_column, |total, p| total.mul_by_pow_2(w as u32) + p)
|
.fold(hi_column, |total, p| total.mul_by_pow_2(w as u32) + p),
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ impl CompressedEdwardsY {
|
||||||
let compressed_sign_bit = Choice::from(self.as_bytes()[31] >> 7);
|
let compressed_sign_bit = Choice::from(self.as_bytes()[31] >> 7);
|
||||||
X.conditional_negate(compressed_sign_bit);
|
X.conditional_negate(compressed_sign_bit);
|
||||||
|
|
||||||
Some(EdwardsPoint{ X: X, Y: Y, Z: Z, T: &X * &Y })
|
Some(EdwardsPoint{ X, Y, Z, T: &X * &Y })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -449,7 +449,7 @@ impl EdwardsPoint {
|
||||||
AffineNielsPoint{
|
AffineNielsPoint{
|
||||||
y_plus_x: &y + &x,
|
y_plus_x: &y + &x,
|
||||||
y_minus_x: &y - &x,
|
y_minus_x: &y - &x,
|
||||||
xy2d: xy2d
|
xy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -810,7 +810,7 @@ impl<'a, 'b> Mul<&'a EdwardsBasepointTable> for &'b Scalar {
|
||||||
/// Construct an `EdwardsPoint` from a `Scalar` \\(a\\) by
|
/// Construct an `EdwardsPoint` from a `Scalar` \\(a\\) by
|
||||||
/// computing the multiple \\(aB\\) of this basepoint \\(B\\).
|
/// computing the multiple \\(aB\\) of this basepoint \\(B\\).
|
||||||
fn mul(self, basepoint_table: &'a EdwardsBasepointTable) -> EdwardsPoint {
|
fn mul(self, basepoint_table: &'a EdwardsBasepointTable) -> EdwardsPoint {
|
||||||
basepoint_table * &self
|
basepoint_table * self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -908,7 +908,7 @@ impl EdwardsPoint {
|
||||||
/// assert_eq!((P+Q).is_torsion_free(), false);
|
/// assert_eq!((P+Q).is_torsion_free(), false);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn is_torsion_free(&self) -> bool {
|
pub fn is_torsion_free(&self) -> bool {
|
||||||
(self * &constants::BASEPOINT_ORDER).is_identity()
|
(self * constants::BASEPOINT_ORDER).is_identity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1181,7 +1181,7 @@ mod test {
|
||||||
|
|
||||||
// Test that sum works on owning iterators
|
// Test that sum works on owning iterators
|
||||||
let s = Scalar::from(2u64);
|
let s = Scalar::from(2u64);
|
||||||
let mapped = vec.iter().map(|x| x * &s);
|
let mapped = vec.iter().map(|x| x * s);
|
||||||
let sum: EdwardsPoint = mapped.sum();
|
let sum: EdwardsPoint = mapped.sum();
|
||||||
|
|
||||||
assert_eq!(sum, &P1 * &s + &P2 * &s);
|
assert_eq!(sum, &P1 * &s + &P2 * &s);
|
||||||
|
|
@ -1204,10 +1204,10 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn is_small_order() {
|
fn is_small_order() {
|
||||||
// The basepoint has large prime order
|
// The basepoint has large prime order
|
||||||
assert!(constants::ED25519_BASEPOINT_POINT.is_small_order() == false);
|
assert!(!constants::ED25519_BASEPOINT_POINT.is_small_order());
|
||||||
// constants::EIGHT_TORSION has all points of small order.
|
// constants::EIGHT_TORSION has all points of small order.
|
||||||
for torsion_point in &constants::EIGHT_TORSION {
|
for torsion_point in &constants::EIGHT_TORSION {
|
||||||
assert!(torsion_point.is_small_order() == true);
|
assert!(torsion_point.is_small_order());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1219,8 +1219,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_identity() {
|
fn is_identity() {
|
||||||
assert!( EdwardsPoint::identity().is_identity() == true);
|
assert!( EdwardsPoint::identity().is_identity());
|
||||||
assert!(constants::ED25519_BASEPOINT_POINT.is_identity() == false);
|
assert!(!constants::ED25519_BASEPOINT_POINT.is_identity());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rust's debug builds have overflow and underflow trapping,
|
/// Rust's debug builds have overflow and underflow trapping,
|
||||||
|
|
|
||||||
|
|
@ -297,9 +297,9 @@ impl CompressedRistretto {
|
||||||
let t = &x * &y;
|
let t = &x * &y;
|
||||||
|
|
||||||
if ok.unwrap_u8() == 0u8 || t.is_negative().unwrap_u8() == 1u8 || y.is_zero().unwrap_u8() == 1u8 {
|
if ok.unwrap_u8() == 0u8 || t.is_negative().unwrap_u8() == 1u8 || y.is_zero().unwrap_u8() == 1u8 {
|
||||||
return None;
|
None
|
||||||
} else {
|
} else {
|
||||||
return Some(RistrettoPoint(EdwardsPoint{X: x, Y: y, Z: one, T: t}));
|
Some(RistrettoPoint(EdwardsPoint{X: x, Y: y, Z: one, T: t}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -529,11 +529,11 @@ impl RistrettoPoint {
|
||||||
let eg = &e * &g;
|
let eg = &e * &g;
|
||||||
let fh = &f * &h;
|
let fh = &f * &h;
|
||||||
|
|
||||||
BatchCompressState{ e: e, f: f, g: g, h: h, eg: eg, fh: fh }
|
BatchCompressState{ e, f, g, h, eg, fh }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let states: Vec<BatchCompressState> = points.into_iter().map(|P| BatchCompressState::from(P)).collect();
|
let states: Vec<BatchCompressState> = points.into_iter().map(BatchCompressState::from).collect();
|
||||||
|
|
||||||
let mut invs: Vec<FieldElement> = states.iter().map(|state| state.efgh()).collect();
|
let mut invs: Vec<FieldElement> = states.iter().map(|state| state.efgh()).collect();
|
||||||
|
|
||||||
|
|
@ -847,7 +847,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a RistrettoPoint {
|
||||||
type Output = RistrettoPoint;
|
type Output = RistrettoPoint;
|
||||||
/// Scalar multiplication: compute `scalar * self`.
|
/// Scalar multiplication: compute `scalar * self`.
|
||||||
fn mul(self, scalar: &'b Scalar) -> RistrettoPoint {
|
fn mul(self, scalar: &'b Scalar) -> RistrettoPoint {
|
||||||
RistrettoPoint(&self.0 * scalar)
|
RistrettoPoint(self.0 * scalar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -856,7 +856,7 @@ impl<'a, 'b> Mul<&'b RistrettoPoint> for &'a Scalar {
|
||||||
|
|
||||||
/// Scalar multiplication: compute `self * scalar`.
|
/// Scalar multiplication: compute `self * scalar`.
|
||||||
fn mul(self, point: &'b RistrettoPoint) -> RistrettoPoint {
|
fn mul(self, point: &'b RistrettoPoint) -> RistrettoPoint {
|
||||||
RistrettoPoint(self * &point.0)
|
RistrettoPoint(self * point.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -902,7 +902,7 @@ impl VartimeMultiscalarMul for RistrettoPoint {
|
||||||
{
|
{
|
||||||
let extended_points = points.into_iter().map(|opt_P| opt_P.map(|P| P.borrow().0));
|
let extended_points = points.into_iter().map(|opt_P| opt_P.map(|P| P.borrow().0));
|
||||||
|
|
||||||
EdwardsPoint::optional_multiscalar_mul(scalars, extended_points).map(|P| RistrettoPoint(P))
|
EdwardsPoint::optional_multiscalar_mul(scalars, extended_points).map(RistrettoPoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -948,7 +948,7 @@ impl VartimePrecomputedMultiscalarMul for VartimeRistrettoPrecomputation {
|
||||||
dynamic_scalars,
|
dynamic_scalars,
|
||||||
dynamic_points.into_iter().map(|P_opt| P_opt.map(|P| P.0)),
|
dynamic_points.into_iter().map(|P_opt| P_opt.map(|P| P.0)),
|
||||||
)
|
)
|
||||||
.map(|P_ed| RistrettoPoint(P_ed))
|
.map(RistrettoPoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1081,7 +1081,7 @@ mod test {
|
||||||
use scalar::Scalar;
|
use scalar::Scalar;
|
||||||
use constants;
|
use constants;
|
||||||
use edwards::CompressedEdwardsY;
|
use edwards::CompressedEdwardsY;
|
||||||
use traits::{Identity, ValidityCheck};
|
use traits::{Identity};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -1136,7 +1136,7 @@ mod test {
|
||||||
|
|
||||||
// Test that sum works on owning iterators
|
// Test that sum works on owning iterators
|
||||||
let s = Scalar::from(2u64);
|
let s = Scalar::from(2u64);
|
||||||
let mapped = vec.iter().map(|x| x * &s);
|
let mapped = vec.iter().map(|x| x * s);
|
||||||
let sum: RistrettoPoint = mapped.sum();
|
let sum: RistrettoPoint = mapped.sum();
|
||||||
|
|
||||||
assert_eq!(sum, &P1 * &s + &P2 * &s);
|
assert_eq!(sum, &P1 * &s + &P2 * &s);
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ impl Scalar {
|
||||||
/// modulo the group order \\( \ell \\).
|
/// modulo the group order \\( \ell \\).
|
||||||
pub fn from_bytes_mod_order(bytes: [u8; 32]) -> Scalar {
|
pub fn from_bytes_mod_order(bytes: [u8; 32]) -> Scalar {
|
||||||
// Temporarily allow s_unreduced.bytes > 2^255 ...
|
// Temporarily allow s_unreduced.bytes > 2^255 ...
|
||||||
let s_unreduced = Scalar{bytes: bytes};
|
let s_unreduced = Scalar{bytes};
|
||||||
|
|
||||||
// Then reduce mod the group order and return the reduced representative.
|
// Then reduce mod the group order and return the reduced representative.
|
||||||
let s = s_unreduced.reduce();
|
let s = s_unreduced.reduce();
|
||||||
|
|
@ -242,7 +242,7 @@ impl Scalar {
|
||||||
/// require specific bit-patterns when performing scalar
|
/// require specific bit-patterns when performing scalar
|
||||||
/// multiplication.
|
/// multiplication.
|
||||||
pub fn from_bits(bytes: [u8; 32]) -> Scalar {
|
pub fn from_bits(bytes: [u8; 32]) -> Scalar {
|
||||||
let mut s = Scalar{bytes: bytes};
|
let mut s = Scalar{bytes};
|
||||||
// Ensure that s < 2^255 by masking the high bit
|
// Ensure that s < 2^255 by masking the high bit
|
||||||
s.bytes[31] &= 0b0111_1111;
|
s.bytes[31] &= 0b0111_1111;
|
||||||
|
|
||||||
|
|
@ -799,7 +799,7 @@ impl Scalar {
|
||||||
|
|
||||||
// Pass through the vector backwards to compute the inverses
|
// Pass through the vector backwards to compute the inverses
|
||||||
// in place
|
// in place
|
||||||
for (input, scratch) in inputs.iter_mut().rev().zip(scratch.into_iter().rev()) {
|
for (input, scratch) in inputs.iter_mut().rev().zip(scratch.iter().rev()) {
|
||||||
let tmp = UnpackedScalar::montgomery_mul(&acc, &input.unpack());
|
let tmp = UnpackedScalar::montgomery_mul(&acc, &input.unpack());
|
||||||
*input = UnpackedScalar::montgomery_mul(&acc, &scratch).pack();
|
*input = UnpackedScalar::montgomery_mul(&acc, &scratch).pack();
|
||||||
acc = tmp;
|
acc = tmp;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue