OpenTTD Source 20241224-master-gee860a5c8e
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.
 
 ~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.
 
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.
 
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.
 

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.

◆ ~X25519EncryptionHandler()

X25519EncryptionHandler::~X25519EncryptionHandler ( )
inline

Ensure the encryption context is wiped!

Definition at line 114 of file network_crypto.cpp.

References crypto_wipe().

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.

Field Documentation

◆ context

crypto_aead_ctx X25519EncryptionHandler::context
private

The actual encryption context.

Definition at line 99 of file network_crypto.cpp.


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