mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
split low-level engine verification routines into a feature flag
to use these, one must include engine-25519 and also not use the curve25519-dalek native primitives. Probably what we *should* do is create some backend calls that allow us to queue up local jobs only for this sort of testing.
This commit is contained in:
parent
04abd3f331
commit
3bcc0dcd88
2 changed files with 27 additions and 4 deletions
|
|
@ -28,7 +28,7 @@ sha2 = { version = "0.10.8" }
|
||||||
digest = "0.10.7"
|
digest = "0.10.7"
|
||||||
aes = { path = "../aes" }
|
aes = { path = "../aes" }
|
||||||
cipher = "0.4.4"
|
cipher = "0.4.4"
|
||||||
engine-25519 = { path = "../engine-25519" }
|
engine-25519 = { path = "../engine-25519", optional = true }
|
||||||
spinor = { path = "../spinor" }
|
spinor = { path = "../spinor" }
|
||||||
root-keys = { path = "../root-keys" }
|
root-keys = { path = "../root-keys" }
|
||||||
jtag = { path = "../jtag" }
|
jtag = { path = "../jtag" }
|
||||||
|
|
@ -105,13 +105,13 @@ version = "=4.1.1" # note this is patched to our fork in ./Cargo.toml
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.x25519-dalek]
|
[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
|
# 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
|
default-features = false
|
||||||
features = ["static_secrets"]
|
features = ["static_secrets"]
|
||||||
|
|
||||||
[dependencies.ed25519-dalek]
|
[dependencies.ed25519-dalek]
|
||||||
version = "2.1.0"
|
version = "=2.1.0"
|
||||||
#path = "../../../ed25519-dalek"
|
#path = "../../../ed25519-dalek"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["rand_core"]
|
features = ["rand_core"]
|
||||||
|
|
@ -127,6 +127,7 @@ benchmarks = [
|
||||||
] # adds the benchmark routines. Left off normally to free up code and memory space.
|
] # adds the benchmark routines. Left off normally to free up code and memory space.
|
||||||
hashtest = []
|
hashtest = []
|
||||||
aestests = [] # adds AES tests
|
aestests = [] # adds AES tests
|
||||||
|
engine-ll = [] # low-level engine tests
|
||||||
tts = [] # adds text to speech plugin
|
tts = [] # adds text to speech plugin
|
||||||
pddbtest = ["rand_chacha"]
|
pddbtest = ["rand_chacha"]
|
||||||
autobasis = ["rand_chacha"]
|
autobasis = ["rand_chacha"]
|
||||||
|
|
@ -153,4 +154,4 @@ rand-api = []
|
||||||
locktests = [
|
locktests = [
|
||||||
] # for debugging some specific `std` tests cherry-picked out of the test suite
|
] # for debugging some specific `std` tests cherry-picked out of the test suite
|
||||||
simple-tls = ["rustls", "webpki-roots"]
|
simple-tls = ["rustls", "webpki-roots"]
|
||||||
default = [] # "debugprint"
|
default = ["benchmarks"] # "debugprint"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
use engine_25519::*;
|
use engine_25519::*;
|
||||||
use num_traits::*;
|
use num_traits::*;
|
||||||
use xous_ipc::String;
|
use xous_ipc::String;
|
||||||
|
|
@ -27,9 +28,12 @@ pub(crate) enum BenchResult {
|
||||||
DhDone,
|
DhDone,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
const TEST_ITERS: usize = 10;
|
const TEST_ITERS: usize = 10;
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
const TEST_ITERS_DH: usize = 200;
|
const TEST_ITERS_DH: usize = 200;
|
||||||
|
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
fn vector_read(word_offset: usize) -> u32 {
|
fn vector_read(word_offset: usize) -> u32 {
|
||||||
let mut bytes: [u8; 4] = [0; 4];
|
let mut bytes: [u8; 4] = [0; 4];
|
||||||
for i in 0..4 {
|
for i in 0..4 {
|
||||||
|
|
@ -38,6 +42,7 @@ fn vector_read(word_offset: usize) -> u32 {
|
||||||
u32::from_le_bytes(bytes)
|
u32::from_le_bytes(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
fn run_vectors(engine: &mut Engine25519) -> (usize, usize) {
|
fn run_vectors(engine: &mut Engine25519) -> (usize, usize) {
|
||||||
let mut test_offset: usize = 0x0;
|
let mut test_offset: usize = 0x0;
|
||||||
let mut passes: usize = 0;
|
let mut passes: usize = 0;
|
||||||
|
|
@ -129,6 +134,7 @@ benchmark notes:
|
||||||
+59mA +/-1mA current draw off fully charged battery when running the benchmark
|
+59mA +/-1mA current draw off fully charged battery when running the benchmark
|
||||||
1246-1261ms/check vector iteration (10 iters total, 1450 vectors total)
|
1246-1261ms/check vector iteration (10 iters total, 1450 vectors total)
|
||||||
*/
|
*/
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
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 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 xns = xous_names::XousNames::new().unwrap();
|
||||||
|
|
@ -284,11 +290,13 @@ pub struct Engine {
|
||||||
impl Engine {
|
impl Engine {
|
||||||
pub fn new(xns: &xous_names::XousNames, env: &mut CommonEnv) -> Self {
|
pub fn new(xns: &xous_names::XousNames, env: &mut CommonEnv) -> Self {
|
||||||
let sid = xous::create_server().unwrap();
|
let sid = xous::create_server().unwrap();
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
let sid_tuple = sid.to_u32();
|
let sid_tuple = sid.to_u32();
|
||||||
|
|
||||||
let cb_id = env.register_handler(String::<256>::from_str("engine"));
|
let cb_id = env.register_handler(String::<256>::from_str("engine"));
|
||||||
CB_ID.store(cb_id, Ordering::Relaxed);
|
CB_ID.store(cb_id, Ordering::Relaxed);
|
||||||
|
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
xous::create_thread_4(
|
xous::create_thread_4(
|
||||||
benchmark_thread,
|
benchmark_thread,
|
||||||
sid_tuple.0 as usize,
|
sid_tuple.0 as usize,
|
||||||
|
|
@ -299,6 +307,7 @@ impl Engine {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Engine {
|
Engine {
|
||||||
susres: susres::Susres::new_without_hook(&xns).unwrap(),
|
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(),
|
benchmark_cid: xous::connect(sid).unwrap(),
|
||||||
start_time: None,
|
start_time: None,
|
||||||
}
|
}
|
||||||
|
|
@ -317,12 +326,16 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
||||||
) -> Result<Option<String<1024>>, xous::Error> {
|
) -> Result<Option<String<1024>>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
let helpstring = "engine [check] [bench] [benchdh] [susres] [dh] [ed] [wycheproof]";
|
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(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
"check" => {
|
"check" => {
|
||||||
let mut engine = engine_25519::Engine25519::new();
|
let mut engine = engine_25519::Engine25519::new();
|
||||||
log::debug!("running vectors");
|
log::debug!("running vectors");
|
||||||
|
|
@ -330,6 +343,7 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
||||||
|
|
||||||
write!(ret, "Engine passed {} vectors, failed {} vectors", passes, fails).unwrap();
|
write!(ret, "Engine passed {} vectors, failed {} vectors", passes, fails).unwrap();
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
"bench" => {
|
"bench" => {
|
||||||
let start = env.ticktimer.elapsed_ms();
|
let start = env.ticktimer.elapsed_ms();
|
||||||
self.start_time = Some(start);
|
self.start_time = Some(start);
|
||||||
|
|
@ -340,6 +354,7 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
write!(ret, "Starting Engine hardware benchmark with {} iters", TEST_ITERS).unwrap();
|
write!(ret, "Starting Engine hardware benchmark with {} iters", TEST_ITERS).unwrap();
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "engine-ll")]
|
||||||
"benchdh" => {
|
"benchdh" => {
|
||||||
let start = env.ticktimer.elapsed_ms();
|
let start = env.ticktimer.elapsed_ms();
|
||||||
self.start_time = Some(start);
|
self.start_time = Some(start);
|
||||||
|
|
@ -364,13 +379,18 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
||||||
write!(ret, "Interrupted Engine hardware benchmark with a suspend/resume").unwrap();
|
write!(ret, "Interrupted Engine hardware benchmark with a suspend/resume").unwrap();
|
||||||
}
|
}
|
||||||
"dh" => {
|
"dh" => {
|
||||||
|
log::info!("starting DH test");
|
||||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||||
let alice_secret = EphemeralSecret::random_from_rng(&mut env.trng);
|
let alice_secret = EphemeralSecret::random_from_rng(&mut env.trng);
|
||||||
|
log::info!("1");
|
||||||
let alice_public = PublicKey::from(&alice_secret);
|
let alice_public = PublicKey::from(&alice_secret);
|
||||||
let bob_secret = EphemeralSecret::random_from_rng(&mut env.trng);
|
let bob_secret = EphemeralSecret::random_from_rng(&mut env.trng);
|
||||||
let bob_public = PublicKey::from(&bob_secret);
|
let bob_public = PublicKey::from(&bob_secret);
|
||||||
|
log::info!("2");
|
||||||
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
||||||
|
log::info!("3");
|
||||||
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
||||||
|
log::info!("4");
|
||||||
let mut pass = true;
|
let mut pass = true;
|
||||||
for (&alice, &bob) in
|
for (&alice, &bob) in
|
||||||
alice_shared_secret.as_bytes().iter().zip(bob_shared_secret.as_bytes().iter())
|
alice_shared_secret.as_bytes().iter().zip(bob_shared_secret.as_bytes().iter())
|
||||||
|
|
@ -571,6 +591,8 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
||||||
} else {
|
} else {
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
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))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue