From eb45d338eea0de6f1fb2ef15fbc23dbdc17022a6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 21 Aug 2020 01:37:10 +0800 Subject: [PATCH] mods to get hardware integration to actually work. --- Cargo.toml | 6 ++++-- src/lib.rs | 2 +- src/montgomery.rs | 11 +++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea6dd72..6e822e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,9 +48,11 @@ serde = { version = "1.0", default-features = false, optional = true, features = packed_simd = { version = "0.3", features = ["into_bits"], optional = true } zeroize = { version = "1", default-features = false } engine25519-as = { path="../engine25519-as", default-features = false, features = [] } -rand = { version = "0.7" } +rand = { version = "0.7", default-features = false, features = [] } volatile = "0.2.6" -pac = { path = "../../../../sim_support/rust/pac" } +#pac = { path = "../../../../sim_support/rust/pac" } # used in test simulation environment, need to figure out how to make a switch for this +betrusted-pac = { path = "../betrusted-pac" } +#pac = { package = "betrusted-pac" } [features] nightly = ["subtle/nightly"] diff --git a/src/lib.rs b/src/lib.rs index 29e0a82..9930e48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,7 @@ pub(crate) mod macros; extern crate engine25519_as; extern crate rand; extern crate volatile; -extern crate pac; +extern crate betrusted_pac; //------------------------------------------------------------------------ // curve25519-dalek public modules diff --git a/src/montgomery.rs b/src/montgomery.rs index cf65fa3..1e10ec4 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -296,7 +296,7 @@ pub fn differential_add_and_double_hw( affine_PmQ: &FieldElement, ) { use volatile::Volatile; - let p = unsafe { pac::Peripherals::steal() }; + let p = unsafe { betrusted_pac::Peripherals::steal() }; let mcode = assemble_engine25519!( start: // P.U in %20 @@ -443,9 +443,16 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a MontgomeryPoint { copy_to_rf(x1.W.to_bytes(), 28); copy_to_rf(affine_u.to_bytes(), 24); copy_to_rf(scalar.bytes, 31); + // load the number 254 into the loop index register + copy_to_rf([ + 254, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], 19); use volatile::Volatile; - let p = unsafe { pac::Peripherals::steal() }; + let p = unsafe { betrusted_pac::Peripherals::steal() }; let mcode = assemble_engine25519!( start: // P.U in %20