ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
tls.h File Reference

Deterministic TLS engine: mbedTLS over a static memory pool (PC_ENABLE_TLS). More...

#include "protocore_config.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Detailed Description

Deterministic TLS engine: mbedTLS over a static memory pool (PC_ENABLE_TLS).

Wraps mbedTLS as a server-side TLS layer that keeps the library's zero-heap guarantee: mbedTLS is pointed at a fixed BSS arena via MBEDTLS_MEMORY_BUFFER_ALLOC_C (no system heap), per-connection ssl_context lives in BSS, the RNG is the ESP32 hardware CSPRNG, and the transport BIO is bridged directly to the existing lwIP tcp_pcb + per-connection rx ring - so there is no socket layer and no extra task. The handshake is pumped from the single handle() loop.

ESP32/Arduino only - mbedTLS is not part of the native build. The header compiles everywhere (the functions are no-op stubs unless PC_ENABLE_TLS and ARDUINO are both set) so call sites need no extra guards.

Lifecycle per connection:

pc_tls_conn_begin(slot); // at accept on the TLS port
// each EvtType::EVT_DATA, until established:
int h = pc_tls_handshake(slot); // 1 done, 0 pending, <0 fatal
// once established, app data:
int n = pc_tls_read(slot, buf, sizeof buf); // >0 plaintext, 0 again, <0 closed
pc_tls_write(slot, data, len); // encrypts -> tcp_write
pc_tls_conn_end(slot); // close_notify + free slot ctx

Definition in file tls.h.