DKTP: Dual Key Tunneling Protocol 1.0.0.0a (A1)
A quantum secure dual-key encrypted tunneling protocol
dktp.h File Reference

DKTP support header Common defined parameters and functions of the DKTP client and server implementations. More...

#include "rcs.h"
#include "sha3.h"
#include "dktpcommon.h"
#include "socketbase.h"
#include "dilithium.h"
#include "kyber.h"

Go to the source code of this file.

Data Structures

struct  dktp_asymmetric_cipher_keypair
 The DKTP asymmetric cipher key container. More...
struct  dktp_asymmetric_signature_keypair
 The DKTP asymmetric signature key container. More...
struct  dktp_network_packet
 The DKTP packet structure. More...
struct  dktp_remote_peer_key
 The DKTP client key structure. More...
struct  dktp_local_peer_key
 The DKTP server key structure. More...
struct  dktp_keepalive_state
 The DKTP keep alive state structure. More...
struct  dktp_connection_state
 The DKTP socket connection state structure. More...

Macros

#define DKTP_CONFIG_DILITHIUM_KYBER
 Sets the asymmetric cryptographic primitive-set to Dilithium/Kyber.
#define DKTP_DOMAIN_IDENTITY_SIZE   16U
 The size of the domain identity string. This string size can be modified to accomodate different length domain strings.
#define DKTP_ASYMMETRIC_RATCHET
 Enable the asymmetric ratchet option.
#define DKTP_CONFIG_SIZE   48U
 The size of the protocol configuration string.
#define DKTP_HASH_SIZE   64U
 The 512-bit hash function size.
#define DKTP_MACKEY_SIZE   64U
 The 512-bit mac key size.
#define DKTP_MACTAG_SIZE   64U
 The 512-bit mac key size.
#define DKTP_SYMMETRIC_KEY_SIZE   64U
 The 512-bit symmetric cipher key size.
#define DKTP_SYMMETRIC_NONCE_SIZE   32U
 The 256-bit symmetric cipher nonce size.
#define DKTP_ASYMMETRIC_KEYCHAIN_COUNT   10U
 The key-chain asymmetric key count.
#define DKTP_CLIENT_PORT   31118U
 The default client port address.
#define DKTP_CONNECTIONS_INIT   1000U
 The intitial DKTP connections queue size.
#define DKTP_CONNECTIONS_MAX   50000U
 The maximum number of connections Calculated given approx 5k (3480 connection state + 1500 mtu + overhead), per connection on 256GB of DRAM. Can be scaled to a greater number provided the hardware can support it.
#define DKTP_CONNECTION_MTU   1500U
 The DKTP packet buffer size.
#define DKTP_ERROR_SEQUENCE   0xFF00000000000000ULL
 The packet error sequence number.
#define DKTP_ERROR_MESSAGE_SIZE   1U
 The packet error message size.
#define DKTP_FLAG_SIZE   1U
 The packet flag size.
#define DKTP_HEADER_SIZE   21U
 The DKTP packet header size.
#define DKTP_KEEPALIVE_STRING   20U
 The keep alive string size.
#define DKTP_KEEPALIVE_TIMEOUT   (120U * 1000U)
 The keep alive timeout in milliseconds (2 minutes)
#define DKTP_KEYID_SIZE   16U
 The DKTP key identity size.
#define DKTP_MSGLEN_SIZE   4U
 The size of the packet message length.
#define DKTP_NONCE_SIZE   32U
 The size of the symmetric cipher nonce.
#define DKTP_SERVER_PORT   31119U
 The default server port address.
#define DKTP_PACKET_TIME_THRESHOLD   60U
 The maximum number of seconds a packet is valid Note: On interior networks with a shared (NTP) time source, this could be set at 1 second, depending on network and device traffic conditions. For exterior networks, this time needs to be adjusted to account for clock-time differences, between 30-100 seconds.
#define DKTP_POLLING_INTERVAL   (120U * 1000U)
 The polling interval in milliseconds (2 minutes)
#define DKTP_PUBKEY_DURATION_DAYS   365U
 The number of days a public key remains valid.
#define DKTP_PUBKEY_DURATION_SECONDS   (DKTP_PUBKEY_DURATION_DAYS * 24U * 60U * 60U)
 The number of seconds a public key remains valid.
#define DKTP_PUBKEY_LINE_LENGTH   64U
 The line length of the printed DKTP public key.
#define DKTP_SECRET_SIZE   32U
 The size of the shared secret for each channel.
#define DKTP_SEQUENCE_SIZE   8U
 The size of the packet sequence number.
#define DKTP_SEQUENCE_TERMINATOR   0xFFFFFFFFUL
 The sequence number of a packet that closes a connection.
#define DKTP_TIMESTAMP_SIZE   8U
 The key expiration timestamp size.
#define DKTP_TIMESTAMP_STRING_SIZE   20U
 The key expiration timestamp string size.
#define DKTP_MESSAGE_MAX   0x3D090000UL
 The maximum message size used during the key exchange (1 GB)
#define dktp_cipher_generate_keypair   qsc_kyber_generate_keypair
 Generate an asymmetric cipher key-pair.
#define dktp_cipher_decapsulate   qsc_kyber_decapsulate
 Decapsulate a shared-secret with the asymmetric cipher.
#define dktp_cipher_encapsulate   qsc_kyber_encapsulate
 Encapsulate a shared-secret with the asymmetric cipher.
#define dktp_signature_generate_keypair   qsc_dilithium_generate_keypair
 Generate an asymmetric signature key-pair.
#define dktp_signature_sign   qsc_dilithium_sign
 Sign a message with the asymmetric signature scheme.
#define dktp_signature_verify   qsc_dilithium_verify
 Verify a message with the asymmetric signature scheme.
#define DKTP_ASYMMETRIC_CIPHER_TEXT_SIZE   (QSC_KYBER_CIPHERTEXT_SIZE)
 The byte size of the asymmetric cipher-text array.
#define DKTP_ASYMMETRIC_DECAPSULATION_KEY_SIZE   (QSC_KYBER_PRIVATEKEY_SIZE)
 The byte size of the asymmetric cipher private-key array.
#define DKTP_ASYMMETRIC_ENCAPSULATION_KEY_SIZE   (QSC_KYBER_PUBLICKEY_SIZE)
 The byte size of the asymmetric cipher public-key array.
#define DKTP_ASYMMETRIC_SIGNING_KEY_SIZE   (QSC_DILITHIUM_PRIVATEKEY_SIZE)
 The byte size of the asymmetric signature signing-key array.
#define DKTP_ASYMMETRIC_VERIFY_KEY_SIZE   (QSC_DILITHIUM_PUBLICKEY_SIZE)
 The byte size of the asymmetric signature verification-key array.
#define DKTP_ASYMMETRIC_SIGNATURE_SIZE   (QSC_DILITHIUM_SIGNATURE_SIZE)
 The byte size of the asymmetric signature array.
#define DKTP_REMOTE_PEER_KEY_ENCODED_SIZE   (DKTP_KEYID_SIZE + DKTP_TIMESTAMP_SIZE + DKTP_CONFIG_SIZE + DKTP_SECRET_SIZE + DKTP_ASYMMETRIC_VERIFY_KEY_SIZE)
 The peer key size.
#define DKTP_LOCAL_PEER_KEY_ENCODED_SIZE   (DKTP_KEYID_SIZE + DKTP_KEYID_SIZE + DKTP_TIMESTAMP_SIZE + DKTP_CONFIG_SIZE + DKTP_SECRET_SIZE + DKTP_ASYMMETRIC_SIGNING_KEY_SIZE + DKTP_ASYMMETRIC_VERIFY_KEY_SIZE)
 The secret signature key size.
#define DKTP_ERROR_STRING_DEPTH   30U
 The depth of the DKTP error string array.
#define DKTP_ERROR_STRING_WIDTH   128U
 The width of each DKTP error string.
#define DKTP_MESSAGE_STRING_DEPTH   21U
 The depth of the DKTP message string array.
#define DKTP_MESSAGE_STRING_WIDTH   128U
 The width of each DKTP message string.

Typedefs

typedef DKTP_EXPORT_API enum dktp_configuration dktp_configuration
typedef DKTP_EXPORT_API enum dktp_messages dktp_messages
typedef DKTP_EXPORT_API enum dktp_errors dktp_errors
typedef DKTP_EXPORT_API enum dktp_flags dktp_flags
typedef DKTP_EXPORT_API struct dktp_asymmetric_cipher_keypair dktp_asymmetric_cipher_keypair
typedef DKTP_EXPORT_API struct dktp_asymmetric_signature_keypair dktp_asymmetric_signature_keypair
typedef DKTP_EXPORT_API struct dktp_network_packet dktp_network_packet
typedef DKTP_EXPORT_API struct dktp_remote_peer_key dktp_remote_peer_key
typedef DKTP_EXPORT_API struct dktp_local_peer_key dktp_local_peer_key
typedef DKTP_EXPORT_API struct dktp_keepalive_state dktp_keepalive_state
typedef DKTP_EXPORT_API struct dktp_connection_state dktp_connection_state

