Quantum Secure Tunneling Protocol 1.0.0.0a (A1)
A three-party quantum secure encrypted tunneling protocol
|
QSTP support header. More...
#include "common.h"
#include "../../QSC/QSC/socketbase.h"
#include "../../QSC/QSC/rcs.h"
#include "../../QSC/QSC/sha3.h"
#include "../../QSC/QSC/dilithium.h"
#include "../../QSC/QSC/kyber.h"
Go to the source code of this file.
Data Structures | |
struct | qstp_certificate_expiration |
Certificate expiration time structure. More... | |
struct | qstp_keep_alive_state |
The QSTP keep alive state structure. More... | |
struct | qstp_server_certificate |
The server certificate structure. More... | |
struct | qstp_server_signature_key |
The QSTP server key structure. More... | |
struct | qstp_root_certificate |
The root certificate structure. More... | |
struct | qstp_root_signature_key |
The QSTP root key structure. More... | |
struct | qstp_network_packet |
The QSTP network packet structure. More... | |
struct | qstp_connection_state |
The QSTP socket connection state structure. More... | |
Macros | |
#define | QSTP_CONFIG_DILITHIUM_KYBER |
Sets the asymmetric cryptographic primitive-set to Dilithium/Kyber. | |
#define | QSTP_PROTOCOL_SET_SIZE 42 |
The size of the protocol configuration string. | |
#define | qstp_cipher_generate_keypair qsc_kyber_generate_keypair |
Generate an asymmetric cipher key-pair using Kyber. | |
#define | qstp_cipher_decapsulate qsc_kyber_decapsulate |
Decapsulate a shared-secret with the Kyber asymmetric cipher. | |
#define | qstp_cipher_encapsulate qsc_kyber_encapsulate |
Encapsulate a shared-secret with the Kyber asymmetric cipher. | |
#define | qstp_signature_generate_keypair qsc_dilithium_generate_keypair |
Generate an asymmetric signature key-pair using Dilithium. | |
#define | qstp_signature_sign qsc_dilithium_sign |
Sign a message using the Dilithium signature scheme. | |
#define | qstp_signature_verify qsc_dilithium_verify |
Verify a message using the Dilithium signature scheme. | |
#define | QSTP_ASYMMETRIC_CIPHER_TEXT_SIZE (QSC_KYBER_CIPHERTEXT_SIZE) |
The byte size of the asymmetric cipher-text array (Kyber) | |
#define | QSTP_ASYMMETRIC_PRIVATE_KEY_SIZE (QSC_KYBER_PRIVATEKEY_SIZE) |
The byte size of the asymmetric cipher private-key array (Kyber) | |
#define | QSTP_ASYMMETRIC_PUBLIC_KEY_SIZE (QSC_KYBER_PUBLICKEY_SIZE) |
The byte size of the asymmetric cipher public-key array (Kyber) | |
#define | QSTP_ASYMMETRIC_SIGNING_KEY_SIZE (QSC_DILITHIUM_PRIVATEKEY_SIZE) |
The byte size of the asymmetric signature signing-key array (Dilithium) | |
#define | QSTP_ASYMMETRIC_VERIFICATION_KEY_SIZE (QSC_DILITHIUM_PUBLICKEY_SIZE) |
The byte size of the asymmetric signature verification-key array (Dilithium) | |
#define | QSTP_ASYMMETRIC_SIGNATURE_SIZE (QSC_DILITHIUM_SIGNATURE_SIZE) |
The byte size of the asymmetric signature array (Dilithium) | |
#define | QSTP_ACTIVE_VERSION 1 |
The QSTP active version. | |
#define | QSTP_CERTIFICATE_ALGORITHM_SIZE 1 |
The certificate algorithm type field size in bytes. | |
#define | QSTP_CERTIFICATE_DESIGNATION_SIZE 1 |
The certificate designation field size in bytes. | |
#define | QSTP_CERTIFICATE_EXPIRATION_SIZE 16 |
The length (in bytes) of the certificate expiration date. | |
#define | QSTP_CERTIFICATE_HASH_SIZE 32 |
The size in bytes of the certificate hash. | |
#define | QSTP_CERTIFICATE_ISSUER_SIZE 32 |
The maximum length of the certificate issuer string (including terminator). | |
#define | QSTP_CERTIFICATE_LINE_LENGTH 64 |
The line length for printing the MPDC certificate. | |
#define | QSTP_CERTIFICATE_DEFAULT_PERIOD ((uint64_t)365 * 24 * 60 * 60) |
The default certificate validity period in milliseconds. | |
#define | QSTP_CERTIFICATE_DEFAULT_DURATION_DAYS 365 |
The default number of days a public key remains valid. | |
#define | QSTP_CERTIFICATE_DEFAULT_DURATION_SECONDS (QSTP_CERTIFICATE_DEFAULT_DURATION_DAYS * 24 * 60 * 60) |
The number of seconds a public key remains valid. | |
#define | QSTP_CERTIFICATE_LINE_LENGTH 64 |
The line length for printing the MPDC certificate. | |
#define | QSTP_CERTIFICATE_MAXIMUM_PERIOD (QSTP_CERTIFICATE_DEFAULT_PERIOD * 2) |
The maximum certificate validity period in milliseconds. | |
#define | QSTP_CERTIFICATE_MINIMUM_PERIOD ((uint64_t)1 * 24 * 60 * 60) |
The minimum certificate validity period in milliseconds. | |
#define | QSTP_CERTIFICATE_SERIAL_SIZE 16 |
The length of the certificate serial number field in bytes. | |
#define | QSTP_CERTIFICATE_SERIAL_ENCODED_SIZE 32 |
The length of the hex-encoded certificate serial number string. | |
#define | QSTP_CERTIFICATE_SIGNED_HASH_SIZE (QSTP_ASYMMETRIC_SIGNATURE_SIZE + QSTP_CERTIFICATE_HASH_SIZE) |
The size in bytes of the signature and hash field in a certificate. | |
#define | QSTP_CERTIFICATE_TIMESTAMP_SIZE 8 |
The size in bytes of the key expiration timestamp. | |
#define | QSTP_CERTIFICATE_VERSION_SIZE 1 |
The size in bytes of the certificate version field. | |
#define | QSTP_CONNECTIONS_INIT 1000 |
The initial QSTP connections queue size. | |
#define | QSTP_CONNECTIONS_MAX 50000 |
The maximum number of QSTP connections. | |
#define | QSTP_CONNECTION_MTU 1500 |
The QSTP packet buffer (MTU) size in bytes. | |
#define | QSTP_KEEPALIVE_TIMEOUT (120 * 1000) |
The keep alive timeout in milliseconds (2 minutes). | |
#define | QSTP_MACTAG_SIZE 32 |
The MAC tag size in bytes. | |
#define | QSTP_NONCE_SIZE 32 |
The size in bytes of the symmetric cipher nonce. | |
#define | QSTP_PACKET_ERROR_SEQUENCE 0xFF00000000000000ULL |
The packet error sequence number. | |
#define | QSTP_PACKET_ERROR_SIZE 1 |
The size in bytes of the packet error message. | |
#define | QSTP_PACKET_FLAG_SIZE 1 |
The size in bytes of the packet flag field. | |
#define | QSTP_PACKET_HEADER_SIZE 21 |
The size in bytes of the QSTP packet header. | |
#define | QSTP_PACKET_MESSAGE_LENGTH_SIZE 4 |
The size in bytes of the packet message length field. | |
#define | QSTP_PACKET_MESSAGE_MAX 0x3D090000 |
The maximum message size (in bytes) used during the key exchange (approximately 1 GB). | |
#define | QSTP_PACKET_REVOCATION_SEQUENCE 0xFFUL |
The packet sequence number used for revocation messages. | |
#define | QSTP_PACKET_SEQUENCE_SIZE 8 |
The size in bytes of the packet sequence number. | |
#define | QSTP_PACKET_SEQUENCE_TERMINATOR 0xFFFFFFFFUL |
The packet sequence number that indicates a connection termination. | |
#define | QSTP_PACKET_TIME_THRESHOLD 60 |
The maximum number of seconds a packet is considered valid. | |
#define | QSTP_SECRET_SIZE 32 |
The size in bytes of the shared secret for each channel. | |
#define | QSTP_CLIENT_PORT 32118 |
The default QSTP client port number. | |
#define | QSTP_SERVER_PORT 32119 |
The default QSTP server port number. | |
#define | QSTP_ROOT_PORT 32120 |
The default QSTP root port number. | |
#define | QSTP_SYMMETRIC_KEY_SIZE 32 |
The size in bytes of the Simplex 256-bit symmetric cipher key. | |
#define | QSTP_STORAGE_PATH_MAX 260 |
The maximum file system path size. | |
#define | QSTP_ROOT_CERTIFICATE_SIZE |
The total length in bytes of the root certificate. | |
#define | QSTP_ROOT_SIGNATURE_KEY_SIZE |
The total length in bytes of the root signature key. | |
#define | QSTP_SERVER_CERTIFICATE_SIZE |
The total length in bytes of a server certificate. | |
#define | QSTP_SERVER_SIGNATURE_KEY_SIZE |
The total length in bytes of a server signing key. | |
Typedefs | |
typedef QSTP_EXPORT_API enum qstp_configuration_sets | qstp_configuration_sets |
typedef QSTP_EXPORT_API enum qstp_messages | qstp_messages |
typedef QSTP_EXPORT_API enum qstp_errors | qstp_errors |
typedef QSTP_EXPORT_API enum qstp_flags | qstp_flags |
typedef QSTP_EXPORT_API enum qstp_network_designations | qstp_network_designations |
typedef QSTP_EXPORT_API enum qstp_version_sets | qstp_version_sets |
typedef QSTP_EXPORT_API struct qstp_certificate_expiration | qstp_certificate_expiration |
typedef QSTP_EXPORT_API struct qstp_keep_alive_state | qstp_keep_alive_state |
typedef QSTP_EXPORT_API struct qstp_server_certificate | qstp_server_certificate |
typedef QSTP_EXPORT_API struct qstp_server_signature_key | qstp_server_signature_key |
typedef QSTP_EXPORT_API struct qstp_root_certificate | qstp_root_certificate |
typedef QSTP_EXPORT_API struct qstp_root_signature_key | qstp_root_signature_key |
typedef QSTP_EXPORT_API struct qstp_network_packet | qstp_network_packet |
typedef QSTP_EXPORT_API struct qstp_connection_state | qstp_connection_state |
Functions | |
QSTP_EXPORT_API qstp_configuration_sets | qstp_configuration_from_string (const char *config) |
Get the configuration enumerator from a string. | |
QSTP_EXPORT_API const char * | qstp_configuration_to_string (qstp_configuration_sets cset) |
Get the configuration string from the enumerator. | |
QSTP_EXPORT_API void | qstp_connection_close (qstp_connection_state *cns, qstp_errors err, bool notify) |
Close the network connection between hosts. | |
QSTP_EXPORT_API void | qstp_connection_state_dispose (qstp_connection_state *cns) |
Reset the connection state to zero. | |
QSTP_EXPORT_API qstp_errors | qstp_decrypt_packet (qstp_connection_state *cns, uint8_t *message, size_t *msglen, const qstp_network_packet *packetin) |
Decrypt a message from an input packet. | |
QSTP_EXPORT_API qstp_errors | qstp_encrypt_packet (qstp_connection_state *cns, qstp_network_packet *packetout, const uint8_t *message, size_t msglen) |
Encrypt a message and build an output packet. | |
QSTP_EXPORT_API const char * | qstp_error_to_string (qstp_errors error) |
Return a pointer to a string description of an error code. | |
QSTP_EXPORT_API void | qstp_header_create (qstp_network_packet *packetout, qstp_flags flag, uint64_t sequence, uint32_t msglen) |
Populate a packet header and set its creation time. | |
QSTP_EXPORT_API qstp_errors | qstp_header_validate (qstp_connection_state *cns, const qstp_network_packet *packetin, qstp_flags flag, uint64_t sequence, uint32_t msglen) |
Validate a packet header and timestamp. | |
QSTP_EXPORT_API const char * | qstp_get_error_description (qstp_messages emsg) |
Get the error description string for a QSTP logging message. | |
QSTP_EXPORT_API void | qstp_packet_header_deserialize (const uint8_t *header, qstp_network_packet *packet) |
Deserialize a byte array into a QSTP packet header. | |
QSTP_EXPORT_API void | qstp_packet_header_serialize (const qstp_network_packet *packet, uint8_t *header) |
Serialize a QSTP packet header into a byte array. | |
QSTP_EXPORT_API void | qstp_log_error (qstp_messages emsg, qsc_socket_exceptions err, const char *msg) |
Log an error with a message, socket error, and description. | |
QSTP_EXPORT_API void | qstp_log_message (qstp_messages emsg) |
Log a QSTP message. | |
QSTP_EXPORT_API void | qstp_log_write (qstp_messages emsg, const char *msg) |
Log a QSTP message with an additional description. | |
QSTP_EXPORT_API void | qstp_packet_clear (qstp_network_packet *packet) |
Clear the state of a QSTP network packet. | |
QSTP_EXPORT_API void | qstp_packet_error_message (qstp_network_packet *packet, qstp_errors error) |
Populate a QSTP packet with an error message. | |
QSTP_EXPORT_API void | qstp_packet_set_utc_time (qstp_network_packet *packet) |
Set the local UTC time (in seconds) in a QSTP packet header. | |
QSTP_EXPORT_API bool | qstp_packet_time_valid (const qstp_network_packet *packet) |
Check if a QSTP packet was received within the valid time threshold. | |
QSTP_EXPORT_API size_t | qstp_packet_to_stream (const qstp_network_packet *packet, uint8_t *pstream) |
Serialize a QSTP packet into a byte array. | |
QSTP_EXPORT_API bool | qstp_root_certificate_compare (const qstp_root_certificate *a, const qstp_root_certificate *b) |
Compare two root certificates for equivalence. | |
QSTP_EXPORT_API bool | qstp_root_certificate_decode (qstp_root_certificate *root, const char *enck, size_t enclen) |
Copy an encoded root certificate into a root certificate structure. | |
QSTP_EXPORT_API void | qstp_root_certificate_deserialize (qstp_root_certificate *root, const uint8_t input[QSTP_ROOT_CERTIFICATE_SIZE]) |
Deserialize a root certificate from a serialized byte array. | |
QSTP_EXPORT_API size_t | qstp_root_certificate_encode (char *enck, size_t enclen, const qstp_root_certificate *root) |
Encode a root certificate into a readable string. | |
QSTP_EXPORT_API size_t | qstp_root_certificate_encoded_size () |
Get the size required to encode a root certificate. | |
QSTP_EXPORT_API void | qstp_root_certificate_extract (qstp_root_certificate *root, const qstp_root_signature_key *kset) |
Extract the root certificate from a root signature key. | |
QSTP_EXPORT_API void | qstp_root_certificate_hash (uint8_t output[QSTP_CERTIFICATE_HASH_SIZE], const qstp_root_certificate *root) |
Compute the hash of a root certificate. | |
QSTP_EXPORT_API void | qstp_root_certificate_serialize (uint8_t output[QSTP_ROOT_CERTIFICATE_SIZE], const qstp_root_certificate *root) |
Serialize a root certificate into a byte array. | |
QSTP_EXPORT_API size_t | qstp_root_certificate_sign (qstp_server_certificate *cert, const qstp_root_certificate *root, const uint8_t *rsigkey) |
Sign a server certificate using the root certificate. | |
QSTP_EXPORT_API bool | qstp_root_certificate_verify (const qstp_root_certificate *root, const qstp_server_certificate *cert) |
Verify that a server certificate is signed by the root. | |
QSTP_EXPORT_API bool | qstp_root_certificate_to_file (const qstp_root_certificate *root, const char *fpath) |
Write a root certificate to a file. | |
QSTP_EXPORT_API bool | qstp_root_file_to_certificate (qstp_root_certificate *root, const char *fpath) |
Read a root certificate from a file into a root certificate structure. | |
QSTP_EXPORT_API bool | qstp_root_file_to_key (qstp_root_signature_key *kset, const char *fpath) |
Read a root signature key from a file into a root signature key structure. | |
QSTP_EXPORT_API void | qstp_root_get_issuer (char issuer[QSTP_CERTIFICATE_ISSUER_SIZE]) |
Get the root certificate issuer name. | |
QSTP_EXPORT_API void | qstp_root_key_deserialize (qstp_root_signature_key *kset, const uint8_t input[QSTP_ROOT_SIGNATURE_KEY_SIZE]) |
Deserialize a root signature key from an encoded array. | |
QSTP_EXPORT_API bool | qstp_root_key_to_file (const qstp_root_signature_key *kset, const char *fpath) |
Write a root signature key to a file. | |
QSTP_EXPORT_API void | qstp_root_key_serialize (uint8_t serk[QSTP_ROOT_SIGNATURE_KEY_SIZE], const qstp_root_signature_key *kset) |
Serialize a root signature key into an encoded array. | |
QSTP_EXPORT_API bool | qstp_server_certificate_compare (const qstp_server_certificate *a, const qstp_server_certificate *b) |
Compare two server certificates for equivalence. | |
QSTP_EXPORT_API void | qstp_server_certificate_deserialize (qstp_server_certificate *cert, const uint8_t input[QSTP_SERVER_CERTIFICATE_SIZE]) |
Deserialize a server certificate from a serialized byte stream. | |
QSTP_EXPORT_API size_t | qstp_server_certificate_encode (char *enck, size_t enclen, const qstp_server_certificate *cert) |
Encode a public server certificate into a readable string. | |
QSTP_EXPORT_API size_t | qstp_server_certificate_encoded_size () |
Get the size required to encode a server certificate. | |
QSTP_EXPORT_API void | qstp_server_certificate_extract (qstp_server_certificate *cert, const qstp_server_signature_key *kset) |
Extract the server certificate from a server signature key. | |
QSTP_EXPORT_API void | qstp_server_certificate_hash (uint8_t output[QSTP_CERTIFICATE_HASH_SIZE], const qstp_server_certificate *cert) |
Compute the hash of a server certificate. | |
QSTP_EXPORT_API void | qstp_server_root_certificate_hash (uint8_t rshash[QSTP_CERTIFICATE_HASH_SIZE], const qstp_root_certificate *root, const qstp_server_certificate *cert) |
Compute a combined hash of the root and server certificates. | |
QSTP_EXPORT_API void | qstp_server_certificate_serialize (uint8_t output[QSTP_SERVER_CERTIFICATE_SIZE], const qstp_server_certificate *cert) |
Serialize a server certificate into a byte array. | |
QSTP_EXPORT_API bool | qstp_server_certificate_to_file (const qstp_server_certificate *cert, const char *fpath) |
Write a server certificate to a file. | |
QSTP_EXPORT_API bool | qstp_server_file_to_certificate (qstp_server_certificate *cert, const char *fpath) |
Read a server certificate from a file into a server certificate structure. | |
QSTP_EXPORT_API bool | qstp_server_file_to_key (qstp_server_signature_key *kset, const char *fpath) |
Read a server signature key from a file into a server key structure. | |
QSTP_EXPORT_API void | qstp_server_get_issuer (char issuer[QSTP_CERTIFICATE_ISSUER_SIZE]) |
Get the server certificate issuer name. | |
QSTP_EXPORT_API void | qstp_server_key_deserialize (qstp_server_signature_key *kset, const uint8_t input[QSTP_SERVER_SIGNATURE_KEY_SIZE]) |
Deserialize a server signature key from an encoded array. | |
QSTP_EXPORT_API void | qstp_server_key_serialize (uint8_t output[QSTP_SERVER_SIGNATURE_KEY_SIZE], const qstp_server_signature_key *kset) |
Serialize a server signature key into a byte array. | |
QSTP_EXPORT_API bool | qstp_server_key_to_file (const qstp_server_signature_key *kset, const char *fpath) |
Write a server signature key to a file. | |
QSTP_EXPORT_API uint8_t | qstp_version_from_string (const char *sver, size_t sverlen) |
Convert a version string to a version number. | |
QSTP_EXPORT_API void | qstp_version_to_string (char *sver, uint8_t version) |
Convert a version number to a hexadecimal string. | |
QSTP_EXPORT_API bool | qstp_test_root_certificate_encoding (const qstp_root_certificate *root) |
Test the root certificate encoding and decoding functions. | |
QSTP_EXPORT_API bool | qstp_test_server_certificate_encoding (const qstp_server_certificate *cert) |
Test the server certificate encoding and decoding functions. | |
QSTP support header.
This header file defines common parameters, macros, enumerations, type definitions, and function prototypes used by the QSTP (Quantum Secure Tunneling Protocol) client and server implementations.
QSTP is designed to provide a complete cryptographic protocol for secure tunneling by integrating post-quantum key exchange, authenticated encryption, and certificate-based authentication. The protocol utilizes various asymmetric cryptographic primitive sets (e.g., Kyber, McEliece, Dilithium, Sphincs+) which are configured in the QSC library's common.h file. For maximum security, the McEliece/SPHINCS+ set is recommended; for a balance of performance and security, the Dilithium/Kyber or Dilithium/McEliece sets are advised.
The parameter sets used by QSTP are selected in the QSC library (via libraries/common.h) at their library defaults. A true 512-bit security level can be achieved by selecting the McEliece/SPHINCS+ parameter and configuring SPHINCS+ to one of the 512-bit options.
#define QSTP_CERTIFICATE_LINE_LENGTH 64 |
The line length for printing the MPDC certificate.
The line length for printing the QSTP public key.
#define QSTP_CERTIFICATE_LINE_LENGTH 64 |
The line length for printing the MPDC certificate.
The line length for printing the QSTP public key.
#define QSTP_CONNECTIONS_MAX 50000 |
The maximum number of QSTP connections.
Calculated based on approximately 5k bytes per connection (3480 for connection state + 1500 for MTU + overhead) on a system with 256GB of DRAM. Can be increased if supported by the hardware.
#define QSTP_PACKET_TIME_THRESHOLD 60 |
The maximum number of seconds a packet is considered valid.
On networks with a shared (NTP) time source, this may be as low as 1 second. On exterior networks, this value should be adjusted (typically between 30 and 100 seconds) to account for clock differences.
#define QSTP_ROOT_CERTIFICATE_SIZE |
The total length in bytes of the root certificate.
#define QSTP_ROOT_SIGNATURE_KEY_SIZE |
The total length in bytes of the root signature key.
#define QSTP_SERVER_CERTIFICATE_SIZE |
The total length in bytes of a server certificate.
#define QSTP_SERVER_SIGNATURE_KEY_SIZE |
The total length in bytes of a server signing key.
The MPDC algorithm configuration sets.
enum qstp_errors |
The QSTP error values.
enum qstp_flags |
The QSTP packet flags.
enum qstp_messages |
The logging message enumeration.
The MPDC device designations.
enum qstp_version_sets |
QSTP_EXPORT_API qstp_configuration_sets qstp_configuration_from_string | ( | const char * | config | ) |
Get the configuration enumerator from a string.
config | The configuration string. |
QSTP_EXPORT_API const char * qstp_configuration_to_string | ( | qstp_configuration_sets | cset | ) |
Get the configuration string from the enumerator.
cset | The configuration set enumerator. |
QSTP_EXPORT_API void qstp_connection_close | ( | qstp_connection_state * | cns, |
qstp_errors | err, | ||
bool | notify ) |
Close the network connection between hosts.
cns | A pointer to the QSTP connection state structure. |
err | The error code. |
notify | If true, notify the remote host that the connection is closing. |
QSTP_EXPORT_API void qstp_connection_state_dispose | ( | qstp_connection_state * | cns | ) |
Reset the connection state to zero.
cns | A pointer to the QSTP connection state structure. |
QSTP_EXPORT_API qstp_errors qstp_decrypt_packet | ( | qstp_connection_state * | cns, |
uint8_t * | message, | ||
size_t * | msglen, | ||
const qstp_network_packet * | packetin ) |
Decrypt a message from an input packet.
cns | A pointer to the QSTP connection state structure. |
message | The output buffer for the decrypted message. |
msglen | A pointer to a variable to receive the message length. |
packetin | A pointer to the input QSTP network packet. |
QSTP_EXPORT_API qstp_errors qstp_encrypt_packet | ( | qstp_connection_state * | cns, |
qstp_network_packet * | packetout, | ||
const uint8_t * | message, | ||
size_t | msglen ) |
Encrypt a message and build an output packet.
cns | A pointer to the QSTP connection state structure. |
packetout | A pointer to the output QSTP network packet. |
message | The input message array. |
msglen | The length of the message in bytes. |
QSTP_EXPORT_API const char * qstp_error_to_string | ( | qstp_errors | error | ) |
Return a pointer to a string description of an error code.
error | The QSTP error code. |
QSTP_EXPORT_API const char * qstp_get_error_description | ( | qstp_messages | emsg | ) |
Get the error description string for a QSTP logging message.
emsg | The QSTP message enumeration. |
QSTP_EXPORT_API void qstp_header_create | ( | qstp_network_packet * | packetout, |
qstp_flags | flag, | ||
uint64_t | sequence, | ||
uint32_t | msglen ) |
Populate a packet header and set its creation time.
packetout | A pointer to the output QSTP network packet. |
flag | The packet flag. |
sequence | The packet sequence number. |
msglen | The length of the message in bytes. |
QSTP_EXPORT_API qstp_errors qstp_header_validate | ( | qstp_connection_state * | cns, |
const qstp_network_packet * | packetin, | ||
qstp_flags | flag, | ||
uint64_t | sequence, | ||
uint32_t | msglen ) |
Validate a packet header and timestamp.
cns | A pointer to the QSTP connection state structure. |
packetin | A pointer to the input QSTP network packet. |
flag | The expected packet flag. |
sequence | The expected packet sequence number. |
msglen | The expected message length. |
QSTP_EXPORT_API void qstp_log_error | ( | qstp_messages | emsg, |
qsc_socket_exceptions | err, | ||
const char * | msg ) |
Log an error with a message, socket error, and description.
emsg | The QSTP message enumeration. |
err | The socket exception enumeration. |
msg | The additional descriptive message. |
QSTP_EXPORT_API void qstp_log_message | ( | qstp_messages | emsg | ) |
Log a QSTP message.
emsg | The QSTP message enumeration. |
QSTP_EXPORT_API void qstp_log_write | ( | qstp_messages | emsg, |
const char * | msg ) |
Log a QSTP message with an additional description.
emsg | The QSTP message enumeration. |
msg | The additional descriptive message. |
QSTP_EXPORT_API void qstp_packet_clear | ( | qstp_network_packet * | packet | ) |
Clear the state of a QSTP network packet.
packet | A pointer to the QSTP network packet to clear. |
QSTP_EXPORT_API void qstp_packet_error_message | ( | qstp_network_packet * | packet, |
qstp_errors | error ) |
Populate a QSTP packet with an error message.
packet | A pointer to the QSTP network packet. |
error | The QSTP error code. |
QSTP_EXPORT_API void qstp_packet_header_deserialize | ( | const uint8_t * | header, |
qstp_network_packet * | packet ) |
Deserialize a byte array into a QSTP packet header.
header | A pointer to the input header byte array. |
packet | A pointer to the QSTP network packet to populate. |
QSTP_EXPORT_API void qstp_packet_header_serialize | ( | const qstp_network_packet * | packet, |
uint8_t * | header ) |
Serialize a QSTP packet header into a byte array.
packet | A pointer to the QSTP network packet to serialize. |
header | The output header byte array. |
QSTP_EXPORT_API void qstp_packet_set_utc_time | ( | qstp_network_packet * | packet | ) |
Set the local UTC time (in seconds) in a QSTP packet header.
packet | A pointer to the QSTP network packet to update. |
QSTP_EXPORT_API bool qstp_packet_time_valid | ( | const qstp_network_packet * | packet | ) |
Check if a QSTP packet was received within the valid time threshold.
packet | A pointer to the QSTP network packet. |
QSTP_EXPORT_API size_t qstp_packet_to_stream | ( | const qstp_network_packet * | packet, |
uint8_t * | pstream ) |
Serialize a QSTP packet into a byte array.
packet | A pointer to the QSTP network packet. |
pstream | The output byte stream buffer. |
QSTP_EXPORT_API bool qstp_root_certificate_compare | ( | const qstp_root_certificate * | a, |
const qstp_root_certificate * | b ) |
Compare two root certificates for equivalence.
a | A pointer to the first root certificate. |
b | A pointer to the second root certificate. |
QSTP_EXPORT_API bool qstp_root_certificate_decode | ( | qstp_root_certificate * | root, |
const char * | enck, | ||
size_t | enclen ) |
Copy an encoded root certificate into a root certificate structure.
root | A pointer to the output root certificate structure. |
enck | The encoded root certificate string. |
enclen | The length of the encoded certificate. |
QSTP_EXPORT_API void qstp_root_certificate_deserialize | ( | qstp_root_certificate * | root, |
const uint8_t | input[QSTP_ROOT_CERTIFICATE_SIZE] ) |
Deserialize a root certificate from a serialized byte array.
root | A pointer to the output root certificate. |
input | A pointer to the serialized root certificate array. |
QSTP_EXPORT_API size_t qstp_root_certificate_encode | ( | char * | enck, |
size_t | enclen, | ||
const qstp_root_certificate * | root ) |
Encode a root certificate into a readable string.
enck | The output encoded certificate string. |
enclen | The length of the output buffer. |
root | A pointer to the root certificate. |
QSTP_EXPORT_API size_t qstp_root_certificate_encoded_size | ( | ) |
Get the size required to encode a root certificate.
QSTP_EXPORT_API void qstp_root_certificate_extract | ( | qstp_root_certificate * | root, |
const qstp_root_signature_key * | kset ) |
Extract the root certificate from a root signature key.
root | The output root certificate. |
kset | A pointer to the input root signature key structure. |
QSTP_EXPORT_API void qstp_root_certificate_hash | ( | uint8_t | output[QSTP_CERTIFICATE_HASH_SIZE], |
const qstp_root_certificate * | root ) |
Compute the hash of a root certificate.
output | The output hash array. |
root | A pointer to the root certificate. |
QSTP_EXPORT_API void qstp_root_certificate_serialize | ( | uint8_t | output[QSTP_ROOT_CERTIFICATE_SIZE], |
const qstp_root_certificate * | root ) |
Serialize a root certificate into a byte array.
output | The array that will receive the serialized certificate. |
root | A pointer to the root certificate. |
QSTP_EXPORT_API size_t qstp_root_certificate_sign | ( | qstp_server_certificate * | cert, |
const qstp_root_certificate * | root, | ||
const uint8_t * | rsigkey ) |
Sign a server certificate using the root certificate.
cert | A pointer to the server certificate to sign. |
root | A pointer to the root certificate. |
rsigkey | A pointer to the root signing key (encoded). |
QSTP_EXPORT_API bool qstp_root_certificate_to_file | ( | const qstp_root_certificate * | root, |
const char * | fpath ) |
Write a root certificate to a file.
root | A pointer to the root certificate. |
fpath | The file path. |
QSTP_EXPORT_API bool qstp_root_certificate_verify | ( | const qstp_root_certificate * | root, |
const qstp_server_certificate * | cert ) |
Verify that a server certificate is signed by the root.
root | A pointer to the root certificate. |
cert | A pointer to the server certificate. |
QSTP_EXPORT_API bool qstp_root_file_to_certificate | ( | qstp_root_certificate * | root, |
const char * | fpath ) |
Read a root certificate from a file into a root certificate structure.
root | A pointer to the root certificate. |
fpath | The file path. |
QSTP_EXPORT_API bool qstp_root_file_to_key | ( | qstp_root_signature_key * | kset, |
const char * | fpath ) |
Read a root signature key from a file into a root signature key structure.
kset | A pointer to the root signature key structure. |
fpath | The file path. |
QSTP_EXPORT_API void qstp_root_get_issuer | ( | char | issuer[QSTP_CERTIFICATE_ISSUER_SIZE] | ) |
Get the root certificate issuer name.
issuer | The output buffer to receive the issuer string. |
QSTP_EXPORT_API void qstp_root_key_deserialize | ( | qstp_root_signature_key * | kset, |
const uint8_t | input[QSTP_ROOT_SIGNATURE_KEY_SIZE] ) |
Deserialize a root signature key from an encoded array.
kset | A pointer to the output root signature key structure. |
input | The input serialized root key array. |
QSTP_EXPORT_API void qstp_root_key_serialize | ( | uint8_t | serk[QSTP_ROOT_SIGNATURE_KEY_SIZE], |
const qstp_root_signature_key * | kset ) |
Serialize a root signature key into an encoded array.
serk | The output array for the serialized root key. |
kset | A pointer to the root signature key structure. |
QSTP_EXPORT_API bool qstp_root_key_to_file | ( | const qstp_root_signature_key * | kset, |
const char * | fpath ) |
Write a root signature key to a file.
kset | A pointer to the root signature key structure. |
fpath | The file path. |
QSTP_EXPORT_API bool qstp_server_certificate_compare | ( | const qstp_server_certificate * | a, |
const qstp_server_certificate * | b ) |
Compare two server certificates for equivalence.
a | A pointer to the first server certificate. |
b | A pointer to the second server certificate. |
QSTP_EXPORT_API void qstp_server_certificate_deserialize | ( | qstp_server_certificate * | cert, |
const uint8_t | input[QSTP_SERVER_CERTIFICATE_SIZE] ) |
Deserialize a server certificate from a serialized byte stream.
cert | A pointer to the server certificate structure to populate. |
input | A pointer to the serialized certificate array. |
QSTP_EXPORT_API size_t qstp_server_certificate_encode | ( | char * | enck, |
size_t | enclen, | ||
const qstp_server_certificate * | cert ) |
Encode a public server certificate into a readable string.
enck | The output buffer for the encoded certificate string. |
enclen | The length of the output buffer. |
cert | A pointer to the server certificate. |
QSTP_EXPORT_API size_t qstp_server_certificate_encoded_size | ( | ) |
Get the size required to encode a server certificate.
QSTP_EXPORT_API void qstp_server_certificate_extract | ( | qstp_server_certificate * | cert, |
const qstp_server_signature_key * | kset ) |
Extract the server certificate from a server signature key.
cert | The output server certificate. |
kset | A pointer to the server signature key structure. |
QSTP_EXPORT_API void qstp_server_certificate_hash | ( | uint8_t | output[QSTP_CERTIFICATE_HASH_SIZE], |
const qstp_server_certificate * | cert ) |
Compute the hash of a server certificate.
output | The output hash array. |
cert | A pointer to the server certificate. |
QSTP_EXPORT_API void qstp_server_certificate_serialize | ( | uint8_t | output[QSTP_SERVER_CERTIFICATE_SIZE], |
const qstp_server_certificate * | cert ) |
Serialize a server certificate into a byte array.
output | The output array for the serialized certificate. |
cert | A pointer to the server certificate. |
QSTP_EXPORT_API bool qstp_server_certificate_to_file | ( | const qstp_server_certificate * | cert, |
const char * | fpath ) |
Write a server certificate to a file.
cert | A pointer to the server certificate structure. |
fpath | The file path. |
QSTP_EXPORT_API bool qstp_server_file_to_certificate | ( | qstp_server_certificate * | cert, |
const char * | fpath ) |
Read a server certificate from a file into a server certificate structure.
cert | A pointer to the server certificate structure. |
fpath | The file path. |
QSTP_EXPORT_API bool qstp_server_file_to_key | ( | qstp_server_signature_key * | kset, |
const char * | fpath ) |
Read a server signature key from a file into a server key structure.
kset | A pointer to the server signature key structure. |
fpath | The file path. |
QSTP_EXPORT_API void qstp_server_get_issuer | ( | char | issuer[QSTP_CERTIFICATE_ISSUER_SIZE] | ) |
Get the server certificate issuer name.
issuer | The output buffer for the issuer string. |
QSTP_EXPORT_API void qstp_server_key_deserialize | ( | qstp_server_signature_key * | kset, |
const uint8_t | input[QSTP_SERVER_SIGNATURE_KEY_SIZE] ) |
Deserialize a server signature key from an encoded array.
kset | A pointer to the output server signature key structure. |
input | The input encoded server key array. |
QSTP_EXPORT_API void qstp_server_key_serialize | ( | uint8_t | output[QSTP_SERVER_SIGNATURE_KEY_SIZE], |
const qstp_server_signature_key * | kset ) |
Serialize a server signature key into a byte array.
output | The output array for the serialized key. |
kset | A pointer to the server signature key structure. |
QSTP_EXPORT_API bool qstp_server_key_to_file | ( | const qstp_server_signature_key * | kset, |
const char * | fpath ) |
Write a server signature key to a file.
kset | A pointer to the server signature key structure. |
fpath | The file path. |
QSTP_EXPORT_API void qstp_server_root_certificate_hash | ( | uint8_t | rshash[QSTP_CERTIFICATE_HASH_SIZE], |
const qstp_root_certificate * | root, | ||
const qstp_server_certificate * | cert ) |
Compute a combined hash of the root and server certificates.
rshash | The output hash array. |
root | A pointer to the root certificate. |
cert | A pointer to the server certificate. |
QSTP_EXPORT_API bool qstp_test_root_certificate_encoding | ( | const qstp_root_certificate * | root | ) |
Test the root certificate encoding and decoding functions.
QSTP_EXPORT_API bool qstp_test_server_certificate_encoding | ( | const qstp_server_certificate * | cert | ) |
Test the server certificate encoding and decoding functions.
QSTP_EXPORT_API uint8_t qstp_version_from_string | ( | const char * | sver, |
size_t | sverlen ) |
Convert a version string to a version number.
sver | The input version string. |
sverlen | The length of the version string. |
QSTP_EXPORT_API void qstp_version_to_string | ( | char * | sver, |
uint8_t | version ) |
Convert a version number to a hexadecimal string.
sver | The output version string. |
version | The version number. |