From c8bd4211f634bf521eef6049c9e64aae8c6fbfdf Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 8 Aug 2020 02:11:00 +0800 Subject: [PATCH] edit test to include normalization after add --- Cargo.toml | 2 ++ src/field.rs | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b042a01..50153a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,3 +64,5 @@ simd_backend = ["nightly", "u64_backend", "packed_simd"] # DEPRECATED: this is now an alias for `simd_backend` and may be removed # in some future release. avx2_backend = ["simd_backend"] + +[workspace] \ No newline at end of file diff --git a/src/field.rs b/src/field.rs index e14653f..b01dbf9 100644 --- a/src/field.rs +++ b/src/field.rs @@ -482,7 +482,10 @@ mod test { let mcode = assemble_engine25519!( start: - add %0, %1, %2 + add %2, %0, %1 + trd %3, %2 + sub %31, %2, %3 + fin ); let path = Path::new("test_vectors.bin"); @@ -490,15 +493,21 @@ mod test { // insert machine code // Metadata record: - // 0x0 [31 load address 16] [15 length of code 0] - // 0x4 [31 N registers to load 27] [26 W window 23] [22 X number of vectors sets 0] - // 0x8 [microcode] (variable length) + // 0x0 0x56454354 "VECT" - indicates a valid vector set + // 0x4 [31 load address 16] [15 length of code 0] + // 0x8 [31 N registers to load 27] [26 W window 23] [22 X number of vectors sets 0] + // 0xC [microcode] (variable length) // [ padding of 0x0 until 0x20 * align ] // 0x20*align [X test vectors] + // Records can repeat, and each one represents a new test + // End of records MUST end with a word that is NOT 0x56454354 + // This is because the ROM read can "wrap around" and the test will run forever + // We use 0xFFFF_FFFF to indicate this // Convention: // Check result is always in r31 // N Registers loaded starting at r0 into window W let mcode_len = mcode.len(); + let _ = file.write(&(0x5645_4354 as u32).to_le_bytes()); let _ = file.write(&( ((0x0 & 0xFFFF << 16) | (mcode_len & 0xFFFF) ) as u32) @@ -514,7 +523,7 @@ mod test { } // pad with 0's to a 256-bit stride - for _ in 0..(8 - ((2 + mcode_len) % 8)) { // 2 words for metadata + code length + for _ in 0..(8 - ((3 + mcode_len) % 8)) { // 3 words for metadata + code length let _ = file.write(&[0,0,0,0]); // write out 32-bit words of 0 (as array of u8) } @@ -522,5 +531,8 @@ mod test { write_helper(&mut file, a); write_helper(&mut file, b); write_helper(&mut file, q); + + // end sequence + let _ = file.write(&(0xFFFF_FFFF as u32).to_le_bytes()); } }