Enumerations

enum  dktp_configuration {
  dktp_configuration_none = 0x00U , dktp_configuration_sphincs_mceliece = 0x01U , dktp_configuration_dilithium_kyber = 0x02U , dktp_configuration_dilithium_mceliece = 0x03U ,
  dktp_configuration_dilithium_ntru = 0x04U , dktp_configuration_falcon_kyber = 0x05U , dktp_configuration_falcon_mceliece = 0x06U , dktp_configuration_falcon_ntru = 0x07U
}
 The asymmetric cryptographic primitive configuration. More...
enum  dktp_messages {
  dktp_messages_none = 0x00U , dktp_messages_accept_fail = 0x01U , dktp_messages_listen_fail = 0x02U , dktp_messages_bind_fail = 0x03U ,
  dktp_messages_create_fail = 0x04U , dktp_messages_connect_success = 0x05U , dktp_messages_receive_fail = 0x06U , dktp_messages_allocate_fail = 0x07U ,
  dktp_messages_kex_fail = 0x08U , dktp_messages_disconnect = 0x09U , dktp_messages_disconnect_fail = 0x0AU , dktp_messages_socket_message = 0x0BU ,
  dktp_messages_queue_empty = 0x0CU , dktp_messages_listener_fail = 0x0DU , dktp_messages_sockalloc_fail = 0x0EU , dktp_messages_decryption_fail = 0x0FU ,
  dktp_messages_keepalive_fail = 0x10U , dktp_messages_keepalive_timeout = 0x11U , dktp_messages_connection_fail = 0x12U , dktp_messages_invalid_request = 0x13U ,
  dktp_messages_peer_key_mismatch = 0x14U
}
 The logging message enumeration. More...
enum  dktp_errors {
  dktp_error_none = 0x00U , dktp_error_accept_fail = 0x01U , dktp_error_authentication_failure = 0x02U , dktp_error_bad_keep_alive = 0x03U ,
  dktp_error_channel_down = 0x04U , dktp_error_connection_failure = 0x05U , dktp_error_connect_failure = 0x06U , dktp_error_decapsulation_failure = 0x07U ,
  dktp_error_decryption_failure = 0x08U , dktp_error_establish_failure = 0x09U , dktp_error_exchange_failure = 0x0AU , dktp_error_hash_invalid = 0x0BU ,
  dktp_error_hosts_exceeded = 0x0CU , dktp_error_invalid_input = 0x0DU , dktp_error_invalid_request = 0x0EU , dktp_error_keepalive_expired = 0x0FU ,
  dktp_error_keepalive_timeout = 0x10U , dktp_error_key_expired = 0x11U , dktp_error_key_unrecognized = 0x12U , dktp_error_keychain_fail = 0x13U ,
  dktp_error_listener_fail = 0x14U , dktp_error_memory_allocation = 0x15U , dktp_error_message_time_invalid = 0x06U , dktp_error_packet_unsequenced = 0x17U ,
  dktp_error_random_failure = 0x18U , dktp_error_receive_failure = 0x19U , dktp_error_transmit_failure = 0x1AU , dktp_error_unknown_protocol = 0x1BU ,
  dktp_error_verify_failure = 0x1CU , dktp_error_peer_key_mismatch = 0x1DU
}
 The DKTP error values. More...
