Skip to content

eBPF-based security platform

testing: prove the config history of an evidence document

Daniel Borkmannb22631bc69c5
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index f227b2c7..4d4e6869 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -517,6 +517,53 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
``Shirudo.ConfigActivation`` does and refuses with ``EUCLEAN``;
``same_event()`` is the equality of TPM boot, sequence, PCR, kind,
initial value and root
+ * - ``config-evidence-event``
+ - ``on_event()``, ``append_event()`` of :src:`util/config_attest.c`
+ - Every event the JSON parser can hand over, into a history of 0, 1,
+ 15, 16, 128, 4095 and 4096 events, allocations allowed to fail
+ - Joins exactly when whole, with a positive sequence, a boot or
+ update kind and a root of 64 hex digits, below 4096 events, as the
+ values given; a refusal keeps the history as it was; room for
+ more than 4096 events is never asked for
+ * - ``config-evidence-parse``
+ - ``config_evidence_parse()``, ``config_evidence_clear()``
+ - Every value, or none, under each key of a config history of 0 to 2
+ events, cut or malformed at any point; ``json_parse()`` a model of
+ its contract, SHA-256 as any result
+ - Takes exactly a history with every key, schema 1, a PCR from 0 to
+ 15 but 9 and 11, 32-bit counts, 64 hex digits of initial value and
+ one boot event then updates in sequence, as said, and names one
+ out of order with ``EKEYREJECTED``; a refusal and evidence without
+ a history return nothing, with nothing left allocated
+ * - ``config-evidence-roundtrip``
+ - ``config_evidence_emit()``, ``emit_hash()`` into
+ ``config_evidence_parse()``
+ - Every view of 0 to 2 events; the JSON writer a model that records
+ each member under its key, ``json_parse()`` one that hands them to
+ the schema
+ - The parser returns every field the writer was given, exactly for a
+ view that replays; a sequence past a ``__s64`` is refused with
+ ``EOVERFLOW``; a view without a history writes nothing
+ * - ``config-evidence-verify``
+ - ``replay()``, ``config_evidence_verify()``,
+ ``config_measure_event()``
+ - Every view of 0 to 3 events, without events or past 4096 of them,
+ every quote mask, TPM boot, PCR value and expectation; SHA-256 as
+ any digest or failure
+ - Passes exactly when the PCR is one from 0 to 15 but 9 and 11,
+ quoted and the expected one, the TPM boot the quote's, the events
+ one boot event then updates in sequence, the quoted value the
+ initial one extended by each event's digest in order, and the last
+ root the expected one; a digest hashes the tag, the kind and the
+ root; a root without its PCR is refused
+ * - ``config-evidence-collect``
+ - ``config_evidence_collect()``, ``collect_event()``
+ - Every journal of 0 to 2 records and every active selection, the
+ journal's reader a stub that may fail; SHA-256 as any result
+ - Exports exactly the records of the selection's TPM boot, in order,
+ when they are on its PCR from its initial value, one boot event
+ then updates in sequence, and end at the selection; a refusal
+ returns nothing, with nothing left allocated
* - ``image-bootstrap``
- ``bootstrap_parse()`` with ``read_text_line()``
- One settings line of 0 to 8 bytes, failed reads and allocations,
@@ -798,12 +845,10 @@ a proof covers.
* - Files
- Why no proof reads them
* - :src:`util/bpm_state.c`, :src:`util/bpm_tree_overlap.c`,
- :src:`util/bpm_tree_state.c`, :src:`util/conditions.c`,
- :src:`util/config_attest.c`
+ :src:`util/bpm_tree_state.c`, :src:`util/conditions.c`
- No proof is written yet. A harness could carry their logic, in
whole or in part: the package state and tree state readers, which
- selectors of a tree can meet on one node, the status verdict and
- the config history of an evidence document
+ selectors of a tree can meet on one node and the status verdict
* - :src:`tools/shirudo-build/bpm-build.c`,
:src:`tools/shirudo-build/bpm-publish.c`,
:src:`tools/shirudo-build/package.c`,
@@ -863,8 +908,9 @@ does: how ``json_parse()`` dispatches objects, arrays and maps to their
schemas, the OTLP headers a configuration adds, the walk over a
package's tar members, the registry references and URLs, the kernel
configuration the tree selectors read, the tree log, the eventlog's
-lines, the evidence document beyond its PCRs, the config update record,
-the site configuration file and the config image's settings and tree.
+lines, the evidence document beyond its PCRs and its config history,
+the config update record, the site configuration file and the config
+image's settings and tree.
The ``.upatch`` reader, the TPM structures and the package, index and
tree readers are covered part by part, as the table shows; what joins
those parts has no proof.
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 598b9ccc..f82e0ea1 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1139,7 +1139,8 @@ document can carry a software key's signatures (U1).
:Tests: ``t4003``, ``t4004``, ``t4102``
:Proofs: ``tpm-reader``, ``tpm-attest``, ``tpm-signature``,
``tpm-public``, ``attest-pcr``, ``attest-fields``,
- ``attest-name-digest``, ``Shirudo.Chain``, ``Shirudo.Events``
+ ``attest-name-digest``, ``config-evidence-parse``,
+ ``config-evidence-verify``, ``Shirudo.Chain``, ``Shirudo.Events``
:Residual: R10, R11, U1, U9
.. _tm-t10:
diff --git a/testing/proofs/cbmc/config-evidence-collect.c b/testing/proofs/cbmc/config-evidence-collect.c
new file mode 100644
index 00000000..ddb1cdf6
--- /dev/null
+++ b/testing/proofs/cbmc/config-evidence-collect.c
@@ -0,0 +1,185 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * config_evidence_collect() and collect_event() of util/config_attest.c on
+ * every journal of LEN records and every active selection, the journal's
+ * reader a stub that hands them over and SHA-256 any result: a history is
+ * exported only as this TPM boot's records, in order and ending at the
+ * selection, and a refusal returns nothing and leaves nothing allocated.
+ */
+
+#include "proof.h"
+#include "../../../util/malloc.c"
+#include "../../../util/config_measure.c"
+/* The C converts a __s64 and cuts a __u64 to bytes on purpose. */
+#pragma CPROVER check push
+#pragma CPROVER check disable "conversion"
+#include "../../../util/chain.c"
+#pragma CPROVER check pop
+#include "../../../util/config_attest.c"
+
+static const struct config_update_record *journal, *selection;
+static int check_result, read_result;
+static __u8 last_digest[32];
+static bool hash_failed;
+
+static int any_result(void)
+{
+ int ret;
+
+ return ret;
+}
+
+int sha256_buffer(const void *data, size_t len, __u8 out[32])
+{
+ int ret = any_result();
+
+ __CPROVER_assert(__CPROVER_r_ok(data, len), "hashes only its input");
+ __CPROVER_assert(__CPROVER_w_ok(out, 32), "a digest's room");
+ __CPROVER_havoc_slice(out, 32);
+ memcpy(last_digest, out, 32);
+ if (ret)
+ hash_failed = true;
+ return ret;
+}
+
+int config_update_check(struct config_update *update,
+ struct config_update_record *out)
+{
+ if (!check_result)
+ *out = *selection;
+ return check_result;
+}
+
+int config_update_events(struct config_update *update,
+ shirudo_config_cb consume, void *ctx)
+{
+ size_t i;
+ int ret;
+
+ for (i = 0; i < LEN; i++) {
+ ret = consume(&journal[i], ctx);
+ if (ret)
+ return ret;
+ }
+ return read_result;
+}
+
+static bool same(const __u8 *a, const __u8 *b)
+{
+ size_t i;
+
+ for (i = 0; i < 32; i++)
+ if (a[i] != b[i])
+ return false;
+ return true;
+}
+
+static bool blank(const struct config_evidence *view)
+{
+ size_t i;
+
+ for (i = 0; i < 32; i++)
+ if (view->initial_pcr[i] || view->value[i])
+ return false;
+ return !view->events && !view->n_events && !view->capacity &&
+ !view->reset_count && !view->restart_count && !view->pcr &&
+ !view->present;
+}
+
+static bool this_boot(const struct config_update_record *record)
+{
+ return record->reset_count == selection->reset_count &&
+ record->restart_count == selection->restart_count;
+}
+
+/* On the selection's PCR, from its initial value, a sequence in a __s64. */
+static bool agrees(const struct config_update_record *record)
+{
+ return record->pcr == selection->pcr &&
+ record->sequence <= INT64_MAX &&
+ same(record->initial_pcr, selection->initial_pcr);
+}
+
+/*
+ * Whether this boot's records are one boot event, then updates in sequence,
+ * that end at the selection; *n counts them.
+ */
+static bool history(size_t *n)
+{
+ const struct config_update_record *last = NULL;
+ size_t i;
+
+ *n = 0;
+ for (i = 0; i < LEN; i++) {
+ if (!this_boot(&journal[i]))
+ continue;
+ if (!agrees(&journal[i]) || !journal[i].sequence ||
+ journal[i].kind != (last ? CONFIG_EVENT_UPDATE :
+ CONFIG_EVENT_BOOT) ||
+ (last && journal[i].sequence - last->sequence != 1))
+ return false;
+ last = &journal[i];
+ (*n)++;
+ }
+ return last && last->sequence == selection->sequence &&
+ same(last->target.root_hash, selection->target.root_hash);
+}
+
+static void check_exported(const struct config_evidence *view, size_t n)
+{
+ size_t i, at = 0;
+
+ __CPROVER_assert(view->present && view->pcr == selection->pcr &&
+ view->reset_count == selection->reset_count &&
+ view->restart_count == selection->restart_count &&
+ same(view->initial_pcr, selection->initial_pcr),
+ "the selection's PCR, TPM boot and initial value");
+ __CPROVER_assert(view->n_events == n && n <= view->capacity,
+ "this boot's records and no other, inside their room");
+ for (i = 0; i < LEN; i++) {
+ if (!this_boot(&journal[i]))
+ continue;
+ __CPROVER_assert(view->events[at].sequence ==
+ journal[i].sequence &&
+ view->events[at].kind == journal[i].kind &&
+ same(view->events[at].root_hash,
+ journal[i].target.root_hash),
+ "each as the journal has it, in its order");
+ at++;
+ }
+ __CPROVER_assert(same(view->value, last_digest),
+ "the value after the last event");
+}
+
+void harness(void)
+{
+ struct config_update update, *given = NULL;
+ struct config_evidence view;
+ bool attested, whole;
+ size_t n;
+ int ret;
+
+ journal = any_bytes(LEN * sizeof(*journal));
+ selection = any_bytes(sizeof(*selection));
+ check_result = any_result();
+ read_result = any_result();
+ if (attested)
+ given = &update;
+ ret = config_evidence_collect(given, &view);
+ if (!given) {
+ __CPROVER_assert(!ret && blank(&view),
+ "no config state exports no history");
+ return;
+ }
+ whole = history(&n);
+ __CPROVER_assert(!ret == (!check_result && !read_result && whole &&
+ !hash_failed),
+ "exports exactly a checked selection with its history whole");
+ if (ret)
+ __CPROVER_assert(blank(&view), "a refusal returns nothing");
+ else
+ check_exported(&view, n);
+ config_evidence_clear(&view);
+}
diff --git a/testing/proofs/cbmc/config-evidence-document.h b/testing/proofs/cbmc/config-evidence-document.h
new file mode 100644
index 00000000..ed8c2426
--- /dev/null
+++ b/testing/proofs/cbmc/config-evidence-document.h
@@ -0,0 +1,211 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * What a target's evidence says of its config history, key by key, for the
+ * harnesses that prove util/config_attest.c on LEN events: json_parse()
+ * hands it to a schema as util/json.h has it, whole or broken off at any
+ * point, and SHA-256 gives any result.
+ */
+
+#ifndef SHIRUDO_PROOF_CONFIG_EVIDENCE_DOCUMENT_H
+#define SHIRUDO_PROOF_CONFIG_EVIDENCE_DOCUMENT_H
+
+#define HEX_TEXT 65
+
+/* Not given, a key is absent or null. */
+struct said_number {
+ bool given;
+ __s64 value;
+};
+
+struct said_text {
+ bool given;
+ char text[HEX_TEXT];
+};
+
+struct said_event {
+ struct said_number sequence, kind;
+ struct said_text root_hash;
+};
+
+struct said_config {
+ bool config, events;
+ struct said_number schema, pcr, reset_count, restart_count;
+ struct said_text initial_pcr;
+ struct said_event event[LEN + 1];
+};
+
+static struct said_config said;
+static bool breaks, broken, hash_failed;
+static __u8 last_digest[32];
+
+int sha256_buffer(const void *data, size_t len, __u8 out[32])
+{
+ int ret;
+
+ __CPROVER_assert(__CPROVER_r_ok(data, len), "hashes only its input");
+ __CPROVER_assert(__CPROVER_w_ok(out, 32), "a digest's room");
+ __CPROVER_havoc_slice(out, 32);
+ memcpy(last_digest, out, 32);
+ if (ret)
+ hash_failed = true;
+ return ret;
+}
+
+/* Where breaks allows, the document is cut or malformed, with any error. */
+static int breaks_here(void)
+{
+ int err;
+
+ if (!breaks || !err)
+ return 0;
+ broken = true;
+ return err;
+}
+
+static struct json_field *named(struct json_field *fields, size_t n,
+ const char *key)
+{
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if (!strcmp(fields[i].key, key))
+ return &fields[i];
+ return NULL;
+}
+
+/* A key the schema does not declare is parsed and discarded. */
+static int give_number(struct json_field *field,
+ const struct said_number *number)
+{
+ if (!field || !number->given)
+ return 0;
+ if (field->type != JSON_T_INT)
+ return -EINVAL;
+ *(__s64 *)field->dst = number->value;
+ field->seen = 1;
+ return 0;
+}
+
+static int give_text(struct json_field *field, const struct said_text *text)
+{
+ char *dst;
+ size_t i;
+
+ if (!field || !text->given)
+ return 0;
+ if (field->type != JSON_T_STRING)
+ return -EINVAL;
+ dst = field->dst;
+ for (i = 0; i < field->dst_cap; i++) {
+ dst[i] = text->text[i];
+ if (!text->text[i]) {
+ field->seen = 1;
+ return 0;
+ }
+ }
+ return -ENOSPC;
+}
+
+static int give_event(struct json_field *fields, size_t n,
+ const struct said_event *event)
+{
+ size_t i;
+ int ret;
+
+ for (i = 0; i < n; i++)
+ fields[i].seen = 0;
+ ret = give_number(named(fields, n, "sequence"), &event->sequence);
+ if (!ret)
+ ret = give_number(named(fields, n, "kind"), &event->kind);
+ if (!ret)
+ ret = give_text(named(fields, n, "root_hash"),
+ &event->root_hash);
+ return ret;
+}
+
+/*
+ * json_parse() as util/json.h has it: each declared key takes its value
+ * once and is marked seen, null and an absent key leave it unseen, an array
+ * hands each element over with the seen flags of its fields reset, and the
+ * first error, the callback's included, ends the parse.
+ */
+int json_parse(const char *data, size_t len, struct json_field *fields,
+ size_t n_fields)
+{
+ struct json_field *config = named(fields, n_fields, "config");
+ struct json_field *sub, *events;
+ struct json_array *sink;
+ size_t n_sub, i;
+ int ret;
+
+ __CPROVER_assert(config && config->type == JSON_T_OBJECT,
+ "a schema for the config object");
+ sub = config->sub;
+ n_sub = config->n_sub;
+ events = named(sub, n_sub, "events");
+ __CPROVER_assert(events && events->type == JSON_T_ARRAY,
+ "with an array of events");
+ sink = events->dst;
+ config->seen = 0;
+ for (i = 0; i < n_sub; i++)
+ sub[i].seen = 0;
+ ret = breaks_here();
+ if (ret || !said.config)
+ return ret;
+ ret = give_number(named(sub, n_sub, "schema"), &said.schema);
+ if (!ret)
+ ret = give_number(named(sub, n_sub, "pcr"), &said.pcr);
+ if (!ret)
+ ret = give_number(named(sub, n_sub, "reset_count"),
+ &said.reset_count);
+ if (!ret)
+ ret = give_number(named(sub, n_sub, "restart_count"),
+ &said.restart_count);
+ if (!ret)
+ ret = give_text(named(sub, n_sub, "initial_pcr"),
+ &said.initial_pcr);
+ if (ret)
+ return ret;
+ for (i = 0; said.events && i < LEN; i++) {
+ ret = breaks_here();
+ if (!ret)
+ ret = give_event(events->sub, events->n_sub,
+ &said.event[i]);
+ if (!ret)
+ ret = sink->on_elem(sink->ctx);
+ if (ret)
+ return ret;
+ }
+ events->seen = said.events;
+ ret = breaks_here();
+ if (!ret)
+ config->seen = 1;
+ return ret;
+}
+
+static bool spells(const char *text, const __u8 *bytes)
+{
+ size_t i;
+
+ for (i = 0; i < 32; i++)
+ if (bytes[i] != hex_nibble(text[2 * i]) * 16 +
+ hex_nibble(text[2 * i + 1]))
+ return false;
+ return true;
+}
+
+static bool blank(const struct config_evidence *view)
+{
+ size_t i;
+
+ for (i = 0; i < 32; i++)
+ if (view->initial_pcr[i] || view->value[i])
+ return false;
+ return !view->events && !view->n_events && !view->capacity &&
+ !view->reset_count && !view->restart_count && !view->pcr &&
+ !view->present;
+}
+
+#endif /* SHIRUDO_PROOF_CONFIG_EVIDENCE_DOCUMENT_H */
diff --git a/testing/proofs/cbmc/config-evidence-event.c b/testing/proofs/cbmc/config-evidence-event.c
new file mode 100644
index 00000000..111498af
--- /dev/null
+++ b/testing/proofs/cbmc/config-evidence-event.c
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * on_event() and append_event() of util/config_attest.c, which take each
+ * event of a target's evidence, on every event the JSON parser can hand
+ * over and a history of LEN events: only a whole event with a positive
+ * sequence, a known kind and a root of 64 hex digits joins it, never past
+ * 4096 events, and a refusal leaves the history as it was.
+ */
+
+#include "proof.h"
+#include "../../../util/malloc.c"
+#include "../../../util/string.c"
+#include "../../../util/hex.c"
+#include "../../../util/config_attest.c"
+
+#define FIRST_ROOM 16
+#define LIMIT_BYTES (CONFIG_EVIDENCE_EVENTS_MAX * \
+ sizeof(struct config_evidence_event))
+
+/*
+ * The calloc() below util/malloc.c: room for more events than the limit
+ * is never asked for, and is not given, as CBMC cannot carry such a block.
+ */
+void *calloc(size_t nmemb, size_t size)
+{
+ bool fails;
+
+ __CPROVER_assert(nmemb == 1 && size <= LIMIT_BYTES,
+ "no room asked for past the limit");
+ if (fails || nmemb != 1 || size > LIMIT_BYTES)
+ return NULL;
+ return __CPROVER_allocate(size, 1);
+}
+
+/* The room append_event() has made by the time it holds n events. */
+static size_t room_for(size_t n)
+{
+ size_t room = n ? FIRST_ROOM : 0;
+
+ while (room < n)
+ room *= 2;
+ return room;
+}
+
+static bool hex_digits(const char *text, size_t n)
+{
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if (hex_nibble(text[i]) < 0)
+ return false;
+ return !text[n];
+}
+
+static bool same_event(const struct config_evidence_event *a,
+ const struct config_evidence_event *b)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(a->root_hash); i++)
+ if (a->root_hash[i] != b->root_hash[i])
+ return false;
+ return a->sequence == b->sequence && a->kind == b->kind;
+}
+
+void harness(void)
+{
+ struct config_evidence_event *events = NULL, earlier = {};
+ size_t room = room_for(LEN), at, i;
+ struct config_evidence view = {};
+ struct json_field fields[3];
+ struct config_parser parser;
+ bool whole, full;
+ int ret;
+
+ if (room)
+ events = any_bytes(room * sizeof(*events));
+ view.events = events;
+ view.n_events = LEN;
+ view.capacity = room;
+ parser.view = &view;
+ parser.event_fields = fields;
+ parser.n_fields = ARRAY_SIZE(fields);
+ /* json_parse() ends a string inside its dst_cap bytes. */
+ parser.root_hash[sizeof(parser.root_hash) - 1] = '\0';
+ /* CBMC cannot carry a read at any index of thousands of events. */
+ if (at >= LEN || room > FIRST_ROOM)
+ at = LEN ? LEN - 1 : 0;
+ if (LEN)
+ earlier = events[at];
+ whole = fields[0].seen && fields[1].seen && fields[2].seen &&
+ parser.sequence > 0 &&
+ (parser.kind == CONFIG_EVENT_BOOT ||
+ parser.kind == CONFIG_EVENT_UPDATE) &&
+ hex_digits(parser.root_hash, 64);
+ full = !(LEN < CONFIG_EVIDENCE_EVENTS_MAX);
+
+ ret = on_event(&parser);
+
+ __CPROVER_assert(view.n_events <= view.capacity &&
+ view.capacity <= CONFIG_EVIDENCE_EVENTS_MAX,
+ "never past its room or the limit");
+ __CPROVER_assert(!LEN || same_event(&view.events[at], &earlier),
+ "the events before it kept");
+ if (ret) {
+ __CPROVER_assert(ret == (!whole ? -EINVAL :
+ full ? -E2BIG : -ENOMEM),
+ "refuses a broken event, one past the limit or without memory");
+ __CPROVER_assert(ret != -ENOMEM || LEN == room,
+ "memory asked only when the room is full");
+ __CPROVER_assert(view.events == events &&
+ view.n_events == LEN && view.capacity == room,
+ "a refusal keeps the history as it was");
+ return;
+ }
+ __CPROVER_assert(whole && !full, "a whole event, below the limit");
+ __CPROVER_assert(view.n_events == LEN + 1 &&
+ view.events[LEN].sequence == (__u64)parser.sequence &&
+ (__s64)view.events[LEN].kind == parser.kind,
+ "joins with its sequence and kind");
+ for (i = 0; i < sizeof(earlier.root_hash); i++)
+ __CPROVER_assert(view.events[LEN].root_hash[i] ==
+ hex_nibble(parser.root_hash[2 * i]) * 16 +
+ hex_nibble(parser.root_hash[2 * i + 1]),
+ "and the root its digits spell");
+}
diff --git a/testing/proofs/cbmc/config-evidence-parse.c b/testing/proofs/cbmc/config-evidence-parse.c
new file mode 100644
index 00000000..97ca53ab
--- /dev/null
+++ b/testing/proofs/cbmc/config-evidence-parse.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * config_evidence_parse() of util/config_attest.c on everything a target's
+ * evidence can say of a config history of LEN events, key by key, whole or
+ * broken off, json_parse() modelled by its contract: it takes exactly a
+ * whole history in order, as said, and a refusal returns nothing and
+ * leaves nothing allocated.
+ */
+
+#include "proof.h"
+#include "../../../util/malloc.c"
+#include "../../../util/string.c"
+#include "../../../util/hex.c"
+#include "../../../util/config_measure.c"
+/* The C converts a __s64 and cuts a __u64 to bytes on purpose. */
+#pragma CPROVER check push
+#pragma CPROVER check disable "conversion"
+#include "../../../util/chain.c"
+#pragma CPROVER check pop
+#include "../../../util/config_attest.c"
+#include "config-evidence-document.h"
+
+static bool hex_digits(const char *text, size_t n)
+{
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ if (hex_nibble(text[i]) < 0)
+ return false;
+ return !text[n];
+}
+
+static bool count(const struct said_number *number)
+{
+ return number->given && number->value >= 0 &&
+ number->value <= UINT32_MAX;
+}
+
+/* Every key with a value of its kind, and an event or more. */
+static bool whole(void)
+{
+ size_t i;
+
+ if (!said.schema.given || said.schema.value != 1 ||
+ !said.pcr.given || said.pcr.value < 0 || said.pcr.value > 15 ||
+ said.pcr.value == CHAIN_PCR || said.pcr.value == CHAIN_PHASE_PCR ||
+ !count(&said.reset_count) || !count(&said.restart_count) ||
+ !said.initial_pcr.given ||
+ !hex_digits(said.initial_pcr.text, 64) || !said.events || !LEN)
+ return false;
+ for (i = 0; i < LEN; i++) {
+ const struct said_event *event = &said.event[i];
+
+ if (!event->sequence.given || event->sequence.value < 1 ||
+ !event->kind.given ||
+ (event->kind.value != CONFIG_EVENT_BOOT &&
+ event->kind.value != CONFIG_EVENT_UPDATE) ||
+ !event->root_hash.given ||
+ !hex_digits(event->root_hash.text, 64))
+ return false;
+ }
+ return true;
+}
+
+/* One boot event, then updates, each sequence number the one before plus 1. */
+static bool in_order(void)
+{
+ size_t i;
+
+ for (i = 0; i < LEN; i++) {
+ if (said.event[i].kind.value != (i ? CONFIG_EVENT_UPDATE :
+ CONFIG_EVENT_BOOT))
+ return false;
+ if (i && said.event[i].sequence.value - 1 !=
+ said.event[i - 1].sequence.value)
+ return false;
+ }
+ return true;
+}
+
+static void check_as_said(const struct config_evidence *view)
+{
+ size_t i;
+
+ __CPROVER_assert(view->present &&
+ view->pcr == said.pcr.value &&
+ view->reset_count == said.reset_count.value &&
+ view->restart_count == said.restart_count.value &&
+ spells(said.initial_pcr.text, view->initial_pcr),
+ "the PCR, the TPM boot and the initial value said");
+ __CPROVER_assert(view->n_events == LEN &&
+ view->n_events <= view->capacity,
+ "every event, inside its room");
+ for (i = 0; i < LEN; i++)
+ __CPROVER_assert(view->events[i].sequence ==
+ (__u64)said.event[i].sequence.value &&
+ (__s64)view->events[i].kind ==
+ said.event[i].kind.value &&
+ spells(said.event[i].root_hash.text,
+ view->events[i].root_hash),
+ "each event as said, in the order said");
+ for (i = 0; i < 32; i++)
+ __CPROVER_assert(view->value[i] == last_digest[i],
+ "the value after the last event");
+}
+
+/*
+ * A text ends within its 65 bytes: json_parse() refuses a longer one, which
+ * a document broken off there covers.
+ */
+static void any_document(void)
+{
+ struct said_config any;
+ size_t i;
+
+ said = any;
+ said.initial_pcr.text[HEX_TEXT - 1] = '\0';
+ for (i = 0; i < LEN; i++)
+ said.event[i].root_hash.text[HEX_TEXT - 1] = '\0';
+ breaks = true;
+}
+
+void harness(void)
+{
+ struct config_evidence view;
+ char text[1];
+ int ret;
+
+ any_document();
+ ret = config_evidence_parse(text, sizeof(text), &view);
+ if (ret || !said.config)
+ __CPROVER_assert(blank(&view),
+ "a refusal and evidence without a history return nothing");
+ else
+ check_as_said(&view);
+ if (!broken && !hash_failed) {
+ __CPROVER_assert(!ret == (!said.config ||
+ (whole() && in_order())),
+ "takes exactly a whole history in order");
+ __CPROVER_assert((ret == -EKEYREJECTED) ==
+ (said.config && whole() && !in_order()),
+ "and names one out of order as such");
+ }
+ config_evidence_clear(&view);
+ __CPROVER_assert(blank(&view), "cleared, it holds nothing");
+}
diff --git a/testing/proofs/cbmc/config-evidence-roundtrip.c b/testing/proofs/cbmc/config-evidence-roundtrip.c
new file mode 100644
index 00000000..1f51966d
--- /dev/null
+++ b/testing/proofs/cbmc/config-evidence-roundtrip.c
@@ -0,0 +1,219 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * config_evidence_emit() and config_evidence_parse() of
+ * util/config_attest.c on every view of LEN events, the JSON writer
+ * modelled as recording what is said under each key and json_parse() as
+ * handing that to the schema: the parser returns exactly the views a
+ * verifier can replay, with every field the writer was given.
+ */
+
+#include "proof.h"
+#include "../../../util/malloc.c"
+#include "../../../util/string.c"
+#include "../../../util/hex.c"
+#include "../../../util/config_measure.c"
+/* The C converts a __s64 and cuts a __u64 to bytes on purpose. */
+#pragma CPROVER check push
+#pragma CPROVER check disable "conversion"
+#include "../../../util/chain.c"
+#pragma CPROVER check pop
+#include "../../../util/config_attest.c"
+#include "config-evidence-document.h"
+
+enum { OUTSIDE, IN_CONFIG, IN_EVENTS, IN_EVENT };
+
+static int where;
+static size_t n_said;
+
+static struct said_number *number_at(const char *key)
+{
+ if (where == IN_CONFIG && !strcmp(key, "schema"))
+ return &said.schema;
+ if (where == IN_CONFIG && !strcmp(key, "pcr"))
+ return &said.pcr;
+ if (where == IN_CONFIG && !strcmp(key, "reset_count"))
+ return &said.reset_count;
+ if (where == IN_CONFIG && !strcmp(key, "restart_count"))
+ return &said.restart_count;
+ if (where == IN_EVENT && !strcmp(key, "sequence"))
+ return &said.event[n_said].sequence;
+ if (where == IN_EVENT && !strcmp(key, "kind"))
+ return &said.event[n_said].kind;
+ return NULL;
+}
+
+static struct said_text *text_at(const char *key)
+{
+ if (where == IN_CONFIG && !strcmp(key, "initial_pcr"))
+ return &said.initial_pcr;
+ if (where == IN_EVENT && !strcmp(key, "root_hash"))
+ return &said.event[n_said].root_hash;
+ return NULL;
+}
+
+/*
+ * The writer of util/json.h for the calls this document takes: a member
+ * goes under its key in the container open at the time, and any other call
+ * fails the proof.
+ */
+void json_kv_int(struct json_emit *e, const char *key, __s64 val)
+{
+ struct said_number *number = number_at(key);
+
+ __CPROVER_assert(number && !number->given,
+ "a number of the document, said once");
+ number->given = true;
+ number->value = val;
+}
+
+void json_kv_string(struct json_emit *e, const char *key, const char *val)
+{
+ struct said_text *text = text_at(key);
+ size_t i;
+
+ __CPROVER_assert(text && !text->given && strlen(val) < HEX_TEXT,
+ "a text of the document, said once");
+ text->given = true;
+ for (i = 0; i < HEX_TEXT; i++) {
+ text->text[i] = val[i];
+ if (!val[i])
+ break;
+ }
+}
+
+void json_obj_open_key(struct json_emit *e, const char *key)
+{
+ __CPROVER_assert(where == OUTSIDE && !said.config &&
+ !strcmp(key, "config"), "one config object");
+ said.config = true;
+ where = IN_CONFIG;
+}
+
+void json_arr_open(struct json_emit *e, const char *key)
+{
+ __CPROVER_assert(where == IN_CONFIG && !said.events &&
+ !strcmp(key, "events"), "one array of events in it");
+ said.events = true;
+ where = IN_EVENTS;
+}
+
+void json_obj_open(struct json_emit *e)
+{
+ __CPROVER_assert(where == IN_EVENTS && n_said < LEN,
+ "an event in the array");
+ where = IN_EVENT;
+}
+
+void json_obj_close(struct json_emit *e)
+{
+ __CPROVER_assert(where == IN_EVENT || where == IN_CONFIG,
+ "closes the object it opened");
+ if (where == IN_EVENT)
+ n_said++;
+ where = where == IN_EVENT ? IN_EVENTS : OUTSIDE;
+}
+
+void json_arr_close(struct json_emit *e)
+{
+ __CPROVER_assert(where == IN_EVENTS, "closes the array it opened");
+ where = IN_CONFIG;
+}
+
+static bool same(const __u8 *a, const __u8 *b)
+{
+ size_t i;
+
+ for (i = 0; i < 32; i++)
+ if (a[i] != b[i])
+ return false;
+ return true;
+}
+
+/* What replay() takes: a config PCR and one boot event, then updates. */
+static bool replays(const struct config_evidence *view)
+{
+ const struct config_evidence_event *event = view->events;
+ size_t i;
+
+ if (view->pcr > 15 || view->pcr == CHAIN_PCR ||
+ view->pcr == CHAIN_PHASE_PCR || !LEN)
+ return false;
+ for (i = 0; i < LEN; i++) {
+ if (event[i].kind != (i ? CONFIG_EVENT_UPDATE :
+ CONFIG_EVENT_BOOT))
+ return false;
+ if (event[i].sequence < 1 || event[i].sequence > INT64_MAX)
+ return false;
+ if (i && event[i].sequence - event[i - 1].sequence != 1)
+ return false;
+ }
+ return true;
+}
+
+static bool sequence_overflows(const struct config_evidence *view)
+{
+ size_t i;
+
+ for (i = 0; i < LEN; i++)
+ if (view->events[i].sequence > INT64_MAX)
+ return true;
+ return false;
+}
+
+static void check_read_back(const struct config_evidence *view,
+ const struct config_evidence *back)
+{
+ size_t i;
+
+ __CPROVER_assert(back->present && back->pcr == view->pcr &&
+ back->reset_count == view->reset_count &&
+ back->restart_count == view->restart_count &&
+ same(back->initial_pcr, view->initial_pcr),
+ "the PCR, the TPM boot and the initial value");
+ __CPROVER_assert(back->n_events == LEN, "every event");
+ for (i = 0; i < LEN; i++)
+ __CPROVER_assert(back->events[i].sequence ==
+ view->events[i].sequence &&
+ back->events[i].kind == view->events[i].kind &&
+ same(back->events[i].root_hash,
+ view->events[i].root_hash),
+ "each event, in its place");
+}
+
+void harness(void)
+{
+ struct config_evidence view, back;
+ struct json_emit emit = {};
+ char text[1];
+ int err, ret;
+
+ view.events = any_bytes(LEN * sizeof(*view.events));
+ view.n_events = LEN;
+ emit.err = err;
+ ret = config_evidence_emit(&emit, &view);
+ if (!view.present)
+ __CPROVER_assert(!ret && !said.config,
+ "no history says nothing");
+ else
+ __CPROVER_assert(ret == (sequence_overflows(&view) ?
+ -EOVERFLOW : err),
+ "a sequence past a __s64 refused, the writer's error returned");
+ if (ret)
+ return;
+ __CPROVER_assert(where == OUTSIDE &&
+ (!view.present || n_said == LEN),
+ "every event said and every container closed");
+
+ ret = config_evidence_parse(text, sizeof(text), &back);
+ if (!view.present) {
+ __CPROVER_assert(!ret && blank(&back), "and reads back as none");
+ return;
+ }
+ __CPROVER_assert(!ret == (replays(&view) && !hash_failed),
+ "reads back exactly what a verifier can replay");
+ if (!ret)
+ check_read_back(&view, &back);
+ config_evidence_clear(&back);
+}
diff --git a/testing/proofs/cbmc/config-evidence-verify.c b/testing/proofs/cbmc/config-evidence-verify.c
new file mode 100644
index 00000000..aca46470
--- /dev/null
+++ b/testing/proofs/cbmc/config-evidence-verify.c
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * replay() and config_evidence_verify() of util/config_attest.c on every
+ * history of LEN events: a history passes only as one boot event and then
+ * updates in sequence, and only when the quoted PCR holds the initial value
+ * extended by each event's digest in order. SHA-256 gives any digest or
+ * fails: nothing is assumed of it, collision resistance least of all.
+ */
+
+#include "proof.h"
+#include "../../../util/config_measure.c"
+/* The C converts a __s64 and cuts a __u64 to bytes on purpose. */
+#pragma CPROVER check push
+#pragma CPROVER check disable "conversion"
+#include "../../../util/chain.c"
+#pragma CPROVER check pop
+#include "../../../util/config_attest.c"
+
+static const char event_tag[] = "shirudo-config-root-v1";
+
+#define EVENT_BYTES (sizeof(event_tag) + 4 + 32)
+#define EXTEND_BYTES 64
+
+/* A PCR that the history's events extend, as far as they were hashed. */
+static const struct config_evidence *history;
+static __u8 pcr_now[32], event_digest[32];
+static size_t n_extended;
+static bool digest_ready, hash_failed;
+
+static bool same(const __u8 *a, const __u8 *b)
+{
+ size_t i;
+
+ for (i = 0; i < 32; i++)
+ if (a[i] != b[i])
+ return false;
+ return true;
+}
+
+/*
+ * The event digest of the next event: the tag and its NUL, the kind as 32
+ * bits most significant byte first, 1 for the boot event and 2 for an
+ * update, and the root.
+ */
+static void check_event(const __u8 *in)
+{
+ size_t k;
+
+ __CPROVER_assert(!digest_ready && n_extended < LEN,
+ "one digest for each event in turn");
+ for (k = 0; k < sizeof(event_tag); k++)
+ __CPROVER_assert(in[k] == (__u8)event_tag[k],
+ "the tag and its NUL");
+ __CPROVER_assert(!in[k] && !in[k + 1] && !in[k + 2] &&
+ in[k + 3] == (n_extended ? 2 : 1),
+ "boot as 1 and update as 2");
+ __CPROVER_assert(same(in + k + 4,
+ history->events[n_extended].root_hash),
+ "the event's root");
+}
+
+/* A TPM's extend: the PCR's value, then the event's digest. */
+static void check_extend(const __u8 *in)
+{
+ __CPROVER_assert(digest_ready, "an extend after its event's digest");
+ __CPROVER_assert(same(in, pcr_now) && same(in + 32, event_digest),
+ "the PCR extended by the event's digest");
+}
+
+int sha256_buffer(const void *data, size_t len, __u8 out[32])
+{
+ int ret;
+
+ __CPROVER_assert(__CPROVER_r_ok(data, len), "hashes only its input");
+ __CPROVER_assert(__CPROVER_w_ok(out, 32), "a digest's room");
+ __CPROVER_assert(len == EVENT_BYTES || len == EXTEND_BYTES,
+ "an event or an extend");
+ if (len == EVENT_BYTES)
+ check_event(data);
+ else
+ check_extend(data);
+ __CPROVER_havoc_slice(out, 32);
+ if (len == EVENT_BYTES) {
+ memcpy(event_digest, out, 32);
+ digest_ready = true;
+ } else {
+ memcpy(pcr_now, out, 32);
+ digest_ready = false;
+ n_extended++;
+ }
+ if (ret)
+ hash_failed = true;
+ return ret;
+}
+
+/*
+ * The view's LEN events, or a view that holds no history to replay: no
+ * events at all, a count of none, or one past the limit.
+ */
+static void any_view(struct config_evidence *view, bool *holds_events)
+{
+ bool whole;
+
+ if (whole) {
+ view->events = any_bytes(LEN * sizeof(*view->events));
+ view->n_events = LEN;
+ } else if (view->events) {
+ view->events = any_bytes(sizeof(*view->events));
+ if (view->n_events <= CONFIG_EVIDENCE_EVENTS_MAX)
+ view->n_events = 0;
+ }
+ *holds_events = whole && LEN;
+ history = view;
+ memcpy(pcr_now, view->initial_pcr, 32);
+ n_extended = 0;
+ digest_ready = false;
+ hash_failed = false;
+}
+
+/* One boot event, then updates, each sequence number the one before plus 1. */
+static bool in_order(const struct config_evidence *view)
+{
+ const struct config_evidence_event *event = view->events;
+ size_t i;
+
+ for (i = 0; i < LEN; i++) {
+ if (event[i].kind != (i ? CONFIG_EVENT_UPDATE :
+ CONFIG_EVENT_BOOT))
+ return false;
+ if (event[i].sequence < 1 || event[i].sequence > INT64_MAX)
+ return false;
+ if (i && event[i].sequence - event[i - 1].sequence != 1)
+ return false;
+ }
+ return true;
+}
+
+static void replayed(void)
+{
+ struct config_evidence view;
+ bool holds_events;
+ __u8 out[32];
+ int ret;
+
+ any_view(&view, &holds_events);
+ ret = replay(&view, out);
+ if (!holds_events) {
+ __CPROVER_assert(ret == -EINVAL && !n_extended && !digest_ready,
+ "no history, or one past the limit, unread");
+ return;
+ }
+ __CPROVER_assert(!ret == (in_order(&view) && !hash_failed),
+ "replays exactly a history in order");
+ __CPROVER_assert(in_order(&view) || hash_failed ||
+ ret == -EKEYREJECTED,
+ "a history out of order is named as such");
+ __CPROVER_assert(ret || (n_extended == LEN && same(out, pcr_now)),
+ "the PCR after every event");
+}
+
+static void verified(void)
+{
+ bool holds_events, config_pcr, approved, have_root;
+ __u32 quote_mask, reset, restart;
+ const __u8 *expected_root = NULL;
+ struct config_evidence view;
+ const char *reason = NULL;
+ int expected_pcr, ret;
+ __u8 pcrs[24][32];
+
+ any_view(&view, &holds_events);
+ if (have_root)
+ expected_root = any_bytes(32);
+ ret = config_evidence_verify(&view, quote_mask, reset, restart, pcrs,
+ expected_root, expected_pcr, &reason);
+ __CPROVER_assert(reason, "a reason either way");
+ if (!view.present) {
+ __CPROVER_assert(ret == (expected_root || expected_pcr >= 0 ?
+ -EKEYREJECTED : 0),
+ "no history passes only when none is expected");
+ return;
+ }
+ config_pcr = view.pcr < 16 && view.pcr != CHAIN_PCR &&
+ view.pcr != CHAIN_PHASE_PCR;
+ approved = config_pcr && (quote_mask >> view.pcr & 1) &&
+ (expected_pcr < 0 || view.pcr == (__u32)expected_pcr) &&
+ view.reset_count == reset &&
+ view.restart_count == restart &&
+ !(expected_root && expected_pcr < 0);
+ if (!approved) {
+ __CPROVER_assert(ret,
+ "refused unless quoted, expected and of the quote's TPM boot");
+ return;
+ }
+ if (!holds_events || !in_order(&view) || hash_failed) {
+ __CPROVER_assert(ret, "no history and one out of order refused");
+ return;
+ }
+ __CPROVER_assert(n_extended == LEN, "every event extended");
+ __CPROVER_assert(!ret ==
+ (same(pcrs[view.pcr], pcr_now) &&
+ (!expected_root ||
+ same(view.events[LEN - 1].root_hash,
+ expected_root))),
+ "passes exactly on the quoted PCR's replay and the expected last root");
+}
+
+void harness(void)
+{
+ replayed();
+ verified();
+}
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 2d8f5858..c126369f 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -94,3 +94,8 @@ paths-pin --unwind 32 LEN=0,1,28-35
similar-distance --max-field-sensitivity-array-size 65 --unwind 8 --unwindset memcpy.0:18 LEN=0-15
similar-suggest --object-bits 10 --max-field-sensitivity-array-size 65 --unwind 8 --unwindset memcpy.0:14 LEN=0-8,18-26
similar-resolve --object-bits 10 --unwind 8
+config-evidence-event --unwind 1 --unwindset harness.0:33,same_event.0:33,hex_digits.0:65,room_for.0:10,on_event.0:4,hex_decode.0:33,strlen.0:66 LEN=0,1,15,16,128,4095,4096
+config-evidence-parse --unwind 1 --unwindset config_evidence_parse.0:7,on_event.0:4,replay.0:4,hex_decode.0:33,strlen.0:66,strcmp.0:15,named.0:7,json_parse.0:7,json_parse.1:4,give_event.0:4,give_text.0:66,any_document.0:4,whole.0:4,in_order.0:4,hex_digits.0:65,spells.0:33,blank.0:33,check_as_said.0:4,check_as_said.1:33 --memory-leak-check --slice-formula LEN=0-2
+config-evidence-roundtrip --unwind 1 --unwindset config_evidence_emit.0:4,hex_encode.0:33,config_evidence_parse.0:7,on_event.0:4,replay.0:4,hex_decode.0:33,strlen.0:66,strcmp.0:15,named.0:7,json_parse.0:7,json_parse.1:4,give_event.0:4,give_text.0:66,json_kv_string.0:66,sequence_overflows.0:4,replays.0:4,same.0:33,blank.0:33,check_read_back.0:4 --memory-leak-check --slice-formula LEN=0-2
+config-evidence-verify --unwind 1 --unwindset replay.0:4,memcmp.0:33,in_order.0:4,check_event.0:24,same.0:33 --slice-formula LEN=0-3
+config-evidence-collect --unwind 1 --unwindset config_update_events.0:4,replay.0:4,memcmp.0:33,history.0:4,check_exported.0:4,same.0:33,blank.0:33 --memory-leak-check --slice-formula LEN=0-2