MCEL: Merkle-Chaining Event Ledger 1.0.0.0a (A1)
A post-quantum secure block-chain ledger system
mcel.h
Go to the documentation of this file.
1/* 2025-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact\qrcscorp.ca
50 */
51
52/*
53 * \file mcel.h
54 * \brief MCEL support header
55 *
56 * Merkle Chained Event Ledger (MCEL)
57 *
58 * MCEL implements an append-only, cryptographically verifiable event ledger
59 * designed for long-lived audit, provenance, and integrity assurance.
60 * The ledger records discrete events as immutable records, batches records
61 * into Merkle trees, and chains those batches using signed checkpoint
62 * commitments to form a tamper-evident history.
63 *
64 * MCEL is optimized for environments with a bounded set of writers and a
65 * potentially unbounded set of verifiers. It provides strong integrity,
66 * ordering, and non-repudiation guarantees without requiring distributed
67 * consensus, peer-to-peer networking, or economic mechanisms.
68 *
69 * Core properties:
70 * - Append-only event records with canonical serialization
71 * - Domain-separated cryptographic commitments for all object types
72 * - Merkle tree batching for scalable inclusion proofs
73 * - Hash-chained checkpoints with asymmetric signatures
74 * - Portable checkpoint bundles for independent verification
75 * - Support for audit paths, integrity verification, and key rotation
76 *
77 * MCEL is intended to serve as an integrity spine for higher-level systems
78 * such as digital identity frameworks, compliance and evidence ledgers,
79 * authorization workflows, and regulated institutional records.
80 * Payload semantics are intentionally opaque to the ledger, allowing
81 * application-specific object models to evolve independently.
82 *
83 * The implementation assumes a trusted storage backend providing append
84 * semantics and optional overwrite support for the current ledger head.
85 * All security guarantees derive from cryptographic verification rather
86 * than trust in storage correctness.
87 */
88
89#ifndef MCEL_H
90#define MCEL_H
91
92#include "mcelcommon.h"
93
94#if (!defined(MCEL_CONFIG_DILITHIUM) && !defined(MCEL_CONFIG_SPHINCSPLUS))
99# define MCEL_CONFIG_DILITHIUM
100#endif
101
102#if defined(MCEL_CONFIG_DILITHIUM)
103# include "dilithium.h"
104#elif defined(MCEL_CONFIG_SPHINCSPLUS)
105# include "sphincsplus.h"
106#else
107# error Invalid parameter set!
108#endif
109
115#define MCEL_USE_RCS_ENCRYPTION
116
118#if defined(MCEL_USE_RCS_ENCRYPTION)
119# include "rcs.h"
120# define mcel_cipher_state qsc_rcs_state
121# define mcel_cipher_dispose qsc_rcs_dispose
122# define mcel_cipher_initialize qsc_rcs_initialize
123# define mcel_cipher_keyparams qsc_rcs_keyparams
124# define mcel_cipher_set_associated qsc_rcs_set_associated
125# define mcel_cipher_transform qsc_rcs_transform
126#else
127# include "aes.h"
128# define mcel_cipher_state qsc_aes_gcm256_state
129# define mcel_cipher_dispose qsc_aes_gcm256_dispose
130# define mcel_cipher_initialize qsc_aes_gcm256_initialize
131# define mcel_cipher_keyparams qsc_aes_keyparams
132# define mcel_cipher_set_associated qsc_aes_gcm256_set_associated
133# define mcel_cipher_transform qsc_aes_gcm256_transform
134#endif
136
186
187#if defined(MCEL_CONFIG_DILITHIUM)
192# define MCEL_ASYMMETRIC_SIGNING_KEY_SIZE (QSC_DILITHIUM_PRIVATEKEY_SIZE)
193
198# define MCEL_ASYMMETRIC_VERIFY_KEY_SIZE (QSC_DILITHIUM_PUBLICKEY_SIZE)
199
204# define MCEL_ASYMMETRIC_SIGNATURE_SIZE (QSC_DILITHIUM_SIGNATURE_SIZE)
205
206# if defined(QSC_DILITHIUM_S1P44)
211# define MCEL_PARAMETER_SET 1U
212# elif defined(QSC_DILITHIUM_S3P65)
217# define MCEL_PARAMETER_SET 2U
218# elif defined(QSC_DILITHIUM_S5P87)
223# define MCEL_PARAMETER_SET 3U
224# else
225# error "The parameter set is not supported!"
226# endif
231# define mcel_signature_generate_keypair qsc_dilithium_generate_keypair
236# define mcel_signature_sign qsc_dilithium_sign
241# define mcel_signature_verify qsc_dilithium_verify
242#else
247# define MCEL_ASYMMETRIC_SIGNING_KEY_SIZE (QSC_SPHINCSPLUS_PRIVATEKEY_SIZE)
248
253# define MCEL_ASYMMETRIC_VERIFY_KEY_SIZE (QSC_SPHINCSPLUS_PUBLICKEY_SIZE)
254
259# define MCEL_ASYMMETRIC_SIGNATURE_SIZE (QSC_SPHINCSPLUS_SIGNATURE_SIZE)
260
265# if defined(QSC_SPHINCSPLUS_S1S128SHAKERS)
266# define MCEL_PARAMETER_SET 4U
267# elif defined(QSC_SPHINCSPLUS_S3S192SHAKERS)
268# define MCEL_PARAMETER_SET 5U
269# elif defined(QSC_SPHINCSPLUS_S5S256SHAKERS)
270# define MCEL_PARAMETER_SET 6U
271# elif defined(QSC_SPHINCSPLUS_S6S512SHAKERS)
272# define MCEL_PARAMETER_SET 7U
273# else
274# error "The parameter set is not supported!"
275# endif
276
281# define udif_signature_generate_keypair qsc_sphincsplus_generate_keypair
286# define udif_signature_sign qsc_sphincsplus_sign
291# define udif_signature_verify qsc_sphincsplus_verify
292#endif
293
298#define MCEL_BLOCK_HASH_SIZE 32U
299
304#define MCEL_BLOCK_HEADER_ENCODED_SIZE 62U
305
310#define MCEL_BLOCK_ENCODED_FIXED_SIZE ((size_t)MCEL_BLOCK_HEADER_ENCODED_SIZE + ((size_t)MCEL_BLOCK_HASH_SIZE * 2U))
311
316#define MCEL_BLOCK_KEYID_SIZE 32U
317
322#define MCEL_BLOCK_VERSION 1U
323
328#define MCEL_CHECKPOINT_HEADER_ENCODED_SIZE 62U
329
334#define MCEL_CHECKPOINT_BUNDLE_FIXED_SIZE (MCEL_CHECKPOINT_HEADER_ENCODED_SIZE + (MCEL_BLOCK_HASH_SIZE * 2U))
335
340#define MCEL_CHECKPOINT_BUNDLE_ENCODED_SIZE (MCEL_ASYMMETRIC_SIGNATURE_SIZE + MCEL_BLOCK_HASH_SIZE + MCEL_CHECKPOINT_BUNDLE_FIXED_SIZE)
341
346#define MCEL_CHECKPOINT_KEYID_SIZE 32U
347
352#define MCEL_CHECKPOINT_SIGNED_COMMIT_SIZE (MCEL_ASYMMETRIC_SIGNATURE_SIZE + MCEL_BLOCK_HASH_SIZE)
353
358#define MCEL_CHECKPOINT_VERSION 1U
359
364#define MCEL_KEYROTATE_PAYLOAD_VERSION 0x01U
365
370#define MCEL_KEYROTATE_PAYLOAD_FIXED_SIZE (1U + 1U + (uint32_t)MCEL_CHECKPOINT_KEYID_SIZE + 2U)
371
376#define MCEL_KEYROTATE_PAYLOAD_KEY_SIZE (MCEL_KEYROTATE_PAYLOAD_FIXED_SIZE + MCEL_ASYMMETRIC_VERIFY_KEY_SIZE)
377
382#define MCEL_LEDGER_NAMESPACE_ID_MAX 64U
383
388#define MCEL_PAYLOAD_MAX_SIZE 0xFFFFFFFFUL
389
394#define MCEL_RCS256_KEY_SIZE 32U
395
400#define MCEL_RCS256_MAC_SIZE 32U
401
406#define MCEL_RCS_NONCE_SIZE 32U
407
412#define MCEL_RCS_INFO_SIZE 48U
413
418#define MCEL_RECORD_FLAG_ENCRYPTED 0x01U
419
424#define MCEL_RECORD_VERSION 1U
425
430#define MCEL_RECORD_KEYID_SIZE 32U
431
436#define MCEL_RECORD_HEADER_ENCODED_SIZE 58U
437
442#define MCEL_RECORD_TYPE_KEYROTATE 0x3U
443
448#define MCEL_SIGNED_HASH_SIZE (MCEL_ASYMMETRIC_SIGNATURE_SIZE + MCEL_BLOCK_HASH_SIZE)
449
454#if defined(QSC_SYSTEM_OS_WINDOWS)
455# define MCEL_STORE_LOC_BLOCKS "mcel\\blocks"
456#else
457# define MCEL_STORE_LOC_BLOCKS "mcel/blocks"
458#endif
459
464#if defined(QSC_SYSTEM_OS_WINDOWS)
465# define MCEL_STORE_LOC_CHECKPOINTS "mcel\\checkpoints"
466#else
467# define MCEL_STORE_LOC_CHECKPOINTS "mcel/checkpoints"
468#endif
469
474#if defined(QSC_SYSTEM_OS_WINDOWS)
475# define MCEL_STORE_LOC_HEAD "mcel\\head"
476#else
477# define MCEL_STORE_LOC_HEAD "mcel/head"
478#endif
479
484#if defined(QSC_SYSTEM_OS_WINDOWS)
485# define MCEL_STORE_LOC_RECORDS "mcel\\records"
486#else
487# define MCEL_STORE_LOC_RECORDS "mcel/records"
488#endif
489
502
512
528
537MCEL_EXPORT_API typedef struct mcel_store_callbacks
538{
539 void* context;
540
552 bool (*write)(void* context, const uint8_t* loc, size_t loclen, const uint8_t* data, size_t datalen);
553
566 bool (*read)(void* context, const uint8_t* loc, size_t loclen, uint8_t* data, size_t datalen, size_t* outread);
567
580 bool (*append)(void* context, const uint8_t* loc, size_t loclen, const uint8_t* data, size_t datalen, uint64_t* outpos);
581
592 bool (*size)(void* context, const uint8_t* loc, size_t loclen, uint64_t* outlen);
593
603 bool (*flush)(void* context, const uint8_t* loc, size_t loclen);
605
614MCEL_EXPORT_API typedef struct mcel_block_header
615{
617 uint64_t block_sequence;
619 uint64_t timestamp;
620 uint32_t record_count;
621 uint8_t flags;
622 uint8_t version;
624
629MCEL_EXPORT_API typedef struct mcel_checkpoint_audit_item
630{
631 const uint8_t* bundle;
632 size_t bundlelen;
634
643MCEL_EXPORT_API typedef struct mcel_checkpoint_header
644{
646 uint64_t chk_sequence;
648 uint64_t timestamp;
649 uint32_t record_count;
650 uint8_t flags;
651 uint8_t version;
653
668
682
698
707MCEL_EXPORT_API typedef struct mcel_record_header
708{
710 uint64_t sequence;
711 uint64_t timestamp;
712 uint32_t payload_len;
713 uint32_t type;
714 uint8_t flags;
715 uint8_t version;
717
727MCEL_EXPORT_API bool mcel_block_commit(uint8_t* output, const mcel_block_header* header, const uint8_t* blkroot);
728
742MCEL_EXPORT_API bool mcel_block_encode(uint8_t* output, size_t outlen, const mcel_block_header* header, const uint8_t* blkroot,
743 const uint8_t* blkcommit, const uint8_t* reccommits, size_t reccount);
744
752MCEL_EXPORT_API size_t mcel_block_encoded_size(size_t reccount);
753
762MCEL_EXPORT_API bool mcel_block_encode_header(uint8_t* output, const mcel_block_header* header);
763
775MCEL_EXPORT_API bool mcel_block_seal(uint8_t* blkroot, uint8_t* blkcommit, const mcel_block_header* header, const uint8_t* reccommits, size_t reccount);
776
787MCEL_EXPORT_API bool mcel_checkpoint_audit_path_verify(uint8_t* outheadcommit, const mcel_checkpoint_audit_item* items,
788 size_t itemcount, const uint8_t* publickey);
789
803MCEL_EXPORT_API bool mcel_checkpoint_bundle_encode(uint8_t* output, size_t outlen, const mcel_checkpoint_header* header, const uint8_t* blkroot,
804 const uint8_t* prevcommit, const uint8_t* sigcommit, size_t siglen);
805
813MCEL_EXPORT_API size_t mcel_checkpoint_bundle_encoded_size(size_t siglen);
814
828MCEL_EXPORT_API bool mcel_checkpoint_bundle_verify(uint8_t* chkcommit, mcel_checkpoint_header* header, uint8_t* blkroot, uint8_t* prevcommit,
829 const uint8_t* bundle, size_t bundlelen, const uint8_t* publickey);
830
841MCEL_EXPORT_API bool mcel_checkpoint_chain_link_verify(const uint8_t* prevcommit, const uint8_t* curprevcommit,
842 const mcel_checkpoint_header* prevhdr, const mcel_checkpoint_header* curhdr);
843
854MCEL_EXPORT_API bool mcel_checkpoint_commit(uint8_t* output, const mcel_checkpoint_header* header, const uint8_t* blkroot, const uint8_t* pldcommit);
855
868MCEL_EXPORT_API bool mcel_checkpoint_consistency_verify(const uint8_t* firstroot, const uint8_t* secondroot, size_t first,
869 size_t second, const uint8_t* proof, size_t prooflen);
870
879MCEL_EXPORT_API bool mcel_checkpoint_decode_header(mcel_checkpoint_header* header, const uint8_t* input);
880
889MCEL_EXPORT_API bool mcel_checkpoint_encode_header(uint8_t* output, const mcel_checkpoint_header* header);
890
902MCEL_EXPORT_API bool mcel_checkpoint_prove_consistency(uint8_t* proof, size_t prooflen, const uint8_t* leaves, size_t oldcount, size_t newcount);
903
918MCEL_EXPORT_API bool mcel_checkpoint_seal(uint8_t* chkcommit, uint8_t* sigcommit, size_t* siglen, const mcel_checkpoint_header* header,
919 const uint8_t* blkroot, const uint8_t* prevcommit, const uint8_t* privatekey, bool (*rng_generate)(uint8_t*, size_t));
920
932MCEL_EXPORT_API bool mcel_checkpoint_sign(uint8_t* sigcommit, size_t* siglen, const uint8_t* chkcommit,
933 const uint8_t* privatekey, bool (*rng_generate)(uint8_t*, size_t));
934
946MCEL_EXPORT_API bool mcel_checkpoint_verify(uint8_t* chkcommit, size_t* commitlen, const uint8_t* sigcommit,
947 size_t siglen, const uint8_t* publickey);
948
956MCEL_EXPORT_API size_t mcel_keyrotate_payload_size(size_t pubkeylen);
957
972MCEL_EXPORT_API size_t mcel_keyrotate_record_create(mcel_record_header* header, uint8_t* payload, size_t payload_len,
973 uint64_t sequence, uint8_t flags, const uint8_t* newkeyid, const uint8_t* newpubkey, size_t pubkeylen);
974
987MCEL_EXPORT_API bool mcel_ledger_append_record(mcel_ledger_state* state, uint8_t* reccommit, uint64_t* outpos,
988 const mcel_record_header* header, const uint8_t* payload, size_t paylen);
989
999MCEL_EXPORT_API bool mcel_ledger_get_checkpoint_head(mcel_ledger_state* state, uint8_t* head_commit, mcel_checkpoint_header* head_header);
1000
1014MCEL_EXPORT_API bool mcel_ledger_initialize(mcel_ledger_state* state, const mcel_store_callbacks* store, const uint8_t* nsid, size_t nsidlen,
1015 const uint8_t* publickey, uint8_t* headbuf, size_t headbuflen);
1016
1032MCEL_EXPORT_API bool mcel_ledger_seal_block(mcel_ledger_state* state, uint8_t* blkroot, uint8_t* blkcommit, const mcel_block_header* header,
1033 const uint8_t* reccommits, size_t reccount, uint8_t* blockbuf, size_t blockbuflen, uint64_t* outpos);
1034
1049MCEL_EXPORT_API bool mcel_ledger_seal_checkpoint(mcel_ledger_state* state, uint8_t* chkcommit, const mcel_checkpoint_header* header,
1050 const uint8_t* blkroot, const void* sigkey, uint8_t* bundlebuf, size_t bundlebuflen, uint64_t* outpos);
1051
1069MCEL_EXPORT_API bool mcel_ledger_verify_integrity(mcel_ledger_state* state, uint8_t* headbuf, size_t headbuflen,
1070 const mcel_checkpoint_audit_item* audit, size_t auditcount);
1071
1082MCEL_EXPORT_API bool mcel_payload_commit(uint8_t* output, bool encrypted, const uint8_t* payload, size_t paylen);
1083
1096MCEL_EXPORT_API bool mcel_policy_apply(mcel_policy_errors* perr, const mcel_policy* policy, const mcel_policy_context* state, mcel_policy_ops op,
1097 const mcel_record_header* recordhdr, const mcel_checkpoint_header* checkpointhdr);
1098
1113MCEL_EXPORT_API bool mcel_record_decrypt_payload(uint8_t* output, size_t outlen, const uint8_t* ciphertext, size_t ctlen,
1114 const uint8_t* ad, size_t adlen, const uint8_t* key, uint8_t* nonce);
1115
1128MCEL_EXPORT_API void mcel_record_encrypt_payload(uint8_t* output, size_t outlen, const uint8_t* plaintext, size_t ptlen,
1129 const uint8_t* ad, size_t adlen, const uint8_t* key, uint8_t* nonce);
1130
1139MCEL_EXPORT_API bool mcel_record_encode_header(uint8_t* output, const mcel_record_header* header);
1140
1150MCEL_EXPORT_API bool mcel_record_commit(uint8_t* output, const mcel_record_header* header, const uint8_t* pldcommit);
1151
1161MCEL_EXPORT_API bool mcel_store_callbacks_initialize(mcel_store_callbacks* output, const mcel_store_callbacks* input, void* context);
1162
1163#endif
#define MCEL_CHECKPOINT_KEYID_SIZE
The checkpoint key identifier size in bytes.
Definition mcel.h:346
MCEL_EXPORT_API bool mcel_block_encode(uint8_t *output, size_t outlen, const mcel_block_header *header, const uint8_t *blkroot, const uint8_t *blkcommit, const uint8_t *reccommits, size_t reccount)
Serialize a sealed MCEL block into a canonical byte string.
Definition mcel.c:129
MCEL_EXPORT_API bool mcel_block_seal(uint8_t *blkroot, uint8_t *blkcommit, const mcel_block_header *header, const uint8_t *reccommits, size_t reccount)
Seal a MCEL block by computing the Merkle root and block commitment.
Definition mcel.c:226
MCEL_EXPORT_API bool mcel_checkpoint_prove_consistency(uint8_t *proof, size_t prooflen, const uint8_t *leaves, size_t oldcount, size_t newcount)
Generate a MCEL Merkle consistency proof between two tree sizes.
Definition mcel.c:742
MCEL_EXPORT_API bool mcel_record_decrypt_payload(uint8_t *output, size_t outlen, const uint8_t *ciphertext, size_t ctlen, const uint8_t *ad, size_t adlen, const uint8_t *key, uint8_t *nonce)
Decrypt a record payload using the AEAD cipher.
Definition mcel.c:1562
#define MCEL_LEDGER_NAMESPACE_ID_MAX
The maximum namespace identifier size in bytes.
Definition mcel.h:382
MCEL_EXPORT_API bool mcel_ledger_get_checkpoint_head(mcel_ledger_state *state, uint8_t *head_commit, mcel_checkpoint_header *head_header)
Get the current checkpoint head from the ledger state.
Definition mcel.c:1166
MCEL_EXPORT_API size_t mcel_block_encoded_size(size_t reccount)
Get the required buffer size for an encoded MCEL block.
Definition mcel.c:173
MCEL_EXPORT_API bool mcel_record_commit(uint8_t *output, const mcel_record_header *header, const uint8_t *pldcommit)
Compute a MCEL record commitment from a record header and payload commitment.
Definition mcel.c:1656
MCEL_EXPORT_API bool mcel_ledger_seal_block(mcel_ledger_state *state, uint8_t *blkroot, uint8_t *blkcommit, const mcel_block_header *header, const uint8_t *reccommits, size_t reccount, uint8_t *blockbuf, size_t blockbuflen, uint64_t *outpos)
Seal a block from record commitments and write the sealed block through the storage callbacks.
Definition mcel.c:1189
MCEL_EXPORT_API bool mcel_payload_commit(uint8_t *output, bool encrypted, const uint8_t *payload, size_t paylen)
Compute a MCEL payload commitment.
Definition mcel.c:1450
mcel_policy_ops
The MCEL policy operation identifiers.
Definition mcel.h:508
@ mcel_policyop_append_record
Definition mcel.h:509
@ mcel_policyop_seal_checkpoint
Definition mcel.h:510
MCEL_EXPORT_API bool mcel_store_callbacks_initialize(mcel_store_callbacks *output, const mcel_store_callbacks *input, void *context)
Initialize and validate the MCEL storage callback table.
Definition mcel.c:1686
MCEL_EXPORT_API bool mcel_ledger_initialize(mcel_ledger_state *state, const mcel_store_callbacks *store, const uint8_t *nsid, size_t nsidlen, const uint8_t *publickey, uint8_t *headbuf, size_t headbuflen)
Initialize (open) a MCEL ledger namespace and load the checkpoint head if present.
Definition mcel.c:1093
MCEL_EXPORT_API size_t mcel_keyrotate_record_create(mcel_record_header *header, uint8_t *payload, size_t payload_len, uint64_t sequence, uint8_t flags, const uint8_t *newkeyid, const uint8_t *newpubkey, size_t pubkeylen)
Create a key rotation record header and payload.
Definition mcel.c:960
#define MCEL_BLOCK_KEYID_SIZE
The MCEL block key identifier size in bytes.
Definition mcel.h:316
MCEL_EXPORT_API size_t mcel_keyrotate_payload_size(size_t pubkeylen)
Get the required buffer size for a key rotation record payload.
Definition mcel.c:946
MCEL_EXPORT_API bool mcel_checkpoint_verify(uint8_t *chkcommit, size_t *commitlen, const uint8_t *sigcommit, size_t siglen, const uint8_t *publickey)
Verify a MCEL signed checkpoint commitment using Dilithium.
Definition mcel.c:920
MCEL_EXPORT_API bool mcel_policy_apply(mcel_policy_errors *perr, const mcel_policy *policy, const mcel_policy_context *state, mcel_policy_ops op, const mcel_record_header *recordhdr, const mcel_checkpoint_header *checkpointhdr)
Apply namespace policy rules to a MCEL operation.
Definition mcel.c:1474
MCEL_EXPORT_API bool mcel_checkpoint_chain_link_verify(const uint8_t *prevcommit, const uint8_t *curprevcommit, const mcel_checkpoint_header *prevhdr, const mcel_checkpoint_header *curhdr)
Verify the chain linkage between two verified checkpoints.
Definition mcel.c:447
mcel_record_types
The MCEL record type identifiers.
Definition mcel.h:495
@ mcel_record_type_checkpoint
Definition mcel.h:497
@ mcel_record_type_policy
Definition mcel.h:500
@ mcel_record_type_none
Definition mcel.h:496
@ mcel_record_type_event
Definition mcel.h:498
@ mcel_record_type_key_rotate
Definition mcel.h:499
MCEL_EXPORT_API void mcel_record_encrypt_payload(uint8_t *output, size_t outlen, const uint8_t *plaintext, size_t ptlen, const uint8_t *ad, size_t adlen, const uint8_t *key, uint8_t *nonce)
Encrypt a record payload using the AEAD cipher.
Definition mcel.c:1630
MCEL_EXPORT_API bool mcel_checkpoint_bundle_encode(uint8_t *output, size_t outlen, const mcel_checkpoint_header *header, const uint8_t *blkroot, const uint8_t *prevcommit, const uint8_t *sigcommit, size_t siglen)
Serialize a MCEL checkpoint bundle into a canonical byte string.
Definition mcel.c:323
mcel_policy_errors
The MCEL policy error values.
Definition mcel.h:518
@ mcel_policyerr_invalid_parameter
Definition mcel.h:520
@ mcel_policyerr_record_type_denied
Definition mcel.h:521
@ mcel_policyerr_keyid_mismatch
Definition mcel.h:526
@ mcel_policyerr_sequence_invalid
Definition mcel.h:524
@ mcel_policyerr_timestamp_invalid
Definition mcel.h:525
@ mcel_policyerr_plaintext_denied
Definition mcel.h:523
@ mcel_policyerr_none
Definition mcel.h:519
@ mcel_policyerr_payload_too_large
Definition mcel.h:522
MCEL_EXPORT_API bool mcel_block_encode_header(uint8_t *output, const mcel_block_header *header)
Encode a MCEL block header using canonical fixed-size encoding.
Definition mcel.c:189
MCEL_EXPORT_API bool mcel_checkpoint_sign(uint8_t *sigcommit, size_t *siglen, const uint8_t *chkcommit, const uint8_t *privatekey, bool(*rng_generate)(uint8_t *, size_t))
Sign a MCEL checkpoint commitment using Dilithium.
Definition mcel.c:899
#define MCEL_RECORD_KEYID_SIZE
The record signer or policy key identifier size in bytes.
Definition mcel.h:430
MCEL_EXPORT_API bool mcel_checkpoint_audit_path_verify(uint8_t *outheadcommit, const mcel_checkpoint_audit_item *items, size_t itemcount, const uint8_t *publickey)
Verify an ordered audit path of MCEL checkpoint bundles.
Definition mcel.c:251
MCEL_EXPORT_API bool mcel_record_encode_header(uint8_t *output, const mcel_record_header *header)
Encode a MCEL record header using canonical fixed-size encoding.
Definition mcel.c:1594
MCEL_EXPORT_API size_t mcel_checkpoint_bundle_encoded_size(size_t siglen)
Get the required buffer size for an encoded MCEL checkpoint bundle.
Definition mcel.c:312
MCEL_EXPORT_API bool mcel_ledger_append_record(mcel_ledger_state *state, uint8_t *reccommit, uint64_t *outpos, const mcel_record_header *header, const uint8_t *payload, size_t paylen)
Append a record to the ledger record log and return its commitment.
Definition mcel.c:1009
#define MCEL_BLOCK_HASH_SIZE
The MCEL 256-bit digest size in bytes.
Definition mcel.h:298
MCEL_EXPORT_API bool mcel_checkpoint_commit(uint8_t *output, const mcel_checkpoint_header *header, const uint8_t *blkroot, const uint8_t *pldcommit)
Compute a MCEL checkpoint commitment from a checkpoint header, block root, and previous checkpoint co...
Definition mcel.c:485
MCEL_EXPORT_API bool mcel_block_commit(uint8_t *output, const mcel_block_header *header, const uint8_t *blkroot)
Compute a MCEL block commitment from a block header and Merkle root.
Definition mcel.c:99
MCEL_EXPORT_API bool mcel_checkpoint_encode_header(uint8_t *output, const mcel_checkpoint_header *header)
Encode a MCEL checkpoint header using canonical fixed-size encoding.
Definition mcel.c:706
MCEL_EXPORT_API bool mcel_ledger_seal_checkpoint(mcel_ledger_state *state, uint8_t *chkcommit, const mcel_checkpoint_header *header, const uint8_t *blkroot, const void *sigkey, uint8_t *bundlebuf, size_t bundlebuflen, uint64_t *outpos)
Seal a checkpoint from a sealed block root and update the ledger head.
Definition mcel.c:1249
MCEL_EXPORT_API bool mcel_checkpoint_bundle_verify(uint8_t *chkcommit, mcel_checkpoint_header *header, uint8_t *blkroot, uint8_t *prevcommit, const uint8_t *bundle, size_t bundlelen, const uint8_t *publickey)
Verify a serialized MCEL checkpoint bundle.
Definition mcel.c:373
MCEL_EXPORT_API bool mcel_checkpoint_consistency_verify(const uint8_t *firstroot, const uint8_t *secondroot, size_t first, size_t second, const uint8_t *proof, size_t prooflen)
Verify a MCEL Merkle consistency proof between two tree roots.
Definition mcel.c:517
MCEL_EXPORT_API bool mcel_ledger_verify_integrity(mcel_ledger_state *state, uint8_t *headbuf, size_t headbuflen, const mcel_checkpoint_audit_item *audit, size_t auditcount)
Verify the cryptographic integrity of the ledger state.
Definition mcel.c:1348
MCEL_EXPORT_API bool mcel_checkpoint_decode_header(mcel_checkpoint_header *header, const uint8_t *input)
Decode a MCEL checkpoint header from its canonical encoding.
Definition mcel.c:671
MCEL_EXPORT_API bool mcel_checkpoint_seal(uint8_t *chkcommit, uint8_t *sigcommit, size_t *siglen, const mcel_checkpoint_header *header, const uint8_t *blkroot, const uint8_t *prevcommit, const uint8_t *privatekey, bool(*rng_generate)(uint8_t *, size_t))
Seal a MCEL checkpoint from a sealed block by generating the checkpoint commitment and signing it.
Definition mcel.c:868
The MCEL block header structure.
Definition mcel.h:615
uint64_t timestamp
Definition mcel.h:619
uint32_t record_count
Definition mcel.h:620
uint64_t first_record_seq
Definition mcel.h:618
uint64_t block_sequence
Definition mcel.h:617
uint8_t keyid[MCEL_BLOCK_KEYID_SIZE]
Definition mcel.h:616
uint8_t flags
Definition mcel.h:621
uint8_t version
Definition mcel.h:622
The MCEL audit path item container.
Definition mcel.h:630
size_t bundlelen
Definition mcel.h:632
const uint8_t * bundle
Definition mcel.h:631
The MCEL checkpoint header structure.
Definition mcel.h:644
uint64_t timestamp
Definition mcel.h:648
uint32_t record_count
Definition mcel.h:649
uint64_t first_record_seq
Definition mcel.h:647
uint8_t flags
Definition mcel.h:650
uint8_t version
Definition mcel.h:651
uint8_t keyid[MCEL_CHECKPOINT_KEYID_SIZE]
Definition mcel.h:645
uint64_t chk_sequence
Definition mcel.h:646
The MCEL ledger instance state.
Definition mcel.h:659
uint8_t have_head
Definition mcel.h:666
size_t nsidlen
Definition mcel.h:662
const uint8_t * publickey
Definition mcel.h:663
mcel_store_callbacks store
Definition mcel.h:660
mcel_checkpoint_header head_header
Definition mcel.h:665
uint8_t head_commit[MCEL_BLOCK_HASH_SIZE]
Definition mcel.h:664
uint8_t nsid[MCEL_LEDGER_NAMESPACE_ID_MAX]
Definition mcel.h:661
The MCEL policy context (caller-maintained).
Definition mcel.h:692
uint64_t last_record_timestamp
Definition mcel.h:696
uint8_t have_checkpoint
Definition mcel.h:693
uint64_t last_record_sequence
Definition mcel.h:695
mcel_checkpoint_header checkpoint
Definition mcel.h:694
The MCEL namespace policy container.
Definition mcel.h:674
uint32_t allowed_record_mask
Definition mcel.h:676
uint8_t require_encryption
Definition mcel.h:677
uint8_t enforce_monotonic_time
Definition mcel.h:678
uint8_t enforce_monotonic_seq
Definition mcel.h:679
size_t max_payload_size
Definition mcel.h:675
uint8_t enforce_keyid_link
Definition mcel.h:680
The MCEL record header structure.
Definition mcel.h:708
uint8_t keyid[MCEL_RECORD_KEYID_SIZE]
Definition mcel.h:709
uint64_t timestamp
Definition mcel.h:711
uint8_t flags
Definition mcel.h:714
uint8_t version
Definition mcel.h:715
uint64_t sequence
Definition mcel.h:710
uint32_t type
Definition mcel.h:713
uint32_t payload_len
Definition mcel.h:712
The MCEL storage callback table.
Definition mcel.h:538
bool(* flush)(void *context, const uint8_t *loc, size_t loclen)
Flush any buffered data for a logical location.
Definition mcel.h:603
bool(* read)(void *context, const uint8_t *loc, size_t loclen, uint8_t *data, size_t datalen, size_t *outread)
Read a complete object from a logical location.
Definition mcel.h:566
bool(* size)(void *context, const uint8_t *loc, size_t loclen, uint64_t *outlen)
Get the size of an object at a logical location.
Definition mcel.h:592
bool(* append)(void *context, const uint8_t *loc, size_t loclen, const uint8_t *data, size_t datalen, uint64_t *outpos)
Append bytes to an append-only object.
Definition mcel.h:580
bool(* write)(void *context, const uint8_t *loc, size_t loclen, const uint8_t *data, size_t datalen)
Write a complete object at a logical location.
Definition mcel.h:552
void * context
Definition mcel.h:539