UDIF: Universal Digital Identification Framework 1.1.0.0a (A1)
A quantum-secure cryptographic identification
tunnel.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#ifndef UDIF_TUNNEL_H
53#define UDIF_TUNNEL_H
54
55#include "udif.h"
56#include "message.h"
57#include "qstp.h"
58
94
95/* UDIF-over-QSTP transport profile */
96
104#define UDIF_TRANSPORT_PROFILE_QSTP_INNER_HEADER 1U
105
113#define UDIF_TRANSPORT_HEADER_EXTERNAL_AAD 0U
114
119#define UDIF_TRANSPORT_RATCHET_DELEGATED_TO_QSTP 1U
120
121/* UDIF record header */
122
127#define UDIF_TUNNEL_RECORD_HEADER_SIZE 26U
128
133#define UDIF_TUNNEL_TIME_WINDOW_SECONDS 60U
134
139#define UDIF_TUNNEL_FLAG_DATA 0x01U
140
145#define UDIF_TUNNEL_FLAG_KEEPALIVE 0x02U
146
151#define UDIF_TUNNEL_FLAG_CLOSE 0x04U
152
157#define UDIF_TUNNEL_FLAG_CONTROL 0x08U
158
164{
165 uint64_t sequence;
166 uint64_t utctime;
167 uint64_t epoch;
168 uint8_t flags;
169 uint8_t suiteid;
171
172/* Cadence macros */
173
178#define UDIF_KEEPALIVE_INTERVAL_A_SECONDS 300U
179
184#define UDIF_KEEPALIVE_INTERVAL_E_SECONDS 120U
185
190#define UDIF_KEEPALIVE_INTERVAL_U_SECONDS 120U
191
196#if !defined(UDIF_KEEPALIVE_INTERVAL_SECONDS)
197# define UDIF_KEEPALIVE_INTERVAL_SECONDS UDIF_KEEPALIVE_INTERVAL_E_SECONDS
198#endif
199
204#define UDIF_IDLE_TEARDOWN_MULTIPLIER 2U
205
210#define UDIF_IDLE_TEARDOWN_SECONDS (UDIF_KEEPALIVE_INTERVAL_SECONDS * UDIF_IDLE_TEARDOWN_MULTIPLIER)
211
216#define UDIF_RATCHET_INTERVAL_SECONDS 3600U
217
222#define UDIF_RATCHET_JITTER_SECONDS 300U
223
224/* Role-pair and side enums */
225
242
255
256/* Tunnel state */
257
283
284/* Record header helpers */
285
296
307
318
327
328/* Tunnel lifecycle */
329
351UDIF_EXPORT_API udif_errors udif_tunnel_init(udif_tunnel* tun, qstp_connection_state* qstpcns, const uint8_t* peerserial,
352 udif_rolepair rolepair, udif_tunnel_side side, const uint8_t* treatyid, uint64_t nowsecs);
353
363UDIF_EXPORT_API void udif_tunnel_close(udif_tunnel* tun, bool notify);
364
365/* Send and receive */
366
384UDIF_EXPORT_API udif_errors udif_tunnel_send(udif_tunnel* tun, const udif_message* msg, uint64_t nowsecs);
385
411UDIF_EXPORT_API udif_errors udif_tunnel_on_receive(udif_tunnel* tun, const uint8_t* input, size_t inplen, udif_message* outmsg, uint64_t nowsecs);
412
413/* Timer tick: keepalive, idle teardown, QSTP rekey */
414
441
454
468
469/* Introspection */
470
482UDIF_EXPORT_API bool udif_tunnel_is_open(const udif_tunnel* tun, uint64_t nowsecs);
483
484#endif
UDIF application-layer message framing.
udif_message_type
Canonical UDIF message type codes.
Definition message.h:119
A single UDIF application message.
Definition message.h:160
Canonical UDIF transport record header.
Definition tunnel.h:164
uint8_t suiteid
Definition tunnel.h:169
uint64_t epoch
Definition tunnel.h:167
uint8_t flags
Definition tunnel.h:168
uint64_t utctime
Definition tunnel.h:166
uint64_t sequence
Definition tunnel.h:165
Per-connection UDIF state layered atop a QSTP channel.
Definition tunnel.h:267
bool closing
Definition tunnel.h:281
udif_tunnel_side side
Definition tunnel.h:280
uint8_t treatyid[UDIF_SERIAL_NUMBER_SIZE]
Definition tunnel.h:269
uint8_t peerserial[UDIF_SERIAL_NUMBER_SIZE]
Definition tunnel.h:268
uint64_t idledeadline
Definition tunnel.h:277
uint64_t epoch
Definition tunnel.h:273
uint64_t txsequence
Definition tunnel.h:271
uint64_t rxsequence
Definition tunnel.h:272
uint64_t keepalivedeadline
Definition tunnel.h:276
uint64_t lastrxsecs
Definition tunnel.h:274
qstp_connection_state * qstpcns
Definition tunnel.h:270
udif_rolepair rolepair
Definition tunnel.h:279
uint64_t lasttxsecs
Definition tunnel.h:275
uint64_t ratchetdeadline
Definition tunnel.h:278
UDIF_EXPORT_API udif_errors udif_tunnel_trigger_ratchet(udif_tunnel *tun, uint64_t nowsecs)
Force an immediate ratchet trigger on a BC<->BC trunk.
Definition tunnel.c:462
udif_rolepair
Identifies the trust-tree relationship a tunnel spans.
Definition tunnel.h:234
@ udif_rolepair_bc_bc
Definition tunnel.h:238
@ udif_rolepair_none
Definition tunnel.h:235
@ udif_rolepair_treaty
Definition tunnel.h:240
@ udif_rolepair_bc_root
Definition tunnel.h:239
@ udif_rolepair_ua_gc
Definition tunnel.h:236
@ udif_rolepair_gc_bc
Definition tunnel.h:237
UDIF_EXPORT_API udif_errors udif_tunnel_send(udif_tunnel *tun, const udif_message *msg, uint64_t nowsecs)
Encode and send a UDIF message over the tunnel.
Definition tunnel.c:234
UDIF_EXPORT_API udif_errors udif_tunnel_record_header_deserialize(udif_tunnel_record_header *header, const uint8_t *input, size_t inlen)
Deserialize a UDIF tunnel record header.
Definition tunnel.c:89
UDIF_EXPORT_API udif_errors udif_tunnel_send_keepalive(udif_tunnel *tun, uint64_t nowsecs)
Force an immediate keepalive send, independent of the timer.
Definition tunnel.c:439
UDIF_EXPORT_API udif_errors udif_tunnel_on_receive(udif_tunnel *tun, const uint8_t *input, size_t inplen, udif_message *outmsg, uint64_t nowsecs)
Process an inbound decrypted payload delivered by QSTP.
Definition tunnel.c:371
UDIF_EXPORT_API uint8_t udif_tunnel_record_flag(udif_message_type msgtype)
Return the UDIF tunnel record flag for a message type.
Definition tunnel.c:40
UDIF_EXPORT_API udif_errors udif_tunnel_init(udif_tunnel *tun, qstp_connection_state *qstpcns, const uint8_t *peerserial, udif_rolepair rolepair, udif_tunnel_side side, const uint8_t *treatyid, uint64_t nowsecs)
Initialize a freshly-opened tunnel record.
Definition tunnel.c:160
UDIF_EXPORT_API udif_errors udif_tunnel_record_header_serialize(uint8_t *output, size_t outlen, const udif_tunnel_record_header *header)
Serialize a UDIF tunnel record header.
Definition tunnel.c:67
UDIF_EXPORT_API bool udif_tunnel_is_open(const udif_tunnel *tun, uint64_t nowsecs)
Check whether the tunnel is open and operational.
Definition tunnel.c:563
UDIF_EXPORT_API void udif_tunnel_close(udif_tunnel *tun, bool notify)
Close the tunnel and clear its state.
Definition tunnel.c:212
udif_tunnel_side
Which end of a tunnel this entity occupies.
Definition tunnel.h:251
@ udif_tunnel_side_client
Definition tunnel.h:252
@ udif_tunnel_side_server
Definition tunnel.h:253
UDIF_EXPORT_API udif_errors udif_tunnel_record_header_validate(const udif_tunnel *tun, const udif_tunnel_record_header *header, uint64_t nowsecs)
Validate a received UDIF tunnel record header against tunnel state.
Definition tunnel.c:111
UDIF_EXPORT_API udif_errors udif_tunnel_tick(udif_tunnel *tun, uint64_t nowsecs)
Drive per-tunnel timers forward.
Definition tunnel.c:501
UDIF Common Definitions and Protocol Configuration.
#define UDIF_SERIAL_NUMBER_SIZE
The certificate serial number field length.
Definition udif.h:546
udif_errors
UDIF error codes.
Definition udif.h:1210
#define UDIF_EXPORT_API
The api export prefix.
Definition udifcommon.h:101