enum  dktp_flags {
  dktp_flag_none = 0x00U , dktp_flag_connect_request = 0x01U , dktp_flag_connect_response = 0x02U , dktp_flag_connection_terminate = 0x03U ,
  dktp_flag_encrypted_message = 0x04U , dktp_flag_exstart_request = 0x05U , dktp_flag_exstart_response = 0x06U , dktp_flag_exchange_request = 0x07U ,
  dktp_flag_exchange_response = 0x08U , dktp_flag_establish_request = 0x09U , dktp_flag_establish_response = 0x0AU , dktp_flag_keep_alive_request = 0x0BU ,
  dktp_flag_keep_alive_response = 0x0CU , dktp_flag_remote_connected = 0x0DU , dktp_flag_remote_terminated = 0x0EU , dktp_flag_session_established = 0x0FU ,
  dktp_flag_session_establish_verify = 0x10U , dktp_flag_unrecognized_protocol = 0x11U , dktp_flag_asymmetric_ratchet_request = 0x12U , dktp_flag_asymmetric_ratchet_response = 0x13U ,
  dktp_flag_symmetric_ratchet_request = 0x14U , dktp_flag_transfer_request = 0x15U , dktp_flag_error_condition = 0xFFU
}
 The DKTP packet flags. More...

Functions

DKTP_EXPORT_API void dktp_connection_close (dktp_connection_state *cns, dktp_errors err, bool notify)
 Close the network connection between hosts.
DKTP_EXPORT_API void dktp_connection_state_dispose (dktp_connection_state *cns)
 Reset the connection state.
DKTP_EXPORT_API const char * dktp_error_to_string (dktp_errors error)
 Return a pointer to a string description of an error code.
DKTP_EXPORT_API void dktp_header_create (dktp_network_packet *packetout, dktp_flags flag, uint64_t sequence, uint32_t msglen)
 Populate a packet header and set the creation time.
DKTP_EXPORT_API dktp_errors dktp_header_validate (dktp_connection_state *cns, const dktp_network_packet *packetin, dktp_flags kexflag, dktp_flags pktflag, uint64_t sequence, uint32_t msglen)
 Validate a packet header and timestamp.
DKTP_EXPORT_API void dktp_generate_keypair (dktp_remote_peer_key *enckey, dktp_local_peer_key *deckey, const uint8_t keyid[DKTP_KEYID_SIZE])
 Generate a DKTP key-pair; generates the public and private asymmetric signature keys.
DKTP_EXPORT_API const char * dktp_get_error_description (dktp_messages emsg)
 Get the error string description.
DKTP_EXPORT_API void dktp_log_error (dktp_messages emsg, qsc_socket_exceptions err, const char *msg)
 Log the message, socket error, and string description.
DKTP_EXPORT_API void dktp_log_message (dktp_messages emsg)
 Log a message.
DKTP_EXPORT_API void dktp_log_write (dktp_messages emsg, const char *msg)
 Log a message and description.
DKTP_EXPORT_API void dktp_packet_clear (dktp_network_packet *packet)
 Clear a packet's state.
DKTP_EXPORT_API dktp_errors dktp_packet_decrypt (dktp_connection_state *cns, uint8_t *message, size_t *msglen, const dktp_network_packet *packetin)
 Decrypt a message and copy it to the message output.
DKTP_EXPORT_API dktp_errors dktp_packet_encrypt (dktp_connection_state *cns, dktp_network_packet *packetout, const uint8_t *message, size_t msglen)
 Encrypt a message and build an output packet.
DKTP_EXPORT_API void dktp_packet_error_message (dktp_network_packet *packet, dktp_errors error)
 Populate a packet structure with an error message.
DKTP_EXPORT_API void dktp_packet_header_deserialize (const uint8_t *header, dktp_network_packet *packet)
 Deserialize a byte array to a packet header.
DKTP_EXPORT_API void dktp_packet_header_serialize (const dktp_network_packet *packet, uint8_t *header)
 Serialize a packet header to a byte array.
DKTP_EXPORT_API void dktp_packet_set_utc_time (dktp_network_packet *packet)
 Sets the local UTC seconds time in the packet header.
DKTP_EXPORT_API bool dktp_packet_time_valid (const dktp_network_packet *packet)
 Checks the local UTC seconds time against the packet sent time for validity within the packet time threshold.
DKTP_EXPORT_API size_t dktp_packet_to_stream (const dktp_network_packet *packet, uint8_t *pstream)
 Serialize a packet to a byte array.
DKTP_EXPORT_API void dktp_local_peer_key_deserialize (dktp_local_peer_key *lpk, const uint8_t slpk[DKTP_LOCAL_PEER_KEY_ENCODED_SIZE])
 Deserialize a local peer key structure and copy to an array.
DKTP_EXPORT_API void dktp_local_peer_key_erase (dktp_local_peer_key *lpk)
 Erase a local peer key.
