mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
flesh out keystore api
This commit is contained in:
parent
87140a2024
commit
05720032cf
3 changed files with 67 additions and 3 deletions
|
|
@ -33,7 +33,10 @@ pub enum AesOpType {
|
||||||
#[zeroize(drop)]
|
#[zeroize(drop)]
|
||||||
pub struct AesOp {
|
pub struct AesOp {
|
||||||
/// the caller can try to request "any" index, but it's checked inside the oracle first.
|
/// the caller can try to request "any" index, but it's checked inside the oracle first.
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
pub key_index: u8,
|
pub key_index: u8,
|
||||||
|
#[cfg(feature = "gen2")]
|
||||||
|
pub domain: String,
|
||||||
pub block: AesBlockType,
|
pub block: AesBlockType,
|
||||||
pub aes_op: AesOpType,
|
pub aes_op: AesOpType,
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +68,7 @@ pub enum KeyWrapOp {
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
impl Error for KeywrapError {}
|
impl Error for KeywrapError {}
|
||||||
|
|
||||||
use std::fmt;
|
use std::{fmt, u64};
|
||||||
|
|
||||||
impl fmt::Display for KeywrapError {
|
impl fmt::Display for KeywrapError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
|
|
@ -91,7 +94,10 @@ pub struct KeyWrapper {
|
||||||
pub data: [u8; MAX_WRAP_DATA + 8],
|
pub data: [u8; MAX_WRAP_DATA + 8],
|
||||||
// used to specify the length of the data used in the fixed-length array above
|
// used to specify the length of the data used in the fixed-length array above
|
||||||
pub len: u32,
|
pub len: u32,
|
||||||
|
#[cfg(feature = "gen1")]
|
||||||
pub key_index: u8,
|
pub key_index: u8,
|
||||||
|
#[cfg(feature = "gen2")]
|
||||||
|
pub domain: String,
|
||||||
pub op: KeyWrapOp,
|
pub op: KeyWrapOp,
|
||||||
pub result: Option<KeywrapError>,
|
pub result: Option<KeywrapError>,
|
||||||
// used by the unwrap side
|
// used by the unwrap side
|
||||||
|
|
@ -140,3 +146,44 @@ impl DerefMut for Checksums {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub enum PasswordState {
|
||||||
|
/// Mounted successfully.
|
||||||
|
Correct,
|
||||||
|
/// User-initiated aborted. The main purpose for this path is to facilitate
|
||||||
|
/// developers who want shellchat access but don't want to mount the PDDB.
|
||||||
|
Incorrect(u64),
|
||||||
|
/// Abort initiated by system policy due to too many failed attempts
|
||||||
|
ForcedAbort(u64),
|
||||||
|
/// Failure because the PDDB hasn't been initialized yet (can't mount because nothing to mount)
|
||||||
|
Uninit,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(usize, usize, usize)> for PasswordState {
|
||||||
|
fn from(value: (usize, usize, usize)) -> Self {
|
||||||
|
let (arg1, arg2, arg3) = value;
|
||||||
|
match arg1 {
|
||||||
|
0 => PasswordState::Correct,
|
||||||
|
1 => PasswordState::Incorrect(arg2 as u64 | (arg3 as u64) << 32),
|
||||||
|
2 => PasswordState::ForcedAbort(arg2 as u64 | (arg3 as u64) << 32),
|
||||||
|
3 => PasswordState::Uninit,
|
||||||
|
_ => PasswordState::ForcedAbort(u64::MAX),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<(usize, usize, usize)> for PasswordState {
|
||||||
|
fn into(self) -> (usize, usize, usize) {
|
||||||
|
match self {
|
||||||
|
PasswordState::Correct => (0, 0, 0),
|
||||||
|
PasswordState::Incorrect(arg) => {
|
||||||
|
(1, (arg as usize) & 0xFFFF_FFFF, (arg >> 32) as usize & 0xFFFF_FFFF)
|
||||||
|
}
|
||||||
|
PasswordState::ForcedAbort(arg) => {
|
||||||
|
(2, (arg as usize) & 0xFFFF_FFFF, (arg >> 32) as usize & 0xFFFF_FFFF)
|
||||||
|
}
|
||||||
|
PasswordState::Uninit => (3, 0, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
pub const SERVER_NAME_KEYS: &str = "_Keystore server_";
|
||||||
|
|
||||||
/// Size of a checksummed block in pages. 0x100 = 256 pages,
|
/// Size of a checksummed block in pages. 0x100 = 256 pages,
|
||||||
/// or 1 MiB for a checksummed block. This is specified in 4kiB pages
|
/// or 1 MiB for a checksummed block. This is specified in 4kiB pages
|
||||||
/// because it really doesn't make sense to checksum anything smaller
|
/// because it really doesn't make sense to checksum anything smaller
|
||||||
|
|
@ -6,3 +8,18 @@
|
||||||
pub const CHECKSUM_BLOCKLEN_PAGE: u32 = 0x100;
|
pub const CHECKSUM_BLOCKLEN_PAGE: u32 = 0x100;
|
||||||
/// TODO: set PDDB length based on board-specific config params
|
/// TODO: set PDDB length based on board-specific config params
|
||||||
pub const TOTAL_CHECKSUMS: u32 = 4096 * 1024 / (CHECKSUM_BLOCKLEN_PAGE * 4096);
|
pub const TOTAL_CHECKSUMS: u32 = 4096 * 1024 / (CHECKSUM_BLOCKLEN_PAGE * 4096);
|
||||||
|
|
||||||
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||||
|
pub enum Opcode {
|
||||||
|
/// initiate an AES oracle operation
|
||||||
|
AesOracle = 4,
|
||||||
|
/// initiate key wrapper operation
|
||||||
|
AesKwp = 5,
|
||||||
|
/// clear a cached password
|
||||||
|
ClearPasswordCacheEntry = 7,
|
||||||
|
|
||||||
|
// Gen-2 extensions are at 256 and up
|
||||||
|
/// Get a non-secret 64-bit random identifier
|
||||||
|
GetDna = 256,
|
||||||
|
EnsurePassword = 257,
|
||||||
|
}
|
||||||
|
|
@ -5,9 +5,9 @@ pub mod rootkeys_api;
|
||||||
pub use rootkeys_api::*;
|
pub use rootkeys_api::*;
|
||||||
// gen2 API
|
// gen2 API
|
||||||
#[cfg(feature = "gen2")]
|
#[cfg(feature = "gen2")]
|
||||||
pub mod keystore_api;
|
pub mod gen2_api;
|
||||||
#[cfg(feature = "gen2")]
|
#[cfg(feature = "gen2")]
|
||||||
pub use keystore_api::*;
|
pub use gen2_api::*;
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub use common::*;
|
pub use common::*;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue