interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / fabric / fab_loopback.h

92 lines · 3687 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * fab_loopback.h -- in-process loopback transport and HMAC authenticator for
19 * Fabric F5-0 (fabric.h). Test and simulation only.
20 *
21 * Transport: one FIFO mailbox per registered machine. Delivery order is send
22 * order, so a scenario replays bit for bit. Every send is folded into a
23 * transcript digest. Hooks let a test copy the last message, inject raw
24 * bytes (replay, forgery, misdelivery) and silence a machine.
25 *
26 * Authenticator: HMAC-SHA256 with one 32-byte key per machine, stretched to
27 * the 64-byte FAB_SIG_BYTES field (fab_hmac_sig64: two domain-separated
28 * HMAC-SHA256 halves). This is a
29 * stand-in: a verifier holding a symmetric key could also sign with it, so it
30 * proves only that the sender knew the key. The real transport replaces it
31 * with the machine's owner-key signature (TRUST-1) behind the same FabAuth.
32 */
33#ifndef FAB_LOOPBACK_H
34#define FAB_LOOPBACK_H
35
36/* Lane 32: test-build only. The production program (docs/r16-production-entry-point.md)
37 * never compiles this; the build refuses it without -DAIEN_TEST_BUILD=1. */
38#ifndef AIEN_TEST_BUILD
39#error "fab_loopback.h (Fabric loopback transport + HMAC stand-in authenticator) is test and simulation only: build with -DAIEN_TEST_BUILD=1, never in the production program"
40#endif
41
42#include "fabric.h"
43
44#define FAB_LOOP_NODES 8u
45#define FAB_LOOP_DEPTH 64u
46
47typedef struct {
48 uint32_t len;
49 uint8_t b[FAB_MSG_MAX];
50} FabLoopMsg;
51
52typedef struct {
53 AienMachineId id;
54 int silent; /* 1: messages it sends are dropped */
55 uint32_t head, count;
56 FabLoopMsg q[FAB_LOOP_DEPTH];
57} FabLoopBox;
58
59typedef struct {
60 uint32_t n;
61 FabLoopBox box[FAB_LOOP_NODES];
62 sha256_ctx transcript;
63 uint64_t sent, dropped;
64 FabLoopMsg last; /* copy of the last message sent (or dropped) */
65 FabTransport transport; /* points back at this loop */
66} FabLoop;
67
68void fab_loop_init(FabLoop *l);
69int fab_loop_add(FabLoop *l, const AienMachineId *id);
70void fab_loop_silence(FabLoop *l, const AienMachineId *id, int silent);
71/* Put raw bytes in `to`'s mailbox, bypassing the sender (attack hook). */
72int fab_loop_inject(FabLoop *l, const AienMachineId *to, const uint8_t *msg, size_t len);
73uint32_t fab_loop_pending(const FabLoop *l);
74void fab_loop_transcript(const FabLoop *l, uint8_t out[32]);
75
76typedef struct {
77 AienMachineId self;
78 uint8_t self_key[32];
79 uint32_t n;
80 const AienMachineId *ids;
81 const uint8_t (*keys)[32]; /* keys[i] belongs to ids[i] */
82 FabAuth auth; /* points back at this authenticator */
83} FabHmacAuth;
84
85/* Peer tables hold at most FAB_HMAC_MAX_PEERS entries; ids and keys must each
86 * have n elements. Returns FAB_OK, or FAB_E_ARG (nothing usable) when an
87 * argument is NULL or n is 0 or above the cap. */
88#define FAB_HMAC_MAX_PEERS 64
89int fab_hmac_auth_init(FabHmacAuth *a, const AienMachineId *self, const uint8_t self_key[32],
90 uint32_t n, const AienMachineId *ids, const uint8_t (*keys)[32]);
91
92#endif