From b40ec7135e843bef06c8fa3b93217f47cf34e7f9 Mon Sep 17 00:00:00 2001 From: David Kotval Date: Fri, 1 Mar 2024 13:54:05 -0600 Subject: [PATCH] wip: returning to cfg based dependency specification --- curve25519-dalek/Cargo.toml | 12 ++++++------ curve25519-dalek/build.rs | 4 +++- curve25519-dalek/src/field.rs | 1 + curve25519-dalek/src/lib.rs | 15 +++------------ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/curve25519-dalek/Cargo.toml b/curve25519-dalek/Cargo.toml index fd89fbf..e8cdce9 100644 --- a/curve25519-dalek/Cargo.toml +++ b/curve25519-dalek/Cargo.toml @@ -57,10 +57,12 @@ serde = { version = "1.0", default-features = false, optional = true, features = zeroize = { version = "1", default-features = false, optional = true } # Betrusted/Precursor dependency set, enabled by backend_u32e feature -log = { version = "0.4", optional = true} -engine25519-as = {git = "https://github.com/betrusted-io/engine25519-as.git", rev = "d249c967556b02ab5439eacb5078fa00c60b93d6", default-features = false, features = [], optional = true} -engine-25519 = { git = "https://github.com/betrusted-io/xous-engine-25519.git", rev = "63d3d1f30736022e791deaacf4dd62c00b42fe2e", optional = true} -utralib = {version = "0.1.24", default-features = false, optional = true} +[target.'cfg(curve25519_dalek_backend = "u32e_backend")'.dependencies] +log = { version = "0.4"} +engine25519-as = {git = "https://github.com/betrusted-io/engine25519-as.git", rev = "d249c967556b02ab5439eacb5078fa00c60b93d6", default-features = false, features = []} +engine-25519 = { git = "https://github.com/betrusted-io/xous-engine-25519.git", rev = "63d3d1f30736022e791deaacf4dd62c00b42fe2e"} +utralib = {version = "0.1.24", default-features = false} + [target.'cfg(target_arch = "x86_64")'.dependencies] cpufeatures = "0.2.6" @@ -72,8 +74,6 @@ default = ["alloc", "precomputed-tables", "zeroize"] alloc = ["zeroize?/alloc"] precomputed-tables = [] legacy_compatibility = [] -fiat_backend = ["dep:fiat-crypto"] -u32e_backend = ["dep:engine25519-as","dep:engine-25519","dep:utralib","log","zeroize"] group = ["dep:group", "rand_core"] group-bits = ["group", "ff/bits"] diff --git a/curve25519-dalek/build.rs b/curve25519-dalek/build.rs index aeed124..85c3f56 100644 --- a/curve25519-dalek/build.rs +++ b/curve25519-dalek/build.rs @@ -12,6 +12,7 @@ enum DalekBits { Dalek64, } +//TODO: remove debugging before merging macro_rules! build_debug { ($($tokens: tt)*) => { println!("cargo:warning={}", format!($($tokens)*)) @@ -71,7 +72,7 @@ fn main() { }, //coprocessor for Precursor Ok("u32e_backend") => { - if curve25519_dalek_bits != DalekBits::Dalek64{ + if curve25519_dalek_bits != DalekBits::Dalek32{ panic!("u32e_backend only supports 32 bit bits"); } "u32e_backend" @@ -85,6 +86,7 @@ fn main() { }, } }; + build_debug!("CARGO_CFG_CURVE25519_DALEK_BACKEND: {:?}", std::env::var("CARGO_CFG_CURVE25519_DALEK_BACKEND").as_deref()); build_debug!("curve25519_dalek_backend {:?}", curve25519_dalek_backend); println!("cargo:rustc-cfg=curve25519_dalek_backend=\"{curve25519_dalek_backend}\""); } diff --git a/curve25519-dalek/src/field.rs b/curve25519-dalek/src/field.rs index db65845..f9b192c 100644 --- a/curve25519-dalek/src/field.rs +++ b/curve25519-dalek/src/field.rs @@ -509,6 +509,7 @@ mod test { } #[test] + #[cfg(curve25519_dalek_backend = "u32e_backend")] fn make_vectors() { // reminder to self: to create just this vector, run // cargo test field::test::make_vectors diff --git a/curve25519-dalek/src/lib.rs b/curve25519-dalek/src/lib.rs index aa930a6..aded117 100644 --- a/curve25519-dalek/src/lib.rs +++ b/curve25519-dalek/src/lib.rs @@ -62,21 +62,12 @@ pub(crate) mod macros; //To consider upstreaming, we likely can't do this. Consider the "panic_on_sw_eval" feature #[allow(unused_imports)] -#[cfg(any(test, curve25519_dalek_backend = "u32e_backend"))] +#[cfg(curve25519_dalek_backend = "u32e_backend")] #[macro_use] extern crate engine25519_as; -#[cfg(curve25519_dalek_backend = "u32e_backend")] //this is the binding for betrusted, so it should be gated - //with a "betrusted" flag, but we gate it with the backend - //flag for now. We'd need to refactor this to be - //make it easier to support other platforms, - //though there are no other platforms. For - //upstreaming this might be diserable, but for - //now, we'll leave it as a TODO. +#[cfg(curve25519_dalek_backend = "u32e_backend")] extern crate engine_25519; - -#[cfg(curve25519_dalek_backend = "u32e_backend")] //while this is specific to betrusted, any other - //use of this hardware would likely also need - //utralib, at least that would be easiest. +#[cfg(curve25519_dalek_backend = "u32e_backend")] extern crate utralib; //------------------------------------------------------------------------