DKTP_EXPORT_API void dktp_local_peer_key_serialize (uint8_t slpk[DKTP_LOCAL_PEER_KEY_ENCODED_SIZE], const dktp_local_peer_key *lpk)
 Serialize a local peer key structure.
DKTP_EXPORT_API void dktp_remote_peer_key_erase (dktp_remote_peer_key *rpk)
 Erase a remote peer key.
DKTP_EXPORT_API bool dktp_remote_peer_key_compare (const dktp_remote_peer_key *a, const dktp_remote_peer_key *b)
 Compares two public keys for equality.
DKTP_EXPORT_API void dktp_remote_peer_key_deserialize (dktp_remote_peer_key *rpk, const uint8_t srpk[DKTP_REMOTE_PEER_KEY_ENCODED_SIZE])
 Deserialize a remote peer key and populate a remote peer key structure.
DKTP_EXPORT_API void dktp_remote_peer_key_serialize (uint8_t srpk[DKTP_REMOTE_PEER_KEY_ENCODED_SIZE], const dktp_remote_peer_key *rpk)
 Serialize a remote peer key structure and copy to an array.
DKTP_EXPORT_API void dktp_stream_to_packet (const uint8_t *pstream, dktp_network_packet *packet)
 Deserialize a byte array to a packet.

Detailed Description

DKTP support header Common defined parameters and functions of the DKTP client and server implementations.

Note: These definitions determine the asymmetric protocol set used by DKTP. The individual parameter sets for each cipher and signature scheme, can be configured in the QSC libraries qsccommon.h file. For maximum security, I recommend the McElice/SPHINCS+ set. For a balance of performance and security, the Dilithium/Kyber, or Dilithium/McEliece sets are recommended.

Parameter Sets: Kyber-S1, Dilithium-S1 Kyber-S3, Dilithium-S3 Kyber-S5, Dilithium-S5 Kyber-S6, Dilithium-S5 McEliece-S1, Dilithium-S1 McEliece-S3, Dilithium-S3 McEliece-S5, Dilithium-S5 McEliece-S6, Dilithium-S5 McEliece-S7, Dilithium-S5 McEliece-S1, Sphincs-S1(f,s) McEliece-S3, Sphincs-S3(f,s) McEliece-S5, Sphincs-S5(f,s) McEliece-S6, Sphincs-S5(f,s) McEliece-S7, Sphincs-S6(f,s)

Recommended: Kyber-S5, Dilithium-S5 Kyber-S6, Dilithium-S5 McEliece-S5, Dilithium-S5 McEliece-S5, Sphincs-S5(f,s)

The parameter sets used by DKTP are selected in the QSC library in the libraries qsccommon.h file. Settings are at library defaults, however, a true 512-bit security system can be acheived by selecting the McEliece/SPHINCS+ parameter in DKTP and setting SPHINCS+ to one of the 512-bit options in the QSC library.

Enumeration Type Documentation

◆ dktp_configuration

The asymmetric cryptographic primitive configuration.

Enumerator
dktp_configuration_none 

No configuration was specified

dktp_configuration_sphincs_mceliece 

The Sphincs+ and McEliece configuration

dktp_configuration_dilithium_kyber 

The Dilithium and Kyber configuration

dktp_configuration_dilithium_mceliece 

The Dilithium and Kyber configuration

dktp_configuration_dilithium_ntru 

The Dilithium and NTRU configuration

dktp_configuration_falcon_kyber 

The Falcon and Kyber configuration

dktp_configuration_falcon_mceliece 

The Falcon and McEliece configuration

dktp_configuration_falcon_ntru 

The Falcon and NTRU configuration

◆ dktp_errors

The DKTP error values.

Enumerator
dktp_error_none 

No error was detected

dktp_error_accept_fail 

The socket accept function returned an error

dktp_error_authentication_failure 

The symmetric cipher had an authentication failure

dktp_error_bad_keep_alive 

The keep alive check failed

dktp_error_channel_down 

The communications channel has failed

dktp_error_connection_failure 

The device could not make a connection to the remote host

dktp_error_connect_failure 

The transmission failed at the KEX connection phase

dktp_error_decapsulation_failure 

The asymmetric cipher failed to decapsulate the shared secret

dktp_error_decryption_failure 

The decryption authentication has failed

dktp_error_establish_failure 

The transmission failed at the KEX establish phase

dktp_error_exchange_failure 

The transmission failed at the KEX exchange phase

