From 0b748f63653ee9f04fe9b9bd3ada4f5f826c6803 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 27 Jun 2021 00:30:26 +0800 Subject: [PATCH] stash a version of the XousEngine25519 trait in case we want it later --- Cargo.toml | 14 ++++++++++++-- src/lib.rs | 2 +- src/montgomery.rs | 13 ++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 43bd4b6..e1cdce9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,15 +52,23 @@ packed_simd = { version = "0.3.4", package = "packed_simd_2", features = ["into_ zeroize = { version = "1", default-features = false } rand = { version = "0.7", default-features = false, features = [] } fiat-crypto = { version = "0.1.6", optional = true} -xous-engine-25519 = {path="../xous-engine-25519"} -engine-25519 = {path = "../xous-core/services/engine-25519"} +# 1. eliminate xous-engine-25519 crate +# 2. engine-25519 refers to a "0.1.0" +# 3. patch engine-25519 with a workspace patch in Xous +# 4. make a betrusted-soc accelerated feature configuration +# 5. make engine-25519 dependency only used when the betrusted-soc feature is specified +# 6. test that cargo test still works in `std` + +# Betrusted/Precursor dependency set +engine-25519 = {version = "0.1.0", optional = true} [dependencies.engine25519-as] #git="https://github.com/betrusted-io/engine25519-as.git" #rev="0bafc1ff8f58b66189d8c2f9ab7046cbbef77e6e" path="../engine25519-as" default-features = false features = [] +optional = true [features] nightly = ["subtle/nightly"] @@ -81,5 +89,7 @@ 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"] +# the betrusted backend uses the curve25519 hardware accelerator in betrusted-soc +betrusted = ["engine-25519", "engine25519-as"] [workspace] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 22a9365..b82f379 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub(crate) mod macros; #[macro_use] extern crate engine25519_as; extern crate rand; -extern crate xous_engine_25519; +extern crate engine_25519; //------------------------------------------------------------------------ // curve25519-dalek public modules diff --git a/src/montgomery.rs b/src/montgomery.rs index 306efa5..c4d1836 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -293,14 +293,14 @@ pub fn differential_add_and_double( Q.W = t17; // W_{Q'} = U_D * 4 (W_P U_Q - U_P W_Q)^2 } -fn copy_to_rf(bytes: [u8; 32], register: usize, rf: &mut [u32; xous_engine_25519::RF_SIZE_IN_U32]) { +fn copy_to_rf(bytes: [u8; 32], register: usize, rf: &mut [u32; engine_25519::RF_SIZE_IN_U32]) { use core::convert::TryInto; for (byte, rf_dst) in bytes.chunks_exact(4).zip(rf[register * 8..(register+1)*8].iter_mut()) { *rf_dst = u32::from_le_bytes(byte.try_into().expect("chunks_exact failed us")); } } -fn copy_from_rf(register: usize, rf: &[u32; xous_engine_25519::RF_SIZE_IN_U32]) -> [u8; 32] { +fn copy_from_rf(register: usize, rf: &[u32; engine_25519::RF_SIZE_IN_U32]) -> [u8; 32] { let mut ret: [u8; 32] = [0; 32]; for (src, dst) in rf[register*8 .. (register+1)*8].iter().zip(ret.chunks_exact_mut(4).into_iter()) { @@ -398,16 +398,15 @@ pub fn differential_add_and_double_hw( fin // finish execution ); - //let mut engine = xous_engine_25519::XousEngine25519::new(); let mut engine = engine_25519::Engine25519::new(); - let mut job = xous_engine_25519::Job { + let mut job = engine_25519::Job { id: None, ucode: [0; 1024], uc_len: mcode.len() as u32, uc_start: 0, window: Some(0), - rf: [0; xous_engine_25519::RF_SIZE_IN_U32], + rf: [0; engine_25519::RF_SIZE_IN_U32], }; for (&src, dst) in mcode.iter().zip(job.ucode.iter_mut()) { @@ -593,13 +592,13 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a MontgomeryPoint { fin // finish execution ); let mut engine = engine_25519::Engine25519::new(); - let mut job = xous_engine_25519::Job { + let mut job = engine_25519::Job { id: None, ucode: [0; 1024], uc_len: mcode.len() as u32, uc_start: 0, window: Some(0), - rf: [0; xous_engine_25519::RF_SIZE_IN_U32], + rf: [0; engine_25519::RF_SIZE_IN_U32], }; for (&src, dst) in mcode.iter().zip(job.ucode.iter_mut()) {