diff --git a/Cargo.lock b/Cargo.lock index dd7ed64..81cd7fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,6 +122,16 @@ version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +[[package]] +name = "attest" +version = "0.1.0" +dependencies = [ + "hubpack", + "serde", + "serde_with", + "sha3", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -352,6 +362,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.27", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.27", +] + [[package]] name = "dbl" version = "0.3.2" @@ -581,6 +626,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda653ca797810c02f7ca4b804b40b8b95ae046eb989d356bce17919a8c25499" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "generic-array" version = "0.14.6" @@ -700,6 +751,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "inout" version = "0.1.3" @@ -1225,6 +1282,28 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "serialport" version = "4.2.1-alpha.0" diff --git a/Cargo.toml b/Cargo.toml index 63196f4..3e097bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ + "attest", "dice-cert-check", "dice-cert-tmpl", "dice-mfg", @@ -31,9 +32,10 @@ salty = { version = "0.3", default-features = false } serde = { version = "1", default-features = false } serde-big-array = "0.5" serde_json = { version = "1", features = ["std", "alloc"] } +serde_with = { version = "3.3", default-features = false } serialport = { git = "https://github.com/jgallagher/serialport-rs", branch = "illumos-support" } sha2 = "0.10" -sha3 = "0.10" +sha3 = { version = "0.10", default-features = false } string-error = "0.1" tempfile = { version = "3", default-features = false } thiserror = "1.0.50" diff --git a/attest/Cargo.toml b/attest/Cargo.toml new file mode 100644 index 0000000..0bbc174 --- /dev/null +++ b/attest/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "attest" +version = "0.1.0" +edition = "2021" + +[dependencies] +hubpack.workspace = true +serde = { workspace = true, features = ["derive"] } +serde_with = { workspace = true, features = ["macros"] } +sha3.workspace = true diff --git a/attest/src/lib.rs b/attest/src/lib.rs new file mode 100644 index 0000000..c4e762e --- /dev/null +++ b/attest/src/lib.rs @@ -0,0 +1,86 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#![cfg_attr(not(any(test, feature = "std")), no_std)] + +use hubpack::SerializedSize; +use serde::{Deserialize, Serialize}; +use serde_with::serde_as; +use sha3::{ + digest::{core_api::OutputSizeUser, typenum::Unsigned}, + Sha3_256Core, +}; + +/// ArrayBuf is the type we use as a base for types that are constant sized +/// byte buffers. +#[serde_as] +#[derive( + Clone, Copy, Debug, Deserialize, PartialEq, Serialize, SerializedSize, +)] +pub struct ArrayBuf(#[serde_as(as = "[_; N]")] pub [u8; N]); + +impl Default for ArrayBuf { + fn default() -> Self { + Self([0u8; N]) + } +} + +impl From<[u8; N]> for ArrayBuf { + fn from(item: [u8; N]) -> Self { + Self(item) + } +} + +pub const SHA3_256_DIGEST_SIZE: usize = + ::OutputSize::USIZE; + +pub type Sha3_256Digest = ArrayBuf; + +/// Measurement is an enum that can hold any of the hash algorithms that we support +#[derive( + Clone, Copy, Debug, Deserialize, PartialEq, Serialize, SerializedSize, +)] +pub enum Measurement { + Sha3_256(Sha3_256Digest), +} + +impl Default for Measurement { + fn default() -> Self { + Measurement::Sha3_256(Sha3_256Digest::default()) + } +} + +/// Log is the collection of measurements recorded +#[serde_as] +#[derive(Serialize, SerializedSize)] +pub struct Log { + index: u32, + #[serde_as(as = "[_; N]")] + measurements: [Measurement; N], +} + +impl Log { + pub fn is_full(&self) -> bool { + self.index as usize == N + } + + pub fn push(&mut self, measurement: Measurement) -> bool { + if !self.is_full() { + self.measurements[self.index as usize] = measurement; + self.index += 1; + true + } else { + false + } + } +} + +impl Default for Log { + fn default() -> Self { + Self { + index: 0, + measurements: [Measurement::default(); N], + } + } +}