dktp_error_hash_invalid 

The public-key hash is invalid

dktp_error_hosts_exceeded 

The server has run out of socket connections

dktp_error_invalid_input 

The expected input was invalid

dktp_error_invalid_request 

The packet flag was unexpected

dktp_error_keepalive_expired 

The keep alive has expired with no response

dktp_error_keepalive_timeout 

The decryption authentication has failed

dktp_error_key_expired 

The DKTP public key has expired

dktp_error_key_unrecognized 

The key identity is unrecognized

dktp_error_keychain_fail 

The ratchet operation has failed

dktp_error_listener_fail 

The listener function failed to initialize

dktp_error_memory_allocation 

The server has run out of memory

dktp_error_message_time_invalid 

The packet has valid time expired

dktp_error_packet_unsequenced 

The packet was received out of sequence

dktp_error_random_failure 

The random generator has failed

dktp_error_receive_failure 

The receiver failed at the network layer

dktp_error_transmit_failure 

The transmitter failed at the network layer

dktp_error_unknown_protocol 

The protocol string was not recognized

dktp_error_verify_failure 

The expected data could not be verified

dktp_error_peer_key_mismatch 

The remote peer key identity does not match the local key

◆ dktp_flags

enum dktp_flags

The DKTP packet flags.

Enumerator
dktp_flag_none 

No flag was specified

dktp_flag_connect_request 

The DKTP key-exchange client connection request flag

dktp_flag_connect_response 

The DKTP key-exchange server connection response flag

dktp_flag_connection_terminate 

The connection is to be terminated

dktp_flag_encrypted_message 

The message has been encrypted flag

dktp_flag_exstart_request 

The DKTP key-exchange client exstart request flag

dktp_flag_exstart_response 

The DKTP key-exchange server exstart response flag

dktp_flag_exchange_request 

The DKTP key-exchange client exchange request flag

dktp_flag_exchange_response 

The DKTP key-exchange server exchange response flag

dktp_flag_establish_request 

The DKTP key-exchange client establish request flag

dktp_flag_establish_response 

The DKTP key-exchange server establish response flag

dktp_flag_keep_alive_request 

The packet contains a keep alive request

dktp_flag_keep_alive_response 

The packet contains a keep alive response

dktp_flag_remote_connected 

The remote host is connected flag

dktp_flag_remote_terminated 

The remote host has terminated the connection

dktp_flag_session_established 

The exchange is in the established state

dktp_flag_session_establish_verify 

The exchange is in the established verify state

dktp_flag_unrecognized_protocol 

The protocol string is not recognized

dktp_flag_asymmetric_ratchet_request 

The host has received a asymmetric key ratchet request

dktp_flag_asymmetric_ratchet_response 

The host has received a asymmetric key ratchet request

dktp_flag_symmetric_ratchet_request 

The host has received a symmetric key ratchet request

dktp_flag_transfer_request 

Reserved - The host has received a transfer request

dktp_flag_error_condition 

The connection experienced an error

◆ dktp_messages

The logging message enumeration.

Enumerator
dktp_messages_none 

No configuration was specified

dktp_messages_accept_fail 

The socket accept failed

dktp_messages_listen_fail 

The listener socket could not connect

dktp_messages_bind_fail 

The listener socket could not bind to the address

dktp_messages_create_fail 

The listener socket could not be created

dktp_messages_connect_success 

The server connected to a host

dktp_messages_receive_fail 

The socket receive function failed

dktp_messages_allocate_fail 

The server memory allocation request has failed

dktp_messages_kex_fail 

The key exchange has experienced a failure

dktp_messages_disconnect 

The server has disconnected the client

dktp_messages_disconnect_fail 

The server has disconnected the client due to an error

dktp_messages_socket_message 

The server has had a socket level error

dktp_messages_queue_empty 

The server has reached the maximum number of connections

dktp_messages_listener_fail 

The server listener socket has failed

dktp_messages_sockalloc_fail 

The server has run out of socket connections

dktp_messages_decryption_fail 

The message decryption has failed

dktp_messages_keepalive_fail 

The keepalive function has failed

dktp_messages_keepalive_timeout 

The keepalive period has been exceeded

dktp_messages_connection_fail 

The connection failed or was interrupted

dktp_messages_invalid_request 

The function received an invalid request

dktp_messages_peer_key_mismatch 

The remote peer identity does not match the local key

