mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
Merge branch 'main' into swap
This commit is contained in:
commit
2d68807d51
15 changed files with 74 additions and 1467 deletions
|
|
@ -15,3 +15,6 @@ rustflags = ["--cfg", "crossbeam_no_atomic_64"]
|
|||
# "-C", "link-arg=-shared",
|
||||
# "--cfg", "crossbeam_no_atomic_64"
|
||||
# ]
|
||||
|
||||
[target.riscv32imac-unknown-xous-elf]
|
||||
rustflags = ["--cfg", 'curve25519_dalek_backend="u32e_backend"']
|
||||
49
Cargo.lock
generated
49
Cargo.lock
generated
|
|
@ -1150,26 +1150,27 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
|||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "4.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c"
|
||||
version = "4.1.2"
|
||||
source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#468e304624b4bc4004863c9147176238cfc0dc10"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"curve25519-dalek-derive",
|
||||
"digest 0.10.7",
|
||||
"fiat-crypto 0.2.6",
|
||||
"platforms",
|
||||
"engine25519-as",
|
||||
"fiat-crypto 0.2.7",
|
||||
"log",
|
||||
"rustc_version 0.4.0",
|
||||
"subtle",
|
||||
"utralib 0.1.24",
|
||||
"xous 0.9.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek-derive"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
||||
source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#468e304624b4bc4004863c9147176238cfc0dc10"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -1520,9 +1521,9 @@ checksum = "e18997d4604542d0736fae2c5ad6de987f0a50530cbcc14a7ce5a685328a252d"
|
|||
|
||||
[[package]]
|
||||
name = "ed25519-dalek"
|
||||
version = "2.1.1"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871"
|
||||
checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0"
|
||||
dependencies = [
|
||||
"curve25519-dalek",
|
||||
"ed25519 2.2.3",
|
||||
|
|
@ -1632,26 +1633,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "engine-25519"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"engine25519-as",
|
||||
"llio",
|
||||
"log",
|
||||
"num-derive 0.3.3",
|
||||
"num-traits",
|
||||
"rkyv",
|
||||
"utralib 0.1.24",
|
||||
"xous",
|
||||
"xous-api-log",
|
||||
"xous-api-names",
|
||||
"xous-api-susres",
|
||||
"xous-api-ticktimer",
|
||||
"xous-ipc 0.9.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
source = "git+https://github.com/betrusted-io/xous-engine-25519.git?rev=63d3d1f30736022e791deaacf4dd62c00b42fe2e#63d3d1f30736022e791deaacf4dd62c00b42fe2e"
|
||||
|
||||
[[package]]
|
||||
name = "engine25519-as"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/betrusted-io/engine25519-as.git?rev=d249c967556b02ab5439eacb5078fa00c60b93d6#d249c967556b02ab5439eacb5078fa00c60b93d6"
|
||||
source = "git+https://github.com/betrusted-io/engine25519-as.git?rev=775e8406eb4aad08f05ae10619fcb4ca891ba0a6#775e8406eb4aad08f05ae10619fcb4ca891ba0a6"
|
||||
|
||||
[[package]]
|
||||
name = "enum-iterator"
|
||||
|
|
@ -1815,9 +1802,9 @@ checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77"
|
|||
|
||||
[[package]]
|
||||
name = "fiat-crypto"
|
||||
version = "0.2.6"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382"
|
||||
checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f"
|
||||
|
||||
[[package]]
|
||||
name = "filetime"
|
||||
|
|
@ -3656,12 +3643,6 @@ version = "0.3.29"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb"
|
||||
|
||||
[[package]]
|
||||
name = "platforms"
|
||||
version = "3.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c"
|
||||
|
||||
[[package]]
|
||||
name = "plotters"
|
||||
version = "0.3.5"
|
||||
|
|
@ -4207,7 +4188,6 @@ dependencies = [
|
|||
"curve25519-dalek",
|
||||
"digest 0.10.7",
|
||||
"ed25519-dalek",
|
||||
"engine-25519",
|
||||
"gam",
|
||||
"graphics-server",
|
||||
"hex 0.4.3",
|
||||
|
|
@ -4592,7 +4572,6 @@ dependencies = [
|
|||
"digest 0.10.7",
|
||||
"dns",
|
||||
"ed25519-dalek",
|
||||
"engine-25519",
|
||||
"gam",
|
||||
"graphics-server",
|
||||
"hex 0.4.3",
|
||||
|
|
|
|||
15
Cargo.toml
15
Cargo.toml
|
|
@ -17,8 +17,6 @@ default-members = [
|
|||
"services/shellchat",
|
||||
"services/llio",
|
||||
"services/codec",
|
||||
# "services/engine-sha512",
|
||||
"services/engine-25519",
|
||||
"services/aes",
|
||||
"services/spinor",
|
||||
"services/root-keys",
|
||||
|
|
@ -60,8 +58,6 @@ members = [
|
|||
"services/content-plugin-api",
|
||||
"services/llio",
|
||||
"services/codec",
|
||||
# "services/engine-sha512",
|
||||
"services/engine-25519",
|
||||
"services/aes",
|
||||
"services/spinor",
|
||||
"services/root-keys",
|
||||
|
|
@ -147,15 +143,12 @@ sha2_legacy = { git = "https://github.com/RustCrypto/hashes.git", tag = "sha2-v0
|
|||
[patch.crates-io.aes]
|
||||
path = "services/aes"
|
||||
|
||||
#[patch.crates-io.curve25519-dalek]
|
||||
#git = "https://github.com/betrusted-io/curve25519-dalek.git"
|
||||
#branch = "main"
|
||||
#path = "../curve25519-dalek/curve25519-dalek" # when doing local dev work
|
||||
[patch.crates-io.curve25519-dalek]
|
||||
git = "https://github.com/betrusted-io/curve25519-dalek.git"
|
||||
branch = "main"
|
||||
# path = "../curve25519-dalek/curve25519-dalek" # when doing local dev work
|
||||
# feature overrides are specified at the crate level
|
||||
|
||||
[patch."https://github.com/betrusted-io/xous-engine-25519.git"]
|
||||
engine-25519 = { path = "services/engine-25519" }
|
||||
|
||||
[patch.crates-io.usb-device]
|
||||
git = "https://github.com/betrusted-io/usb-device.git"
|
||||
branch = "main"
|
||||
|
|
|
|||
|
|
@ -471,6 +471,7 @@ perform the Xous firmware upgrade. This requires running manual update commands,
|
|||
- a number of other crates and pins were upgraded in the process due to a cargo `update` run; the `build.rs` changes were reviewed and nothing nefarious was found, so at least this process did not introduce any obvious attacks against build hosts through supply chain contamination.
|
||||
- @gsora has added the `hidapi` - apps can now register a HID descriptor for custom interactions over USB. See `apps/hidv2` for democumentation.
|
||||
- change kernel and loader targets to riscv-unknown-elf-none because `xous` is now a proper target (required for Rust 1.76 compatibility)
|
||||
- `curve25519-dalek` API is now at 4.1.2, thanks to @kotval for pulling it together. The new API removes `engine-25519` and rolls hardware allocate/release into the forked crate, similar to how sha2 was ported. `engine-25519` crate now removed from source tree, as it is now depracted since all the functionality was pulled into `curve25519-dalek`.
|
||||
|
||||
## Roadmap
|
||||
- Lots of testing and bug fixes
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ optional = true
|
|||
|
||||
[dependencies.engine25519-as]
|
||||
git = "https://github.com/betrusted-io/engine25519-as.git"
|
||||
rev = "d249c967556b02ab5439eacb5078fa00c60b93d6"
|
||||
rev = "775e8406eb4aad08f05ae10619fcb4ca891ba0a6"
|
||||
default-features = false
|
||||
features = []
|
||||
optional = true
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
[package]
|
||||
name = "engine-25519"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Curve25519 Engine"
|
||||
|
||||
# Dependency versions enforced by Cargo.lock.
|
||||
[dependencies]
|
||||
xous = "0.9.58"
|
||||
log-server = { package = "xous-api-log", version = "0.1.54" }
|
||||
ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.54" }
|
||||
xous-names = { package = "xous-api-names", version = "0.9.56" }
|
||||
log = "0.4.14"
|
||||
susres = { package = "xous-api-susres", version = "0.9.54" }
|
||||
llio = { path = "../llio" } # temporary for testing some power stuff
|
||||
utralib = { version = "0.1.24", optional = true, default-features = false }
|
||||
|
||||
xous-ipc = "0.9.58"
|
||||
num-derive = { version = "0.3.3", default-features = false }
|
||||
num-traits = { version = "0.2.14", default-features = false }
|
||||
rkyv = { version = "0.4.3", default-features = false, features = [
|
||||
"const_generics",
|
||||
] }
|
||||
|
||||
[dependencies.engine25519-as]
|
||||
git = "https://github.com/betrusted-io/engine25519-as.git"
|
||||
rev = "d249c967556b02ab5439eacb5078fa00c60b93d6"
|
||||
default-features = false
|
||||
features = []
|
||||
|
||||
[features]
|
||||
precursor = ["utralib/precursor"]
|
||||
hosted = ["utralib/hosted"]
|
||||
renode = ["utralib/renode"]
|
||||
default = []
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# Curve 25519 engine
|
||||
|
||||
Please refer to the [datasheet](https://ci.betrusted.io/betrusted-soc/doc/engine.html) for comprehensive documentation
|
||||
on how the hardware engine itself works.
|
||||
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
pub(crate) const SERVER_NAME_ENGINE25519: &str = "_Curve-25519 Accelerator Engine_";
|
||||
|
||||
// I don't understand why clippy says these are unused. But clippy is wrong. Shut up, clippy.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const UCODE_U8_BASE: usize = 0x0;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const UCODE_U32_BASE: usize = 0x0;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const UCODE_U32_SIZE: usize = 0x1000 / 4;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const UCODE_U8_SIZE: usize = 0x1000;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const RF_U8_BASE: usize = 0x1_0000;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const RF_U32_BASE: usize = 0x1_0000 / 4;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const RF_TOTAL_U32_SIZE: usize = 0x4000 / 4;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const RF_TOTAL_U8_SIZE: usize = 0x4000;
|
||||
|
||||
pub(crate) const NUM_REGS: usize = 32;
|
||||
pub(crate) const BITWIDTH: usize = 256;
|
||||
#[allow(dead_code)] // not used in hosted
|
||||
pub(crate) const NUM_WINDOWS: usize = 16;
|
||||
pub const RF_SIZE_IN_U32: usize = NUM_REGS * (BITWIDTH / 32); // 32 registers, 256 bits/register/32 bits per u32
|
||||
#[allow(dead_code)] // not used in hosted
|
||||
pub const TOTAL_RF_SIZE_IN_U32: usize = NUM_REGS * (BITWIDTH / 32) * NUM_WINDOWS; // 32 registers, 256 bits/register/32 bits per u32, times 16 windows
|
||||
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Copy)]
|
||||
pub struct Job {
|
||||
/// If present the SID of the server to which we should return results asynchronously.
|
||||
/// If None, then the job will run synchronously.
|
||||
pub id: Option<[u32; 4]>,
|
||||
/// start location for microcode load
|
||||
pub uc_start: u32,
|
||||
/// length of the microcode to run
|
||||
pub uc_len: u32,
|
||||
/// microcode program
|
||||
pub ucode: [u32; 1024],
|
||||
/// initial register file contents (also contains any arguments to the program)
|
||||
pub rf: [u32; RF_SIZE_IN_U32],
|
||||
/// which register window, if any, to use for the job
|
||||
pub window: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Copy)]
|
||||
pub struct MontgomeryJob {
|
||||
pub x0_u: [u8; 32],
|
||||
pub x0_w: [u8; 32],
|
||||
pub x1_u: [u8; 32],
|
||||
pub x1_w: [u8; 32],
|
||||
pub affine_u: [u8; 32],
|
||||
pub scalar: [u8; 32],
|
||||
}
|
||||
|
||||
mod rkyv_enum;
|
||||
pub use rkyv_enum::*;
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
/// Runs a job, if the server is not already occupied
|
||||
RunJob,
|
||||
|
||||
/// MontgomeryJob
|
||||
MontgomeryJob,
|
||||
|
||||
/// a function that can be polled to determine if the block has been currently acquired
|
||||
IsFree,
|
||||
|
||||
/// IRQ handler feedback
|
||||
EngineDone,
|
||||
IllegalOpcode,
|
||||
|
||||
// note: suspend/resume handled by a separate thread and server
|
||||
/// exit the server
|
||||
Quit,
|
||||
// note that suspend/resume is handled by a secondary thread that can concurrently
|
||||
// interrupt the main thread and store the state
|
||||
}
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Return {
|
||||
Result,
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum SusResOps {
|
||||
/// Suspend/resume callback
|
||||
SuspendResume,
|
||||
/// exit the thread
|
||||
Quit,
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// As of Rust 1.64.0:
|
||||
//
|
||||
// Rkyv-derived enums throw warnings that rkyv::Archive derived enums are never used
|
||||
// and I can't figure out how to make them go away. Since they spam the build log,
|
||||
// rkyv-derived enums are now isolated to their own file with a file-wide `dead_code`
|
||||
// allow on top.
|
||||
//
|
||||
// This might be a temporary compiler regression, or it could just
|
||||
// be yet another indicator that it's time to upgrade rkyv. However, we are waiting
|
||||
// until rkyv hits 0.8 (the "shouldn't ever change again but still not sure enough
|
||||
// for 1.0") release until we rework the entire system to chase the latest rkyv.
|
||||
// As of now, the current version is 0.7.x and there isn't a timeline yet for 0.8.
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub enum JobResult {
|
||||
/// returns a copy of the entire register file as a result
|
||||
Result([u32; crate::RF_SIZE_IN_U32]),
|
||||
SingleResult([u8; 32]),
|
||||
Started,
|
||||
EngineUnavailable,
|
||||
NotAsyncObject, // attempt to run an async job on an object that was setup for sync jobs
|
||||
IllegalOpcodeException,
|
||||
SuspendError,
|
||||
}
|
||||
|
|
@ -1,202 +0,0 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
//! Detailed docs are parked under Structs/Engine25519 down below
|
||||
|
||||
/*
|
||||
#[cfg(any(feature="precursor", feature="renode"))]
|
||||
pub use curve25519_dalek_hw::*;
|
||||
|
||||
#[cfg(not(target_os = "xous"))]
|
||||
pub use curve25519_dalek::*;
|
||||
*/
|
||||
|
||||
pub mod api;
|
||||
pub use api::*;
|
||||
use num_traits::*;
|
||||
use xous::{Message, CID};
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
static mut ENGINE_CB: Option<fn(JobResult)> = None;
|
||||
|
||||
#[doc = include_str!("../README.md")]
|
||||
pub struct Engine25519 {
|
||||
conn: CID,
|
||||
cb_sid: Option<[u32; 4]>,
|
||||
}
|
||||
impl Engine25519 {
|
||||
// this is used to set up a system with async callbacks
|
||||
pub fn new_async(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||
REFCOUNT.fetch_add(1, Ordering::Relaxed);
|
||||
let conn = xns
|
||||
.request_connection_blocking(api::SERVER_NAME_ENGINE25519)
|
||||
.expect("Can't connect to Engine25519 server");
|
||||
|
||||
let sid = xous::create_server().unwrap();
|
||||
let sid_tuple = sid.to_u32();
|
||||
xous::create_thread_4(
|
||||
engine_cb_server,
|
||||
sid_tuple.0 as usize,
|
||||
sid_tuple.1 as usize,
|
||||
sid_tuple.2 as usize,
|
||||
sid_tuple.3 as usize,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Ok(Engine25519 { conn, cb_sid: Some(sid.to_array()) })
|
||||
}
|
||||
|
||||
// typically, we just want synchronous callbacks. This integrates more nicely into single-threaded code.
|
||||
pub fn new() -> Self {
|
||||
REFCOUNT.fetch_add(1, Ordering::Relaxed);
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let conn = xns
|
||||
.request_connection_blocking(api::SERVER_NAME_ENGINE25519)
|
||||
.expect("Can't connect to Engine25519 server");
|
||||
|
||||
Engine25519 { conn, cb_sid: None }
|
||||
}
|
||||
|
||||
/// this is unsafe because the caller must make sure that within their process space, multiple threads
|
||||
/// are not spawing concurrent jobs; or, if they do, they all share a common result_callback method:
|
||||
/// we always blindly replace result_callback!
|
||||
pub unsafe fn spawn_async_job(
|
||||
&mut self,
|
||||
job: &mut Job,
|
||||
result_callback: fn(JobResult),
|
||||
) -> Result<bool, xous::Error> {
|
||||
if let Some(cb_sid) = self.cb_sid {
|
||||
ENGINE_CB = Some(result_callback); // this is the unsafe bit!
|
||||
job.id = Some(cb_sid);
|
||||
let mut buf = Buffer::into_buf(*job).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(self.conn, Opcode::RunJob.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
|
||||
match buf.to_original().unwrap() {
|
||||
JobResult::Started => Ok(true),
|
||||
_ => Ok(false),
|
||||
}
|
||||
} else {
|
||||
Err(xous::Error::InvalidSyscall)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn montgomery_job(&mut self, job: MontgomeryJob) -> Result<[u8; 32], xous::Error> {
|
||||
let mut buf = Buffer::into_buf(job).or(Err(xous::Error::OutOfMemory))?;
|
||||
match buf.lend_mut(self.conn, Opcode::MontgomeryJob.to_u32().unwrap()) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
if e == xous::Error::ServerNotFound {
|
||||
log::error!(
|
||||
"Looks like another thread called disconnect() on us while we weren't looking: {:?}",
|
||||
e
|
||||
);
|
||||
} else {
|
||||
log::error!("couldn't lend buffer: {:?}", e);
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
|
||||
match buf.to_original().unwrap() {
|
||||
JobResult::SingleResult(r) => Ok(r),
|
||||
JobResult::EngineUnavailable => {
|
||||
log::debug!("spawn job: engine unavailable");
|
||||
Err(xous::Error::ServerQueueFull)
|
||||
}
|
||||
JobResult::IllegalOpcodeException => {
|
||||
log::error!("spawn job: illegal opcode");
|
||||
Err(xous::Error::InvalidString)
|
||||
}
|
||||
_ => {
|
||||
log::error!("spawn job: other error");
|
||||
Err(xous::Error::UnknownError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// this is a blocking version of spawn_async_job.
|
||||
/// if the engine is free, it will block until a result is returned
|
||||
/// if the engine is busy, it will return an EngineUnavailable result.
|
||||
pub fn spawn_job(&mut self, job: Job) -> Result<[u32; RF_SIZE_IN_U32], xous::Error> {
|
||||
if job.id.is_some() {
|
||||
log::error!("spawn sync job: don't set a job id if you want a synchronous job!");
|
||||
return Err(xous::Error::InvalidSyscall); // the job.id should be None for a sync job. Do not set it to Some, even as a joke.
|
||||
}
|
||||
let mut buf = Buffer::into_buf(job).or(Err(xous::Error::OutOfMemory))?;
|
||||
match buf.lend_mut(self.conn, Opcode::RunJob.to_u32().unwrap()) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
if e == xous::Error::ServerNotFound {
|
||||
log::error!(
|
||||
"Looks like another thread called disconnect() on us while we weren't looking: {:?}",
|
||||
e
|
||||
);
|
||||
} else {
|
||||
log::error!("couldn't lend buffer: {:?}", e);
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
|
||||
match buf.to_original().unwrap() {
|
||||
JobResult::Result(rf) => Ok(rf),
|
||||
JobResult::EngineUnavailable => {
|
||||
log::debug!("spawn job: engine unavailable");
|
||||
Err(xous::Error::ServerQueueFull)
|
||||
}
|
||||
JobResult::IllegalOpcodeException => {
|
||||
log::error!("spawn job: illegal opcode");
|
||||
Err(xous::Error::InvalidString)
|
||||
}
|
||||
_ => {
|
||||
log::error!("spawn job: other error");
|
||||
Err(xous::Error::UnknownError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
impl Drop for Engine25519 {
|
||||
fn drop(&mut self) {
|
||||
// disconnect from the main server, only if there are no more instances active
|
||||
if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 {
|
||||
unsafe {
|
||||
xous::disconnect(self.conn).unwrap();
|
||||
}
|
||||
}
|
||||
// disconnect and destroy the callback server that is specific to this instance
|
||||
if let Some(cb_sid) = self.cb_sid {
|
||||
let cid = xous::connect(xous::SID::from_array(cb_sid)).unwrap();
|
||||
xous::send_message(cid, Message::new_scalar(Return::Quit.to_usize().unwrap(), 0, 0, 0, 0))
|
||||
.unwrap();
|
||||
unsafe {
|
||||
xous::disconnect(cid).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// handles callback messages from the engine server, in the library user's process space.
|
||||
fn engine_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Return::Result) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let job_result = buffer.to_original::<JobResult, _>().unwrap();
|
||||
unsafe {
|
||||
if let Some(cb) = ENGINE_CB {
|
||||
cb(job_result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Return::Quit) => {
|
||||
break; // this exits the loop and kills the thread
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
xous::destroy_server(sid).unwrap();
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -65,14 +65,15 @@ keyboard = { path = "../keyboard" }
|
|||
sha2 = { version = "0.10.8" }
|
||||
digest = "0.10.7"
|
||||
aes = { path = "../aes" }
|
||||
engine-25519 = { path = "../engine-25519" }
|
||||
byteorder = "1.4.3" # used by keywrap
|
||||
# engine-25519 = { path = "../engine-25519" }
|
||||
byteorder = "1.4.3" # used by keywrap
|
||||
# hardware acceleration adaptations are inserted into a fork of the main branch.
|
||||
hex = { version = "0.4.3", default-features = false, features = [] }
|
||||
|
||||
[dependencies.curve25519-dalek]
|
||||
version = "=4.1.1" # note this is patched to our fork in ./Cargo.toml
|
||||
version = "=4.1.2" # note this is patched to our fork in ./Cargo.toml
|
||||
default-features = false
|
||||
features = ["auto-release", "warn-fallback"]
|
||||
|
||||
[dependencies.ed25519-dalek]
|
||||
version = "2.1.0"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ sha2 = { version = "0.10.8" }
|
|||
digest = "0.10.7"
|
||||
aes = { path = "../aes" }
|
||||
cipher = "0.4.4"
|
||||
engine-25519 = { path = "../engine-25519" }
|
||||
spinor = { path = "../spinor" }
|
||||
root-keys = { path = "../root-keys" }
|
||||
jtag = { path = "../jtag" }
|
||||
|
|
@ -101,17 +100,18 @@ random-pick = { version = "1.2.16", optional = true }
|
|||
hex = { version = "0.4.3", default-features = false, features = [] }
|
||||
#sha2 = {version = "0.9.5", default-features = false, features = []}
|
||||
[dependencies.curve25519-dalek]
|
||||
version = "=4.1.1" # note this is patched to our fork in ./Cargo.toml
|
||||
version = "=4.1.2" # note this is patched to our fork in ./Cargo.toml
|
||||
default-features = false
|
||||
features = ["auto-release", "warn-fallback"]
|
||||
|
||||
[dependencies.x25519-dalek]
|
||||
version = "2.0.1"
|
||||
version = "=2.0.1"
|
||||
# TODO: static_secrets is only needed by the engine tests. Ideally, we would put the static_secrets version in dev deps only
|
||||
default-features = false
|
||||
features = ["static_secrets"]
|
||||
|
||||
[dependencies.ed25519-dalek]
|
||||
version = "2.1.0"
|
||||
version = "=2.1.0"
|
||||
#path = "../../../ed25519-dalek"
|
||||
default-features = false
|
||||
features = ["rand_core"]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
#[cfg(feature = "engine-ll")]
|
||||
use engine_25519::*;
|
||||
use num_traits::*;
|
||||
use xous_ipc::String;
|
||||
|
|
@ -38,7 +39,15 @@ fn vector_read(word_offset: usize) -> u32 {
|
|||
u32::from_le_bytes(bytes)
|
||||
}
|
||||
|
||||
fn run_vectors(engine: &mut Engine25519) -> (usize, usize) {
|
||||
fn run_vectors() -> (usize, usize) {
|
||||
use curve25519_dalek::backend::serial::u32e::*;
|
||||
while ensure_engine().is_err() {
|
||||
xous::yield_slice();
|
||||
}
|
||||
// safety: it's safe because it's after ensure_engine()
|
||||
let ucode_hw = unsafe { get_ucode() };
|
||||
let rf_hw = unsafe { get_rf() };
|
||||
|
||||
let mut test_offset: usize = 0x0;
|
||||
let mut passes: usize = 0;
|
||||
let mut fails: usize = 0;
|
||||
|
|
@ -58,17 +67,9 @@ fn run_vectors(engine: &mut Engine25519) -> (usize, usize) {
|
|||
let num_vectors = (vector_read(test_offset) >> 0) & 0x3F_FFFF;
|
||||
test_offset += 1;
|
||||
|
||||
let mut job = Job {
|
||||
id: None,
|
||||
uc_start: load_addr,
|
||||
uc_len: code_len,
|
||||
ucode: [0; 1024],
|
||||
rf: [0; RF_SIZE_IN_U32],
|
||||
window: Some(window as u8),
|
||||
};
|
||||
|
||||
for i in load_addr as usize..(load_addr + code_len) as usize {
|
||||
job.ucode[i] = vector_read(test_offset);
|
||||
let mut mcode = Vec::<i32>::new();
|
||||
for _i in load_addr as usize..(load_addr + code_len) as usize {
|
||||
mcode.push(vector_read(test_offset) as i32);
|
||||
test_offset += 1;
|
||||
}
|
||||
|
||||
|
|
@ -79,32 +80,20 @@ fn run_vectors(engine: &mut Engine25519) -> (usize, usize) {
|
|||
// a test suite can have numerous vectors against a common code base
|
||||
for argcnt in 0..num_args {
|
||||
for word in 0..8 {
|
||||
job.rf[(/* window * 32 * 8 + */argcnt * 8 + word) as usize] = vector_read(test_offset);
|
||||
rf_hw[(window * 32 * 8 + argcnt * 8 + word) as usize] = vector_read(test_offset);
|
||||
test_offset += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let mut passed = true;
|
||||
log::trace!("spawning job");
|
||||
match engine.spawn_job(job) {
|
||||
Ok(rf_result) => {
|
||||
for word in 0..8 {
|
||||
let expect = vector_read(test_offset);
|
||||
test_offset += 1;
|
||||
let actual = rf_result[(/* window * 32 * 8 + */31 * 8 + word) as usize];
|
||||
if expect != actual {
|
||||
log::error!("e/a {:08x}/{:08x}", expect, actual);
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
"system error {:?} in running test vector: {}/0x{:x}",
|
||||
e,
|
||||
vector,
|
||||
test_offset
|
||||
);
|
||||
run_job(ucode_hw, rf_hw, &mcode, window as usize);
|
||||
for word in 0..8 {
|
||||
let expect = vector_read(test_offset);
|
||||
test_offset += 1;
|
||||
let actual = rf_hw[(window * 32 * 8 + 31 * 8 + word) as usize];
|
||||
if expect != actual {
|
||||
log::error!("e/a {:08x}/{:08x}", expect, actual);
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -121,6 +110,7 @@ fn run_vectors(engine: &mut Engine25519) -> (usize, usize) {
|
|||
}
|
||||
}
|
||||
}
|
||||
curve25519_dalek::backend::serial::u32e::free_engine();
|
||||
(passes, fails)
|
||||
}
|
||||
/*
|
||||
|
|
@ -128,14 +118,16 @@ benchmark notes:
|
|||
|
||||
+59mA +/-1mA current draw off fully charged battery when running the benchmark
|
||||
1246-1261ms/check vector iteration (10 iters total, 1450 vectors total)
|
||||
|
||||
With new curve25519 api:
|
||||
53.6ms/check vector iteration (10 iters total, 1450 vectors total) with engine retained
|
||||
56.5ms/check with auto-free
|
||||
*/
|
||||
pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap();
|
||||
|
||||
let mut engine = engine_25519::Engine25519::new();
|
||||
|
||||
let mut trng = trng::Trng::new(&xns).unwrap();
|
||||
|
||||
loop {
|
||||
|
|
@ -146,7 +138,7 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|||
let mut passes = 0;
|
||||
let mut fails = 0;
|
||||
for _ in 0..TEST_ITERS {
|
||||
let (p, f) = run_vectors(&mut engine);
|
||||
let (p, f) = run_vectors();
|
||||
passes += p;
|
||||
fails += f;
|
||||
}
|
||||
|
|
@ -174,6 +166,9 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|||
13.54ms/2xop (200 iters -hw) -- microcode pre-loaded, minimal registers transferred using MontgomeryJob call
|
||||
12.2ms/2xop (200 iters -hw) -- with L2 cache on (128k)
|
||||
12.29ms/2xop (200 iters -hw) -- with L2 cache on (64k)
|
||||
|
||||
8.37ms/2xop (200 iters - hw) - with new curve25519 lib and engine retained after every loop
|
||||
33.04ms/2xop (200 iters - hw) - with new curve25519 lib and auto-free engine after every loop
|
||||
*/
|
||||
Some(BenchOp::StartDh) => {
|
||||
let mut passes = 0;
|
||||
|
|
@ -299,6 +294,7 @@ impl Engine {
|
|||
.unwrap();
|
||||
Engine {
|
||||
susres: susres::Susres::new_without_hook(&xns).unwrap(),
|
||||
// this is a dummy and hangs if engine-ll is not an active feature
|
||||
benchmark_cid: xous::connect(sid).unwrap(),
|
||||
start_time: None,
|
||||
}
|
||||
|
|
@ -317,16 +313,18 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
) -> Result<Option<String<1024>>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::<1024>::new();
|
||||
#[cfg(feature = "engine-ll")]
|
||||
let helpstring = "engine [check] [bench] [benchdh] [susres] [dh] [ed] [wycheproof]";
|
||||
#[cfg(not(feature = "engine-ll"))]
|
||||
let helpstring = "engine [susres] [dh] [ed] [wycheproof]";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"check" => {
|
||||
let mut engine = engine_25519::Engine25519::new();
|
||||
log::debug!("running vectors");
|
||||
let (passes, fails) = run_vectors(&mut engine);
|
||||
let (passes, fails) = run_vectors();
|
||||
|
||||
write!(ret, "Engine passed {} vectors, failed {} vectors", passes, fails).unwrap();
|
||||
}
|
||||
|
|
@ -364,13 +362,18 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
write!(ret, "Interrupted Engine hardware benchmark with a suspend/resume").unwrap();
|
||||
}
|
||||
"dh" => {
|
||||
log::info!("starting DH test");
|
||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||
let alice_secret = EphemeralSecret::random_from_rng(&mut env.trng);
|
||||
log::info!("1");
|
||||
let alice_public = PublicKey::from(&alice_secret);
|
||||
let bob_secret = EphemeralSecret::random_from_rng(&mut env.trng);
|
||||
let bob_public = PublicKey::from(&bob_secret);
|
||||
log::info!("2");
|
||||
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
||||
log::info!("3");
|
||||
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
||||
log::info!("4");
|
||||
let mut pass = true;
|
||||
for (&alice, &bob) in
|
||||
alice_shared_secret.as_bytes().iter().zip(bob_shared_secret.as_bytes().iter())
|
||||
|
|
@ -571,6 +574,8 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
} else {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
// de-allocate the engine at the end of the test, so other processes can grab it
|
||||
curve25519_dalek::backend::serial::u32e::free_engine();
|
||||
Ok(Some(ret))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
"root-keys",
|
||||
"trng",
|
||||
"sha2@0.10.8",
|
||||
"engine-25519",
|
||||
// "engine-25519",
|
||||
"jtag",
|
||||
// GUI front end
|
||||
"status",
|
||||
|
|
|
|||
Loading…
Reference in a new issue