OpenTTD Source: X25519DerivedKeys Class Reference

OpenTTD Source 15.0-beta1

Public Member Functions | Private Attributes
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.
std::span< const uint8_t > | ServerToClient () const
| Get the key to encrypt or decrypt a message sent from the server to the client.
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.

## Private Attributes
std::array< uint8_t, X25519_KEY_SIZE+X25519_KEY_SIZE > | keys
| 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.

## Constructor & Destructor Documentation

## ◆ ~X25519DerivedKeys()

X25519DerivedKeys::~X25519DerivedKeys | ( |  | ) |

Ensure the derived keys do not get leaked when we're done with it.

Definition at line 32 of file network_crypto.cpp.

References crypto_wipe(), and keys.

## 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_key | The public key chosen by the other participant of the key exchange.
  side | Whether we are the client or server; used to hash the public key of us and the peer in the right order.
  our_secret_key | The secret key of us.
  our_public_key | The public key of us.
  extra_payload | Extra 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.

## Field Documentation

## ◆ keys

std::array<uint8_t, X25519_KEY_SIZE + X25519_KEY_SIZE> X25519DerivedKeys::keys
| private

Single contiguous buffer to store the derived keys in, as they are generated as a single hash.

Definition at line 64 of file network_crypto_internal.h.

Referenced by ClientToServer(), Exchange(), ServerToClient(), and ~X25519DerivedKeys().

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

- src/network/network_crypto_internal.h
- src/network/network_crypto.cpp