The header scan (Captain Bob, 2026-11-10): 788 source files -- 351 with the
SL-1.0 header, 12 with the old name (docs/working/experiments, kept by
ruling), 31 under someone else's licence (tools/kconfig, Linux's, GPL-2.0:
kept), and 394 with none. Ruled: the SPDX form; capsules (.4th, .f18) and
proofs (.thy) left for a ruling of their own (mkcapsule's 64x16 block format,
content-addressed capsules).
253 files now begin
SPDX-License-Identifier: LicenseRef-Starship-1.0
Copyright (c) 2023-2026 Robert A. James
as a /* */ block (C, headers, assembly, linker scripts) or # lines (scripts,
Makefiles, Kconfig; below a shebang or a coding line); tools/mkcapsule.c,
which had the copyright line, gets the SPDX line only.
Not touched: docs/working/ (archive and old campaign material, as the
ruling kept the experiments); v4/system/post_cases.c (generated by
v4/tools/mkpost.py, "do not edit" -- the generator has the header).
Comments only: the kernel builds on amd64, aarch64, riscv64; make -C v4
test-32: 39 programs, 0 failures; every changed script parses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
69 lines
2.8 KiB
C
69 lines
2.8 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/*
|
|
* rng.h — Unified entropy entry point for StarKernel
|
|
*
|
|
* The single place any kernel consumer (keygen, identity mint, drive_uuid,
|
|
* certificate serials, ...) asks for entropy. All entropy flows through
|
|
* rng_get_bytes() and never touches a backend directly.
|
|
*
|
|
* The set of active backends is determined at rng_init() time by probing,
|
|
* in order, until one (or more) come up:
|
|
* - v2.0.0 (QEMU): virtio-rng is the sole backend — there is no virtio-rng
|
|
* on real hardware, but QEMU exposes it uniformly on all three arches
|
|
* (amd64/aarch64/riscv64), and the paravirtualized device sidesteps the
|
|
* per-ISA gap where no single CPU RNG covers all three models (amd64 has
|
|
* RDRAND, riscv64 has Zkr, but QEMU's aarch64 CPU models expose neither —
|
|
* see virtio_rng.h / vm_uuid.h for the identical finding).
|
|
* - v2.5.0 (real hardware): real per-arch backends are inserted here without
|
|
* touching the call path — amd64 RDRAND, riscv64 Zkr (RNDR), aarch64
|
|
* peripheral RNG — each handled by a case in rng_init() and rng_get_bytes()
|
|
* (grid §G.4). On QEMU all three arches stay on virtio-rng; nothing changes.
|
|
*
|
|
* Probe-and-refuse-loudly contract (§G.2): if no backend comes up at
|
|
* rng_init(), the kernel prints a loud boot-time message. A later
|
|
* rng_get_bytes() call with no backend returns -1 (RNG_ERR_NO_BACKEND) rather
|
|
* than ever silently degrading to a deterministic throwaway — the exact failure
|
|
* Phases A/G call out as unacceptable. Callers (e.g. capsule_mint_identity)
|
|
* must surface that refusal as an explicit no-entropy error, never proceed with
|
|
* a deterministic seed.
|
|
*
|
|
* Important ordering: rng_init() must run before any rng_get_bytes()/mint call
|
|
* (it already does in kernel_main phase 8, ahead of Zuse boot attach, which is
|
|
* the only mint path in v2.0.0). rng_get_bytes() with rng_init() never
|
|
* successful returns RNG_ERR_NO_BACKEND, never blocks.
|
|
*/
|
|
|
|
#ifndef STARKERNEL_RNG_H
|
|
#define STARKERNEL_RNG_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
/* Return codes (negative = failure). */
|
|
#define RNG_ERR_NO_BACKEND (-1) /* rng_init() found no working entropy source */
|
|
|
|
/*
|
|
* rng_init — probe and bring up the entropy backends. Returns 0 if at least
|
|
* one backend is active (rng_get_bytes() will succeed), nonzero otherwise.
|
|
* Prints a loud boot-time message when no backend comes up. Call once, early.
|
|
*/
|
|
int rng_init(void);
|
|
|
|
/*
|
|
* rng_ready — 1 if at least one backend is active, 0 otherwise.
|
|
*/
|
|
int rng_ready(void);
|
|
|
|
/*
|
|
* rng_get_bytes — fill buf with n bytes of real entropy, blocking until all
|
|
* n bytes are obtained.
|
|
*
|
|
* Returns 0 on success (buf fully filled).
|
|
* Returns RNG_ERR_NO_BACKEND (-1) if no backend is active.
|
|
*/
|
|
int rng_get_bytes(uint8_t *buf, size_t n);
|
|
|
|
#endif /* STARKERNEL_RNG_H */
|