OpenTTD Source  20240919-master-gdf0233f4c2
X25519DerivedKeys Class Reference

Container for the keys that derived from the X25519 key exchange mechanism. More...

#include <network_crypto_internal.h>

Public Member Functions

 ~X25519DerivedKeys ()
 Ensure the derived keys do not get leaked when we're done with it.
 
std::span< const uint8_t > ClientToServer () const
 Get the key to encrypt or decrypt a message sent from the client to the server. More...
 
std::span< const uint8_t > ServerToClient () const
 Get the key to encrypt or decrypt a message sent from the server to the client. More...
 
bool Exchange (const X25519PublicKey &peer_public_key, X25519KeyExchangeSide side, const X25519SecretKey &our_secret_key, const X25519PublicKey &our_public_key, std::string_view extra_payload)
 Perform the actual key exchange. More...
 

Private Attributes

std::array< uint8_t, X25519_KEY_SIZE+X25519_KEY_SIZEkeys
 Single contiguous buffer to store the derived keys in, as they are generated as a single hash.
 

Detailed Description

Container for the keys that derived from the X25519 key exchange mechanism.

This mechanism derives a key to encrypt both the client-to-server and a key to encrypt server-to-client communication.

Definition at line 61 of file network_crypto_internal.h.

Member Function Documentation

◆ ClientToServer()

std::span< const uint8_t > X25519DerivedKeys::ClientToServer ( ) const

Get the key to encrypt or decrypt a message sent from the client to the server.

Returns
The raw bytes of the key.

Definition at line 41 of file network_crypto.cpp.

References keys, and X25519_KEY_SIZE.

◆ Exchange()

bool X25519DerivedKeys::Exchange ( const X25519PublicKey peer_public_key,
X25519KeyExchangeSide  side,
const X25519SecretKey our_secret_key,
const X25519PublicKey our_public_key,
std::string_view  extra_payload 
)

Perform the actual key exchange.

Parameters
peer_public_keyThe public key chosen by the other participant of the key exchange.
sideWhether we are the client or server; used to hash the public key of us and the peer in the right order.
our_secret_keyThe secret key of us.
our_public_keyThe public key of us.
extra_payloadExtra payload to put into the hash function to create the derived keys.
Returns
True when the key exchange has succeeded, false when an illegal public key was given.

Definition at line 64 of file network_crypto.cpp.

References CLIENT, keys, and SERVER.

Referenced by X25519AuthenticationHandler::ReceiveResponse(), and X25519AuthenticationHandler::SendResponse().

◆ ServerToClient()

std::span< const uint8_t > X25519DerivedKeys::ServerToClient ( ) const

Get the key to encrypt or decrypt a message sent from the server to the client.

Returns
The raw bytes of the key.

Definition at line 50 of file network_crypto.cpp.

References keys, and X25519_KEY_SIZE.


The documentation for this class was generated from the following files: