Skip to content

Commit

Permalink
wip: make tests compile
Browse files Browse the repository at this point in the history
  • Loading branch information
kotval committed Mar 2, 2024
1 parent 9b5b0c5 commit 5a9ef20
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions curve25519-dalek/src/backend/serial/u32e/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub(crate) enum EngineOp {
Sub,
}

#[allow(unused_qualifications)]
pub(crate) fn engine(a: &[u8; 32], b: &[u8; 32], op: EngineOp) -> Engine25519 {
use utralib::generated::*;
let mut engine = utralib::CSR::new(utra::engine::HW_ENGINE_BASE as *mut u32);
Expand Down
2 changes: 1 addition & 1 deletion curve25519-dalek/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mod test {

/// Test that d = -121665/121666
#[test]
#[cfg(all(curve25519_dalek_bits = "32", not(curve25519_dalek_backend = "fiat")))]
#[cfg(all(curve25519_dalek_bits = "32", not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "u32e_backend")))]
fn test_d_vs_ratio() {
use crate::backend::serial::u32::field::FieldElement2625;
let a = -&FieldElement2625([121665, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
Expand Down
50 changes: 25 additions & 25 deletions curve25519-dalek/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! Field operations defined in terms of other field operations, such as
//! field inversion or square roots, are defined here.
#![allow(unused_qualifications)]
#[allow(unused_qualifications)]

use core::cmp::{Eq, PartialEq};

Expand Down Expand Up @@ -520,7 +520,7 @@ mod test {
use self::rand::Rng;

fn write_helper(file: &mut File, elem: FieldElement) {
let elem_bytes = elem.to_bytes();
let elem_bytes = elem.as_bytes();
let _ = file.write(&elem_bytes);
/*
for i in 0..elem_bytes.len()/4 {
Expand Down Expand Up @@ -597,8 +597,8 @@ mod test {

// test vectors
// 1 plus -1 = 0 -> this works overflow path
let a = FieldElement::one();
let b = FieldElement::minus_one();
let a = FieldElement::ONE;
let b = FieldElement::MINUS_ONE;
let q = &a + &b;

write_helper(&mut file, a);
Expand All @@ -617,11 +617,11 @@ mod test {
}

fn ref_fact(n: usize) -> FieldElement {
let mut a = FieldElement::one();
let mut result = FieldElement::one();
let mut a = FieldElement::ONE;
let mut result = FieldElement::ONE;
for _ in 0..n {
result = &result * &a;
a = &a + &FieldElement::one();
a = &a + &FieldElement::ONE;
}
result
}
Expand Down Expand Up @@ -655,10 +655,10 @@ mod test {
write_test_header(&mut file, loading_address, &mcode, num_src_regs, reg_window, num_tests);

// test vectors
let mut n = FieldElement::one();
let mut n = FieldElement::ONE;
for i in 1..6 {
write_helper(&mut file, n);
n = &n + &FieldElement::one(); // mirror i's progression
n = &n + &FieldElement::ONE; // mirror i's progression
let q = ref_fact(i);
write_helper(&mut file, q);
}
Expand Down Expand Up @@ -690,10 +690,10 @@ mod test {
let swap: FieldElement;
let q: FieldElement;
if i % 2 == 0 {
swap = FieldElement::zero();
swap = FieldElement::ZERO;
q = a;
} else {
swap = FieldElement::one();
swap = FieldElement::ONE;
q = b;
}
write_helper(&mut file, a);
Expand All @@ -720,16 +720,16 @@ mod test {
write_test_header(&mut file, loading_address, &mcode, num_src_regs, reg_window, num_tests);

// 1: 1*1 - simple case
let a = FieldElement::one();
let b = FieldElement::one();
let a = FieldElement::ONE;
let b = FieldElement::ONE;
let q = &a * &b;
write_helper(&mut file, a);
write_helper(&mut file, b);
write_helper(&mut file, q);

// 2: 1*-1 - simple case
let a = FieldElement::one();
let b = FieldElement::minus_one();
let a = FieldElement::ONE;
let b = FieldElement::MINUS_ONE;
let q = &a * &b;
write_helper(&mut file, a);
write_helper(&mut file, b);
Expand All @@ -741,7 +741,7 @@ mod test {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7f,]);
let b = FieldElement::one();
let b = FieldElement::ONE;
let q = &a * &b;
write_helper(&mut file, a);
write_helper(&mut file, b);
Expand Down Expand Up @@ -965,7 +965,7 @@ mod test {


fn test_diff_add_and_double(mut file: &mut File) {
use montgomery::ProjectivePoint;
use crate::montgomery::ProjectivePoint;

// test cswap. three input registers: (r0, r1) to swap, (r2) to control swap, one output register (r31).
let num_src_regs = 5;
Expand Down Expand Up @@ -1074,7 +1074,7 @@ mod test {
fin // finish execution
); write_test_header(&mut file, loading_address, &mcode, num_src_regs, reg_window, num_tests);

use montgomery::differential_add_and_double;
use crate::montgomery::differential_add_and_double;

// test vectors
for _ in 0..8 {
Expand All @@ -1098,7 +1098,7 @@ mod test {
}

fn test_scalar_mul(mut file: &mut File) {
use montgomery::ProjectivePoint;
use crate::montgomery::ProjectivePoint;

// test cswap. three input registers: (r0, r1) to swap, (r2) to control swap, one output register (r31).
let num_src_regs = 7;
Expand Down Expand Up @@ -1261,9 +1261,9 @@ mod test {

write_test_header(&mut file, loading_address, &mcode, num_src_regs, reg_window, num_tests);

use scalar::Scalar;
use montgomery::MontgomeryPoint;
use montgomery::differential_add_and_double;
use crate::scalar::Scalar;
use crate::montgomery::MontgomeryPoint;
use crate::montgomery::differential_add_and_double;

fn clamp_scalar(mut scalar: [u8; 32]) -> Scalar {
scalar[0] &= 248;
Expand All @@ -1278,12 +1278,12 @@ mod test {
// Algorithm 8 of Costello-Smith 2017
let affine_u = FieldElement::from_bytes(&mp.0);
let mut x0 = ProjectivePoint {
U: FieldElement::one(),
W: FieldElement::zero(),
U: FieldElement::ONE,
W: FieldElement::ZERO,
};
let mut x1 = ProjectivePoint {
U: affine_u,
W: FieldElement::one(),
W: FieldElement::ONE,
};

// test vectors input to test routine
Expand Down
4 changes: 2 additions & 2 deletions curve25519-dalek/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,11 +1026,11 @@ impl Scalar {
output
}

/// Returns a size hint indicating how many entries of the return
/// value of `to_radix_2w` are nonzero.
cfg_if::cfg_if!{
if #[cfg(curve25519_dalek_backend = "u32e_backend")]{}
else if #[cfg(any(feature = "alloc", all(test, feature = "precomputed-tables")))] {
/// Returns a size hint indicating how many entries of the return
/// value of `to_radix_2w` are nonzero.
pub(crate) fn to_radix_2w_size_hint(w: usize) -> usize {
debug_assert!(w >= 4);
debug_assert!(w <= 8);
Expand Down

0 comments on commit 5a9ef20

Please sign in to comment.