MPDC: Multi Party Domain Cryptosystem 1.0.0.0b (A0)
MPDC Interior protocol
mpdc.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_MPDC_H
41#define MPDC_MPDC_H
42
43#include "common.h"
44#include "../../QSC/QSC/rcs.h"
45#include "../../QSC/QSC/sha3.h"
46#include "../../QSC/QSC/socketbase.h"
47
48#if defined(MPDC_CONFIG_DILITHIUM_KYBER)
49# include "../../QSC/QSC/dilithium.h"
50# include "../../QSC/QSC/kyber.h"
51#elif defined(MPDC_CONFIG_SPHINCS_MCELIECE)
52# include "../../QSC/QSC/mceliece.h"
53# include "../../QSC/QSC/sphincsplus.h"
54#else
55# error Invalid parameter set!
56#endif
57
103
104/* --- Function Mapping Macros --- */
105
114#if defined(MPDC_CONFIG_SPHINCS_MCELIECE)
119# define mpdc_cipher_generate_keypair qsc_mceliece_generate_keypair
124# define mpdc_cipher_decapsulate qsc_mceliece_decapsulate
129# define mpdc_cipher_encapsulate qsc_mceliece_encapsulate
134# define mpdc_signature_generate_keypair qsc_sphincsplus_generate_keypair
139# define mpdc_signature_sign qsc_sphincsplus_sign
144# define mpdc_signature_verify qsc_sphincsplus_verify
145#elif defined(MPDC_CONFIG_DILITHIUM_KYBER)
150# define mpdc_cipher_generate_keypair qsc_kyber_generate_keypair
155# define mpdc_cipher_decapsulate qsc_kyber_decapsulate
160# define mpdc_cipher_encapsulate qsc_kyber_encapsulate
165# define mpdc_signature_generate_keypair qsc_dilithium_generate_keypair
170# define mpdc_signature_sign qsc_dilithium_sign
175# define mpdc_signature_verify qsc_dilithium_verify
176#else
177# error Invalid parameter set!
178#endif
179
180/* ### Modifiable Constants: These constants can be enabled to turn on protocol features ### */
181
183// * \def MPDC_NETWORK_CLIENT_CONNECT
184// * \brief Enable client to client encrypted tunnel.
185// */
186//#define MPDC_NETWORK_CLIENT_CONNECT
187
189// * \def MPDC_NETWORK_MFK_HASH_CYCLED
190// * \brief Enable mfk key cycling (default).
191// */
192//#define MPDC_NETWORK_MFK_HASH_CYCLED
193
198//#define MPDC_NETWORK_PROTOCOL_IPV6
199
201// * \def MPDC_EXTENDED_SESSION_SECURITY
202// * \brief Enable 512-bit security on session tunnels.
203// */
204//#define MPDC_EXTENDED_SESSION_SECURITY
205
206/* ### End of Modifiable Constants ### */
207
208
209#if defined(MPDC_CONFIG_DILITHIUM_KYBER)
210
215# define MPDC_ASYMMETRIC_CIPHERTEXT_SIZE (QSC_KYBER_CIPHERTEXT_SIZE)
216
221# define MPDC_ASYMMETRIC_PRIVATE_KEY_SIZE (QSC_KYBER_PRIVATEKEY_SIZE)
222
227# define MPDC_ASYMMETRIC_PUBLIC_KEY_SIZE (QSC_KYBER_PUBLICKEY_SIZE)
228
233# define MPDC_ASYMMETRIC_SIGNATURE_SIZE (QSC_DILITHIUM_SIGNATURE_SIZE)
234
239# define MPDC_ASYMMETRIC_SIGNING_KEY_SIZE (QSC_DILITHIUM_PRIVATEKEY_SIZE)
240
245# define MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE (QSC_DILITHIUM_PUBLICKEY_SIZE)
246
247# if defined(QSC_DILITHIUM_S1P2544) && defined(QSC_KYBER_S1P1632)
252# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 5612
257# define MPDC_PARAMATERS_DILITHIUM_KYBER_D1K1
262# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 2188
267# define MPDC_SIGNATURE_ENCODING_SIZE 3272
272# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 1752
273# elif defined(QSC_DILITHIUM_S3P4016) && defined(QSC_KYBER_S3P2400)
278# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 7648
283# define MPDC_PARAMATERS_DILITHIUM_KYBER_D3K3
288# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 3053
293# define MPDC_SIGNATURE_ENCODING_SIZE 4436
298# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 2604
299# elif defined(QSC_DILITHIUM_S5P4880) && defined(QSC_KYBER_S5P3168)
304# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 10311
309# define MPDC_PARAMATERS_DILITHIUM_KYBER_D5K5
314# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 3919
319# define MPDC_SIGNATURE_ENCODING_SIZE 6172
324# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 3456
325# elif defined(QSC_DILITHIUM_S5P4880) && defined(QSC_KYBER_S6P3936)
330# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 10311
335# define MPDC_PARAMATERS_DILITHIUM_KYBER_D5K6
340# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 3919
345# define MPDC_SIGNATURE_ENCODING_SIZE 6172
350# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 3456
351# else
352 /* The library signature scheme and asymmetric cipher parameter sets
353 must be synchronized to a common security level; s1, s3, s5, s5+ */
354# error the library parameter sets are mismatched!
355# endif
356
357#elif defined(MPDC_CONFIG_SPHINCS_MCELIECE)
358
363# define MPDC_ASYMMETRIC_CIPHERTEXT_SIZE (QSC_MCELIECE_CIPHERTEXT_SIZE)
364
369# define MPDC_ASYMMETRIC_PRIVATE_KEY_SIZE (QSC_MCELIECE_PRIVATEKEY_SIZE)
370
375# define MPDC_ASYMMETRIC_PUBLIC_KEY_SIZE (QSC_MCELIECE_PUBLICKEY_SIZE)
376
381# define MPDC_ASYMMETRIC_SIGNATURE_SIZE (QSC_SPHINCSPLUS_SIGNATURE_SIZE)
382
387# define MPDC_ASYMMETRIC_SIGNING_KEY_SIZE (QSC_SPHINCSPLUS_PRIVATEKEY_SIZE)
388
393# define MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE (QSC_SPHINCSPLUS_PUBLICKEY_SIZE)
394
395# if defined(QSC_MCELIECE_S1N3488T64)
396# if defined(QSC_SPHINCSPLUS_S1S128SHAKERF)
401# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 23737
406# define MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF1M1
411# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 455
416# define MPDC_SIGNATURE_ENCODING_SIZE 22828
421# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 44
422# elif defined(QSC_SPHINCSPLUS_S1S128SHAKERS)
427# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 11237
432# define MPDC_PARAMATERS_SPHINCSS_MCELIECE_SS1M1
437# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 455
442# define MPDC_SIGNATURE_ENCODING_SIZE 10520
447# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 44
448# endif
449# elif defined(QSC_MCELIECE_S3N4608T96)
450# if defined(QSC_SPHINCSPLUS_S3S192SHAKERF)
455# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 48912
460# define MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF3M3
465# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 476
470# define MPDC_SIGNATURE_ENCODING_SIZE 47596
475# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 64
476# elif defined(QSC_SPHINCSPLUS_S3S192SHAKERS)
481# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 22588
486# define MPDC_PARAMATERS_SPHINCSS_MCELIECE_SS3M3
491# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 476
496# define MPDC_SIGNATURE_ENCODING_SIZE 21676
501# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 64
502# endif
503# elif defined(QSC_MCELIECE_S5N6688T128)
504# if defined(QSC_SPHINCSPLUS_S5S256SHAKERF)
509# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 68158
514# define MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF5M5
519# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 501
524# define MPDC_SIGNATURE_ENCODING_SIZE 66520
529# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 88
530# elif defined(QSC_SPHINCSPLUS_S5S256SHAKERS)
535# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 40987
540# define MPDC_PARAMATERS_SPHINCSS_MCELIECE_SS5M5
545# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 501
550# define MPDC_SIGNATURE_ENCODING_SIZE 39768
555# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 88
556# endif
557# elif defined(QSC_MCELIECE_S6N6960T119)
558# if defined(QSC_SPHINCSPLUS_S5S256SHAKERF)
563# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 68157
568# define MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF5M6
573# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 501
578# define MPDC_SIGNATURE_ENCODING_SIZE 66520
583# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 88
584# elif defined(QSC_SPHINCSPLUS_S5S256SHAKERS)
589# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 40987
594# define MPDC_PARAMATERS_SPHINCSS_MCELIECE_SS5M6
599# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 501
604# define MPDC_SIGNATURE_ENCODING_SIZE 39768
609# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 88
610# endif
611# elif defined(QSC_MCELIECE_S7N8192T128)
612# if defined(QSC_SPHINCSPLUS_S5S256SHAKERF)
617# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 68157
622# define MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF5M7
627# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 501
632# define MPDC_SIGNATURE_ENCODING_SIZE 66520
637# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 88
638# elif defined(QSC_SPHINCSPLUS_S5S256SHAKERS)
643# define MPDC_CHILD_CERTIFICATE_STRING_SIZE 40987
648# define MPDC_PARAMATERS_SPHINCSS_MCELIECE_SS5M7
653# define MPDC_ROOT_CERTIFICATE_STRING_SIZE 501
658# define MPDC_SIGNATURE_ENCODING_SIZE 39768
663# define MPDC_VERIFICATION_KEY_ENCODING_SIZE 88
664# else
665# error Invalid parameter sets, check the QSC library settings
666# endif
667# else
668 /* The library signature scheme and asymmetric cipher parameter sets
669 must be synchronized to a common security level; s1, s3, s5 or s6.
670 Check the QSC library common.h file for cipher and signature security level alignment. */
671# error Invalid parameter sets, check the QSC library settings
672# endif
673#endif
674
679#define MPDC_ACTIVE_VERSION 1
680
685#define MPDC_ACTIVE_VERSION_SIZE 2
686
691#define MPDC_APPLICATION_AGENT_PORT 37766
692
697#define MPDC_AGENT_FULL_TRUST 1000001
698
703#define MPDC_AGENT_MINIMUM_TRUST 1
704
710#define MPDC_AGENT_NAME_MAX_SIZE 256
711
716#define MPDC_AGENT_TWOWAY_TRUST 1000002
717
722#define MPDC_APPLICATION_CLIENT_PORT 37761
723
728#define MPDC_APPLICATION_DLA_PORT 37762
729
734#define MPDC_APPLICATION_IDG_PORT 37763
735
740#define MPDC_APPLICATION_RDS_PORT 37764
741
746#define MPDC_APPLICATION_MAS_PORT 37765
747
752#define MPDC_CANONICAL_NAME_MINIMUM_SIZE 3
753
758#define MPDC_CERTIFICATE_ADDRESS_SIZE 22
759
764#define MPDC_CERTIFICATE_ALGORITHM_SIZE 1
765
770#define MPDC_CERTIFICATE_DEFAULT_PERIOD ((uint64_t)365 * 24 * 60 * 60)
771
776#define MPDC_CERTIFICATE_DESIGNATION_SIZE 1
777
782#define MPDC_CERTIFICATE_EXPIRATION_SIZE 16
783
788#define MPDC_CERTIFICATE_HASH_SIZE 32
789
795#define MPDC_CERTIFICATE_ISSUER_SIZE 256
796
801#define MPDC_CERTIFICATE_LINE_LENGTH 64
802
807#define MPDC_CERTIFICATE_MAXIMUM_PERIOD (MPDC_CERTIFICATE_DEFAULT_PERIOD * 2)
808
813#define MPDC_CERTIFICATE_MINIMUM_PERIOD ((uint64_t)1 * 24 * 60 * 60)
814
819#define MPDC_CERTIFICATE_SERIAL_SIZE 16
820
825#define MPDC_CERTIFICATE_HINT_SIZE (MPDC_CERTIFICATE_HASH_SIZE + MPDC_CERTIFICATE_SERIAL_SIZE)
826
831#define MPDC_CERTIFICATE_SIGNED_HASH_SIZE (MPDC_ASYMMETRIC_SIGNATURE_SIZE + MPDC_CERTIFICATE_HASH_SIZE)
832
837#define MPDC_CERTIFICATE_VERSION_SIZE 1
838
843#define MPDC_CERTIFICATE_CHILD_SIZE (MPDC_CERTIFICATE_SIGNED_HASH_SIZE + \
844 MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE + \
845 MPDC_CERTIFICATE_ISSUER_SIZE + \
846 MPDC_CERTIFICATE_SERIAL_SIZE + \
847 MPDC_CERTIFICATE_SERIAL_SIZE + \
848 MPDC_CERTIFICATE_EXPIRATION_SIZE + \
849 MPDC_CERTIFICATE_DESIGNATION_SIZE + \
850 MPDC_CERTIFICATE_ALGORITHM_SIZE + \
851 MPDC_CERTIFICATE_VERSION_SIZE)
852
857#define MPDC_CERTIFICATE_IDG_SIZE (MPDC_ASYMMETRIC_SIGNATURE_SIZE + \
858 MPDC_CERTIFICATE_HASH_SIZE + \
859 MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE + \
860 MPDC_CERTIFICATE_ISSUER_SIZE + \
861 MPDC_CERTIFICATE_ADDRESS_SIZE + \
862 MPDC_CERTIFICATE_SERIAL_SIZE + \
863 MPDC_CERTIFICATE_SERIAL_SIZE + \
864 MPDC_CERTIFICATE_EXPIRATION_SIZE + \
865 MPDC_CERTIFICATE_DESIGNATION_SIZE + \
866 MPDC_CERTIFICATE_ALGORITHM_SIZE + \
867 MPDC_CERTIFICATE_VERSION_SIZE)
868
873#define MPDC_CERTIFICATE_ROOT_SIZE (MPDC_CERTIFICATE_HASH_SIZE + \
874 MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE + \
875 MPDC_CERTIFICATE_ISSUER_SIZE + \
876 MPDC_CERTIFICATE_SERIAL_SIZE + \
877 MPDC_CERTIFICATE_EXPIRATION_SIZE + \
878 MPDC_CERTIFICATE_ALGORITHM_SIZE + \
879 MPDC_CERTIFICATE_VERSION_SIZE)
880
885#define MPDC_CRYPTO_SYMMETRIC_KEY_SIZE 32
886
891#define MPDC_CRYPTO_SYMMETRIC_NONCE_SIZE 32
892
897#define MPDC_CRYPTO_SEED_SIZE 64
898
903#define MPDC_CRYPTO_SYMMETRIC_TOKEN_SIZE 32
904
909#define MPDC_CRYPTO_SYMMETRIC_HASH_SIZE 32
910
915#if defined(MPDC_EXTENDED_SESSION_SECURITY)
916# define MPDC_CRYPTO_SYMMETRIC_MAC_SIZE 64
917#else
918# define MPDC_CRYPTO_SYMMETRIC_MAC_SIZE 32
919#endif
920
925#define MPDC_CRYPTO_SYMMETRIC_SECRET_SIZE 32
926
931#if defined(MPDC_EXTENDED_SESSION_SECURITY)
932# define MPDC_CRYPTO_SYMMETRIC_SESSION_KEY_SIZE 64
933#else
934# define MPDC_CRYPTO_SYMMETRIC_SESSION_KEY_SIZE 32
935#endif
936
941#define MPDC_DLA_CONVERGENCE_INTERVAL (60 * 60 * 24)
942
947#define MPDC_DLA_IP_MAX 0x41
948
953#define MPDC_DLA_PENALTY_MAX 0x100
954
959#define MPDC_DLA_REDUCTION_INTERVAL 1000000
960
967#define MPDC_DLA_UPDATE_WAIT_TIME (7 * 24 * 60 * 60)
968
973#define MPDC_ERROR_STRING_DEPTH 26
974
979#define MPDC_ERROR_STRING_WIDTH 128
980
985#define MPDC_MESSAGE_MAX_SIZE 1400000
986
991#define MPDC_MFK_EXPIRATION_PERIOD ((uint64_t)60 * 24 * 60 * 60)
992
997#define MPDC_MINIMUM_PATH_LENGTH 9
998
1003#define MPDC_NETWORK_CONNECTION_MTU 1500
1004
1010#define MPDC_NETWORK_DOMAIN_NAME_MAX_SIZE 256
1011
1016#define MPDC_NETWORK_MAX_AGENTS 1000000
1017
1022#define MPDC_NETWORK_NODE_ID_SIZE 16
1023
1028#define MPDC_PERIOD_DAY_TO_SECONDS (24 * 60 * 60)
1029
1034#define MPDC_SOCKET_TERMINATOR_SIZE 1
1035
1040#define MPDC_PACKET_ERROR_SIZE 1
1041
1046#define MPDC_PACKET_HEADER_SIZE 22
1047
1052#define MPDC_PACKET_SUBHEADER_SIZE 16
1053
1058#define MPDC_PACKET_SEQUENCE_TERMINATOR 0xFFFFFFFFUL
1059
1064#define MPDC_PACKET_TIME_SIZE 8
1065
1070#define MPDC_PACKET_TIME_THRESHOLD 60
1071
1076#define MPDC_NETWORK_TERMINATION_MESSAGE_SIZE 1
1077
1082#define MPDC_NETWORK_TERMINATION_PACKET_SIZE (MPDC_PACKET_HEADER_SIZE + MPDC_NETWORK_TERMINATION_MESSAGE_SIZE)
1083
1084/* enumerations */
1085
1108
1126
1162
1167MPDC_EXPORT_API typedef enum mpdc_network_flags
1168{
1213
1218MPDC_EXPORT_API typedef enum mpdc_protocol_errors
1219{
1265
1275
1276/* public structures */
1277
1282MPDC_EXPORT_API typedef struct mpdc_certificate_expiration
1283{
1284 uint64_t from;
1285 uint64_t to;
1287
1304
1309#define MPDC_X509_CERTIFICATE_SIZE 4096
1310
1318#define MPDC_IDG_HINT_SIZE (MPDC_CERTIFICATE_HASH_SIZE + MPDC_CERTIFICATE_SERIAL_SIZE)
1319
1329
1351
1356MPDC_EXPORT_API typedef struct mpdc_connection_state
1357{
1358 qsc_socket target;
1359 qsc_rcs_state rxcpr;
1360 qsc_rcs_state txcpr;
1361 uint64_t rxseq;
1362 uint64_t txseq;
1363 uint32_t instance;
1366
1371MPDC_EXPORT_API typedef struct mpdc_keep_alive_state
1372{
1373 qsc_socket target;
1374 uint64_t etime;
1375 uint64_t seqctr;
1376 bool recd;
1378
1388
1393MPDC_EXPORT_API typedef struct mpdc_network_packet
1394{
1395 uint8_t flag;
1396 uint32_t msglen;
1397 uint64_t sequence;
1398 uint64_t utctime;
1399 uint8_t* pmessage;
1401
1419
1430
1440
1450
1451/* public key encoding constants */
1452
1454
1455#define MPDC_CERTIFICATE_SEPERATOR_SIZE 1
1456#define MPDC_CHILD_CERTIFICATE_HEADER_SIZE 64
1457#define MPDC_CHILD_CERTIFICATE_ROOT_HASH_PREFIX_SIZE 30
1458#define MPDC_CHILD_CERTIFICATE_SIGNATURE_KEY_PREFIX_SIZE 23
1459#define MPDC_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE 9
1460#define MPDC_CHILD_CERTIFICATE_NAME_PREFIX_SIZE 7
1461#define MPDC_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE 9
1462#define MPDC_CHILD_CERTIFICATE_ROOT_SERIAL_PREFIX_SIZE 14
1463#define MPDC_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE 13
1464#define MPDC_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE 6
1465#define MPDC_CHILD_CERTIFICATE_ALGORITHM_PREFIX_SIZE 12
1466#define MPDC_CHILD_CERTIFICATE_VERSION_PREFIX_SIZE 10
1467#define MPDC_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE 14
1468#define MPDC_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE 10
1469#define MPDC_CHILD_CERTIFICATE_FOOTER_SIZE 64
1470#define MPDC_CHILD_CERTIFICATE_DEFAULT_NAME_SIZE 19
1471
1472static const char MPDC_CHILD_CERTIFICATE_HEADER[MPDC_CHILD_CERTIFICATE_HEADER_SIZE] = "-----------BEGIN MPDC CHILD PUBLIC CERTIFICATE BLOCK-----------";
1473static const char MPDC_CHILD_CERTIFICATE_ROOT_HASH_PREFIX[MPDC_CHILD_CERTIFICATE_ROOT_HASH_PREFIX_SIZE] = "Root Signed Public Key Hash: ";
1474static const char MPDC_CHILD_CERTIFICATE_SIGNATURE_KEY_PREFIX[MPDC_CHILD_CERTIFICATE_SIGNATURE_KEY_PREFIX_SIZE] = "Public Signature Key: ";
1475static const char MPDC_CHILD_CERTIFICATE_ISSUER_PREFIX[MPDC_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE] = "Issuer: ";
1476static const char MPDC_CHILD_CERTIFICATE_NAME_PREFIX[MPDC_CHILD_CERTIFICATE_NAME_PREFIX_SIZE] = "Name: ";
1477static const char MPDC_CHILD_CERTIFICATE_SERIAL_PREFIX[MPDC_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE] = "Serial: ";
1478static const char MPDC_CHILD_CERTIFICATE_ROOT_SERIAL_PREFIX[MPDC_CHILD_CERTIFICATE_ROOT_SERIAL_PREFIX_SIZE] = "Root Serial: ";
1479static const char MPDC_CHILD_CERTIFICATE_VALID_FROM_PREFIX[MPDC_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE] = "Valid From: ";
1480static const char MPDC_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX[MPDC_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE] = " To: ";
1481static const char MPDC_CHILD_CERTIFICATE_ALGORITHM_PREFIX[MPDC_CHILD_CERTIFICATE_ALGORITHM_PREFIX_SIZE] = "Algorithm: ";
1482static const char MPDC_CHILD_CERTIFICATE_VERSION_PREFIX[MPDC_CHILD_CERTIFICATE_VERSION_PREFIX_SIZE] = "Version: ";
1483static const char MPDC_CHILD_CERTIFICATE_DESIGNATION_PREFIX[MPDC_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE] = "Designation: ";
1484static const char MPDC_CHILD_CERTIFICATE_ADDRESS_PREFIX[MPDC_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE] = "Address: ";
1485static const char MPDC_CHILD_CERTIFICATE_FOOTER[MPDC_CHILD_CERTIFICATE_FOOTER_SIZE] = "------------END MPDC CHILD PUBLIC CERTIFICATE BLOCK------------";
1486static const char MPDC_CHILD_CERTIFICATE_DEFAULT_NAME[MPDC_CHILD_CERTIFICATE_DEFAULT_NAME_SIZE] = " Child Certificate";
1487
1488#define MPDC_NETWORK_DESIGNATION_SIZE 33
1489static const char MPDC_NETWORK_DESIGNATION_NONE[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_none";
1490static const char MPDC_NETWORK_DESIGNATION_AGENT[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_agent";
1491static const char MPDC_NETWORK_DESIGNATION_CLIENT[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_client";
1492static const char MPDC_NETWORK_DESIGNATION_DLA[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_dla";
1493static const char MPDC_NETWORK_DESIGNATION_IDG[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_idg";
1494static const char MPDC_NETWORK_DESIGNATION_REMOTE[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_remote";
1495static const char MPDC_NETWORK_DESIGNATION_ROOT[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_rds";
1496static const char MPDC_NETWORK_DESIGNATION_SERVER[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_mas";
1497static const char MPDC_NETWORK_DESIGNATION_ALL[MPDC_NETWORK_DESIGNATION_SIZE] = "mpdc_network_designation_all";
1498
1500
1505#define MPDC_PROTOCOL_SET_SIZE 41
1506
1507/* Valid parameter sets:
1508Kyber-S1, Dilithium-S1
1509Kyber-S3, Dilithium-S3
1510Kyber-S5, Dilithium-S5
1511Kyber-S6, Dilithium-S5
1512McEliece-S1, Sphincs-S1(f,s)
1513McEliece-S3, Sphincs-S3(f,s)
1514McEliece-S5, Sphincs-S5(f,s)
1515McEliece-S6, Sphincs-S5(f,s)
1516McEliece-S7, Sphincs-S6(f,s) */
1517
1519
1520#if defined(MPDC_PARAMATERS_DILITHIUM_KYBER_D1K1)
1521static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "dilithium-s1_kyber-s1_rcs-256_sha3-256";
1523#elif defined(MPDC_PARAMATERS_DILITHIUM_KYBER_D3K3)
1524static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "dilithium-s3_kyber-s3_rcs-256_sha3-256";
1526#elif defined(MPDC_PARAMATERS_DILITHIUM_KYBER_D5K5)
1527static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "dilithium-s5_kyber-s5_rcs-256_sha3-256";
1529#elif defined(MPDC_PARAMATERS_DILITHIUM_KYBER_D5K6)
1530static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "dilithium-s5_kyber-s6_rcs-512_sha3-512";
1531static const mpdc_configuration_sets MPDC_CONFIGURATION_SET = mpdc_configuration_set_dilithium5_kyber6_rcs512_shake512;
1532#elif defined(MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF1M1)
1533static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-1f_mceliece-s1_rcs-256_sha3-256";
1535#elif defined(MPDC_PARAMATERS_SPHINCSPLUS_S1S128SHAKERS)
1536static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-1s_mceliece-s1_rcs-256_sha3-256";
1538#elif defined(MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF3M3)
1539static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-3f_mceliece-s3_rcs-256_sha3-256";
1541#elif defined(MPDC_PARAMATERS_SPHINCSPLUS_S3S192SHAKERS)
1542static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-3s_mceliece-s3_rcs-256_sha3-256";
1544#elif defined(MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF5M5)
1545static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-5f_mceliece-s5_rcs-256_sha3-256";
1547#elif defined(MPDC_PARAMATERS_SPHINCSPLUS_S5S256SHAKERS)
1548static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-5s_mceliece-s5_rcs-256_sha3-256";
1550#elif defined(MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF5M6)
1551static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-5f_mceliece-s6_rcs-256_sha3-256";
1553#elif defined(MPDC_PARAMATERS_SPHINCSPLUS_S5S256SHAKERS)
1554static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-5s_mceliece-s6_rcs-256_sha3-256";
1556#elif defined(MPDC_PARAMATERS_SPHINCSF_MCELIECE_SF5M7)
1557static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-5f_mceliece-s7_rcs-256_sha3-256";
1559#elif defined(MPDC_PARAMATERS_SPHINCSPLUS_S5S256SHAKERS)
1560static const char MPDC_CONFIG_STRING[MPDC_PROTOCOL_SET_SIZE] = "sphincs-5s_mceliece-s7_rcs-256_sha3-256";
1562#else
1563# error Invalid parameter set!
1564#endif
1565
1567
1569
1570#define MPDC_ROOT_CERTIFICATE_HEADER_SIZE 64
1571#define MPDC_ROOT_CERTIFICATE_HASH_PREFIX_SIZE 19
1572#define MPDC_ROOT_CERTIFICATE_PUBLICKEY_PREFIX_SIZE 13
1573#define MPDC_ROOT_CERTIFICATE_ISSUER_PREFIX_SIZE 9
1574#define MPDC_ROOT_CERTIFICATE_NAME_PREFIX_SIZE 7
1575#define MPDC_ROOT_CERTIFICATE_SERIAL_PREFIX_SIZE 9
1576#define MPDC_ROOT_CERTIFICATE_FOOTER_SIZE 64
1577#define MPDC_ROOT_CERTIFICATE_VALID_FROM_PREFIX_SIZE 13
1578#define MPDC_ROOT_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE 6
1579#define MPDC_ROOT_CERTIFICATE_ALGORITHM_PREFIX_SIZE 12
1580#define MPDC_ROOT_CERTIFICATE_VERSION_PREFIX_SIZE 10
1581#define MPDC_ROOT_CERTIFICATE_DEFAULT_NAME_SIZE 18
1582#define MPDC_ACTIVE_VERSION_STRING_SIZE 5
1583
1585
1587
1588static const char MPDC_ROOT_CERTIFICATE_HEADER[MPDC_ROOT_CERTIFICATE_HEADER_SIZE] = "------------BEGIN MPDC ROOT PUBLIC CERTIFICATE BLOCK-----------";
1589static const char MPDC_ROOT_CERTIFICATE_ISSUER_PREFIX[MPDC_ROOT_CERTIFICATE_ISSUER_PREFIX_SIZE] = "Issuer: ";
1590static const char MPDC_ROOT_CERTIFICATE_NAME_PREFIX[MPDC_ROOT_CERTIFICATE_NAME_PREFIX_SIZE] = "Name: ";
1591static const char MPDC_ROOT_CERTIFICATE_SERIAL_PREFIX[MPDC_ROOT_CERTIFICATE_SERIAL_PREFIX_SIZE] = "Serial: ";
1592static const char MPDC_ROOT_CERTIFICATE_VALID_FROM_PREFIX[MPDC_ROOT_CERTIFICATE_VALID_FROM_PREFIX_SIZE] = "Valid From: ";
1593static const char MPDC_ROOT_CERTIFICATE_EXPIRATION_TO_PREFIX[MPDC_ROOT_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE] = " To: ";
1594static const char MPDC_ROOT_CERTIFICATE_ALGORITHM_PREFIX[MPDC_ROOT_CERTIFICATE_ALGORITHM_PREFIX_SIZE] = "Algorithm: ";
1595static const char MPDC_ROOT_CERTIFICATE_VERSION_PREFIX[MPDC_ROOT_CERTIFICATE_VERSION_PREFIX_SIZE] = "Version: ";
1596static const char MPDC_ROOT_CERTIFICATE_HASH_PREFIX[MPDC_ROOT_CERTIFICATE_HASH_PREFIX_SIZE] = "Certificate Hash: ";
1597static const char MPDC_ROOT_CERTIFICATE_PUBLICKEY_PREFIX[MPDC_ROOT_CERTIFICATE_PUBLICKEY_PREFIX_SIZE] = "Public Key: ";
1598static const char MPDC_ROOT_CERTIFICATE_FOOTER[MPDC_ROOT_CERTIFICATE_FOOTER_SIZE] = "------------END MPDC ROOT PUBLIC CERTIFICATE BLOCK-------------";
1599static const char MPDC_ROOT_CERTIFICATE_DEFAULT_NAME[MPDC_ROOT_CERTIFICATE_DEFAULT_NAME_SIZE] = " Root Certificate";
1600
1601static const char MPDC_ACTIVE_VERSION_STRING[MPDC_ACTIVE_VERSION_STRING_SIZE] = "0x01";
1602static const char MPDC_CERTIFICATE_CHILD_EXTENSION[] = ".ccert";
1603static const char MPDC_CERTIFICATE_MFCOL_EXTENSION[] = ".mfcol";
1604static const char MPDC_CERTIFICATE_ROOT_EXTENSION[] = ".rcert";
1605static const char MPDC_CERTIFICATE_TOPOLOGY_EXTENSION[] = ".dtop";
1606static const char MPDC_APPLICATION_ROOT_PATH[] = "\\MPDC";
1607static const char MPDC_CERTIFICATE_BACKUP_PATH[] = "\\Backup";
1608static const char MPDC_CERTIFICATE_STORE_PATH[] = "\\Certificates";
1609static const char MPDC_ROOT_CERTIFICATE_PATH[] = "\\Root";
1610static const char MPDC_CERTIFICATE_TOPOLOGY_PATH[] = "\\Topology";
1611
1613
1614#define MPDC_NETWORK_ERROR_STRING_DEPTH 28
1615#define MPDC_NETWORK_ERROR_STRING_SIZE 128
1616
1618
1619static const char MPDC_NETWORK_ERROR_STRINGS[MPDC_NETWORK_ERROR_STRING_DEPTH][MPDC_NETWORK_ERROR_STRING_SIZE] =
1620{
1621 "No error was detected",
1622 "The socket accept function returned an error",
1623 "The cipher authentication has failed",
1624 "The keep alive check failed",
1625 "The communications channel has failed",
1626 "The device could not make a connnection to the remote host",
1627 "The decryption authentication has failed",
1628 "The transmission failed at the kex establish phase",
1629 "The connection experienced an unexpected error",
1630 "The server has run out of socket connections",
1631 "The random generator experienced a failure",
1632 "The input is invalid",
1633 "The request is invalid",
1634 "The keep alive has expired with no response",
1635 "The keepalive failure counter has exceeded maximum ",
1636 "The kex authentication has failed",
1637 "The key-id is not recognized",
1638 "The certificate has expired",
1639 "The listener function failed to initialize",
1640 "The server has run out of memory",
1641 "The random generator experienced a failure",
1642 "The random generator experienced a failure",
1643 "The ratchet operation has failed",
1644 "The receiver failed at the network layer",
1645 "The transmitter failed at the network layer",
1646 "The protocol version is unknown",
1647 "The packet was received out of sequence",
1648 "The expected data could not be verified"
1649};
1650
1651#define MPDC_PROTOCOL_ERROR_STRING_DEPTH 44
1652#define MPDC_PROTOCOL_ERROR_STRING_SIZE 128
1653
1654static const char MPDC_PROTOCOL_ERROR_STRINGS[MPDC_PROTOCOL_ERROR_STRING_DEPTH][MPDC_PROTOCOL_ERROR_STRING_SIZE] =
1655{
1656 "No error was detected",
1657 "The symmetric cipher had an authentication failure",
1658 "The node certificate could not be found",
1659 "The communications channel has failed",
1660 "The device could not make a connection to the remote host",
1661 "The transmission failed at the KEX connection phase",
1662 "The convergence call has returned an error",
1663 "The database is already synchronized",
1664 "The asymmetric cipher failed to decapsulate the shared secret",
1665 "The node or certificate decoding failed",
1666 "The decryption authentication has failed",
1667 "The transmission failed at the KEX establish phase",
1668 "The transmission failed at the KEX exchange phase",
1669 "The application could not delete a local file",
1670 "The file could not be found",
1671 "The file could not be written to storage",
1672 "The public-key hash is invalid",
1673 "The server has run out of socket connections",
1674 "The packet flag was unexpected",
1675 "The certificate has expired and is invalid",
1676 "The MPDC public key has expired ",
1677 "The key identity is unrecognized",
1678 "The listener function failed to initialize",
1679 "The server has run out of memory",
1680 "The network time is invalid or has substantial delay",
1681 "The expected data could not be verified",
1682 "The server has no usable IP address, assign in configuration",
1683 "The node is offline or not available for connection",
1684 "The node could not be found in the database",
1685 "The node was previously registered in the database",
1686 "The operation was cancelled by the user",
1687 "The packet header received was invalid",
1688 "The packet was received out of sequence",
1689 "The receiver failed at the network layer",
1690 "The root signature failed authentication",
1691 "The certificate could not be serialized",
1692 "The signature scheme could not sign a message",
1693 "The transmission failed to sign the data",
1694 "The socket could not be bound to an IP address",
1695 "The socket could not be created",
1696 "The transmitter failed at the network layer",
1697 "The topological database has no agent entries",
1698 "The protocol string was not recognized",
1699 "The transmission failed at the KEX verify phase"
1700};
1701
1703
1704/* API */
1705
1713MPDC_EXPORT_API void mpdc_connection_close(qsc_socket* rsock, mpdc_network_errors err, bool notify);
1714
1725MPDC_EXPORT_API mpdc_network_errors mpdc_decrypt_packet(mpdc_connection_state* cns, uint8_t* message, size_t* msglen, const mpdc_network_packet* packetin);
1726
1737MPDC_EXPORT_API mpdc_network_errors mpdc_encrypt_packet(mpdc_connection_state* cns, mpdc_network_packet* packetout, const uint8_t* message, size_t msglen);
1738
1744MPDC_EXPORT_API void mpdc_connection_state_dispose(mpdc_connection_state* cns);
1745
1753MPDC_EXPORT_API const char* mpdc_network_error_to_string(mpdc_network_errors error);
1754
1762MPDC_EXPORT_API const char* mpdc_protocol_error_to_string(mpdc_protocol_errors error);
1763
1769MPDC_EXPORT_API void mpdc_packet_clear(mpdc_network_packet* packet);
1770
1777MPDC_EXPORT_API void mpdc_packet_error_message(mpdc_network_packet* packet, mpdc_protocol_errors error);
1778
1785MPDC_EXPORT_API void mpdc_packet_header_deserialize(const uint8_t* header, mpdc_network_packet* packet);
1786
1793MPDC_EXPORT_API void mpdc_packet_header_serialize(const mpdc_network_packet* packet, uint8_t* header);
1794
1800MPDC_EXPORT_API void mpdc_packet_set_utc_time(mpdc_network_packet* packet);
1801
1809MPDC_EXPORT_API bool mpdc_packet_time_valid(const mpdc_network_packet* packet);
1810
1819MPDC_EXPORT_API size_t mpdc_packet_to_stream(const mpdc_network_packet* packet, uint8_t* pstream);
1820
1827MPDC_EXPORT_API void mpdc_stream_to_packet(const uint8_t* pstream, mpdc_network_packet* packet);
1828
1829#endif
mpdc_network_errors
The MPDC network error values.
Definition mpdc.h:1132
@ mpdc_network_error_channel_down
Definition mpdc.h:1137
@ mpdc_network_error_unsequenced
Definition mpdc.h:1159
@ mpdc_network_error_receive_failure
Definition mpdc.h:1156
@ mpdc_network_error_transmit_failure
Definition mpdc.h:1157
@ mpdc_network_error_key_not_recognized
Definition mpdc.h:1149
@ mpdc_network_error_none
Definition mpdc.h:1133
@ mpdc_network_error_unknown_protocol
Definition mpdc.h:1158
@ mpdc_network_error_bad_keep_alive
Definition mpdc.h:1136
@ mpdc_network_error_kex_auth_failure
Definition mpdc.h:1148
@ mpdc_network_error_packet_unsequenced
Definition mpdc.h:1153
@ mpdc_network_error_listener_fail
Definition mpdc.h:1151
@ mpdc_network_error_memory_allocation
Definition mpdc.h:1152
@ mpdc_network_error_random_failure
Definition mpdc.h:1154
@ mpdc_network_error_key_has_expired
Definition mpdc.h:1150
@ mpdc_network_error_invalid_request
Definition mpdc.h:1145
@ mpdc_network_error_ratchet_fail
Definition mpdc.h:1155
@ mpdc_network_error_invalid_input
Definition mpdc.h:1144
@ mpdc_network_error_establish_failure
Definition mpdc.h:1140
@ mpdc_network_error_accept_fail
Definition mpdc.h:1134
@ mpdc_network_error_keep_alive_expired
Definition mpdc.h:1146
@ mpdc_network_error_identity_unknown
Definition mpdc.h:1143
@ mpdc_network_error_decryption_failure
Definition mpdc.h:1139
@ mpdc_network_error_keep_alive_timeout
Definition mpdc.h:1147
@ mpdc_network_error_hosts_exceeded
Definition mpdc.h:1142
@ mpdc_network_error_verify_failure
Definition mpdc.h:1160
@ mpdc_network_error_connection_failure
Definition mpdc.h:1138
@ mpdc_network_error_general_failure
Definition mpdc.h:1141
@ mpdc_network_error_auth_failure
Definition mpdc.h:1135
MPDC_EXPORT_API bool mpdc_packet_time_valid(const mpdc_network_packet *packet)
Check if the packet's UTC time is within the valid time threshold.
Definition mpdc.c:236
MPDC_EXPORT_API void mpdc_packet_header_deserialize(const uint8_t *header, mpdc_network_packet *packet)
Deserialize a byte array into a packet header.
Definition mpdc.c:193
#define MPDC_ASYMMETRIC_PRIVATE_KEY_SIZE
The byte size of the asymmetric cipher private-key array.
Definition mpdc.h:221
#define MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE
The byte size of the asymmetric signature verification-key array.
Definition mpdc.h:245
MPDC_EXPORT_API void mpdc_packet_error_message(mpdc_network_packet *packet, mpdc_protocol_errors error)
Populate a packet structure with an error message.
Definition mpdc.c:180
#define MPDC_CERTIFICATE_ISSUER_SIZE
The maximum certificate issuer string length. The last character must be a string terminator.
Definition mpdc.h:795
MPDC_EXPORT_API void mpdc_packet_clear(mpdc_network_packet *packet)
Clear the state of a network packet.
Definition mpdc.c:172
mpdc_configuration_sets
The MPDC algorithm configuration sets.
Definition mpdc.h:1091
@ mpdc_configuration_set_sphincsplus5s_mceliece6_rcs256_shake256
Definition mpdc.h:1104
@ mpdc_configuration_set_dilithium5_kyber6_rcs512_shake256
Definition mpdc.h:1096
@ mpdc_configuration_set_dilithium1_kyber1_rcs256_shake256
Definition mpdc.h:1093
@ mpdc_configuration_set_sphincsplus5f_mceliece5_rcs256_shake256
Definition mpdc.h:1101
@ mpdc_configuration_set_sphincsplus5s_mceliece7_rcs256_shake256
Definition mpdc.h:1106
@ mpdc_configuration_set_sphincsplus5f_mceliece7_rcs256_shake256
Definition mpdc.h:1105
@ mpdc_configuration_set_dilithium5_kyber5_rcs256_shake256
Definition mpdc.h:1095
@ mpdc_configuration_set_none
Definition mpdc.h:1092
@ mpdc_configuration_set_sphincsplus5f_mceliece6_rcs256_shake256
Definition mpdc.h:1103
@ mpdc_configuration_set_sphincsplus1s_mceliece1_rcs256_shake256
Definition mpdc.h:1098
@ mpdc_configuration_set_sphincsplus5s_mceliece5_rcs256_shake256
Definition mpdc.h:1102
@ mpdc_configuration_set_sphincsplus1f_mceliece1_rcs256_shake256
Definition mpdc.h:1097
@ mpdc_configuration_set_sphincsplus3s_mceliece3_rcs256_shake256
Definition mpdc.h:1100
@ mpdc_configuration_set_dilithium3_kyber3_rcs256_shake256
Definition mpdc.h:1094
@ mpdc_configuration_set_sphincsplus3f_mceliece3_rcs256_shake256
Definition mpdc.h:1099
#define MPDC_PROTOCOL_SET_SIZE
The size of the protocol configuration string.
Definition mpdc.h:1505
MPDC_EXPORT_API void mpdc_packet_header_serialize(const mpdc_network_packet *packet, uint8_t *header)
Serialize a packet header into a byte array.
Definition mpdc.c:212
mpdc_network_flags
The MPDC network flags.
Definition mpdc.h:1168
@ mpdc_network_flag_register_update_request
Definition mpdc.h:1182
@ mpdc_network_flag_tunnel_connection_terminate
Definition mpdc.h:1199
@ mpdc_network_flag_network_signature_request
Definition mpdc.h:1197
@ mpdc_network_flag_fragment_request
Definition mpdc.h:1174
@ mpdc_network_flag_network_converge_response
Definition mpdc.h:1192
@ mpdc_network_flag_network_announce_broadcast
Definition mpdc.h:1190
@ mpdc_network_flag_mfk_verify
Definition mpdc.h:1189
@ mpdc_network_flag_topology_status_response
Definition mpdc.h:1206
@ mpdc_network_flag_fragment_query_request
Definition mpdc.h:1176
@ mpdc_network_flag_mfk_establish
Definition mpdc.h:1186
@ mpdc_network_flag_incremental_update_response
Definition mpdc.h:1179
@ mpdc_network_flag_tunnel_session_established
Definition mpdc.h:1201
@ mpdc_network_flag_fragment_collection_response
Definition mpdc.h:1173
@ mpdc_network_flag_incremental_update_request
Definition mpdc.h:1178
@ mpdc_network_flag_tunnel_encrypted_message
Definition mpdc.h:1200
@ mpdc_network_flag_topology_query_request
Definition mpdc.h:1203
@ mpdc_network_flag_error_condition
Definition mpdc.h:1171
@ mpdc_network_flag_network_converge_request
Definition mpdc.h:1191
@ mpdc_network_flag_fragment_query_response
Definition mpdc.h:1177
@ mpdc_network_flag_fragment_response
Definition mpdc.h:1175
@ mpdc_network_flag_mfk_request
Definition mpdc.h:1187
@ mpdc_network_flag_network_converge_update
Definition mpdc.h:1193
@ mpdc_network_flag_network_remote_signing_response
Definition mpdc.h:1211
@ mpdc_network_flag_topology_status_request
Definition mpdc.h:1205
@ mpdc_network_flag_connection_terminate_request
Definition mpdc.h:1170
@ mpdc_network_flag_register_update_response
Definition mpdc.h:1183
@ mpdc_network_flag_topology_status_unavailable
Definition mpdc.h:1209
@ mpdc_network_flag_network_resign_response
Definition mpdc.h:1195
@ mpdc_network_flag_network_revocation_broadcast
Definition mpdc.h:1196
@ mpdc_network_flag_keep_alive_request
Definition mpdc.h:1184
@ mpdc_network_flag_topology_query_response
Definition mpdc.h:1204
@ mpdc_network_flag_mfk_response
Definition mpdc.h:1188
@ mpdc_network_flag_topology_status_synchronized
Definition mpdc.h:1208
@ mpdc_network_flag_network_remote_signing_request
Definition mpdc.h:1210
@ mpdc_network_flag_network_resign_request
Definition mpdc.h:1194
@ mpdc_network_flag_register_request
Definition mpdc.h:1180
@ mpdc_network_flag_fragment_collection_request
Definition mpdc.h:1172
@ mpdc_network_flag_topology_status_available
Definition mpdc.h:1207
@ mpdc_network_flag_keep_alive_response
Definition mpdc.h:1185
@ mpdc_network_flag_register_response
Definition mpdc.h:1181
@ mpdc_network_flag_tunnel_transfer_request
Definition mpdc.h:1202
@ mpdc_network_flag_system_error_condition
Definition mpdc.h:1198
@ mpdc_network_flag_none
Definition mpdc.h:1169
MPDC_EXPORT_API void mpdc_connection_state_dispose(mpdc_connection_state *cns)
Dispose of the tunnel connection state.
Definition mpdc.c:302
MPDC_EXPORT_API size_t mpdc_packet_to_stream(const mpdc_network_packet *packet, uint8_t *pstream)
Serialize a network packet to a byte stream.
Definition mpdc.c:245
MPDC_EXPORT_API const char * mpdc_protocol_error_to_string(mpdc_protocol_errors error)
Return a pointer to a string description of a protocol error code.
Definition mpdc.c:158
#define MPDC_CERTIFICATE_HINT_SIZE
The topological hint.
Definition mpdc.h:825
#define MPDC_CRYPTO_SYMMETRIC_KEY_SIZE
The byte length of the symmetric cipher key.
Definition mpdc.h:885
MPDC_EXPORT_API mpdc_network_errors mpdc_decrypt_packet(mpdc_connection_state *cns, uint8_t *message, size_t *msglen, const mpdc_network_packet *packetin)
Decrypt a message and copy it to the output buffer.
Definition mpdc.c:41
#define MPDC_CERTIFICATE_HASH_SIZE
The size of the certificate hash in bytes.
Definition mpdc.h:788
#define MPDC_ASYMMETRIC_PUBLIC_KEY_SIZE
The byte size of the asymmetric cipher public-key array.
Definition mpdc.h:227
mpdc_network_designations
The MPDC device designation.
Definition mpdc.h:1114
@ mpdc_network_designation_mas
Definition mpdc.h:1120
@ mpdc_network_designation_agent
Definition mpdc.h:1116
@ mpdc_network_designation_remote
Definition mpdc.h:1121
@ mpdc_network_designation_all
Definition mpdc.h:1124
@ mpdc_network_designation_rds
Definition mpdc.h:1122
@ mpdc_network_designation_none
Definition mpdc.h:1115
@ mpdc_network_designation_dla
Definition mpdc.h:1118
@ mpdc_network_designation_revoked
Definition mpdc.h:1123
@ mpdc_network_designation_client
Definition mpdc.h:1117
@ mpdc_network_designation_idg
Definition mpdc.h:1119
MPDC_EXPORT_API mpdc_network_errors mpdc_encrypt_packet(mpdc_connection_state *cns, mpdc_network_packet *packetout, const uint8_t *message, size_t msglen)
Encrypt a message and build an output packet.
Definition mpdc.c:102
#define MPDC_CERTIFICATE_SERIAL_SIZE
The certificate serial number field length.
Definition mpdc.h:819
mpdc_version_sets
The MPDC version sets.
Definition mpdc.h:1271
@ mpdc_version_set_none
Definition mpdc.h:1272
@ mpdc_version_set_one_zero
Definition mpdc.h:1273
#define MPDC_X509_CERTIFICATE_SIZE
x509 implementation where algorithm/signature output size is stored.
Definition mpdc.h:1309
#define MPDC_CRYPTO_SYMMETRIC_NONCE_SIZE
The byte length of the symmetric cipher nonce.
Definition mpdc.h:891
MPDC_EXPORT_API const char * mpdc_network_error_to_string(mpdc_network_errors error)
Return a pointer to a string description of a network error code.
Definition mpdc.c:144
MPDC_EXPORT_API void mpdc_stream_to_packet(const uint8_t *pstream, mpdc_network_packet *packet)
Deserialize a byte stream into a network packet.
Definition mpdc.c:277
MPDC_EXPORT_API void mpdc_connection_close(qsc_socket *rsock, mpdc_network_errors err, bool notify)
Close the network connection between hosts.
Definition mpdc.c:10
#define MPDC_ASYMMETRIC_SIGNING_KEY_SIZE
The byte size of the asymmetric signature signing-key array.
Definition mpdc.h:239
MPDC_EXPORT_API void mpdc_packet_set_utc_time(mpdc_network_packet *packet)
Set the local UTC time in the packet header.
Definition mpdc.c:231
#define MPDC_CERTIFICATE_SIGNED_HASH_SIZE
The size of the signature and hash field in a certificate.
Definition mpdc.h:831
mpdc_protocol_errors
The MPDC protocol error values.
Definition mpdc.h:1219
@ mpdc_protocol_error_decapsulation_failure
Definition mpdc.h:1228
@ mpdc_protocol_error_root_signature_invalid
Definition mpdc.h:1254
@ mpdc_protocol_error_channel_down
Definition mpdc.h:1223
@ mpdc_protocol_error_establish_failure
Definition mpdc.h:1231
@ mpdc_protocol_error_verification_failure
Definition mpdc.h:1263
@ mpdc_protocol_error_key_expired
Definition mpdc.h:1240
@ mpdc_protocol_error_signing_failure
Definition mpdc.h:1257
@ mpdc_protocol_error_none
Definition mpdc.h:1220
@ mpdc_protocol_error_certificate_expired
Definition mpdc.h:1239
@ mpdc_protocol_error_invalid_request
Definition mpdc.h:1238
@ mpdc_protocol_error_hash_invalid
Definition mpdc.h:1236
@ mpdc_protocol_error_key_unrecognized
Definition mpdc.h:1241
@ mpdc_protocol_error_file_not_found
Definition mpdc.h:1234
@ mpdc_protocol_error_signature_failure
Definition mpdc.h:1256
@ mpdc_protocol_error_message_time_invalid
Definition mpdc.h:1244
@ mpdc_protocol_error_certificate_not_found
Definition mpdc.h:1222
@ mpdc_protocol_error_convergence_failure
Definition mpdc.h:1226
@ mpdc_protocol_error_convergence_synchronized
Definition mpdc.h:1227
@ mpdc_protocol_error_authentication_failure
Definition mpdc.h:1221
@ mpdc_protocol_error_serialization_failure
Definition mpdc.h:1255
@ mpdc_protocol_error_hosts_exceeded
Definition mpdc.h:1237
@ mpdc_protocol_error_unknown_protocol
Definition mpdc.h:1262
@ mpdc_protocol_error_topology_no_agent
Definition mpdc.h:1261
@ mpdc_protocol_error_packet_header_invalid
Definition mpdc.h:1251
@ mpdc_protocol_error_decoding_failure
Definition mpdc.h:1229
@ mpdc_protocol_error_node_not_found
Definition mpdc.h:1248
@ mpdc_protocol_error_socket_creation
Definition mpdc.h:1259
@ mpdc_protocol_error_socket_binding
Definition mpdc.h:1258
@ mpdc_protocol_error_listener_fail
Definition mpdc.h:1242
@ mpdc_protocol_error_memory_allocation
Definition mpdc.h:1243
@ mpdc_protocol_error_connect_failure
Definition mpdc.h:1225
@ mpdc_protocol_error_decryption_failure
Definition mpdc.h:1230
@ mpdc_protocol_error_exchange_failure
Definition mpdc.h:1232
@ mpdc_protocol_error_file_not_written
Definition mpdc.h:1235
@ mpdc_protocol_error_transmit_failure
Definition mpdc.h:1260
@ mpdc_protocol_error_file_not_deleted
Definition mpdc.h:1233
@ mpdc_protocol_error_node_not_available
Definition mpdc.h:1247
@ mpdc_protocol_error_connection_failure
Definition mpdc.h:1224
@ mpdc_protocol_error_receive_failure
Definition mpdc.h:1253
@ mpdc_protocol_error_node_was_registered
Definition mpdc.h:1249
@ mpdc_protocol_error_packet_unsequenced
Definition mpdc.h:1252
@ mpdc_protocol_error_no_usable_address
Definition mpdc.h:1246
@ mpdc_protocol_error_operation_cancelled
Definition mpdc.h:1250
@ mpdc_protocol_error_message_verification_failure
Definition mpdc.h:1245
The certificate expiration time structure.
Definition mpdc.h:1283
uint64_t to
Definition mpdc.h:1285
uint64_t from
Definition mpdc.h:1284
The child certificate structure.
Definition mpdc.h:1293
uint8_t serial[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1297
uint8_t rootser[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1298
char issuer[MPDC_CERTIFICATE_ISSUER_SIZE]
Definition mpdc.h:1296
uint8_t csig[MPDC_CERTIFICATE_SIGNED_HASH_SIZE]
Definition mpdc.h:1294
mpdc_certificate_expiration expiration
Definition mpdc.h:1299
mpdc_network_designations designation
Definition mpdc.h:1300
uint8_t version
Definition mpdc.h:1302
mpdc_configuration_sets algorithm
Definition mpdc.h:1301
uint8_t verkey[MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE]
Definition mpdc.h:1295
The MPDC asymmetric cipher key container.
Definition mpdc.h:1446
uint8_t pubkey[MPDC_ASYMMETRIC_PUBLIC_KEY_SIZE]
Definition mpdc.h:1448
uint8_t prikey[MPDC_ASYMMETRIC_PRIVATE_KEY_SIZE]
Definition mpdc.h:1447
The MPDC socket connection state structure.
Definition mpdc.h:1357
uint64_t txseq
Definition mpdc.h:1362
qsc_rcs_state txcpr
Definition mpdc.h:1360
uint64_t rxseq
Definition mpdc.h:1361
uint32_t instance
Definition mpdc.h:1363
mpdc_network_flags exflag
Definition mpdc.h:1364
qsc_socket target
Definition mpdc.h:1358
qsc_rcs_state rxcpr
Definition mpdc.h:1359
The IDG certificate structure.
Definition mpdc.h:1338
uint8_t serial[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1342
uint8_t xcert[MPDC_X509_CERTIFICATE_SIZE]
Definition mpdc.h:1341
uint8_t vkey[MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE]
Definition mpdc.h:1340
uint8_t rootser[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1343
char issuer[MPDC_CERTIFICATE_ISSUER_SIZE]
Definition mpdc.h:1345
uint8_t hint[MPDC_CERTIFICATE_HINT_SIZE]
Definition mpdc.h:1344
uint8_t csig[MPDC_CERTIFICATE_SIGNED_HASH_SIZE]
Definition mpdc.h:1339
mpdc_certificate_expiration expiration
Definition mpdc.h:1346
mpdc_network_designations designation
Definition mpdc.h:1347
uint8_t version
Definition mpdc.h:1349
mpdc_configuration_sets algorithm
Definition mpdc.h:1348
The IDG hint structure.
Definition mpdc.h:1325
uint8_t chash[MPDC_CERTIFICATE_HASH_SIZE]
Definition mpdc.h:1326
uint8_t rootser[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1327
The MPDC keep alive state structure.
Definition mpdc.h:1372
bool recd
Definition mpdc.h:1376
uint64_t seqctr
Definition mpdc.h:1375
qsc_socket target
Definition mpdc.h:1373
uint64_t etime
Definition mpdc.h:1374
The MPDC master fragment key structure.
Definition mpdc.h:1384
uint8_t serial[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1385
uint8_t mfk[MPDC_CRYPTO_SYMMETRIC_KEY_SIZE]
Definition mpdc.h:1386
The MPDC packet structure.
Definition mpdc.h:1394
uint8_t * pmessage
Definition mpdc.h:1399
uint32_t msglen
Definition mpdc.h:1396
uint64_t utctime
Definition mpdc.h:1398
uint64_t sequence
Definition mpdc.h:1397
uint8_t flag
Definition mpdc.h:1395
The root certificate structure.
Definition mpdc.h:1411
uint8_t serial[MPDC_CERTIFICATE_SERIAL_SIZE]
Definition mpdc.h:1414
mpdc_version_sets version
Definition mpdc.h:1417
char issuer[MPDC_CERTIFICATE_ISSUER_SIZE]
Definition mpdc.h:1413
mpdc_certificate_expiration expiration
Definition mpdc.h:1415
mpdc_configuration_sets algorithm
Definition mpdc.h:1416
uint8_t verkey[MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE]
Definition mpdc.h:1412
The structure for a serialized symmetric key.
Definition mpdc.h:1425
uint8_t key[MPDC_CRYPTO_SYMMETRIC_KEY_SIZE]
Definition mpdc.h:1427
uint8_t nonce[MPDC_CRYPTO_SYMMETRIC_NONCE_SIZE]
Definition mpdc.h:1428
uint64_t keyid
Definition mpdc.h:1426
The MPDC asymmetric signature scheme key container.
Definition mpdc.h:1436
uint8_t prikey[MPDC_ASYMMETRIC_SIGNING_KEY_SIZE]
Definition mpdc.h:1437
uint8_t pubkey[MPDC_ASYMMETRIC_VERIFICATION_KEY_SIZE]
Definition mpdc.h:1438