Skip to content

Commit

Permalink
cleanup warnings, as much as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Mar 25, 2024
1 parent 0fc7183 commit b6ce2f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 40 deletions.
2 changes: 1 addition & 1 deletion curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ zeroize = { version = "1", default-features = false, optional = true }
# Betrusted/Precursor dependency set, enabled by backend_u32e feature
[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 = []}
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}
zeroize = { version = "1", default-features = false }
xous = "0.9.58"
Expand Down
57 changes: 19 additions & 38 deletions curve25519-dalek/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@

#![deny(clippy::unwrap_used, dead_code)]

use platforms::Platform;
use platforms::target;

#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug)]
enum DalekBits {
Dalek32,
Dalek64,
}

//TODO: remove debugging before merging
macro_rules! build_debug {
($($tokens: tt)*) => {
println!("cargo:warning={}", format!($($tokens)*))
use std::fmt::Formatter;

impl std::fmt::Display for DalekBits {
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() {
let target_triplet = std::env::var("TARGET").unwrap();
let platform = platforms::Platform::find(&target_triplet).unwrap();
let target_arch = match std::env::var("CARGO_CFG_TARGET_ARCH") {
Ok(arch) => arch,
_ => "".to_string(),
};

let curve25519_dalek_bits = match std::env::var("CARGO_CFG_CURVE25519_DALEK_BITS").as_deref() {
Ok("32") => DalekBits::Dalek32,
Ok("64") => DalekBits::Dalek64,
_ => 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}\"");

Expand All @@ -47,12 +50,6 @@ fn main() {
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
let curve25519_dalek_backend =
match std::env::var("CARGO_CFG_CURVE25519_DALEK_BACKEND").as_deref() {
Expand All @@ -66,36 +63,20 @@ fn main() {
// See: issues/532
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}\"");
}

// Is the target arch & curve25519_dalek_bits potentially simd capable ?
fn is_capable_simd(arch: &str, bits: DalekBits) -> bool {
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.
mod deterministic {
Expand Down
1 change: 1 addition & 0 deletions curve25519-dalek/src/backend/serial/u32e/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

/// `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([
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]);

Expand Down
1 change: 0 additions & 1 deletion curve25519-dalek/src/backend/serial/u32e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//! This code is intended to be portable, but it requires that
//! multiplication of two \\(32\\)-bit values to a \\(64\\)-bit result
//! is constant-time on the target platform.

use utralib::generated::*;

pub mod field;
Expand Down

0 comments on commit b6ce2f6

Please sign in to comment.