Skip to main content

tf_core_no_std/
lib.rs

1#![allow(clippy::doc_overindented_list_items)]
2//! `tf-core-no-std` — TrustForge embedded core (Phase K1).
3//!
4//! This crate is the no_std subset of `tf-types`, intended for
5//! microcontrollers (Cortex-M4F, RV32IMAC, ESP32-class) that cannot pull
6//! in the full std-only protocol surface. It re-implements just the
7//! bits a constrained device must do on its own:
8//!
9//! * `packet`        — sign / verify a packet-mode envelope (TF-0011).
10//! * `relay`         — verify a `RelayAuthority` so a relay can refuse
11//!                     to forward unauthorised frames offline.
12//! * `orl`           — load and consult an Offline Revocation List.
13//! * `nonce_cache`   — fixed-capacity replay-protected packet receiver.
14//!
15//! The crate is `#![no_std]`. With the default `alloc` feature it uses
16//! `BTreeMap` / `Vec` / `String`; with `--no-default-features` it falls
17//! back to `heapless` containers and is strictly no_alloc, so it links
18//! on bare-metal targets without an allocator.
19//!
20//! Canonicalisation note: the std side (`tf-types::packet`) hashes a
21//! canonical-JSON serialisation. Doing that without `alloc` would
22//! require a streaming canonical-JSON encoder, which the embedded
23//! profile does not need: in packet mode the wire format is CBOR. We
24//! therefore hash the CBOR-encoded packet (with the `signature` field
25//! zeroed) for the embedded path. The two derivations are not
26//! byte-compatible across modes; an embedded device verifies packets
27//! signed by another embedded device or by a host that uses this same
28//! crate. Cross-mode interop with the std `Packet` is intentionally
29//! out of scope for K1 and is the responsibility of a future bridge
30//! adaptor.
31
32#![no_std]
33#![cfg_attr(docsrs, feature(doc_cfg))]
34#![forbid(unsafe_code)]
35#![deny(missing_debug_implementations)]
36#![warn(rust_2018_idioms)]
37
38#[cfg(feature = "alloc")]
39extern crate alloc;
40
41pub mod nonce_cache;
42pub mod orl;
43pub mod packet;
44pub mod relay;
45
46/// Compact ed25519 public key (32 bytes).
47pub type PublicKeyBytes = [u8; 32];
48/// Compact ed25519 secret-key seed (32 bytes).
49pub type SecretSeedBytes = [u8; 32];
50/// Compact ed25519 signature (64 bytes).
51pub type SignatureBytes = [u8; 64];