mirror of
https://github.com/saymrwulf/betrusted-curve25519-dalek-source.git
synced 2026-09-10 21:21:08 +00:00
fix: build.rs now selects accelerated backend for xous
This commit is contained in:
parent
b7c3eb9b67
commit
486cd1315f
5 changed files with 34 additions and 14 deletions
|
|
@ -58,9 +58,9 @@ zeroize = { version = "1", default-features = false, optional = true }
|
||||||
|
|
||||||
# Betrusted/Precursor dependency set
|
# Betrusted/Precursor dependency set
|
||||||
[target.'cfg(curve25519_dalek_backend = "u32e_backend")'.dependencies]
|
[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}
|
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", optional = true}
|
engine-25519 = { git = "https://github.com/betrusted-io/xous-engine-25519.git", rev = "63d3d1f30736022e791deaacf4dd62c00b42fe2e"}
|
||||||
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
|
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]
|
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
||||||
cpufeatures = "0.2.6"
|
cpufeatures = "0.2.6"
|
||||||
|
|
@ -76,5 +76,5 @@ legacy_compatibility = []
|
||||||
group = ["dep:group", "rand_core"]
|
group = ["dep:group", "rand_core"]
|
||||||
group-bits = ["group", "ff/bits"]
|
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" }
|
curve25519-dalek-derive = { version = "0.1", path = "../curve25519-dalek-derive" }
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
#![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 {
|
||||||
|
|
@ -10,6 +13,9 @@ enum DalekBits {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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() {
|
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,
|
||||||
|
|
@ -54,12 +60,22 @@ 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"),
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 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}\"");
|
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 {
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
//! This module contains backend-specific constant values, such as the 64-bit limbs of curve constants.
|
//! 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::field::Engine25519;
|
||||||
use super::scalar::Scalar29;
|
use super::scalar::Scalar29;
|
||||||
use edwards::{EdwardsBasepointTable, EdwardsPoint};
|
use crate::edwards::{EdwardsBasepointTable, EdwardsPoint};
|
||||||
use window::{LookupTable, NafLookupTable8};
|
use crate::window::{LookupTable, NafLookupTable8};
|
||||||
|
|
||||||
/// The value of minus one, equal to `-&FieldElement::one()`
|
/// The value of minus one, equal to `-&FieldElement::one()`
|
||||||
pub(crate) const MINUS_ONE: Engine25519 = Engine25519([
|
pub(crate) const MINUS_ONE: Engine25519 = Engine25519([
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use core::ops::{Index, IndexMut};
|
||||||
|
|
||||||
use zeroize::Zeroize;
|
use zeroize::Zeroize;
|
||||||
|
|
||||||
use constants;
|
use crate::constants;
|
||||||
|
|
||||||
/// The `Scalar29` struct represents an element in ℤ/lℤ as 9 29-bit limbs
|
/// The `Scalar29` struct represents an element in ℤ/lℤ as 9 29-bit limbs
|
||||||
#[derive(Copy,Clone)]
|
#[derive(Copy,Clone)]
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ cfg_if! {
|
||||||
/// module.
|
/// module.
|
||||||
//TODO: this should be the same as the u32 backend such that we don't even need to have
|
//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.
|
//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")] {
|
else if #[cfg(curve25519_dalek_backend = "fiat")] {
|
||||||
/// An `UnpackedScalar` represents an element of the field GF(l), optimized for speed.
|
/// An `UnpackedScalar` represents an element of the field GF(l), optimized for speed.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue