diff --git a/Cargo.toml b/Cargo.toml index 8636385..2e2e34a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ zeroize = { version = "1", default-features = false } fiat-crypto = { version = "0.1.6", optional = true} # Betrusted/Precursor dependency set +log = {version = "0.4", optional = true} [dependencies.engine-25519] git="https://github.com/betrusted-io/xous-engine-25519.git" rev="63d3d1f30736022e791deaacf4dd62c00b42fe2e" @@ -89,6 +90,6 @@ simd_backend = ["nightly", "u64_backend", "packed_simd"] # in some future release. avx2_backend = ["simd_backend"] # the betrusted backend uses the curve25519 hardware accelerator in betrusted-soc -betrusted = ["engine-25519", "engine25519-as"] +betrusted = ["engine-25519", "engine25519-as", "log"] [workspace] \ No newline at end of file diff --git a/src/montgomery.rs b/src/montgomery.rs index 1de47be..7266fd2 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -291,7 +291,7 @@ pub fn differential_add_and_double( Q.W = t17; // W_{Q'} = U_D * 4 (W_P U_Q - U_P W_Q)^2 } -#[cfg(betrusted)] +#[cfg(feature = "betrusted")] 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()) { @@ -299,7 +299,7 @@ fn copy_to_rf(bytes: [u8; 32], register: usize, rf: &mut [u32; engine_25519::RF_ } } -#[cfg(betrusted)] +#[cfg(feature = "betrusted")] fn copy_from_rf(register: usize, rf: &[u32; engine_25519::RF_SIZE_IN_U32]) -> [u8; 32] { let mut ret: [u8; 32] = [0; 32]; @@ -312,7 +312,7 @@ fn copy_from_rf(register: usize, rf: &[u32; engine_25519::RF_SIZE_IN_U32]) -> [u ret } -#[cfg(betrusted)] +#[cfg(feature = "betrusted")] pub fn differential_add_and_double_hw( P: &mut ProjectivePoint, Q: &mut ProjectivePoint, @@ -444,8 +444,9 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a MontgomeryPoint { type Output = MontgomeryPoint; /// Given `self` \\( = u\_0(P) \\), and a `Scalar` \\(n\\), return \\( u\_0([n]P) \\). - #[cfg(betrusted)] + #[cfg(feature = "betrusted")] fn mul(self, scalar: &'b Scalar) -> MontgomeryPoint { + log::debug!("hw mont"); // Algorithm 8 of Costello-Smith 2017 let affine_u = FieldElement::from_bytes(&self.0); let mut x0 = ProjectivePoint::identity(); @@ -454,7 +455,6 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a MontgomeryPoint { W: FieldElement::one(), }; - let mcode = assemble_engine25519!( start: // P.U in %20 @@ -633,9 +633,11 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a MontgomeryPoint { // curve25519 acceleration! x0.to_affine() } - #[cfg(not(betrusted))] + #[cfg(not(feature = "betrusted"))] fn mul(self, scalar: &'b Scalar) -> MontgomeryPoint { // Algorithm 8 of Costello-Smith 2017 + #[cfg(not(test))] // due to issue https://github.com/rust-lang/rust/issues/59168, you will have to manually comment this out when running a test on the full system and not just this crate. + log::warn!("sw montgomery multiply being used - check for build config errors!"); let affine_u = FieldElement::from_bytes(&self.0); let mut x0 = ProjectivePoint::identity(); let mut x1 = ProjectivePoint { diff --git a/src/scalar.rs b/src/scalar.rs index 773dcb4..05b4381 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -822,6 +822,7 @@ impl Scalar { } /// Get the bits of the scalar. + #[cfg(not(feature = "betrusted"))] pub(crate) fn bits(&self) -> [i8; 256] { let mut bits = [0i8; 256]; for i in 0..256 {