cleanup warnings, as much as possible.

This commit is contained in:
bunnie 2024-03-25 08:04:26 +08:00
parent 0fc7183a2a
commit b6ce2f60a9
4 changed files with 21 additions and 40 deletions

View file

@ -58,7 +58,7 @@ zeroize = { version = "1", default-features = false, optional = true }
# Betrusted/Precursor dependency set, enabled by backend_u32e feature # Betrusted/Precursor dependency set, enabled by backend_u32e feature
[target.'cfg(curve25519_dalek_backend = "u32e_backend")'.dependencies] [target.'cfg(curve25519_dalek_backend = "u32e_backend")'.dependencies]
log = { version = "0.4"} log = { version = "0.4"}
engine25519-as = {git = "https://github.com/betrusted-io/engine25519-as.git", rev = "d249c967556b02ab5439eacb5078fa00c60b93d6", default-features = false, features = []} engine25519-as = {git = "https://github.com/betrusted-io/engine25519-as.git", rev = "775e8406eb4aad08f05ae10619fcb4ca891ba0a6", default-features = false, features = []}
utralib = {version = "0.1.24", default-features = false} utralib = {version = "0.1.24", default-features = false}
zeroize = { version = "1", default-features = false } zeroize = { version = "1", default-features = false }
xous = "0.9.58" xous = "0.9.58"

View file

@ -2,9 +2,6 @@
#![deny(clippy::unwrap_used, dead_code)] #![deny(clippy::unwrap_used, dead_code)]
use platforms::Platform;
use platforms::target;
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
enum DalekBits { enum DalekBits {
@ -12,23 +9,29 @@ enum DalekBits {
Dalek64, Dalek64,
} }
//TODO: remove debugging before merging use std::fmt::Formatter;
macro_rules! build_debug {
($($tokens: tt)*) => { impl std::fmt::Display for DalekBits {
println!("cargo:warning={}", format!($($tokens)*)) fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
let w_bits = match self {
DalekBits::Dalek32 => "32",
DalekBits::Dalek64 => "64",
};
write!(f, "{}", w_bits)
} }
} }
fn main() { fn main() {
let target_triplet = std::env::var("TARGET").unwrap(); let target_arch = match std::env::var("CARGO_CFG_TARGET_ARCH") {
let platform = platforms::Platform::find(&target_triplet).unwrap(); Ok(arch) => arch,
_ => "".to_string(),
};
let curve25519_dalek_bits = match std::env::var("CARGO_CFG_CURVE25519_DALEK_BITS").as_deref() { let curve25519_dalek_bits = match std::env::var("CARGO_CFG_CURVE25519_DALEK_BITS").as_deref() {
Ok("32") => DalekBits::Dalek32, Ok("32") => DalekBits::Dalek32,
Ok("64") => DalekBits::Dalek64, Ok("64") => DalekBits::Dalek64,
_ => deterministic::determine_curve25519_dalek_bits(&target_arch), _ => deterministic::determine_curve25519_dalek_bits(&target_arch),
}; };
build_debug!("CARGO_CFG_CURVE25519_DALEK_BITS: {:?}", std::env::var("CARGO_CFG_CURVE25519_DALEK_BITS").as_deref());
build_debug!("curve25519_dalek_bits {:?}", curve25519_dalek_bits);
println!("cargo:rustc-cfg=curve25519_dalek_bits=\"{curve25519_dalek_bits}\""); println!("cargo:rustc-cfg=curve25519_dalek_bits=\"{curve25519_dalek_bits}\"");
@ -47,12 +50,6 @@ fn main() {
println!("cargo:rustc-cfg=allow_unused_unsafe"); println!("cargo:rustc-cfg=allow_unused_unsafe");
} }
let target_arch = match std::env::var("CARGO_CFG_TARGET_ARCH") {
Ok(arch) => arch,
_ => "".to_string(),
};
build_debug!("target_arch {}",target_arch);
// Backend overrides / defaults // Backend overrides / defaults
let curve25519_dalek_backend = let curve25519_dalek_backend =
match std::env::var("CARGO_CFG_CURVE25519_DALEK_BACKEND").as_deref() { match std::env::var("CARGO_CFG_CURVE25519_DALEK_BACKEND").as_deref() {
@ -66,25 +63,13 @@ fn main() {
// See: issues/532 // See: issues/532
false => panic!("Could not override curve25519_dalek_backend to simd"), false => panic!("Could not override curve25519_dalek_backend to simd"),
} }
},
//coprocessor for Precursor
Ok("u32e_backend") => {
if curve25519_dalek_bits != DalekBits::Dalek32{
panic!("u32e_backend only supports 32 bit bits");
}
"u32e_backend"
},
// default between serial / simd (if potentially capable)
_ => match is_precursor(platform) {
true => "u32e_backend",
false => match is_capable_simd(&target_arch, curve25519_dalek_bits) {
true => "simd",
false => "serial",
},
} }
// default between serial / simd (if potentially capable)
_ => match is_capable_simd(&target_arch, curve25519_dalek_bits) {
true => "simd",
false => "serial",
},
}; };
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}\""); println!("cargo:rustc-cfg=curve25519_dalek_backend=\"{curve25519_dalek_backend}\"");
} }
@ -92,10 +77,6 @@ fn main() {
fn is_capable_simd(arch: &str, bits: DalekBits) -> bool { fn is_capable_simd(arch: &str, bits: DalekBits) -> bool {
arch == "x86_64" && bits == DalekBits::Dalek64 arch == "x86_64" && bits == DalekBits::Dalek64
} }
// Is the target the Precursor?
fn is_precursor(platform: &Platform) -> bool {
platform.target_os == target::OS::Xous && platform.target_arch == target::Arch::Riscv32
}
// Deterministic cfg(curve25519_dalek_bits) when this is not explicitly set. // Deterministic cfg(curve25519_dalek_bits) when this is not explicitly set.
mod deterministic { mod deterministic {

View file

@ -54,6 +54,7 @@ pub(crate) const SQRT_M1: Engine25519 = Engine25519([
176, 160, 14, 74, 39, 27, 238, 196, 120, 228, 47, 173, 6, 24, 67, 47, 167, 215, 251, 61, 153, 0, 77, 43, 11, 223, 193, 79, 128, 36, 131, 43]); 176, 160, 14, 74, 39, 27, 238, 196, 120, 228, 47, 173, 6, 24, 67, 47, 167, 215, 251, 61, 153, 0, 77, 43, 11, 223, 193, 79, 128, 36, 131, 43]);
/// `APLUS2_OVER_FOUR` is (A+2)/4. (This is used internally within the Montgomery ladder.) /// `APLUS2_OVER_FOUR` is (A+2)/4. (This is used internally within the Montgomery ladder.)
#[allow(dead_code)]
pub(crate) const APLUS2_OVER_FOUR: Engine25519 = Engine25519([ pub(crate) const APLUS2_OVER_FOUR: Engine25519 = Engine25519([
66, 219, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); 66, 219, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);

View file

@ -14,7 +14,6 @@
//! This code is intended to be portable, but it requires that //! This code is intended to be portable, but it requires that
//! multiplication of two \\(32\\)-bit values to a \\(64\\)-bit result //! multiplication of two \\(32\\)-bit values to a \\(64\\)-bit result
//! is constant-time on the target platform. //! is constant-time on the target platform.
use utralib::generated::*; use utralib::generated::*;
pub mod field; pub mod field;