|
auth 0.0.1
Authenticated computation with C++26 modules
|
C++26 authenticated computation. Run the same algorithm with a prover to produce a proof and with a verifier to check it. Pass the db by reference:
seal retains the value and its SHA-256 digest in prover mode, and only the digest in verifier mode. unseal appends the value's serialized bytes to p.proof, or reconstructs and checks the value when verifying. finish() rejects unused bytes.
Pass a copyable sealed value as an lvalue to keep it, or use std::move to consume it. The proof buffer must outlive its verifier and remain unchanged during replay.
Build a tree with bin and integer leaves, then follow a path through its sealed children. A std::variant distinguishes leaves from bins. Each bin seals its two children:
The proof contains the serialized values unsealed during proving, so its size equals the serialized size of the portion of the sealed structure you walk, counting each opening. The expected root digest is supplied separately to the verifier and is not part of p.proof.
Unvisited subtrees contribute only their digests in visited parents. Their contents are absent from the proof, however large those subtrees become. Sealing values does not append to the proof; unsealing does. Repeatedly unsealing the same value records its serialized bytes each time. There are no framing bytes between openings.
Use CMake 3.30 or newer, Ninja, a compiler supporting C++26 modules and explicit object parameters, and OpenSSL. The tested compiler is Homebrew Clang 21.
On other systems, select the appropriate clang++ path and omit CMAKE_OSX_SYSROOT. The explicit SDK path lets Clang's module dependency scanner find macOS headers. If OpenSSL is not found, set OPENSSL_ROOT_DIR to its installation prefix. Exceptions must be enabled.
Applications using add_subdirectory link to auth::auth, which supplies the modules and C++26 requirement. Set AUTH_BUILD_TESTS=OFF to omit the tests.
| Import | API |
|---|---|
| auth | db, sealed<DB, T>, prover, verifier, auth_error |
| auth.hash | digest, sha256, auth_error |
| auth.serialization | bytes, writer, reader, encode, decode, auth_error |
| auth.error | auth_error |
All names belong to namespace auth. Import hashing and serialization separately when needed. sealed<DB, T> names a db's sealed value type. prover::proof is the flat byte vector containing the computation's ordered sequence of openings.
Custom types define one serialize method for both directions, following Glenn Fiedler's Serialization Strategies. The stream supplies checked field operations and a compile-time reading flag:
Unsigned integers use fixed-width little-endian encoding; booleans use one byte. Arrays serialize their elements without a length prefix. Variants encode an alternative index followed by its value. A boxed value adds no pointer or presence bytes; use a variant to express an empty alternative. A serializer must be deterministic and preserve its input while writing. Decoding default-constructs the destination and returns {value, next}, where next points into the original input immediately after the consumed bytes. The caller keeps the original end. Concatenated openings therefore need no external framing.
With Doxygen 1.18 or newer and Python 3 installed:
Open build/docs/html/index.html. API contracts live beside their declarations; documentation warnings fail the build. The build also emits XML for tooling.
Licensed under your choice of BSD-2-Clause or Apache-2.0. See the contribution guidelines, code of conduct, and security policy.
Edward Kmett can be reached at ekmet.nosp@m.t@gm.nosp@m.ail.c.nosp@m.om, on Libera Chat as ekmett, and on Twitter/X as @kmett.