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
omega-mv / src / runtime / rx_caller.h
| 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 | * rx_caller.h -- runtime-issued caller credentials (R16 clarification C5). |
| 19 | * |
| 20 | * A subject number (the principal a reaction or a promotion names) is a |
| 21 | * plain value any caller can write. On its own it proves nothing. A world |
| 22 | * that has bound its callers (rx_world_bind_callers) accepts a subject only |
| 23 | * together with the credential the runtime issued for it: |
| 24 | * |
| 25 | * - rx_world_enroll_caller mints one per subject, before the world is |
| 26 | * bound: a fresh 32-byte secret from getrandom(2) and a generation. |
| 27 | * The secret is handed back once, to the enroller. The world keeps only |
| 28 | * SHA-256(domain, subject, generation, secret), never the secret. |
| 29 | * - Every authority-bearing call checks it: reaction registration (and |
| 30 | * again at each activation and commit: the enrollment must still be |
| 31 | * live at the same generation), R9 proposal and promotion (a store bound |
| 32 | * with rx_gen_bind_authority). |
| 33 | * - Revocation (rx_world_revoke_caller, which needs the credential itself) |
| 34 | * retires the enrollment; the old credential never validates again. |
| 35 | * Enrollment closes when the world is bound, so a revoked subject stays |
| 36 | * revoked for that world's life. |
| 37 | * |
| 38 | * Generation 0 is never issued: an all-zero credential is "absent". |
| 39 | * The limit that remains is the process boundary: code in the same address |
| 40 | * space can read any memory, including a credential. R16-G3 shows the |
| 41 | * production binary does not link or execute legacy code at all. |
| 42 | */ |
| 43 | #ifndef RX_CALLER_H |
| 44 | #define RX_CALLER_H |
| 45 | |
| 46 | #include <stdint.h> |
| 47 | |
| 48 | #define RX_CALLER_SECRET_LEN 32u |
| 49 | #define RX_CALLER_MAX 64u |
| 50 | #define RX_CALLER_KEYRING_MAX 8u |
| 51 | |
| 52 | typedef struct { |
| 53 | uint64_t generation; /* 0: absent */ |
| 54 | uint8_t secret[RX_CALLER_SECRET_LEN]; |
| 55 | } RxCallerCred; |
| 56 | |
| 57 | /* Why a credential was refused (rx_world_check_caller). At the authority |
| 58 | * boundary every one of these is RX_ERR_IDENTITY (world) or |
| 59 | * RX_GEN_ERR_IDENTITY (R9). */ |
| 60 | #define RX_CALLER_OK 0 |
| 61 | #define RX_CALLER_ERR_ABSENT -1 /* no credential presented */ |
| 62 | #define RX_CALLER_ERR_UNKNOWN -2 /* subject never enrolled in this world */ |
| 63 | #define RX_CALLER_ERR_REVOKED -3 /* enrollment revoked */ |
| 64 | #define RX_CALLER_ERR_STALE -4 /* credential of another generation */ |
| 65 | #define RX_CALLER_ERR_FORGED -5 /* secret does not match this subject */ |
| 66 | #define RX_CALLER_ERR_CLOSED -6 /* enrollment closed (world bound) */ |
| 67 | #define RX_CALLER_ERR_EXISTS -7 /* subject already enrolled */ |
| 68 | #define RX_CALLER_ERR_ENTROPY -8 /* getrandom failed */ |
| 69 | #define RX_CALLER_ERR_FULL -9 /* enrollment table full (RX_CALLER_MAX) */ |
| 70 | #define RX_CALLER_ERR_HALTED -10 /* operator emergency stop in force (rx_world_caller_check_fn): |
| 71 | RX_GEN_ERR_HALTED at the R9 boundary, not an identity fault */ |
| 72 | |
| 73 | /* What a caller check does (RxGenCallerFn, rx_world_caller_check_fn). |
| 74 | * HOLD is the full check that, when it passes, keeps the enrollment table |
| 75 | * locked so no revocation can land until the matching RELEASE: the R9 |
| 76 | * store holds it across the durable flip of the active pointer (R16 C7). */ |
| 77 | #define RX_CALLER_OP_CHECK 0 |
| 78 | #define RX_CALLER_OP_HOLD 1 |
| 79 | #define RX_CALLER_OP_RELEASE 2 |
| 80 | |
| 81 | /* The credentials one component holds, looked up by subject when it |
| 82 | * registers a reaction or calls R9. Held by the component, never published |
| 83 | * into the world. */ |
| 84 | typedef struct { |
| 85 | uint32_t n; |
| 86 | uint32_t subject[RX_CALLER_KEYRING_MAX]; |
| 87 | RxCallerCred cred[RX_CALLER_KEYRING_MAX]; |
| 88 | } RxCallerKeyring; |
| 89 | |
| 90 | static inline const RxCallerCred *rx_caller_find(const RxCallerKeyring *k, uint32_t subject) { |
| 91 | if (!k) return 0; |
| 92 | for (uint32_t i = 0; i < k->n && i < RX_CALLER_KEYRING_MAX; i++) |
| 93 | if (k->subject[i] == subject) return &k->cred[i]; |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static inline void rx_caller_wipe(RxCallerCred *c) { |
| 98 | volatile uint8_t *p = (volatile uint8_t *)c; |
| 99 | for (unsigned i = 0; i < sizeof *c; i++) p[i] = 0; |
| 100 | } |
| 101 | |
| 102 | #endif |