prism_crypto/verbs.rs
1//! Layer-3 substrate-Term verbs per [Wiki ADR-024][09-adr-024] +
2//! [Wiki ADR-055][09-adr-055] + [Wiki ADR-056][09-adr-056].
3//!
4//! Per ADR-056 the ψ-residuals discipline applies only to the route
5//! body's syntactic surface; verb bodies admit the full substrate
6//! vocabulary including `hash(...)` axis invocations and `concat(...)`.
7//! This unblocks the canonical cryptographic compound verbs the wiki
8//! commits to per ADR-031: HMAC, HKDF, ECDSA, Merkle-tree construction.
9//!
10//! # Verbs shipped
11//!
12//! - [`merkle_reduce_pair`] — Merkle-tree internal-node reducer
13//! `H(left || right)` over a `partition_product(Digest32, Digest32)`
14//! input. Composes `hash(concat(input.0, input.1))`. This is the
15//! reducer that drives any Merkle-tree `tree_fold` composition.
16//! - [`hmac_inner_prep`] — HMAC inner-hash step
17//! `H(K_ipad || message)`. The full HMAC composition
18//! `H(K_opad || H(K_ipad || message))` chains two instances of this
19//! verb plus an outer key prep — the wiki names this as the
20//! canonical prism-crypto verb roster's HMAC realization per
21//! ADR-031.
22//!
23//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
24//! [09-adr-055]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
25//! [09-adr-056]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
26
27#![allow(missing_docs)]
28
29use uor_foundation_sdk::{partition_product, verb};
30
31use crate::Digest;
32
33/// 32-byte digest leaf (alias for the parametric `Digest<32>`).
34pub type Digest32 = Digest<32>;
35
36/// 64-byte block leaf for HMAC's keyed-prefix composition.
37pub type HmacBlock64 = Digest<64>;
38
39partition_product!(DigestPair32, Digest32, Digest32);
40
41verb! {
42 pub fn merkle_reduce_pair(input: DigestPair32) -> Digest32 {
43 hash(concat(input.0, input.1))
44 }
45}
46
47partition_product!(HmacInputs, HmacBlock64, HmacBlock64);
48
49verb! {
50 pub fn hmac_inner_prep(input: HmacInputs) -> Digest32 {
51 hash(concat(input.0, input.1))
52 }
53}