Function Documentation

◆ dktp_connection_close()

DKTP_EXPORT_API void dktp_connection_close ( dktp_connection_state * cns,
dktp_errors err,
bool notify )

Close the network connection between hosts.

Parameters
cnsA pointer to the connection state structure
errThe error message
notifyNotify the remote host connection is closing

◆ dktp_connection_state_dispose()

DKTP_EXPORT_API void dktp_connection_state_dispose ( dktp_connection_state * cns)

Reset the connection state.

Parameters
cnsA pointer to the connection state structure

◆ dktp_error_to_string()

DKTP_EXPORT_API const char * dktp_error_to_string ( dktp_errors error)

Return a pointer to a string description of an error code.

Parameters
errorThe error type
Returns
Returns a pointer to an error string or NULL

◆ dktp_generate_keypair()

DKTP_EXPORT_API void dktp_generate_keypair ( dktp_remote_peer_key * enckey,
dktp_local_peer_key * deckey,
const uint8_t keyid[DKTP_KEYID_SIZE] )

Generate a DKTP key-pair; generates the public and private asymmetric signature keys.

Parameters
enckeyThe public key, distributed to clients
deckeyThe private key, a secret key known only by the server
keyid[const] The key identity string

◆ dktp_get_error_description()

DKTP_EXPORT_API const char * dktp_get_error_description ( dktp_messages emsg)

Get the error string description.

Parameters
emsgThe message enumeration
Returns
Returns a pointer to the message string or NULL

◆ dktp_header_create()

DKTP_EXPORT_API void dktp_header_create ( dktp_network_packet * packetout,
dktp_flags flag,
uint64_t sequence,
uint32_t msglen )

Populate a packet header and set the creation time.

Parameters
packetoutA pointer to the output packet structure
flagThe packet flag
sequenceThe packet sequence number
msglenThe length of the message array

◆ dktp_header_validate()

DKTP_EXPORT_API dktp_errors dktp_header_validate ( dktp_connection_state * cns,
const dktp_network_packet * packetin,
dktp_flags kexflag,
dktp_flags pktflag,
uint64_t sequence,
uint32_t msglen )

Validate a packet header and timestamp.

Parameters
cnsA pointer to the connection state structure
packetinA pointer to the input packet structure
kexflagThe packet flag
pktflagThe packet flag
sequenceThe packet sequence number
msglenThe length of the message array
Returns
: Returns the function error state

◆ dktp_local_peer_key_deserialize()

DKTP_EXPORT_API void dktp_local_peer_key_deserialize ( dktp_local_peer_key * lpk,
const uint8_t slpk[DKTP_LOCAL_PEER_KEY_ENCODED_SIZE] )

Deserialize a local peer key structure and copy to an array.

Parameters
lpkA pointer to the output local peer key structure
slpk[const] The input serialized local peer key

◆ dktp_local_peer_key_erase()

DKTP_EXPORT_API void dktp_local_peer_key_erase ( dktp_local_peer_key * lpk)

Erase a local peer key.

Parameters
lpkA pointer to the output local peer key structure

◆ dktp_local_peer_key_serialize()

DKTP_EXPORT_API void dktp_local_peer_key_serialize ( uint8_t slpk[DKTP_LOCAL_PEER_KEY_ENCODED_SIZE],
const dktp_local_peer_key * lpk )

Serialize a local peer key structure.

Parameters
slpkThe output serialized local peer key
lpk[const] A pointer to the local peer key structure

◆ dktp_log_error()

DKTP_EXPORT_API void dktp_log_error ( dktp_messages emsg,
qsc_socket_exceptions err,
const char * msg )

Log the message, socket error, and string description.

Parameters
emsgThe message enumeration
errThe socket exception enumeration
msg[const] The message string

◆ dktp_log_message()

DKTP_EXPORT_API void dktp_log_message ( dktp_messages emsg)

Log a message.

Parameters
emsgThe message enumeration

◆ dktp_log_write()

DKTP_EXPORT_API void dktp_log_write ( dktp_messages emsg,
const char * msg )

Log a message and description.

Parameters
emsgThe message enumeration
msg[const] The message string

◆ dktp_packet_clear()

DKTP_EXPORT_API void dktp_packet_clear ( dktp_network_packet * packet)

Clear a packet's state.

Parameters
packetA pointer to the packet structure

◆ dktp_packet_decrypt()

