mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
Merge branch 'bunnie-dev' into main
This commit is contained in:
commit
4a3258f6bd
9 changed files with 245 additions and 44 deletions
75
Cargo.lock
generated
75
Cargo.lock
generated
|
|
@ -444,6 +444,15 @@ dependencies = [
|
|||
"volatile-register",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc"
|
||||
version = "1.8.1"
|
||||
|
|
@ -496,25 +505,13 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "639891fde0dbea823fc3d798a0fdf9d2f9440a42d64a78ab3488b0ca025117b3"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"digest",
|
||||
"rand_core 0.5.1",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "3.1.0"
|
||||
source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#6ee5e8aeb1e53bf76bacc9708656a8a1897cc027"
|
||||
source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#9ffc75dd3cccd93478521414f5e1298da4eb831e"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"digest",
|
||||
"engine-25519",
|
||||
"engine25519-as",
|
||||
"log",
|
||||
"rand_core 0.5.1",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
|
|
@ -535,6 +532,27 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
|
||||
|
||||
[[package]]
|
||||
name = "ed25519"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d0860415b12243916284c67a9be413e044ee6668247b99ba26d94b2bc06c8f6"
|
||||
dependencies = [
|
||||
"signature",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ed25519-dalek"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d"
|
||||
dependencies = [
|
||||
"curve25519-dalek",
|
||||
"ed25519",
|
||||
"sha2",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.5"
|
||||
|
|
@ -820,9 +838,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hex-literal"
|
||||
|
|
@ -1576,6 +1594,19 @@ version = "1.0.123"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"cfg-if 1.0.0",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shellchat"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1585,13 +1616,15 @@ dependencies = [
|
|||
"codec",
|
||||
"com",
|
||||
"content-plugin-api",
|
||||
"curve25519-dalek 3.1.0 (git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main)",
|
||||
"curve25519-dalek",
|
||||
"digest",
|
||||
"ed25519-dalek",
|
||||
"engine-25519",
|
||||
"engine-sha512",
|
||||
"gam",
|
||||
"graphics-server",
|
||||
"heapless 0.7.0",
|
||||
"hex",
|
||||
"ime-plugin-api",
|
||||
"ime-plugin-shell",
|
||||
"keyboard",
|
||||
|
|
@ -1619,6 +1652,12 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
|
||||
|
||||
[[package]]
|
||||
name = "signature"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f0242b8e50dd9accdd56170e94ca1ebd223b098eb9c83539a6e367d0f36ae68"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.6.1"
|
||||
|
|
@ -2046,7 +2085,7 @@ version = "1.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f"
|
||||
dependencies = [
|
||||
"curve25519-dalek 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"curve25519-dalek",
|
||||
"rand_core 0.5.1",
|
||||
"zeroize",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -90,6 +90,13 @@ lto = "fat"
|
|||
[patch.crates-io]
|
||||
xous = {path = "xous-rs"}
|
||||
xous-macros = {path = "macros"}
|
||||
# prefer hardware-accelerated versions of services
|
||||
sha2 = {path = "services/engine-sha512", package = "engine-sha512"}
|
||||
[patch.crates-io.curve25519-dalek]
|
||||
git="https://github.com/betrusted-io/curve25519-dalek.git"
|
||||
branch="main"
|
||||
default-features = false
|
||||
features = ["u32_backend", "betrusted"]
|
||||
|
||||
[patch."https://github.com/betrusted-io/xous-engine-25519.git"]
|
||||
engine-25519 = {path = "services/engine-25519"}
|
||||
|
|
@ -86,7 +86,7 @@ trng_server: Miscellaneous.BetrustedRNGServer @ sysbus 0xf001c000
|
|||
|
||||
// Physical base addresses of memory regions
|
||||
rom: Memory.MappedMemory @ sysbus 0x00000000
|
||||
size: 0x00008000
|
||||
size: 0x00001000
|
||||
|
||||
sram: Memory.MappedMemory @ sysbus 0x10000000
|
||||
size: 0x00020000
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
|
||||
<vendor>litex</vendor>
|
||||
<name>SOC</name>
|
||||
<description><![CDATA[Litex SoC 2021-06-11 15:52:54]]></description>
|
||||
<description><![CDATA[Litex SoC 2021-06-25 18:26:55]]></description>
|
||||
|
||||
<addressUnitBits>8</addressUnitBits>
|
||||
<width>32</width>
|
||||
|
|
@ -1222,10 +1222,10 @@ register to disable individual events.]]></description>
|
|||
<register>
|
||||
<name>GIT_GITREV</name>
|
||||
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
|
||||
``92629e91``, so this value is 2455936657, which should be enough to check out
|
||||
``fce2f15c``, so this value is 4242731356, which should be enough to check out
|
||||
the exact git version used to build this firmware.]]></description>
|
||||
<addressOffset>0x0014</addressOffset>
|
||||
<resetValue>0x92629e91</resetValue>
|
||||
<resetValue>0xfce2f15c</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -1242,7 +1242,7 @@ the exact git version used to build this firmware.]]></description>
|
|||
is ``1``, then the repository this was built from has one additional commit
|
||||
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
|
||||
<addressOffset>0x0018</addressOffset>
|
||||
<resetValue>0x16</resetValue>
|
||||
<resetValue>0x21</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -3451,7 +3451,7 @@ inject too fast.]]></description>
|
|||
<name>SEED1</name>
|
||||
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
|
||||
<addressOffset>0x0000</addressOffset>
|
||||
<resetValue>0x24a0246f</resetValue>
|
||||
<resetValue>0x199653c4</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -3466,7 +3466,7 @@ inject too fast.]]></description>
|
|||
<name>SEED0</name>
|
||||
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
|
||||
<addressOffset>0x0004</addressOffset>
|
||||
<resetValue>0x43f81cb4</resetValue>
|
||||
<resetValue>0x5a781786</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
|
|
@ -6406,10 +6406,25 @@ microcode instructions starting at mpstart]]></description>
|
|||
</fields>
|
||||
</register>
|
||||
<register>
|
||||
<name>POWER</name>
|
||||
<name>MPRESUME</name>
|
||||
<addressOffset>0x0010</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
<name>mpresume</name>
|
||||
<msb>9</msb>
|
||||
<bitRange>[9:0]</bitRange>
|
||||
<lsb>0</lsb>
|
||||
<description><![CDATA[Where to resume execution after a pause]]></description>
|
||||
</field>
|
||||
</fields>
|
||||
</register>
|
||||
<register>
|
||||
<name>POWER</name>
|
||||
<addressOffset>0x0014</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
<field>
|
||||
<name>on</name>
|
||||
|
|
@ -6417,13 +6432,23 @@ microcode instructions starting at mpstart]]></description>
|
|||
<bitRange>[0:0]</bitRange>
|
||||
<lsb>0</lsb>
|
||||
<description><![CDATA[Writing `1` turns on the clocks to this block, `0` stops the clocks (for power
|
||||
savings)]]></description>
|
||||
savings). The handling of the clock gate is in a different module, this is just
|
||||
a flag to that block.]]></description>
|
||||
</field>
|
||||
<field>
|
||||
<name>pause_req</name>
|
||||
<msb>1</msb>
|
||||
<bitRange>[1:1]</bitRange>
|
||||
<lsb>1</lsb>
|
||||
<description><![CDATA[Writing a `1` to this block will pause execution at the next micro-op, and allow
|
||||
for read-out of data from RF/microcode. Must check pause_gnt to confirm the
|
||||
pause has happened. Used to interrupt flow for suspend/resume.]]></description>
|
||||
</field>
|
||||
</fields>
|
||||
</register>
|
||||
<register>
|
||||
<name>STATUS</name>
|
||||
<addressOffset>0x0014</addressOffset>
|
||||
<addressOffset>0x0018</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
|
|
@ -6442,12 +6467,20 @@ microcode memory areas will stall until this bit is clear]]></description>
|
|||
<lsb>1</lsb>
|
||||
<description><![CDATA[Current location of the microcode program counter. Mostly for debug.]]></description>
|
||||
</field>
|
||||
<field>
|
||||
<name>pause_gnt</name>
|
||||
<msb>11</msb>
|
||||
<bitRange>[11:11]</bitRange>
|
||||
<lsb>11</lsb>
|
||||
<description><![CDATA[When set, the engine execution has been paused, and the RF & microcode ROM can
|
||||
be read out for suspend/resume]]></description>
|
||||
</field>
|
||||
</fields>
|
||||
</register>
|
||||
<register>
|
||||
<name>EV_STATUS</name>
|
||||
<description><![CDATA[Illegal opcode encountered]]></description>
|
||||
<addressOffset>0x0018</addressOffset>
|
||||
<addressOffset>0x001c</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
|
|
@ -6470,7 +6503,7 @@ microcode memory areas will stall until this bit is clear]]></description>
|
|||
<register>
|
||||
<name>EV_PENDING</name>
|
||||
<description><![CDATA[Illegal opcode encountered]]></description>
|
||||
<addressOffset>0x001c</addressOffset>
|
||||
<addressOffset>0x0020</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
|
|
@ -6493,7 +6526,7 @@ microcode memory areas will stall until this bit is clear]]></description>
|
|||
<register>
|
||||
<name>EV_ENABLE</name>
|
||||
<description><![CDATA[Illegal opcode encountered]]></description>
|
||||
<addressOffset>0x0020</addressOffset>
|
||||
<addressOffset>0x0024</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
|
|
@ -6517,7 +6550,7 @@ microcode memory areas will stall until this bit is clear]]></description>
|
|||
<name>INSTRUCTION</name>
|
||||
<description><![CDATA[Current instruction being executed by the engine. The format of this register
|
||||
exactly reflects the binary layout of an Engine instruction.]]></description>
|
||||
<addressOffset>0x0024</addressOffset>
|
||||
<addressOffset>0x0028</addressOffset>
|
||||
<resetValue>0x00</resetValue>
|
||||
<size>32</size>
|
||||
<fields>
|
||||
|
|
@ -6575,7 +6608,7 @@ exactly reflects the binary layout of an Engine instruction.]]></description>
|
|||
</registers>
|
||||
<addressBlock>
|
||||
<offset>0</offset>
|
||||
<size>0x28</size>
|
||||
<size>0x2c</size>
|
||||
<usage>registers</usage>
|
||||
</addressBlock>
|
||||
<interrupt>
|
||||
|
|
@ -6919,7 +6952,7 @@ of the PLL]]></description>
|
|||
<memoryRegion>
|
||||
<name>ROM</name>
|
||||
<baseAddress>0x00000000</baseAddress>
|
||||
<size>0x00008000</size>
|
||||
<size>0x0000000C</size>
|
||||
</memoryRegion>
|
||||
<memoryRegion>
|
||||
<name>SRAM</name>
|
||||
|
|
|
|||
|
|
@ -447,11 +447,16 @@ fn xmain() -> ! {
|
|||
xous::create_thread_1(susres_thread, (&mut engine25519) as *mut Engine25519Hw as usize).expect("couldn't start susres handler thread");
|
||||
|
||||
let mut client_cid: Option<xous::CID> = None;
|
||||
let mut job_count = 0;
|
||||
loop {
|
||||
let mut msg = xous::receive_message(engine25519_sid).unwrap();
|
||||
log::trace!("Message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::RunJob) => {
|
||||
if job_count % 100 == 0 {
|
||||
log::info!("engine job {}", job_count); // leave this here for now so we can confirm that HW acceleration is being selected when we think it is!
|
||||
}
|
||||
job_count += 1;
|
||||
// don't start a new job if a suspend is in progress
|
||||
while SUSPEND_IN_PROGRESS.load(Ordering::Relaxed) {
|
||||
log::trace!("waiting for suspend to finish");
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ impl Sha512 {
|
|||
FallbackStrategy::HardwareThenSoftware
|
||||
};
|
||||
Sha512 {
|
||||
use_soft: true,
|
||||
use_soft: false,
|
||||
strategy,
|
||||
engine: Engine512::new(&H512),
|
||||
in_progress: false,
|
||||
|
|
@ -344,7 +344,7 @@ impl Sha512Trunc256 {
|
|||
FallbackStrategy::HardwareThenSoftware
|
||||
};
|
||||
Sha512Trunc256 {
|
||||
use_soft: true,
|
||||
use_soft: false,
|
||||
strategy,
|
||||
engine: Engine512::new(&H512_TRUNC_256),
|
||||
in_progress: false,
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ fn xmain() -> ! {
|
|||
|
||||
let mut client_id: Option<[u32; 3]> = None;
|
||||
let mut mode: Option<Sha2Config> = None;
|
||||
|
||||
let mut job_count = 0;
|
||||
loop {
|
||||
let mut msg = xous::receive_message(engine512_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
|
|
@ -401,6 +401,10 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
Some(Opcode::Finalize) => {
|
||||
if job_count % 100 == 0 {
|
||||
log::info!("sha512 job {}", job_count); // leave this here for now so we can confirm HW accel is being used when we think it is!
|
||||
}
|
||||
job_count += 1;
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut finalized = buffer.to_original::<Sha2Finalize, _>().unwrap();
|
||||
match client_id {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ rkyv = {version = "0.4.3", default-features = false, features = ["const_generics
|
|||
# for the curve25519 tests
|
||||
# hardware acceleration adaptations are inserted into a fork of the main branch.
|
||||
rand_core = "0.5"
|
||||
hex = {version = "0.4.3", default-features = false, features = []}
|
||||
[dependencies.curve25519-dalek]
|
||||
git="https://github.com/betrusted-io/curve25519-dalek.git"
|
||||
branch="main"
|
||||
|
|
@ -51,6 +52,12 @@ version = "1.1.1"
|
|||
default-features = false
|
||||
features = ["u32_backend"]
|
||||
|
||||
[dependencies.ed25519-dalek]
|
||||
version = "1.0.1"
|
||||
#path = "../../../ed25519-dalek"
|
||||
default-features = false
|
||||
features = ["u32_backend"]
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = {path = "../../utralib"}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,15 +18,18 @@ pub static ENGINE_VECTORS: &[u8; 15652] = include_bytes!("engine25519_vectors.bi
|
|||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum BenchOp {
|
||||
StartEngine,
|
||||
StartDh,
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum BenchResult {
|
||||
EngineDone,
|
||||
DhDone,
|
||||
}
|
||||
|
||||
const TEST_ITERS: usize = 10;
|
||||
const TEST_ITERS_DH: usize = 200;
|
||||
|
||||
fn vector_read(word_offset: usize) -> u32 {
|
||||
let mut bytes: [u8; 4] = [0; 4];
|
||||
|
|
@ -125,6 +128,8 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|||
|
||||
let mut engine = engine_25519::Engine25519::new();
|
||||
|
||||
let mut trng = trng::Trng::new(&xns).unwrap();
|
||||
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
log::debug!("benchmark got msg {:?}", msg);
|
||||
|
|
@ -142,9 +147,47 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|||
xous::Message::new_scalar(CB_ID.load(Ordering::Relaxed) as usize,
|
||||
passes as usize,
|
||||
fails as usize,
|
||||
0, 0)
|
||||
BenchResult::EngineDone.to_usize().unwrap(), TEST_ITERS as usize)
|
||||
).unwrap();
|
||||
},
|
||||
/*
|
||||
2xop => each iteration has 2x DH ops in it (one for alice, one for bob)
|
||||
202ms/2xop (10 x 10 iters - sw)
|
||||
40.5ms/2xop (10 x 10 iters - hw)
|
||||
33ms/2xop (200 iters - hw)
|
||||
190ms/2xop (200 iters - sw)
|
||||
*/
|
||||
Some(BenchOp::StartDh) => {
|
||||
let mut passes = 0;
|
||||
let mut fails = 0;
|
||||
|
||||
use x25519_dalek::{StaticSecret, PublicKey};
|
||||
let alice_secret = StaticSecret::new(&mut trng);
|
||||
let alice_public = PublicKey::from(&alice_secret);
|
||||
let bob_secret = StaticSecret::new(&mut trng);
|
||||
let bob_public = PublicKey::from(&bob_secret);
|
||||
for _ in 0..TEST_ITERS_DH {
|
||||
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
||||
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
||||
let mut pass = true;
|
||||
for (&alice, &bob) in alice_shared_secret.as_bytes().iter().zip(bob_shared_secret.as_bytes().iter()) {
|
||||
if alice != bob {
|
||||
pass = false;
|
||||
}
|
||||
}
|
||||
if pass {
|
||||
passes += 2; // 2 diffie_hellman ops / iter
|
||||
} else {
|
||||
fails += 2;
|
||||
}
|
||||
}
|
||||
xous::send_message(callback_conn,
|
||||
xous::Message::new_scalar(CB_ID.load(Ordering::Relaxed) as usize,
|
||||
passes as usize,
|
||||
fails as usize,
|
||||
BenchResult::DhDone.to_usize().unwrap(), TEST_ITERS_DH as usize)
|
||||
).unwrap();
|
||||
}
|
||||
Some(BenchOp::Quit) => {
|
||||
log::info!("quitting benchmark thread");
|
||||
break;
|
||||
|
|
@ -186,7 +229,7 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::<1024>::new();
|
||||
let helpstring = "engine [check] [bench] [susres]";
|
||||
let helpstring = "engine [check] [bench] [benchdh] [susres] [dh] [ed]";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
|
|
@ -207,6 +250,14 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
).unwrap();
|
||||
write!(ret, "Starting Engine hardware benchmark with {} iters", TEST_ITERS).unwrap();
|
||||
}
|
||||
"benchdh" => {
|
||||
let start = env.ticktimer.elapsed_ms();
|
||||
self.start_time = Some(start);
|
||||
xous::send_message(self.benchmark_cid,
|
||||
xous::Message::new_scalar(BenchOp::StartDh.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).unwrap();
|
||||
write!(ret, "Starting DH hardware benchmark").unwrap();
|
||||
}
|
||||
"susres" => {
|
||||
let start = env.ticktimer.elapsed_ms();
|
||||
self.start_time = Some(start);
|
||||
|
|
@ -232,14 +283,59 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
pass = false;
|
||||
}
|
||||
}
|
||||
log::info!("alice: {:?}", alice_shared_secret.as_bytes());
|
||||
log::info!("bob: {:?}", bob_shared_secret.as_bytes());
|
||||
log::info!("alice: {:02x?}", alice_shared_secret.as_bytes());
|
||||
log::info!("bob: {:02x?}", bob_shared_secret.as_bytes());
|
||||
if pass {
|
||||
write!(ret, "x25519 key exchange pass").unwrap();
|
||||
} else {
|
||||
write!(ret, "x25519 key exchange fail").unwrap();
|
||||
}
|
||||
}
|
||||
"ed" => {
|
||||
use ed25519_dalek::*;
|
||||
use ed25519::signature::Signature as _;
|
||||
use hex::FromHex;
|
||||
let secret_key: &[u8] = b"833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42";
|
||||
let public_key: &[u8] = b"ec172b93ad5e563bf4932c70e1245034c35467ef2efd4d64ebf819683467e2bf";
|
||||
let message: &[u8] = b"616263";
|
||||
let signature: &[u8] = b"98a70222f0b8121aa9d30f813d683f809e462b469c7ff87639499bb94e6dae4131f85042463c2a355a2003d062adf5aaa10b8c61e636062aaad11c2a26083406";
|
||||
|
||||
let sec_bytes = <[u8; 32]>::from_hex(secret_key).unwrap();
|
||||
let pub_bytes = <[u8; 32]>::from_hex(public_key).unwrap();
|
||||
let msg_bytes = <[u8; 3]>::from_hex(message).unwrap();
|
||||
let sig_bytes = <[u8; 64]>::from_hex(signature).unwrap();
|
||||
|
||||
let secret: SecretKey = SecretKey::from_bytes(&sec_bytes[..SECRET_KEY_LENGTH]).unwrap();
|
||||
let public: PublicKey = PublicKey::from_bytes(&pub_bytes[..PUBLIC_KEY_LENGTH]).unwrap();
|
||||
let keypair: Keypair = Keypair{ secret: secret, public: public };
|
||||
let sig1: Signature = Signature::from_bytes(&sig_bytes[..]).unwrap();
|
||||
|
||||
let mut prehash_for_signing = engine_sha512::Sha512::default(); // this defaults to Hw then Sw strategy
|
||||
let mut prehash_for_verifying = engine_sha512::Sha512::default();
|
||||
|
||||
prehash_for_signing.update(&msg_bytes[..]);
|
||||
prehash_for_verifying.update(&msg_bytes[..]);
|
||||
|
||||
let sig2: Signature = keypair.sign_prehashed(prehash_for_signing, None).unwrap();
|
||||
|
||||
log::info!("original: {:02x?}", sig1);
|
||||
log::info!("produced: {:02x?}", sig2);
|
||||
let mut pass = true;
|
||||
if sig1 != sig2 {
|
||||
pass = false;
|
||||
write!(ret,
|
||||
"Original signature from test vectors doesn't equal signature produced:\
|
||||
\noriginal:\n{:?}\nproduced:\n{:?}", sig1, sig2).unwrap();
|
||||
}
|
||||
if keypair.verify_prehashed(prehash_for_verifying, None, &sig2).is_err() {
|
||||
pass = false;
|
||||
write!(ret,
|
||||
"Could not verify ed25519ph signature!").unwrap();
|
||||
}
|
||||
if pass {
|
||||
write!(ret, "Passed ed25519 simple check").unwrap();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
|
|
@ -257,10 +353,20 @@ impl<'a> ShellCmdApi<'a> for Engine {
|
|||
log::debug!("benchmark callback");
|
||||
let mut ret = String::<1024>::new();
|
||||
|
||||
xous::msg_scalar_unpack!(msg, passes, fails, _, _, {
|
||||
xous::msg_scalar_unpack!(msg, passes, fails, result_type, iters, {
|
||||
let end = env.ticktimer.elapsed_ms();
|
||||
let elapsed: f64 = ((end - self.start_time.unwrap()) as f64) / TEST_ITERS as f64;
|
||||
write!(ret, "{}ms/check_iter; In total, Engine passed {} vectors, failed {} vectors", elapsed, passes, fails).unwrap();
|
||||
let elapsed: f64 = ((end - self.start_time.unwrap()) as f64) / iters as f64;
|
||||
match FromPrimitive::from_usize(result_type) {
|
||||
Some(BenchResult::EngineDone) => {
|
||||
write!(ret, "{}ms/check_iter; In total, Engine passed {} vectors, failed {} vectors", elapsed, passes, fails).unwrap();
|
||||
},
|
||||
Some(BenchResult::DhDone) => {
|
||||
write!(ret, "{}ms/DH_iter; Passed {} ops, failed {} ops", elapsed, passes, fails).unwrap();
|
||||
},
|
||||
_ => {
|
||||
write!(ret, "Engine bench callback with unknown bench type").unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(Some(ret))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue