fix: build.rs now selects accelerated backend for xous

This commit is contained in:
David Kotval 2024-02-08 14:20:02 -06:00
parent b7c3eb9b67
commit 486cd1315f
5 changed files with 34 additions and 14 deletions

View file

@ -58,9 +58,9 @@ zeroize = { version = "1", default-features = false, optional = true }
# Betrusted/Precursor dependency set
[target.'cfg(curve25519_dalek_backend = "u32e_backend")'.dependencies]
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.0", optional = true} # this is bogus -- must be patched in the invoking build environment TODO: if this builds, it seems a crate has been released as version 0.1.23 that could replace this
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.0"} # this is bogus -- must be patched in the invoking build environment TODO: if this builds, it seems a crate has been released as version 0.1.23 that could replace this
[target.'cfg(target_arch = "x86_64")'.dependencies]
cpufeatures = "0.2.6"
@ -76,5 +76,5 @@ legacy_compatibility = []
group = ["dep:group", "rand_core"]
group-bits = ["group", "ff/bits"]
[target.'cfg(all(not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "serial"), target_arch = "x86_64"))'.dependencies]
[target.'cfg(all(not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "serial"), target_arch = "x86_64", not(curve25519_dalek_backend = "u32e_backend")))'.dependencies]
curve25519-dalek-derive = { version = "0.1", path = "../curve25519-dalek-derive" }

View file

@ -2,6 +2,9 @@
#![deny(clippy::unwrap_used, dead_code)]
use platforms::Platform;
use platforms::target;
#[allow(non_camel_case_types)]
#[derive(PartialEq, Debug)]
enum DalekBits {
@ -10,6 +13,9 @@ enum DalekBits {
}
fn main() {
let target_triplet = std::env::var("TARGET").unwrap();
let platform = platforms::Platform::find(&target_triplet).unwrap();
//Xous running on
let curve25519_dalek_bits = match std::env::var("CARGO_CFG_CURVE25519_DALEK_BITS").as_deref() {
Ok("32") => DalekBits::Dalek32,
Ok("64") => DalekBits::Dalek64,
@ -54,12 +60,22 @@ fn main() {
// See: issues/532
false => panic!("Could not override curve25519_dalek_backend to simd"),
}
}
// default between serial / simd (if potentially capable)
_ => match is_capable_simd(&target_arch, curve25519_dalek_bits) {
true => "simd",
false => "serial",
},
//coprocessor for Precursor
Ok("u32e_backend") => {
if curve25519_dalek_bits != DalekBits::Dalek64{
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",
},
}
};
println!("cargo:rustc-cfg=curve25519_dalek_backend=\"{curve25519_dalek_backend}\"");
}
@ -68,6 +84,10 @@ fn main() {
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 {

View file

@ -11,11 +11,11 @@
//! This module contains backend-specific constant values, such as the 64-bit limbs of curve constants.
use backend::serial::curve_models::AffineNielsPoint;
use crate::backend::serial::curve_models::AffineNielsPoint;
use super::field::Engine25519;
use super::scalar::Scalar29;
use edwards::{EdwardsBasepointTable, EdwardsPoint};
use window::{LookupTable, NafLookupTable8};
use crate::edwards::{EdwardsBasepointTable, EdwardsPoint};
use crate::window::{LookupTable, NafLookupTable8};
/// The value of minus one, equal to `-&FieldElement::one()`
pub(crate) const MINUS_ONE: Engine25519 = Engine25519([

View file

@ -14,7 +14,7 @@ use core::ops::{Index, IndexMut};
use zeroize::Zeroize;
use constants;
use crate::constants;
/// The `Scalar29` struct represents an element in /l as 9 29-bit limbs
#[derive(Copy,Clone)]

View file

@ -159,7 +159,7 @@ cfg_if! {
/// module.
//TODO: this should be the same as the u32 backend such that we don't even need to have
//backend/serial/scalar.rs defined. Double check that to simplify the code.
type UnpackedScalar = backend::serial::u32::scalar::Scalar29;
type UnpackedScalar = backend::serial::u32e::scalar::Scalar29;
}
else if #[cfg(curve25519_dalek_backend = "fiat")] {
/// An `UnpackedScalar` represents an element of the field GF(l), optimized for speed.