Skip to content

Commit

Permalink
Move api module and dependencies into trussed-core
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Oct 31, 2024
1 parent 0beb6ef commit 82d354e
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 410 deletions.
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ edition = "2021"
homepage = "https://trussed.dev"
license = "Apache-2.0 OR MIT"

[workspace.dependencies]
heapless = "0.7"
heapless-bytes = "0.3"
littlefs2-core = { version = "0.1", features = ["serde"] }
rand_core = "0.6"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[package]
name = "trussed"
version = "0.1.0"
Expand All @@ -29,12 +36,12 @@ cfg-if = "1.0"
embedded-hal = { version = "0.2.3", features = ["unproven"] }
flexiber = { version = "0.1.0", features = ["derive", "heapless"] }
generic-array = "0.14.4"
heapless = { version = "0.7", features = ["serde"] }
heapless = { workspace = true, features = ["serde"] }
hex-literal = "0.4.1"
nb = "1"
postcard = "0.7.0"
rand_core = "0.6"
serde = { version = "1.0", default-features = false }
rand_core.workspace = true
serde.workspace = true
zeroize = { version = "1.2", default-features = false, features = ["zeroize_derive"] }
rand_chacha = { version = "0.3.1", default-features = false }

Expand All @@ -53,13 +60,12 @@ sha2 = { version = "0.10", default-features = false }
cosey = "0.3"
delog = "0.1.0"
cbor-smol = { version = "0.5", features = ["heapless-bytes-v0-3"] }
heapless-bytes = { version = "0.3.0" }
heapless-bytes.workspace = true
interchange = "0.3.0"
littlefs2 = "0.5.0"
littlefs2-core = { version = "0.1", features = ["heapless-bytes03"] }
littlefs2-core = { workspace = true, features = ["heapless-bytes03"] }
p256-cortex-m4 = { version = "0.1.0-alpha.6", features = ["prehash", "sec1-signatures"] }
salty = { version = "0.3.0", features = ["cose"] }
serde-indexed = "0.1.0"
p384 = { version = "0.13.0", optional = true, default-features = false, features = ["sha384", "ecdh", "ecdsa"] }
p521 = { version = "0.13.3", optional = true, default-features = false, features = ["sha512", "ecdh", "ecdsa"] }
ecdsa = { version = "0.16.9", optional = true, default-features = false }
Expand Down
7 changes: 7 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ homepage.workspace = true
license.workspace = true

[dependencies]
heapless.workspace = true
heapless-bytes.workspace = true
littlefs2-core.workspace = true
rand_core.workspace = true
serde.workspace = true

serde-indexed = "0.1"

[features]
7 changes: 4 additions & 3 deletions src/api.rs → core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
//! [pkcs11-v3]: https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/pkcs11-base-v3.0.html
//! [pkcs11-headers]: https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/cs01/include/pkcs11-v3.0/
use core::time::Duration;

use crate::types::{
consent, reboot, Bytes, CertId, CounterId, DirEntry, KeyId, KeySerialization, Location,
Mechanism, MediumData, Message, PathBuf, SerializedKey, ShortData, Signature,
SignatureSerialization, StorageAttributes, UserAttribute,
};
use core::time::Duration;

#[macro_use]
mod macros;
Expand Down Expand Up @@ -143,11 +144,11 @@ generate_enums! {
SerdeExtension: 0x5E
}

pub trait RequestVariant: Into<Request> + TryFrom<Request, Error = crate::Error> {
pub trait RequestVariant: Into<Request> + TryFrom<Request, Error = crate::error::Error> {
type Reply: ReplyVariant<Request = Self>;
}

pub trait ReplyVariant: Into<Reply> + TryFrom<Reply, Error = crate::Error> {
pub trait ReplyVariant: Into<Reply> + TryFrom<Reply, Error = crate::error::Error> {
type Request: RequestVariant<Reply = Self>;
}

Expand Down
8 changes: 4 additions & 4 deletions src/api/macros.rs → core/src/api/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ macro_rules! impl_request {
}
}
impl core::convert::TryFrom<Request> for $request {
type Error = crate::Error;
type Error = crate::error::Error;
fn try_from(request: Request) -> Result<request::$request, Self::Error> {
match request {
Request::$request(request) => Ok(request),
_ => Err(crate::Error::InternalError),
_ => Err(Self::Error::InternalError),
}
}
}
Expand Down Expand Up @@ -118,11 +118,11 @@ macro_rules! impl_reply {

$(#[$attr])?
impl core::convert::TryFrom<Reply> for $reply {
type Error = crate::Error;
type Error = crate::error::Error;
fn try_from(reply: Reply) -> Result<reply::$reply, Self::Error> {
match reply {
Reply::$reply(reply) => Ok(reply),
_ => Err(crate::Error::InternalError),
_ => Err(Self::Error::InternalError),
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions core/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub const MAX_MESSAGE_LENGTH: usize = 1024;
pub const MAX_MEDIUM_DATA_LENGTH: usize = 256;
pub const MAX_SHORT_DATA_LENGTH: usize = 128;
pub const MAX_SIGNATURE_LENGTH: usize = 512 * 2;
// FIXME: Value from https://stackoverflow.com/questions/5403808/private-key-length-bytes for Rsa2048 Private key
pub const MAX_KEY_MATERIAL_LENGTH: usize = 1160 * 2 + 72;
pub const MAX_USER_ATTRIBUTE_LENGTH: usize = 256;

// request size is chosen to not exceed the largest standard syscall, Decrypt, so that the Request
// enum does not grow from this variant
pub const SERDE_EXTENSION_REQUEST_LENGTH: usize =
2 * MAX_MESSAGE_LENGTH + 2 * MAX_SHORT_DATA_LENGTH;
// reply size is chosen to not exceed the largest standard syscall, Encrypt, so that the Reply enum
// does not grow from this variant
pub const SERDE_EXTENSION_REPLY_LENGTH: usize = MAX_MESSAGE_LENGTH + 2 * MAX_SHORT_DATA_LENGTH;
File renamed without changes.
4 changes: 4 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
//!
//! [`trussed`]: https://docs.rs/trussed
pub mod api;
pub mod config;
pub mod error;
pub mod interrupt;
pub mod types;
Loading

0 comments on commit 82d354e

Please sign in to comment.