Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
94497b0
contrib: Add const sha256 implementation.
korran Feb 28, 2025
6a254a1
sha256: Remove unsafe.
korran Mar 1, 2025
22fb608
Make sha256 no_std :)
korran Mar 1, 2025
388310e
sha256_sw: Replace finalize_words() with finalize_words_le().
korran Mar 2, 2025
c8664e5
Make rust_lib() names consistent.
korran Mar 28, 2025
e21d267
Rename @crates repo to @crates_mutask.
korran Apr 23, 2025
0ecf042
Add aliases to third-party crates under third_party/.
korran Apr 23, 2025
0f491a6
Add "golden" library.
korran Jun 25, 2025
d5d10d9
golden: Support source files in subdirs.
korran Jun 30, 2025
a7cfc30
Add edition = "2024" to all crates.
korran Apr 10, 2026
b7ae04d
Add mutask_codegen_test() rule.
korran May 18, 2026
b2f5be7
Fix new clippy warnings.
korran Jun 22, 2026
1b7d936
TLV: Add library
ckungler Jun 29, 2026
7712c8f
Protobuf reader and reflection lib
ckungler Jun 29, 2026
df0d584
TLV: Protobuf to TLV
ckungler Jun 29, 2026
a0ea900
TLV codegen: Use #[no_std]
korran Jul 16, 2026
7ca58bc
Document the TLV format.
korran Jun 25, 2026
2752d7c
TLV codegen: Add extra_data support
ckungler Aug 14, 2026
596cf7f
Move U64Aligned to it's owm crate
mfield4 Aug 27, 2026
7db8d7c
TLV: Introduce TlvContainer type.
korran Sep 1, 2026
95aabc6
Make sha256() function usable at compile time.
korran Sep 3, 2026
f4a7e21
Add deps to TLV codegen
mfield4 Sep 4, 2026
7c56955
fix.sh: Add TLV regeneration
ckungler Sep 10, 2026
9761195
Crypto: Add TLV proto and generated structs
ckungler Sep 10, 2026
2e859db
KeyRotation: Add TLV proto and generated structs
ckungler Sep 10, 2026
42e612c
bazel: fix deprecated `$(location)` warning
rkr35 Sep 14, 2026
929fb8d
Key Rotation : Add fingerprint calculation for crypto types
mfield4 Aug 31, 2026
6e6f3f3
tlv: Add inline(always) strategically.
korran Sep 17, 2026
14452c0
Add add_copy() function to TlvBuilder.
korran Sep 16, 2026
c119568
tlv: Use Label() for mutask dependencies in tlv_codegen macro
paipeng-g Sep 30, 2026
e8ccd5b
openprot/proto: Add chipid.proto and generated chipid_tlv.rs
paipeng-g Oct 1, 2026
fdd2578
crypto: Decouple sha256_sw from mutask
mfield4 Oct 27, 2026
0618a88
tlv: Build in libhoth
mfield4 Oct 27, 2026
bdf2c21
Rename mutask crates and proto packages to openprot
mfield4 Oct 27, 2026
9bcd16c
Format the imported protos with clang-format
mfield4 Oct 27, 2026
67e89dc
Move TLV libraries to shared/
mfield4 Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
375 changes: 375 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions shared/aligned/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_rust//rust:defs.bzl", "rust_doc_test", "rust_library", "rust_test")

rust_library(
name = "aligned",
srcs = [
"lib.rs",
"u64.rs",
],
crate_features = [
"ufmt",
],
crate_name = "openprot_aligned",
edition = "2024",
visibility = ["//visibility:public"],
deps = [
"//third_party:ufmt",
"//third_party:zerocopy",
],
)

rust_test(
name = "aligned_test",
crate = ":aligned",
edition = "2024",
)

rust_doc_test(
name = "aligned_doctest",
crate = ":aligned",
)
19 changes: 19 additions & 0 deletions shared/aligned/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(test), no_std)]

mod u64;

pub use u64::U64Align4;
197 changes: 197 additions & 0 deletions shared/aligned/u64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use zerocopy::FromBytes;
use zerocopy::Immutable;
use zerocopy::IntoBytes;
use zerocopy::KnownLayout;

/// A 64-bit integer type that is represented as 2 32-bit words; useful
/// on 32-bit microcontrollers that can't efficiently read unaligned 32-bit
/// words.
#[derive(Clone, Copy, Default, Eq, PartialEq, FromBytes, IntoBytes, Immutable, KnownLayout)]
#[repr(C)]
pub struct U64Align4 {
pub low: u32,
pub high: u32,
}

impl U64Align4 {
pub const fn new(val: u64) -> Self {
Self {
low: val as u32,
high: (val >> 32) as u32,
}
}

pub const fn get(self) -> u64 {
self.low as u64 | ((self.high as u64) << 32)
}
}

