From 7208a86fdb00a7a15a6629f3e688f86087af806c Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 7 Nov 2021 05:17:34 +0800 Subject: [PATCH] rename aes-xous to aes, and change version number this allows us to patch AES for external crates, too, such as aes_gcm_siv --- Cargo.toml | 2 ++ services/aes/Cargo.toml | 6 +++--- services/root-keys/Cargo.toml | 4 ++-- services/root-keys/src/implementation.rs | 2 +- services/root-keys/src/implementation/oracle.rs | 2 +- services/shellchat/Cargo.toml | 2 +- services/shellchat/src/cmds.rs | 2 +- .../shellchat/src/cmds/{aes.rs => aes_cmd.rs} | 16 ++++++++-------- .../src/cmds/{aes => aes_cmd}/aes128tests.rs | 0 .../src/cmds/{aes => aes_cmd}/aes256tests.rs | 0 services/shellchat/src/cmds/keys.rs | 2 +- 11 files changed, 20 insertions(+), 18 deletions(-) rename services/shellchat/src/cmds/{aes.rs => aes_cmd.rs} (97%) rename services/shellchat/src/cmds/{aes => aes_cmd}/aes128tests.rs (100%) rename services/shellchat/src/cmds/{aes => aes_cmd}/aes256tests.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 12d289711..3bfbf0019 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,6 +116,8 @@ xous-macros = {path = "macros"} # prefer hardware-accelerated versions of services [patch.crates-io.sha2] path = "services/engine-sha512" +[patch.crates-io.aes] +path = "services/aes" [patch.crates-io.curve25519-dalek] git="https://github.com/betrusted-io/curve25519-dalek.git" diff --git a/services/aes/Cargo.toml b/services/aes/Cargo.toml index ebcad3094..badd19efb 100644 --- a/services/aes/Cargo.toml +++ b/services/aes/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "aes-xous" -version = "0.1.0" +name = "aes" +version = "0.7.5" authors = ["bunnie "] edition = "2018" description = "AES library for Xous" @@ -13,7 +13,7 @@ cipher = "0.3" ctr = { version = "0.7", optional = true } opaque-debug = "0.3" hex-literal = "0.2" -zeroize = "1.4.1" +zeroize = "1" [features] compact = [] # Reduce code size at the cost of slower performance diff --git a/services/root-keys/Cargo.toml b/services/root-keys/Cargo.toml index 6b9aac87e..763d6d7d2 100644 --- a/services/root-keys/Cargo.toml +++ b/services/root-keys/Cargo.toml @@ -22,7 +22,7 @@ xous-ipc = {path = "../../xous-ipc"} num-derive = {version = "0.3", default-features = false} num-traits = {version = "0.2", default-features = false} rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} -zeroize = "1.4.1" +zeroize = "1" # bcrypt cipher = "0.3" @@ -42,7 +42,7 @@ jtag = {path = "../jtag"} #sha2 = {version = "0.9.5", default-features = false, features = []} sha2 = {path = "../engine-sha512"} digest = "0.9" -aes-xous={path="../aes"} +aes={path="../aes"} engine-25519 = {path="../engine-25519"} # hardware acceleration adaptations are inserted into a fork of the main branch. rand_core = "0.5" diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index f0c13e892..d7803d406 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -23,7 +23,7 @@ use graphics_server::BulkRead; use core::mem::size_of; use core::cell::RefCell; -use aes_xous::{Aes256, NewBlockCipher, BlockDecrypt, BlockEncrypt}; +use aes::{Aes256, NewBlockCipher, BlockDecrypt, BlockEncrypt}; use cipher::generic_array::GenericArray; use crate::{SignatureResult, GatewareRegion, MetadataInFlash}; diff --git a/services/root-keys/src/implementation/oracle.rs b/services/root-keys/src/implementation/oracle.rs index b14efb188..6eb57d657 100644 --- a/services/root-keys/src/implementation/oracle.rs +++ b/services/root-keys/src/implementation/oracle.rs @@ -3,7 +3,7 @@ use crate::bitflip; use core::convert::TryInto; -use aes_xous::{Aes256, NewBlockCipher, BlockDecrypt, BlockEncrypt}; +use aes::{Aes256, NewBlockCipher, BlockDecrypt, BlockEncrypt}; use cipher::generic_array::GenericArray; #[derive(Debug, Copy, Clone)] diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml index 87003eff6..7ad5d6fbe 100644 --- a/services/shellchat/Cargo.toml +++ b/services/shellchat/Cargo.toml @@ -26,7 +26,7 @@ codec = {path = "../codec"} #engine-sha512 = {path="../engine-sha512"} sha2 = {path="../engine-sha512"} digest = "0.9" -aes-xous={path="../aes"} +aes={path="../aes"} cipher = "0.3" engine-25519 = {path="../engine-25519"} spinor = {path="../spinor"} diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index c3edfb4de..2d8b53608 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -91,7 +91,7 @@ mod backlight; use backlight::*; mod accel; use accel::*; mod sha; use sha::*; mod ecup; use ecup::*; -mod aes; use aes::*; +mod aes_cmd; use aes_cmd::*; mod trng_cmd; use trng_cmd::*; mod engine; use engine::*; mod console; use console::*; diff --git a/services/shellchat/src/cmds/aes.rs b/services/shellchat/src/cmds/aes_cmd.rs similarity index 97% rename from services/shellchat/src/cmds/aes.rs rename to services/shellchat/src/cmds/aes_cmd.rs index cd6e69d0f..8c4253f0a 100644 --- a/services/shellchat/src/cmds/aes.rs +++ b/services/shellchat/src/cmds/aes_cmd.rs @@ -103,7 +103,7 @@ macro_rules! block_cipher_test { use crate::{ShellCmdApi, CommonEnv}; use xous_ipc::String; -use aes_xous::*; +use aes::*; use cipher::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; use num_traits::*; @@ -179,14 +179,14 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { for _ in 0..TEST_ITERS { if hw_mode { - for mut chunk in dataset_op.chunks_exact_mut(aes_xous::BLOCK_SIZE) { + for mut chunk in dataset_op.chunks_exact_mut(aes::BLOCK_SIZE) { let mut block = GenericArray::clone_from_slice(&mut chunk); cipher_hw.encrypt_block(&mut block); for (&src, dst) in block.iter().zip(chunk.iter_mut()) { *dst = src; } } - for mut chunk in dataset_op.chunks_exact_mut(aes_xous::BLOCK_SIZE) { + for mut chunk in dataset_op.chunks_exact_mut(aes::BLOCK_SIZE) { let mut block = GenericArray::clone_from_slice(&mut chunk); cipher_hw.decrypt_block(&mut block); for (&src, dst) in block.iter().zip(chunk.iter_mut()) { @@ -194,14 +194,14 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { } } } else { - for mut chunk in dataset_op.chunks_exact_mut(aes_xous::BLOCK_SIZE) { + for mut chunk in dataset_op.chunks_exact_mut(aes::BLOCK_SIZE) { let mut block = GenericArray::clone_from_slice(&mut chunk); cipher_sw.encrypt_block(&mut block); for (&src, dst) in block.iter().zip(chunk.iter_mut()) { *dst = src; } } - for mut chunk in dataset_op.chunks_exact_mut(aes_xous::BLOCK_SIZE) { + for mut chunk in dataset_op.chunks_exact_mut(aes::BLOCK_SIZE) { let mut block = GenericArray::clone_from_slice(&mut chunk); cipher_sw.decrypt_block(&mut block); for (&src, dst) in block.iter().zip(chunk.iter_mut()) { @@ -293,7 +293,7 @@ impl<'a> ShellCmdApi<'a> for Aes { xous::send_message(self.benchmark_cid, xous::Message::new_scalar(BenchOp::StartAesHw.to_usize().unwrap(), 0, 0, 0, 0) ).unwrap(); - write!(ret, "Starting Aes hardware benchmark with {} iters of {} blocks", TEST_ITERS, TEST_MAX_LEN / aes_xous::BLOCK_SIZE).unwrap(); + write!(ret, "Starting Aes hardware benchmark with {} iters of {} blocks", TEST_ITERS, TEST_MAX_LEN / aes::BLOCK_SIZE).unwrap(); } "swbench" => { let start = env.ticktimer.elapsed_ms(); @@ -301,7 +301,7 @@ impl<'a> ShellCmdApi<'a> for Aes { xous::send_message(self.benchmark_cid, xous::Message::new_scalar(BenchOp::StartAesSw.to_usize().unwrap(), 0, 0, 0, 0) ).unwrap(); - write!(ret, "Starting Aes software benchmark with {} iters of {} blocks", TEST_ITERS, TEST_MAX_LEN / aes_xous::BLOCK_SIZE).unwrap(); + write!(ret, "Starting Aes software benchmark with {} iters of {} blocks", TEST_ITERS, TEST_MAX_LEN / aes::BLOCK_SIZE).unwrap(); } "susres" => { let start = env.ticktimer.elapsed_ms(); @@ -331,7 +331,7 @@ impl<'a> ShellCmdApi<'a> for Aes { xous::msg_scalar_unpack!(msg, pass, hw_mode, keybits, _, { let end = env.ticktimer.elapsed_ms(); - let elapsed: f64 = ((end - self.start_time.unwrap()) as f64) / (TEST_ITERS as f64 * (TEST_MAX_LEN / aes_xous::BLOCK_SIZE) as f64); + let elapsed: f64 = ((end - self.start_time.unwrap()) as f64) / (TEST_ITERS as f64 * (TEST_MAX_LEN / aes::BLOCK_SIZE) as f64); let modestr = if hw_mode != 0 { &"hw" } else { &"sw" }; if pass != 0 { write!(ret, "[{}] passed: {:.02}µs/block enc+dec AES{}", modestr, elapsed * 1000.0, keybits).unwrap(); diff --git a/services/shellchat/src/cmds/aes/aes128tests.rs b/services/shellchat/src/cmds/aes_cmd/aes128tests.rs similarity index 100% rename from services/shellchat/src/cmds/aes/aes128tests.rs rename to services/shellchat/src/cmds/aes_cmd/aes128tests.rs diff --git a/services/shellchat/src/cmds/aes/aes256tests.rs b/services/shellchat/src/cmds/aes_cmd/aes256tests.rs similarity index 100% rename from services/shellchat/src/cmds/aes/aes256tests.rs rename to services/shellchat/src/cmds/aes_cmd/aes256tests.rs diff --git a/services/shellchat/src/cmds/keys.rs b/services/shellchat/src/cmds/keys.rs index 19704688a..f5e81ab45 100644 --- a/services/shellchat/src/cmds/keys.rs +++ b/services/shellchat/src/cmds/keys.rs @@ -61,7 +61,7 @@ impl<'a> ShellCmdApi<'a> for Keys { write!(ret, "Provisioning BBRAM").unwrap(); } "aes" => { - use aes_xous::{BlockEncrypt, BlockDecrypt}; + use aes::{BlockEncrypt, BlockDecrypt}; let mut pass = true; let mut block = Block::clone_from_slice(&[0; 16]); self.rootkeys.encrypt_block(&mut block);