From df22ecd98905213c1c9353c2f6de4587ff898f39 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 8 Jun 2026 23:54:52 +0800 Subject: [PATCH] add apis for application keys --- libs/keystore-api/Cargo.toml | 2 ++ libs/keystore-api/src/gen2_api.rs | 6 ++++++ libs/keystore-api/src/rkyv_enum.rs | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/libs/keystore-api/Cargo.toml b/libs/keystore-api/Cargo.toml index 914035a6b..c0c242978 100644 --- a/libs/keystore-api/Cargo.toml +++ b/libs/keystore-api/Cargo.toml @@ -29,6 +29,8 @@ efuse = [] policy-menu = [] gen2 = [] +owc-inc = [] +app-keys = [] std = ["derive-rkyv", "xous-names", "xous-ipc", "locales"] derive-rkyv = ["rkyv"] diff --git a/libs/keystore-api/src/gen2_api.rs b/libs/keystore-api/src/gen2_api.rs index 10a125cba..40ac7c729 100644 --- a/libs/keystore-api/src/gen2_api.rs +++ b/libs/keystore-api/src/gen2_api.rs @@ -26,8 +26,13 @@ pub enum Opcode { SetFlags = 513, /// One way counter operations GetOneWayCounter = 768, + #[cfg(feature = "owc-inc")] IncOneWayCounter = 769, + /// Application key operations + #[cfg(feature = "app-keys")] + AppKeyOp = 1024, + // ----- below are non-cryptographic opcodes but used to manipulate sensitive state ----- /// Set bootwait parameters Bootwait = 4096, @@ -49,3 +54,4 @@ pub enum EphemeralOp { /// but for detecting fat-fingered API implementations. pub const OWC_MAGIC_GET: [usize; 3] = [0x2b46_2ab3, 0xf7e3_1b59, 0x7bba_d222]; pub const OWC_MAGIC_INC: [usize; 3] = [0xeb5d_fc81, 0x8b6d_6a90, 0xf720_491a]; +pub const APPKEY_GUARD: [u32; 4] = [0x3936_e7a6, 0xfc53_a1f7, 0xf2eb_16f3, 0xd2cc_22d9]; diff --git a/libs/keystore-api/src/rkyv_enum.rs b/libs/keystore-api/src/rkyv_enum.rs index 4368ee921..cbbc5bb4b 100644 --- a/libs/keystore-api/src/rkyv_enum.rs +++ b/libs/keystore-api/src/rkyv_enum.rs @@ -35,3 +35,21 @@ pub enum KeywrapError { /// The return tuple is: (unwrapped key, correctly wrapped key) UpgradeToNew(([u8; 32], [u8; 40])), } + +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq, Copy, Clone)] +pub enum AppKey { + // guard is a sequence of magic numbers that prevent fat-fingering this API + // it does not prevent malicious, directed attacks, but rather prevents accidents + Write { guard: [u32; 4], index: usize, data: [u8; 32] }, + ReadRequest { guard: [u32; 4], index: usize }, + ReadResponse { data: [u8; 32] }, + Uninit, + AccessDenied, + WriteError, + Success, + InternalError, +} + +impl Default for AppKey { + fn default() -> Self { Self::Uninit } +}