mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
fixup merge
This commit is contained in:
parent
bafa6c2d58
commit
a4c72cc9bb
5 changed files with 72 additions and 92 deletions
71
Cargo.lock
generated
71
Cargo.lock
generated
|
|
@ -89,6 +89,12 @@ version = "1.0.57"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
|
||||
|
||||
[[package]]
|
||||
name = "atomic-polyfill"
|
||||
version = "0.1.8"
|
||||
|
|
@ -379,6 +385,10 @@ dependencies = [
|
|||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cbor"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.73"
|
||||
|
|
@ -712,6 +722,18 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctap-crypto"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"cbor",
|
||||
"rand_core 0.5.1",
|
||||
"subtle",
|
||||
"trng",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctr"
|
||||
version = "0.7.0"
|
||||
|
|
@ -3513,7 +3535,7 @@ dependencies = [
|
|||
"susres",
|
||||
"ticktimer-server",
|
||||
"usb-device",
|
||||
"usbd-human-interface-device",
|
||||
"usbd-human-interface-device 0.1.1 (git+https://github.com/betrusted-io/usbd-human-interface-device.git?branch=main)",
|
||||
"utralib",
|
||||
"vcell",
|
||||
"xous",
|
||||
|
|
@ -3537,7 +3559,7 @@ dependencies = [
|
|||
"susres",
|
||||
"ticktimer-server",
|
||||
"usb-device",
|
||||
"usbd-human-interface-device",
|
||||
"usbd-human-interface-device 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utralib",
|
||||
"vcell",
|
||||
"xous",
|
||||
|
|
@ -3562,6 +3584,23 @@ dependencies = [
|
|||
"usb-device",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "usbd-human-interface-device"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/betrusted-io/usbd-human-interface-device.git?branch=main#744ab68464daf2f419b0149bc95ce41b01c7623d"
|
||||
dependencies = [
|
||||
"delegate",
|
||||
"embedded-time",
|
||||
"frunk",
|
||||
"hash32",
|
||||
"hash32-derive",
|
||||
"heapless",
|
||||
"log",
|
||||
"num_enum",
|
||||
"packed_struct",
|
||||
"usb-device",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utralib"
|
||||
version = "0.1.0"
|
||||
|
|
@ -3569,6 +3608,34 @@ dependencies = [
|
|||
"svd2utra",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vault"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"byteorder",
|
||||
"cbor",
|
||||
"content-plugin-api",
|
||||
"ctap-crypto",
|
||||
"gam",
|
||||
"graphics-server",
|
||||
"ime-plugin-api",
|
||||
"ime-plugin-shell",
|
||||
"locales",
|
||||
"log",
|
||||
"log-server",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"pddb",
|
||||
"subtle",
|
||||
"tts-frontend",
|
||||
"usb-device-xous",
|
||||
"usbd-human-interface-device 0.1.1 (git+https://github.com/betrusted-io/usbd-human-interface-device.git?branch=main)",
|
||||
"xous",
|
||||
"xous-ipc 0.9.7",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.3"
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ subtle = { version = "2.2.3", default-features = false}
|
|||
trng = {path = "../../../../services/trng"}
|
||||
xous-names = {path = "../../../../services/xous-names"}
|
||||
rand_core = "0.5.1"
|
||||
p256 = {version = "0.11.0", default-features = false, features = ["ecdsa", "ecdh", "std"]}
|
||||
#p256 = {version = "0.11.0", default-features = false, features = ["ecdsa", "ecdh", "std"]}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
<<<<<<< HEAD
|
||||
=======
|
||||
// Copyright 2019 Developers of the Rand project.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
|
|
@ -247,7 +245,6 @@ cfg_if! {
|
|||
}
|
||||
}
|
||||
|
||||
>>>>>>> main
|
||||
/// Fill `dest` with random bytes from the system's preferred random number
|
||||
/// source.
|
||||
///
|
||||
|
|
@ -261,93 +258,9 @@ cfg_if! {
|
|||
/// In general, `getrandom` will be fast enough for interactive usage, though
|
||||
/// significantly slower than a user-space CSPRNG; for the latter consider
|
||||
/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html).
|
||||
<<<<<<< HEAD
|
||||
|
||||
use std::atomic::AtomicU32;
|
||||
use std::atomic::Ordering::*;
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
static TRNG_CONN: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
struct TrngBuf {
|
||||
pub data: [u32; 1024],
|
||||
pub len: u16,
|
||||
}
|
||||
|
||||
fn ensure_trng_conn() {
|
||||
if TRNG_CONN.load(Ordering::SeqCst) == 0 {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
TRNG_CONN.store(
|
||||
xns
|
||||
.request_connection_blocking("_TRNG manager_")
|
||||
.expect("Can't connect to TRNG server")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> main
|
||||
pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
|
||||
if dest.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
ensure_trng_conn();
|
||||
fill_bytes(dest);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn fill_buf(data: &mut [u32]) {
|
||||
let mut tb = TrngBuf {
|
||||
data: [0; 1024],
|
||||
len: 0,
|
||||
};
|
||||
assert!(data.len() > tb.data.len());
|
||||
tb.len = data.len() as u16;
|
||||
let mut buf = Buffer::into_buf(tb).or(Err(xous::Error::InternalError)).unwrap();
|
||||
buf.lend_mut(TRNG_CONN.load(Ordering::SeqCst), api::Opcode::FillTrng.to_u32().unwrap()).unwrap();
|
||||
let rtb: TrngBuf = buf.as_flat().unwrap();
|
||||
assert!(rtb.len as usize == data.len());
|
||||
data.copy_from_slice(&rtb.data);
|
||||
}
|
||||
/// this is less efficient that the implementation in TRNG, but has fewer dependencies
|
||||
/// In particular, it will always use a memory message to fetch a TRNG value, even if it's just a u32 or u64
|
||||
fn fill_bytes(dest: &mut [u8]) {
|
||||
// big chunks handled here, using in-place transformations
|
||||
for chunk in dest.chunks_exact_mut(4096) {
|
||||
let chunk_u32 = unsafe {
|
||||
core::slice::from_raw_parts_mut(dest.as_mut_ptr() as *mut u32, chunk.len() / 4)
|
||||
};
|
||||
fill_buf(&chunk);
|
||||
}
|
||||
// smaller chunks, we absorb the fill_buf routine above here so we amortize the cost of
|
||||
// initializing the empty 4k-page...
|
||||
let remainder = dest.chunks_exact_mut(4096).into_remainder();
|
||||
if remainder.len() != 0 {
|
||||
let mut tb = TrngBuf {
|
||||
data: [0; 1024],
|
||||
len: 0,
|
||||
};
|
||||
tb.len = if remainder.len() % 4 == 0 {
|
||||
remainder.len() / 4
|
||||
} else {
|
||||
1 + (remainder.len() / 4)
|
||||
};
|
||||
let mut buf = Buffer::into_buf(tb).unwrap();
|
||||
buf.lend_mut(TRNG_CONN.load(Ordering::SeqCst), api::Opcode::FillTrng.to_u32().unwrap()).unwrap();
|
||||
let rtb: TrngBuf = buf.as_flat().unwrap();
|
||||
// copy the bulk
|
||||
dest.copy_from_slice(&tb.data[..remainder.len() / 4]);
|
||||
// handle the trailing odd bytes, if any
|
||||
if remainder.len() % 4 != 0 {
|
||||
let last_word = tb.data[remainder.len() / 4 .. 1 + remainder.len() / 4][0].to_le_bytes();
|
||||
for (&src, dst) in last_word.iter().zip(dest[remainder.len() / 4 .. remainder.len()].iter_mut()) {
|
||||
*dst = src;
|
||||
}
|
||||
}
|
||||
}
|
||||
=======
|
||||
imp::getrandom_inner(dest)
|
||||
>>>>>>> main
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ rand_core = { version = "0.5", default-features = false, optional = true }
|
|||
serde_crate = { package = "serde", version = "1.0", default-features = false, optional = true }
|
||||
serde_bytes = { version = "0.11", optional = true }
|
||||
sha2-loader = { path = "../sha2-loader", default-features = false }
|
||||
zeroize = { version = "1.5.5", default-features = false }
|
||||
zeroize = { version = "~1.3", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
hex = "^0.4"
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ aes = {path="../aes"}
|
|||
root-keys = {path="../root-keys"}
|
||||
cipher = "0.3.0"
|
||||
bitfield = "0.13.2"
|
||||
aes-gcm-siv = "0.11.0-pre" # necessary to break zeroize dependency deadlock on ecdsa crate
|
||||
aes-gcm-siv = "0.10.3" #"0.11.0-pre" # necessary to break zeroize dependency deadlock on ecdsa crate
|
||||
llio = {path="../llio"}
|
||||
subtle = {version = "2.4.1", default-features = false}
|
||||
tts-frontend = {path="../tts"}
|
||||
|
|
|
|||
Loading…
Reference in a new issue