MPDC: Multi Party Domain Cryptosystem 1.0.0.0b (A0)
MPDC Interior protocol
topology.h
Go to the documentation of this file.
1/* 2025 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE: This software and all accompanying materials are the exclusive
5 * property of Quantum Resistant Cryptographic Solutions Corporation (QRCS).
6 * The intellectual and technical concepts contained within this implementation
7 * are proprietary to QRCS and its authorized licensors and are protected under
8 * applicable U.S. and international copyright, patent, and trade secret laws.
9 *
10 * CRYPTOGRAPHIC STANDARDS:
11 * - This software includes implementations of cryptographic algorithms such as
12 * SHA3, AES, and others. These algorithms are public domain or standardized
13 * by organizations such as NIST and are NOT the property of QRCS.
14 * - However, all source code, optimizations, and implementations in this library
15 * are original works of QRCS and are protected under this license.
16 *
17 * RESTRICTIONS:
18 * - Redistribution, modification, or unauthorized distribution of this software,
19 * in whole or in part, is strictly prohibited.
20 * - This software is provided for non-commercial, educational, and research
21 * purposes only. Commercial use in any form is expressly forbidden.
22 * - Licensing and authorized distribution are solely at the discretion of QRCS.
23 * - Any use of this software implies acceptance of these restrictions.
24 *
25 * DISCLAIMER:
26 * This software is provided "as is," without warranty of any kind, express or
27 * implied, including but not limited to warranties of merchantability or fitness
28 * for a particular purpose. QRCS disclaims all liability for any direct, indirect,
29 * incidental, or consequential damages resulting from the use or misuse of this software.
30 *
31 * FULL LICENSE:
32 * This software is subject to the **Quantum Resistant Cryptographic Solutions
33 * Proprietary License (QRCS-PL)**. The complete license terms are included
34 * in the LICENSE.txt file distributed with this software.
35 *
36 * Written by: John G. Underhill
37 * Contact: john.underhill@protonmail.com
38 */
39
40#ifndef MPDC_TOPOLOGY_H
41#define MPDC_TOPOLOGY_H
42
43#include "mpdc.h"
44#include "certificate.h"
45#include "../../QSC/QSC/ipinfo.h"
46#include "../../QSC/QSC/list.h"
47#include "../../QSC/QSC/timestamp.h"
48
80
81/*---------------------------------------------------------------------------
82 MACRO DEFINITIONS
83---------------------------------------------------------------------------*/
84
92#if defined(MPDC_NETWORK_PROTOCOL_IPV6)
93# define MPDC_TOPOLOGY_NODE_ENCODED_SIZE (MPDC_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE + MPDC_CERTIFICATE_ISSUER_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
94 MPDC_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE + QSC_IPINFO_IPV6_STRNLEN + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
95 MPDC_ROOT_CERTIFICATE_HASH_PREFIX_SIZE + (MPDC_CERTIFICATE_HASH_SIZE * 2) + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
96 MPDC_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE + (MPDC_CERTIFICATE_SERIAL_SIZE * 2) + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
97 MPDC_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE + MPDC_NETWORK_DESIGNATION_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
98 MPDC_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
99 MPDC_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE)
100#else
101# define MPDC_TOPOLOGY_NODE_ENCODED_SIZE (MPDC_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE + MPDC_CERTIFICATE_ISSUER_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
102 MPDC_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE + QSC_IPINFO_IPV4_STRNLEN + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
103 MPDC_ROOT_CERTIFICATE_HASH_PREFIX_SIZE + (MPDC_CERTIFICATE_HASH_SIZE * 2) + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
104 MPDC_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE + (MPDC_CERTIFICATE_SERIAL_SIZE * 2) + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
105 MPDC_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE + MPDC_NETWORK_DESIGNATION_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
106 MPDC_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE + \
107 MPDC_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + MPDC_CERTIFICATE_SEPERATOR_SIZE)
108#endif
109
114#define MPDC_TOPOLOGY_NODE_MINIMUM_ISSUER_SIZE 3
115
120#define MPDC_TOPOLOGY_NODE_NOT_FOUND -1
121
126#define MPDC_NETWORK_TOPOLOGY_MAX_SIZE 1024
127
132#define MPDC_NETWORK_TOPOLOGY_NODE_SIZE (MPDC_CERTIFICATE_ADDRESS_SIZE + \
133 MPDC_CERTIFICATE_HASH_SIZE + \
134 MPDC_CERTIFICATE_SERIAL_SIZE + \
135 MPDC_CERTIFICATE_ISSUER_SIZE + \
136 MPDC_CERTIFICATE_EXPIRATION_SIZE + \
137 MPDC_CERTIFICATE_DESIGNATION_SIZE)
138
139/*---------------------------------------------------------------------------
140 STATIC CONSTANTS
141---------------------------------------------------------------------------*/
142
146static const char MPDC_TOPOLOGY_NETWORK_DELIMITER[] = "/";
147
151static const char MPDC_TOPOLOGY_CTYPE_DELIMITER[] = ".";
152
156static const char MPDC_TOPOLOGY_ALIAS_DELIMITER[] = ":";
157
158/*---------------------------------------------------------------------------
159 DATA STRUCTURES
160---------------------------------------------------------------------------*/
161
177
184MPDC_EXPORT_API typedef struct mpdc_topology_list_state
185{
186 uint8_t* topology;
187 uint32_t count;
189
190/*---------------------------------------------------------------------------
191 FUNCTION PROTOTYPES
192---------------------------------------------------------------------------*/
193
204MPDC_EXPORT_API void mpdc_topology_address_from_issuer(char* address, const char* issuer, const mpdc_topology_list_state* list);
205
214MPDC_EXPORT_API void mpdc_topology_node_add_alias(mpdc_topology_node_state* node, const char* alias);
215
226
237
247
259MPDC_EXPORT_API bool mpdc_topology_canonical_to_issuer_name(char* issuer, size_t isslen, const char* domain, const char* cname);
260
271MPDC_EXPORT_API bool mpdc_topology_issuer_to_canonical_name(char* cname, size_t namelen, const char* issuer);
272
282MPDC_EXPORT_API void mpdc_topology_child_register(mpdc_topology_list_state* list, const mpdc_child_certificate* ccert, const char* address);
283
292MPDC_EXPORT_API void mpdc_topology_list_clone(const mpdc_topology_list_state* tlist, mpdc_topology_list_state* tcopy);
293
303MPDC_EXPORT_API void mpdc_topology_list_deserialize(mpdc_topology_list_state* list, const uint8_t* input, size_t inplen);
304
312MPDC_EXPORT_API void mpdc_topology_list_dispose(mpdc_topology_list_state* list);
313
322
333MPDC_EXPORT_API bool mpdc_topology_list_item(const mpdc_topology_list_state* list, mpdc_topology_node_state* node, size_t index);
334
344
355
365MPDC_EXPORT_API size_t mpdc_topology_list_serialize(uint8_t* output, const mpdc_topology_list_state* list);
366
375MPDC_EXPORT_API size_t mpdc_topology_list_size(const mpdc_topology_list_state* list);
376
387MPDC_EXPORT_API size_t mpdc_topology_list_to_string(const mpdc_topology_list_state* list, char* output, size_t outlen);
388
399MPDC_EXPORT_API size_t mpdc_topology_list_update_pack(uint8_t* output, const mpdc_topology_list_state* list, mpdc_network_designations ntype);
400
411MPDC_EXPORT_API size_t mpdc_topology_list_update_unpack(mpdc_topology_list_state* list, const uint8_t* input, size_t inplen);
412
425
433MPDC_EXPORT_API void mpdc_topology_node_clear(mpdc_topology_node_state* node);
434
443MPDC_EXPORT_API void mpdc_topology_node_copy(const mpdc_topology_node_state* source, mpdc_topology_node_state* destination);
444
453MPDC_EXPORT_API void mpdc_topology_node_deserialize(mpdc_topology_node_state* node, const uint8_t* input);
454
464MPDC_EXPORT_API size_t mpdc_topology_node_encode(const mpdc_topology_node_state* node, char output[MPDC_TOPOLOGY_NODE_ENCODED_SIZE]);
465
475MPDC_EXPORT_API bool mpdc_topology_node_exists(const mpdc_topology_list_state* list, const uint8_t* serial);
476
486MPDC_EXPORT_API int32_t mpdc_topology_node_get_index(const mpdc_topology_list_state* list, const uint8_t* serial);
487
498MPDC_EXPORT_API bool mpdc_topology_node_find(const mpdc_topology_list_state* list, mpdc_topology_node_state* node, const uint8_t* serial);
499
510MPDC_EXPORT_API bool mpdc_topology_node_find_address(const mpdc_topology_list_state* list, mpdc_topology_node_state* node, const char* address);
511
522MPDC_EXPORT_API bool mpdc_topology_node_find_alias(const mpdc_topology_list_state* list, mpdc_topology_node_state* node, const char* alias);
523
534
545MPDC_EXPORT_API bool mpdc_topology_node_find_issuer(const mpdc_topology_list_state* list, mpdc_topology_node_state* node, const char* issuer);
546
557
566MPDC_EXPORT_API void mpdc_topology_node_remove(mpdc_topology_list_state* list, const uint8_t* serial);
567
576MPDC_EXPORT_API void mpdc_topology_node_remove_duplicate(mpdc_topology_list_state* list, const char* issuer);
577
587MPDC_EXPORT_API bool mpdc_topology_node_verify_dla(const mpdc_topology_list_state* list, const mpdc_child_certificate* ccert);
588
599MPDC_EXPORT_API bool mpdc_topology_node_verify_issuer(const mpdc_topology_list_state* list, const mpdc_child_certificate* ccert, const char* issuer);
600
610MPDC_EXPORT_API bool mpdc_topology_node_verify_root(const mpdc_topology_list_state* list, const mpdc_root_certificate* rcert);
611
621MPDC_EXPORT_API size_t mpdc_topology_node_serialize(uint8_t* output, const mpdc_topology_node_state* node);
622
632MPDC_EXPORT_API void mpdc_topology_root_register(mpdc_topology_list_state* list, const mpdc_root_certificate* rcert, const char* address);
633
642MPDC_EXPORT_API void mpdc_topology_from_file(const char* fpath, mpdc_topology_list_state* list);
643
652MPDC_EXPORT_API void mpdc_topology_to_file(const mpdc_topology_list_state* list, const char* fpath);
653
654#if defined(QSC_DEBUG_MODE)
662MPDC_EXPORT_API bool mpdc_topology_functions_test();
663#endif
664
665#endif
MPDC Certificate Handling Functions.
MPDC Common Definitions and Protocol Configuration.
#define MPDC_CERTIFICATE_ADDRESS_SIZE
The maximum IP address length.
Definition mpdc.h:758
#define MPDC_CERTIFICATE_ISSUER_SIZE
The maximum certificate issuer string length. The last character must be a string terminator.
Definition mpdc.h:795
#define MPDC_CERTIFICATE_HASH_SIZE
The size of the certificate hash in bytes.
Definition mpdc.h:788
mpdc_network_designations
The MPDC device designation.
Definition mpdc.h:1114
#define MPDC_CERTIFICATE_SERIAL_SIZE
The certificate serial number field length.
Definition mpdc.h:819
The certificate expiration time structure.
Definition mpdc.h:1283
The child certificate structure.
Definition mpdc.h:1293
The root certificate structure.
Definition mpdc.h:1411
The MPDC topology list structure.
Definition topology.h:185
uint8_t * topology
Definition topology.h:186
uint32_t count
Definition topology.h:187
The MPDC topology node structure.
Definition topology.h:169
uint8_t serial[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition topology.h:172
uint8_t chash[MPDC_CERTIFICATE_HASH_SIZE]
Definition topology.h:171
char issuer[MPDC_CERTIFICATE_ISSUER_SIZE]
Definition topology.h:173
mpdc_certificate_expiration expiration
Definition topology.h:174
mpdc_network_designations designation
Definition topology.h:175
char address[MPDC_CERTIFICATE_ADDRESS_SIZE]
Definition topology.h:170
MPDC_EXPORT_API void mpdc_topology_node_remove(mpdc_topology_list_state *list, const uint8_t *serial)
Find and remove a node from the topology.
Definition topology.c:987
MPDC_EXPORT_API bool mpdc_topology_node_find_root(const mpdc_topology_list_state *list, mpdc_topology_node_state *node)
Return the RDS server node from the list.
Definition topology.c:905
MPDC_EXPORT_API void mpdc_topology_child_add_item(mpdc_topology_list_state *list, const mpdc_topology_node_state *node)
Add a node to the topology list.
Definition topology.c:87
MPDC_EXPORT_API size_t mpdc_topology_ordered_server_list(mpdc_topology_list_state *olist, const mpdc_topology_list_state *tlist, mpdc_network_designations ntype)
Return a list of nodes of a type, sorted by serial number.
Definition topology.c:527
MPDC_EXPORT_API size_t mpdc_topology_list_update_unpack(mpdc_topology_list_state *list, const uint8_t *input, size_t inplen)
Unpack a node update set to the topology list.
Definition topology.c:497
MPDC_EXPORT_API size_t mpdc_topology_list_server_count(const mpdc_topology_list_state *list, mpdc_network_designations ntype)
Get the count of a type of node in the database.
Definition topology.c:393
MPDC_EXPORT_API bool mpdc_topology_node_find_dla(const mpdc_topology_list_state *list, mpdc_topology_node_state *node)
Return the DLA node from the list.
Definition topology.c:822
MPDC_EXPORT_API void mpdc_topology_root_register(mpdc_topology_list_state *list, const mpdc_root_certificate *rcert, const char *address)
Register a root to a topology list.
Definition topology.c:1158
MPDC_EXPORT_API bool mpdc_topology_node_find_issuer(const mpdc_topology_list_state *list, mpdc_topology_node_state *node, const char *issuer)
Return the node pointer in the list matching the name string.
Definition topology.c:858
MPDC_EXPORT_API void mpdc_topology_list_clone(const mpdc_topology_list_state *tlist, mpdc_topology_list_state *tcopy)
Clone a topology list.
Definition topology.c:220
#define MPDC_TOPOLOGY_NODE_ENCODED_SIZE
The size of an encoded node string.
Definition topology.h:101
MPDC_EXPORT_API size_t mpdc_topology_list_to_string(const mpdc_topology_list_state *list, char *output, size_t outlen)
Convert the topology list to a printable string.
Definition topology.c:1181
MPDC_EXPORT_API size_t mpdc_topology_list_update_pack(uint8_t *output, const mpdc_topology_list_state *list, mpdc_network_designations ntype)
Pack a node update set to an array.
Definition topology.c:468
MPDC_EXPORT_API bool mpdc_topology_node_find(const mpdc_topology_list_state *list, mpdc_topology_node_state *node, const uint8_t *serial)
Return the node pointer in the list matching the serial number.
Definition topology.c:711
MPDC_EXPORT_API bool mpdc_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
MPDC_EXPORT_API void mpdc_topology_from_file(const char *fpath, mpdc_topology_list_state *list)
Copy a topology list from a file.
Definition topology.c:1299
MPDC_EXPORT_API bool mpdc_topology_node_verify_dla(const mpdc_topology_list_state *list, const mpdc_child_certificate *ccert)
Verify that the DLA certificate matches the hash stored in the topology.
Definition topology.c:1082
MPDC_EXPORT_API void mpdc_topology_child_register(mpdc_topology_list_state *list, const mpdc_child_certificate *ccert, const char *address)
Register a child to a topology list.
Definition topology.c:187
MPDC_EXPORT_API void mpdc_topology_node_clear(mpdc_topology_node_state *node)
Erase a node structure.
Definition topology.c:653
MPDC_EXPORT_API size_t mpdc_topology_list_remove_duplicates(mpdc_topology_list_state *list)
Remove duplicate nodes from the topology.
Definition topology.c:320
MPDC_EXPORT_API bool mpdc_topology_node_exists(const mpdc_topology_list_state *list, const uint8_t *serial)
Queries on the serial number if the node is in the database.
Definition topology.c:941
MPDC_EXPORT_API void mpdc_topology_node_copy(const mpdc_topology_node_state *source, mpdc_topology_node_state *destination)
Copy a source node to a destination node structure.
Definition topology.c:669
MPDC_EXPORT_API size_t mpdc_topology_list_serialize(uint8_t *output, const mpdc_topology_list_state *list)
Serialize a topology list.
Definition topology.c:420
MPDC_EXPORT_API int32_t mpdc_topology_node_get_index(const mpdc_topology_list_state *list, const uint8_t *serial)
Find the index number of a node in an array.
Definition topology.c:958
MPDC_EXPORT_API bool mpdc_topology_node_find_address(const mpdc_topology_list_state *list, mpdc_topology_node_state *node, const char *address)
Return the node pointer in the list matching the address string.
Definition topology.c:748
MPDC_EXPORT_API bool mpdc_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
MPDC_EXPORT_API uint8_t * mpdc_topology_child_add_empty_node(mpdc_topology_list_state *list)
Get an empty node pointer from the topology list.
Definition topology.c:43
MPDC_EXPORT_API void mpdc_topology_list_deserialize(mpdc_topology_list_state *list, const uint8_t *input, size_t inplen)
Deserialize a topology list.
Definition topology.c:235
MPDC_EXPORT_API size_t mpdc_topology_node_encode(const mpdc_topology_node_state *node, char output[MPDC_TOPOLOGY_NODE_ENCODED_SIZE])
Encode a topological node into a printable string.
Definition topology.c:1210
MPDC_EXPORT_API void mpdc_topology_address_from_issuer(char *address, const char *issuer, const mpdc_topology_list_state *list)
Returns an IP address from an issuer string.
Definition topology.c:12
MPDC_EXPORT_API bool mpdc_topology_node_verify_root(const mpdc_topology_list_state *list, const mpdc_root_certificate *rcert)
Verify that the root certificate matches the hash stored in the topology.
Definition topology.c:1133
MPDC_EXPORT_API void mpdc_topology_list_dispose(mpdc_topology_list_state *list)
Dispose of the topology list and release memory.
Definition topology.c:267
MPDC_EXPORT_API bool mpdc_topology_list_item(const mpdc_topology_list_state *list, mpdc_topology_node_state *node, size_t index)
Get a node from the index.
Definition topology.c:294
MPDC_EXPORT_API bool mpdc_topology_node_find_alias(const mpdc_topology_list_state *list, mpdc_topology_node_state *node, const char *alias)
Return the node pointer in the list matching the alias string.
Definition topology.c:785
MPDC_EXPORT_API void mpdc_topology_to_file(const mpdc_topology_list_state *list, const char *fpath)
Copy a topology list to a file.
Definition topology.c:1328
MPDC_EXPORT_API bool mpdc_topology_node_verify_issuer(const mpdc_topology_list_state *list, const mpdc_child_certificate *ccert, const char *issuer)
Verify that an issuing node's certificate matches the hash stored in the topology.
Definition topology.c:1107
MPDC_EXPORT_API bool mpdc_topology_nodes_are_equal(const mpdc_topology_node_state *a, const mpdc_topology_node_state *b)
Compare two topological nodes for equality.
Definition topology.c:618
MPDC_EXPORT_API size_t mpdc_topology_list_size(const mpdc_topology_list_state *list)
Get the byte size of the serialized list.
Definition topology.c:449
MPDC_EXPORT_API void mpdc_topology_node_add_alias(mpdc_topology_node_state *node, const char *alias)
Add an alias string to an issuer path.
Definition topology.c:585
MPDC_EXPORT_API size_t mpdc_topology_node_serialize(uint8_t *output, const mpdc_topology_node_state *node)
Serialize a topological node structure, including the mfk.
Definition topology.c:1052
MPDC_EXPORT_API void mpdc_topology_node_remove_duplicate(mpdc_topology_list_state *list, const char *issuer)
Remove a node from the topology with the same issuer name.
Definition topology.c:1035
MPDC_EXPORT_API void mpdc_topology_list_initialize(mpdc_topology_list_state *list)
Initialize the topology list.
Definition topology.c:283
MPDC_EXPORT_API void mpdc_topology_node_deserialize(mpdc_topology_node_state *node, const uint8_t *input)
Deserialize a topological node.
Definition topology.c:686