DKTP_EXPORT_API dktp_errors dktp_packet_decrypt ( dktp_connection_state * cns,
uint8_t * message,
size_t * msglen,
const dktp_network_packet * packetin )

Decrypt a message and copy it to the message output.

Parameters
cnsA pointer to the connection state structure
messageThe message output array
msglenA pointer receiving the message length
packetin[const] A pointer to the input packet structure
Returns
: Returns the function error state

◆ dktp_packet_encrypt()

DKTP_EXPORT_API dktp_errors dktp_packet_encrypt ( dktp_connection_state * cns,
dktp_network_packet * packetout,
const uint8_t * message,
size_t msglen )

Encrypt a message and build an output packet.

Parameters
cnsA pointer to the connection state structure
packetoutA pointer to the output packet structure
message[const] The input message array
msglenThe length of the message array
Returns
: Returns the function error state

◆ dktp_packet_error_message()

DKTP_EXPORT_API void dktp_packet_error_message ( dktp_network_packet * packet,
dktp_errors error )

Populate a packet structure with an error message.

Parameters
packetA pointer to the packet structure
errorThe error type

◆ dktp_packet_header_deserialize()

DKTP_EXPORT_API void dktp_packet_header_deserialize ( const uint8_t * header,
dktp_network_packet * packet )

Deserialize a byte array to a packet header.

Parameters
packet[const] The header byte array to deserialize
headerA pointer to the packet structure

◆ dktp_packet_header_serialize()

DKTP_EXPORT_API void dktp_packet_header_serialize ( const dktp_network_packet * packet,
uint8_t * header )

Serialize a packet header to a byte array.

Parameters
packet[const] A pointer to the packet structure to serialize
headerThe header byte array

◆ dktp_packet_set_utc_time()

DKTP_EXPORT_API void dktp_packet_set_utc_time ( dktp_network_packet * packet)

Sets the local UTC seconds time in the packet header.

Parameters
packetA pointer to a network packet

◆ dktp_packet_time_valid()

DKTP_EXPORT_API bool dktp_packet_time_valid ( const dktp_network_packet * packet)

Checks the local UTC seconds time against the packet sent time for validity within the packet time threshold.

Parameters
packet[const] A pointer to a network packet
Returns
Returns true if the packet was received within the valid-time threhold

◆ dktp_packet_to_stream()

DKTP_EXPORT_API size_t dktp_packet_to_stream ( const dktp_network_packet * packet,
uint8_t * pstream )

Serialize a packet to a byte array.

Parameters
packet[const] The header byte array to deserialize
pstreamA pointer to the packet structure
Returns
Returns the size of the byte stream

◆ dktp_remote_peer_key_compare()

DKTP_EXPORT_API bool dktp_remote_peer_key_compare ( const dktp_remote_peer_key * a,
const dktp_remote_peer_key * b )

Compares two public keys for equality.

Parameters
a[const] The first public key
b[const] The second public key
Returns
Returns true if the certificates are identical

◆ dktp_remote_peer_key_deserialize()

DKTP_EXPORT_API void dktp_remote_peer_key_deserialize ( dktp_remote_peer_key * rpk,
const uint8_t srpk[DKTP_REMOTE_PEER_KEY_ENCODED_SIZE] )

Deserialize a remote peer key and populate a remote peer key structure.

Parameters
rpkA pointer to the output remote peer key
srpk[const] The input serialized remote peer key

◆ dktp_remote_peer_key_erase()

DKTP_EXPORT_API void dktp_remote_peer_key_erase ( dktp_remote_peer_key * rpk)

Erase a remote peer key.

Parameters
lpkA pointer to the output remote peer key structure

◆ dktp_remote_peer_key_serialize()

DKTP_EXPORT_API void dktp_remote_peer_key_serialize ( uint8_t srpk[DKTP_REMOTE_PEER_KEY_ENCODED_SIZE],
const dktp_remote_peer_key * rpk )

Serialize a remote peer key structure and copy to an array.

Parameters
srpkThe output serialized remote peer key array
rpk[const] A pointer to the remote peer key structure

◆ dktp_stream_to_packet()

DKTP_EXPORT_API void dktp_stream_to_packet ( const uint8_t * pstream,
dktp_network_packet * packet )

Deserialize a byte array to a packet.

Parameters
pstream[const] The header byte array to deserialize
packetA pointer to the packet structure