impl From<U64Align4> for u64 {
fn from(value: U64Align4) -> Self {
value.get()
}
}

impl From<u64> for U64Align4 {
fn from(value: u64) -> Self {
Self::new(value)
}
}

impl core::fmt::Display for U64Align4 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Display::fmt(&u64::from(*self), f)
}
}

impl core::fmt::LowerHex for U64Align4 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::LowerHex::fmt(&u64::from(*self), f)
}
}

impl core::fmt::Debug for U64Align4 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(&u64::from(*self), f)
}
}

#[cfg(feature = "ufmt")]
impl ufmt::uDisplay for U64Align4 {
fn fmt<W: ufmt::uWrite + ?Sized>(
&self,
f: &mut ufmt::Formatter<'_, W>,
) -> Result<(), W::Error> {
ufmt::uDisplay::fmt(&u64::from(*self), f)
}
}

#[cfg(feature = "ufmt")]
impl ufmt::uDisplayHex for U64Align4 {
fn fmt_hex<W: ufmt::uWrite + ?Sized>(
&self,
f: &mut ufmt::Formatter<'_, W>,
options: ufmt::HexOptions,
) -> Result<(), W::Error> {
ufmt::uDisplayHex::fmt_hex(&u64::from(*self), f, options)
}
}

#[cfg(feature = "ufmt")]
impl ufmt::uDebug for U64Align4 {
fn fmt<W: ufmt::uWrite + ?Sized>(
&self,
f: &mut ufmt::Formatter<'_, W>,
) -> Result<(), W::Error> {
ufmt::uDebug::fmt(&u64::from(*self), f)
}
}

#[cfg(test)]
mod test {
#[cfg(feature = "ufmt")]
use ufmt::uwrite;

use super::*;

#[cfg(feature = "ufmt")]
struct Buffer<const N: usize> {
buf: [u8; N],
len: usize,
}

#[cfg(feature = "ufmt")]
impl<const N: usize> Buffer<N> {
fn new() -> Self {
Self {
buf: [0; N],
len: 0,
}
}
fn as_bytes(&self) -> &[u8] {
&self.buf[..self.len]
}
}

#[cfg(feature = "ufmt")]
impl<const N: usize> ufmt::uWrite for Buffer<N> {
type Error = ();
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
let bytes = s.as_bytes();
if self.len + bytes.len() > N {
return Err(());
}
self.buf[self.len..self.len + bytes.len()].copy_from_slice(bytes);
self.len += bytes.len();
Ok(())
}
}

#[test]
pub fn test_unaligned_u64() {
assert_eq!(
U64Align4::new(0xcd65_0941_8884_3461),
U64Align4 {
low: 0x8884_3461,
high: 0xcd65_0941,
}
);
assert_eq!(
U64Align4 {
low: 0x8884_3461,
high: 0xcd65_0941,
}
.get(),
0xcd65_0941_8884_3461
);
assert_eq!(
u64::from(U64Align4::new(0xabbc_3d97_ecfc_8aae)),
0xabbc_3d97_ecfc_8aae,
);
assert_eq!(
U64Align4::from(0xd172_0953_6a66_d89e),
U64Align4::new(0xd172_0953_6a66_d89e),
);
assert_eq!(
format!("{}", U64Align4::new(15092135555144013982)),
"15092135555144013982",
);
assert_eq!(
format!("{:?}", U64Align4::new(15092135555144013982)),
"15092135555144013982",
);
assert_eq!(
format!("{:x}", U64Align4::new(0xd17209536a66d89e)),
"d17209536a66d89e",
);

#[cfg(feature = "ufmt")]
{
let mut buf = Buffer::<32>::new();
uwrite!(&mut buf, "{}", U64Align4::new(15092135555144013982)).unwrap();
assert_eq!(buf.as_bytes(), b"15092135555144013982");

let mut buf = Buffer::<32>::new();
uwrite!(&mut buf, "{:?}", U64Align4::new(15092135555144013982)).unwrap();
assert_eq!(buf.as_bytes(), b"15092135555144013982");

let mut buf = Buffer::<32>::new();
uwrite!(&mut buf, "{:x}", U64Align4::new(15092135555144013982)).unwrap();
assert_eq!(buf.as_bytes(), b"d17209536a66d89e");
}
}
}
38 changes: 38 additions & 0 deletions shared/crypto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

rust_library(
name = "sha256_sw",
srcs = [
"sha256_sw.rs",
],
crate_name = "openprot_sha256_sw",
edition = "2024",
visibility = ["//visibility:public"],
deps = [
"//third_party:zerocopy",
],
)

rust_test(
name = "sha256_sw_test",
crate = ":sha256_sw",
edition = "2024",
rustc_flags = [
"-C",
"debug-assertions",
],
)
Loading
Loading