UDIF: Universal Digital Identification Framework 1.0.0.0a (A1)
A quantum-secure cryptographic identification
topology.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_TOPOLOGY_H
53#define UDIF_TOPOLOGY_H
54
55#include "udif.h"
56#include "certificate.h"
57#include "ipinfo.h"
58#include "list.h"
59#include "timestamp.h"
60
92
93/*---------------------------------------------------------------------------
94 MACRO DEFINITIONS
95---------------------------------------------------------------------------*/
96
104#if defined(UDIF_NETWORK_PROTOCOL_IPV6)
105# define UDIF_TOPOLOGY_NODE_ENCODED_SIZE (UDIF_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE + UDIF_CERTIFICATE_ISSUER_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
106 UDIF_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE + QSC_IPINFO_IPV6_STRNLEN + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
107 UDIF_ROOT_CERTIFICATE_HASH_PREFIX_SIZE + (UDIF_CERTIFICATE_HASH_SIZE * 2U) + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
108 UDIF_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE + (UDIF_CERTIFICATE_SERIAL_SIZE * 2U) + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
109 UDIF_CHILD_CERTIFICATE_DESIGNATION_PREFIX + UDIF_NETWORK_DESIGNATION_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
110 UDIF_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
111 UDIF_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE)
112#else
113# define UDIF_TOPOLOGY_NODE_ENCODED_SIZE (UDIF_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE + UDIF_CERTIFICATE_ISSUER_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
114 UDIF_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE + QSC_IPINFO_IPV4_STRNLEN + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
115 UDIF_ROOT_CERTIFICATE_HASH_PREFIX_SIZE + (UDIF_CERTIFICATE_HASH_SIZE * 2U) + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
116 UDIF_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE + (UDIF_CERTIFICATE_SERIAL_SIZE * 2U) + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
117 UDIF_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE + UDIF_NETWORK_DESIGNATION_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
118 UDIF_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE + \
119 UDIF_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + UDIF_CERTIFICATE_SEPERATOR_SIZE)
120#endif
121
126#define UDIF_TOPOLOGY_NODE_MINIMUM_ISSUER_SIZE 3U
127
132#define UDIF_TOPOLOGY_NODE_NOT_FOUND -1
133
138#define UDIF_NETWORK_TOPOLOGY_MAX_SIZE 1024U
139
144#define UDIF_NETWORK_TOPOLOGY_NODE_SIZE (UDIF_CERTIFICATE_ADDRESS_SIZE + \
145 UDIF_CERTIFICATE_HASH_SIZE + \
146 UDIF_CERTIFICATE_SERIAL_SIZE + \
147 UDIF_CERTIFICATE_ISSUER_SIZE + \
148 UDIF_CERTIFICATE_EXPIRATION_SIZE + \
149 UDIF_CERTIFICATE_DESIGNATION_SIZE)
150
151/*---------------------------------------------------------------------------
152 STATIC CONSTANTS
153---------------------------------------------------------------------------*/
154
158static const char UDIF_TOPOLOGY_NETWORK_DELIMITER[] = "/";
159
163static const char UDIF_TOPOLOGY_CTYPE_DELIMITER[] = ".";
164
168static const char UDIF_TOPOLOGY_ALIAS_DELIMITER[] = ":";
169
170/*---------------------------------------------------------------------------
171 DATA STRUCTURES
172---------------------------------------------------------------------------*/
173
181{
183 uint8_t chash[UDIF_CERTIFICATE_HASH_SIZE];
184 uint8_t serial[UDIF_CERTIFICATE_SERIAL_SIZE];
186 udif_certificate_expiration expiration;
187 udif_network_designations designation;
189
201
202/*---------------------------------------------------------------------------
203 FUNCTION PROTOTYPES
204---------------------------------------------------------------------------*/
205
216UDIF_EXPORT_API void udif_topology_address_from_issuer(char* address, const char* issuer, const udif_topology_list_state* list);
217
227
238
249
259
271UDIF_EXPORT_API bool udif_topology_canonical_to_issuer_name(char* issuer, size_t isslen, const char* domain, const char* cname);
272
283UDIF_EXPORT_API bool udif_topology_issuer_to_canonical_name(char* cname, size_t namelen, const char* issuer);
284
294UDIF_EXPORT_API void udif_topology_child_register(udif_topology_list_state* list, const udif_child_certificate* ccert, const char* address);
295
305
315UDIF_EXPORT_API void udif_topology_list_deserialize(udif_topology_list_state* list, const uint8_t* input, size_t inplen);
316
325
334
346
356
366UDIF_EXPORT_API size_t udif_topology_list_server_count(const udif_topology_list_state* list, udif_network_designations ntype);
367
378
388
399UDIF_EXPORT_API size_t udif_topology_list_to_string(const udif_topology_list_state* list, char* output, size_t outlen);
400
411UDIF_EXPORT_API size_t udif_topology_list_update_pack(uint8_t* output, const udif_topology_list_state* list, udif_network_designations ntype);
412
423UDIF_EXPORT_API size_t udif_topology_list_update_unpack(udif_topology_list_state* list, const uint8_t* input, size_t inplen);
424
436UDIF_EXPORT_API size_t udif_topology_ordered_server_list(udif_topology_list_state* olist, const udif_topology_list_state* tlist, udif_network_designations ntype);
437
446
456
466
477
487UDIF_EXPORT_API bool udif_topology_node_exists(const udif_topology_list_state* list, const uint8_t* serial);
488
498UDIF_EXPORT_API int32_t udif_topology_node_get_index(const udif_topology_list_state* list, const uint8_t* serial);
499
511
523
535
546
558
569
579
589
599UDIF_EXPORT_API bool udif_topology_node_verify_ads(const udif_topology_list_state* list, const udif_child_certificate* ccert);
600
611UDIF_EXPORT_API bool udif_topology_node_verify_issuer(const udif_topology_list_state* list, const udif_child_certificate* ccert, const char* issuer);
612
622UDIF_EXPORT_API bool udif_topology_node_verify_root(const udif_topology_list_state* list, const udif_root_certificate* rcert);
623
634
644UDIF_EXPORT_API void udif_topology_root_register(udif_topology_list_state* list, const udif_root_certificate* rcert, const char* address);
645
655
664UDIF_EXPORT_API void udif_topology_to_file(const udif_topology_list_state* list, const char* fpath);
665
666#if defined(UDIF_DEBUG_MODE)
674UDIF_EXPORT_API bool udif_topology_functions_test();
675#endif
676
677#endif
UDIF Certificate Handling Functions.
#define UDIF_CERTIFICATE_ADDRESS_SIZE
The maximum IP address length.
Definition certificate.h:83
#define UDIF_CERTIFICATE_ISSUER_SIZE
The maximum certificate issuer string length. The last character must be a string terminator.
Definition certificate.h:138
The UDIF topology list structure.
Definition topology.h:197
uint8_t * topology
Definition topology.h:198
uint32_t count
Definition topology.h:199
The UDIF topology node structure.
Definition topology.h:181
udif_certificate_expiration expiration
Definition topology.h:186
uint8_t chash[UDIF_CERTIFICATE_HASH_SIZE]
Definition topology.h:183
char address[UDIF_CERTIFICATE_ADDRESS_SIZE]
Definition topology.h:182
uint8_t serial[UDIF_CERTIFICATE_SERIAL_SIZE]
Definition topology.h:184
udif_network_designations designation
Definition topology.h:187
char issuer[UDIF_CERTIFICATE_ISSUER_SIZE]
Definition topology.h:185
UDIF_EXPORT_API size_t udif_topology_list_size(const udif_topology_list_state *list)
Get the byte size of the serialized list.
Definition topology.c:449
UDIF_EXPORT_API bool udif_topology_node_verify_root(const udif_topology_list_state *list, const udif_root_certificate *rcert)
Verify that the root certificate matches the hash stored in the topology.
Definition topology.c:1133
UDIF_EXPORT_API bool udif_topology_canonical_to_issuer_name(char *issuer, size_t isslen, const char *domain, const char *cname)
Translate a canonical name to an issuer name.
Definition topology.c:109
UDIF_EXPORT_API bool udif_topology_node_verify_issuer(const udif_topology_list_state *list, const udif_child_certificate *ccert, const char *issuer)
Verify that an issuing node's certificate matches the hash stored in the topology.
Definition topology.c:1107
UDIF_EXPORT_API bool udif_topology_node_find_alias(const udif_topology_list_state *list, udif_topology_node_state *node, const char *alias)
Return the node pointer in the list matching the alias string.
Definition topology.c:785
UDIF_EXPORT_API void udif_topology_address_from_issuer(char *address, const char *issuer, const udif_topology_list_state *list)
Returns an IP address from an issuer string.
Definition topology.c:12
UDIF_EXPORT_API void udif_topology_list_clone(const udif_topology_list_state *tlist, udif_topology_list_state *tcopy)
Clone a topology list.
Definition topology.c:220
UDIF_EXPORT_API void udif_topology_node_remove(udif_topology_list_state *list, const uint8_t *serial)
Find and remove a node from the topology.
Definition topology.c:987
UDIF_EXPORT_API bool udif_topology_node_find(const udif_topology_list_state *list, udif_topology_node_state *node, const uint8_t *serial)
Return the node pointer in the list matching the serial number.
Definition topology.c:711
UDIF_EXPORT_API void udif_topology_list_dispose(udif_topology_list_state *list)
Dispose of the topology list and release memory.
Definition topology.c:267
UDIF_EXPORT_API void udif_topology_list_deserialize(udif_topology_list_state *list, const uint8_t *input, size_t inplen)
Deserialize a topology list.
Definition topology.c:235
UDIF_EXPORT_API void udif_topology_to_file(const udif_topology_list_state *list, const char *fpath)
Copy a topology list to a file.
Definition topology.c:1328
UDIF_EXPORT_API void udif_topology_list_initialize(udif_topology_list_state *list)
Initialize the topology list.
Definition topology.c:283
UDIF_EXPORT_API size_t udif_topology_node_encode(const udif_topology_node_state *node, char output[UDIF_TOPOLOGY_NODE_ENCODED_SIZE])
Encode a topological node into a printable string.
Definition topology.c:1210
UDIF_EXPORT_API size_t udif_topology_ordered_server_list(udif_topology_list_state *olist, const udif_topology_list_state *tlist, udif_network_designations ntype)
Return a list of nodes of a type, sorted by serial number.
Definition topology.c:527
UDIF_EXPORT_API size_t udif_topology_list_remove_duplicates(udif_topology_list_state *list)
Remove duplicate nodes from the topology.
Definition topology.c:320
UDIF_EXPORT_API void udif_topology_root_register(udif_topology_list_state *list, const udif_root_certificate *rcert, const char *address)
Register a root to a topology list.
Definition topology.c:1158
UDIF_EXPORT_API void udif_topology_child_add_item(udif_topology_list_state *list, const udif_topology_node_state *node)
Add a node to the topology list.
Definition topology.c:87
UDIF_EXPORT_API size_t udif_topology_list_serialize(uint8_t *output, const udif_topology_list_state *list)
Serialize a topology list.
Definition topology.c:420
UDIF_EXPORT_API bool udif_topology_nodes_are_equal(const udif_topology_node_state *a, const udif_topology_node_state *b)
Compare two topological nodes for equality.
Definition topology.c:618
#define UDIF_TOPOLOGY_NODE_ENCODED_SIZE
The size of an encoded node string.
Definition topology.h:113
UDIF_EXPORT_API size_t udif_topology_list_update_unpack(udif_topology_list_state *list, const uint8_t *input, size_t inplen)
Unpack a node update set to the topology list.
Definition topology.c:497
UDIF_EXPORT_API size_t udif_topology_list_update_pack(uint8_t *output, const udif_topology_list_state *list, udif_network_designations ntype)
Pack a node update set to an array.
Definition topology.c:468
UDIF_EXPORT_API int32_t udif_topology_node_get_index(const udif_topology_list_state *list, const uint8_t *serial)
Find the index number of a node in an array.
Definition topology.c:958
UDIF_EXPORT_API bool udif_topology_node_find_issuer(const udif_topology_list_state *list, udif_topology_node_state *node, const char *issuer)
Return the node pointer in the list matching the name string.
Definition topology.c:858
UDIF_EXPORT_API void udif_topology_from_file(const char *fpath, udif_topology_list_state *list)
Copy a topology list from a file.
Definition topology.c:1299
UDIF_EXPORT_API bool udif_topology_list_item(const udif_topology_list_state *list, udif_topology_node_state *node, size_t index)
Get a node from the index.
Definition topology.c:294
UDIF_EXPORT_API size_t udif_topology_list_server_count(const udif_topology_list_state *list, udif_network_designations ntype)
Get the count of a type of node in the database.
Definition topology.c:393
UDIF_EXPORT_API void udif_topology_node_deserialize(udif_topology_node_state *node, const uint8_t *input)
Deserialize a topological node.
Definition topology.c:686
UDIF_EXPORT_API bool udif_topology_node_find_ads(const udif_topology_list_state *list, udif_topology_node_state *node)
Return the ADC node from the list.
Definition topology.c:822
UDIF_EXPORT_API void udif_topology_node_remove_duplicate(udif_topology_list_state *list, const char *issuer)
Remove a node from the topology with the same issuer name.
Definition topology.c:1035
UDIF_EXPORT_API size_t udif_topology_list_to_string(const udif_topology_list_state *list, char *output, size_t outlen)
Convert the topology list to a printable string.
Definition topology.c:1181
UDIF_EXPORT_API void udif_topology_node_copy(const udif_topology_node_state *source, udif_topology_node_state *destination)
Copy a source node to a destination node structure.
Definition topology.c:669
UDIF_EXPORT_API size_t udif_topology_node_serialize(uint8_t *output, const udif_topology_node_state *node)
Serialize a topological node structure, including the mfk.
Definition topology.c:1052
UDIF_EXPORT_API bool udif_topology_node_find_root(const udif_topology_list_state *list, udif_topology_node_state *node)
Return the ARS server node from the list.
Definition topology.c:905
UDIF_EXPORT_API void udif_topology_node_add_alias(udif_topology_node_state *node, const char *alias)
Add an alias string to an issuer path.
Definition topology.c:585
UDIF_EXPORT_API void udif_topology_child_register(udif_topology_list_state *list, const udif_child_certificate *ccert, const char *address)
Register a child to a topology list.
Definition topology.c:187
UDIF_EXPORT_API bool udif_topology_node_find_address(const udif_topology_list_state *list, udif_topology_node_state *node, const char *address)
Return the node pointer in the list matching the address string.
Definition topology.c:748
UDIF_EXPORT_API bool udif_topology_issuer_to_canonical_name(char *cname, size_t namelen, const char *issuer)
Translate an issuer name to a canonical name.
Definition topology.c:147
UDIF_EXPORT_API void udif_topology_node_clear(udif_topology_node_state *node)
Erase a node structure.
Definition topology.c:653
UDIF_EXPORT_API bool udif_topology_node_verify_ads(const udif_topology_list_state *list, const udif_child_certificate *ccert)
Verify that the ADC certificate matches the hash stored in the topology.
Definition topology.c:1082
UDIF_EXPORT_API bool udif_topology_node_exists(const udif_topology_list_state *list, const uint8_t *serial)
Queries on the serial number if the node is in the database.
Definition topology.c:941
UDIF_EXPORT_API uint8_t * udif_topology_child_add_empty_node(udif_topology_list_state *list)
Get an empty node pointer from the topology list.
Definition topology.c:43
UDIF Common Definitions and Protocol Configuration.
#define UDIF_EXPORT_API
The api export prefix.
Definition udifcommon.h:103