add test is not working

This commit is contained in:
bunnie 2020-08-10 18:32:46 +08:00
parent c8bd4211f6
commit 616801bd4c
3 changed files with 68 additions and 51 deletions

View file

@ -48,6 +48,7 @@ serde = { version = "1.0", default-features = false, optional = true, features =
packed_simd = { version = "0.3", features = ["into_bits"], optional = true } packed_simd = { version = "0.3", features = ["into_bits"], optional = true }
zeroize = { version = "1", default-features = false } zeroize = { version = "1", default-features = false }
engine25519-as = { path="../engine25519-as", default-features = false, features = [] } engine25519-as = { path="../engine25519-as", default-features = false, features = [] }
rand = { version = "0.7" }
[features] [features]
nightly = ["subtle/nightly"] nightly = ["subtle/nightly"]

View file

@ -464,6 +464,7 @@ mod test {
use std::io::prelude::*; use std::io::prelude::*;
use std::path::Path; use std::path::Path;
use engine25519_as::*; use engine25519_as::*;
use rand::Rng;
fn write_helper(file: &mut File, elem: FieldElement) { fn write_helper(file: &mut File, elem: FieldElement) {
let elem_bytes = elem.to_bytes(); let elem_bytes = elem.to_bytes();
@ -476,10 +477,10 @@ mod test {
let _ = write!(file, " ");*/ let _ = write!(file, " ");*/
} }
let a = FieldElement::one(); let path = Path::new("test_vectors.bin");
let b = FieldElement::minus_one(); let mut file = File::create(&path).unwrap();
let q = &a + &b;
fn test_add(mut file: &mut File) {
let mcode = assemble_engine25519!( let mcode = assemble_engine25519!(
start: start:
add %2, %0, %1 add %2, %0, %1
@ -488,9 +489,6 @@ mod test {
fin fin
); );
let path = Path::new("test_vectors.bin");
let mut file = File::create(&path).unwrap();
// insert machine code // insert machine code
// Metadata record: // Metadata record:
// 0x0 0x56454354 "VECT" - indicates a valid vector set // 0x0 0x56454354 "VECT" - indicates a valid vector set
@ -512,9 +510,9 @@ mod test {
| (mcode_len & 0xFFFF) | (mcode_len & 0xFFFF)
) as u32) ) as u32)
.to_le_bytes() ); // load address 0 + code length .to_le_bytes() ); // load address 0 + code length
let _ = file.write(&( ((2 & 0x1F) << 27 let _ = file.write(&( ((2 & 0x1F) << 27 // number of source registers per test
| (0 & 0xF) << 23 | (0 & 0xF) << 23 // register window to use
| (1 & 0x3F_FFFF) | (5 & 0x3F_FFFF) // number of tests
) as u32) ) as u32)
.to_le_bytes() ); // 2 registers, window 0, 1 vector .to_le_bytes() ); // 2 registers, window 0, 1 vector
// the actual microcode // the actual microcode
@ -528,10 +526,27 @@ mod test {
} }
// test vectors // test vectors
// 1 plus -1 = 0 -> this works overflow path
let a = FieldElement::one();
let b = FieldElement::minus_one();
let q = &a + &b;
write_helper(&mut file, a); write_helper(&mut file, a);
write_helper(&mut file, b); write_helper(&mut file, b);
write_helper(&mut file, q); write_helper(&mut file, q);
// four random numbers
for _ in 0..4 {
let a = FieldElement::from_bytes(&rand::thread_rng().gen::<[u8; 32]>());
let b = FieldElement::from_bytes(&rand::thread_rng().gen::<[u8; 32]>());
let q = &a + &b;
write_helper(&mut file, a);
write_helper(&mut file, b);
write_helper(&mut file, q);
}
}
test_add(&mut file);
// end sequence // end sequence
let _ = file.write(&(0xFFFF_FFFF as u32).to_le_bytes()); let _ = file.write(&(0xFFFF_FFFF as u32).to_le_bytes());
} }

View file

@ -61,6 +61,7 @@ pub(crate) mod macros;
#[macro_use] #[macro_use]
extern crate engine25519_as; extern crate engine25519_as;
extern crate rand;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// curve25519-dalek public modules // curve25519-dalek public modules