OpenTTD Source  20240919-master-gdf0233f4c2
X25519EncryptionHandler Class Reference

Encryption handler implementation for monocypther encryption after a X25519 key exchange. More...

Inheritance diagram for X25519EncryptionHandler:
NetworkEncryptionHandler

Public Member Functions

 X25519EncryptionHandler (const std::span< const uint8_t > key, const X25519Nonce &nonce)
 Create the encryption handler. More...
 
 ~X25519EncryptionHandler ()
 Ensure the encryption context is wiped!
 
size_t MACSize () const override
 Get the size of the MAC (Message Authentication Code) used by the underlying encryption protocol. More...
 
bool Decrypt (std::span< std::uint8_t > mac, std::span< std::uint8_t > message) override
 Decrypt the given message in-place, validating against the given MAC. More...
 
void Encrypt (std::span< std::uint8_t > mac, std::span< std::uint8_t > message) override
 Encrypt the given message in-place, and write the associated MAC. More...
 

Private Attributes

crypto_aead_ctx context
 The actual encryption context.
 

Detailed Description

Encryption handler implementation for monocypther encryption after a X25519 key exchange.

Definition at line 97 of file network_crypto.cpp.

Constructor & Destructor Documentation

◆ X25519EncryptionHandler()

X25519EncryptionHandler::X25519EncryptionHandler ( const std::span< const uint8_t >  key,
const X25519Nonce nonce 
)
inline

Create the encryption handler.

Parameters
keyThe key used for the encryption.
nonceThe nonce used for the encryption.

Definition at line 107 of file network_crypto.cpp.

References X25519_KEY_SIZE.

Member Function Documentation

◆ Decrypt()

bool X25519EncryptionHandler::Decrypt ( std::span< std::uint8_t >  mac,
std::span< std::uint8_t >  message 
)
inlineoverridevirtual

Decrypt the given message in-place, validating against the given MAC.

Parameters
macThe message authentication code (MAC).
messageThe location of the message to decrypt.
Returns
Whether decryption and authentication/validation of the message succeeded.

Implements NetworkEncryptionHandler.

Definition at line 124 of file network_crypto.cpp.

◆ Encrypt()

void X25519EncryptionHandler::Encrypt ( std::span< std::uint8_t >  mac,
std::span< std::uint8_t >  message 
)
inlineoverridevirtual

Encrypt the given message in-place, and write the associated MAC.

Parameters
macThe location to write the message authentication code (MAC) to.
messageThe location of the message to encrypt.

Implements NetworkEncryptionHandler.

Definition at line 129 of file network_crypto.cpp.

◆ MACSize()

size_t X25519EncryptionHandler::MACSize ( ) const
inlineoverridevirtual

Get the size of the MAC (Message Authentication Code) used by the underlying encryption protocol.

Returns
The size, in bytes, of the MACs.

Implements NetworkEncryptionHandler.

Definition at line 119 of file network_crypto.cpp.

References X25519_MAC_SIZE.


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