|
cwist
Modern C web framework with libttak runtime
|
Hooks a bare-metal firmware supplies to CWIST (issue #447). More...
#include <stddef.h>#include <stdint.h>
Go to the source code of this file.
Functions | |
| int | cwist_port_entropy (void *buf, size_t len) |
| Fill a buffer with cryptographically secure random bytes. | |
| uint64_t | cwist_port_monotonic_ns (void) |
| Monotonic time since an arbitrary epoch (usually boot). | |
Hooks a bare-metal firmware supplies to CWIST (issue #447).
A CWIST_BAREMETAL build has no OS to ask for time or randomness, so the firmware defines the functions below (typically on top of SysTick/DWT and the RNG peripheral). They are plain link-time symbols with no default: leaving one out is a link error, never a silent fallback.
Everything else the core needs from the OS is either standard newlib (malloc via _sbrk, stdio via _write, time() via _gettimeofday) or provided by CWIST itself in src/sys/port/baremetal.c (single-threaded pthread, clock_gettime, nanosleep, 64-bit atomics for Cortex-M).
The bare-metal runtime is single-threaded: call into CWIST from one context only (the main loop or one RTOS task), never from an ISR.
Wall clock: CWIST reads it through time(). Without an RTC behind newlib's _gettimeofday, time() fails and responses carry no Date header, as RFC 9110 section 6.6.1 requires for servers without a clock.
Definition in file port.h.
Fill a buffer with cryptographically secure random bytes.
Seeds the hash-flooding defense (siphash) and generates session secrets and sequence-auth nonces. Back it with a hardware TRNG; a PRNG seeded from a constant or a timer makes those defenses guessable.
| buf | Destination buffer. |
| len | Number of bytes to write. |
Referenced by cwist_seq_auth_random().
Monotonic time since an arbitrary epoch (usually boot).
Backs clock_gettime(CLOCK_MONOTONIC), which drives timeouts, the GC and metrics. Must never go backwards; resolution of 1 ms or better.