AES-DH Implementation
Loading...
Searching...
No Matches
util Namespace Reference

The utility namespace. More...

Functions

void clear ()
 Clear the screen.
 
template<typename T = bool>
input (const std::string &title, const T &error_ret=T())
 std::cin can be a little difficult to use, particularly handling bad input. This sanitized it.
 
void prompt (const std::string &message)
 Prompt the user and wait until they have confirmed it.
 
void construct_shared_key (std::array< uint64_t, 4 > &sk, const bool &server)
 Genreate a shared key over a connection.
 
void receive_message (const std::array< uint64_t, 4 > &sk)
 Receive an encrypted message from the peer.
 
void send_message (const std::array< uint64_t, 4 > &sk)
 Send an encrypted message to a peer.
 
bool acknowledge (const std::string &what)
 Acknowledge a request from a peer.
 

Detailed Description

The utility namespace.

Remarks
A namespace isn't really necessary, since this is only used by main, but it allows Doxygen to document these functions on the HTML.

Function Documentation

◆ acknowledge()

bool util::acknowledge ( const std::string & what)

Acknowledge a request from a peer.

Parameters
whatWhat is the acknowledgement for?
Returns
The return code of the send_packet.

◆ clear()

void util::clear ( )
inline

Clear the screen.

Remarks
This works on UNIX/Windows. It's a shell escape sequence.

◆ construct_shared_key()

void util::construct_shared_key ( std::array< uint64_t, 4 > & sk,
const bool & server )

Genreate a shared key over a connection.

Parameters
skThe shared key array to populate.
serverWhether we are the server or not.
Remarks
AES requires key sizes of 128, 192, or 256 bits, but our uint64_t is just 64. So, we just perform 4 key exchanges to get 256 bits.
Warning
Selecting different modes of AES merely truncates this key (IE AES-128 uses sk[0,1], AES-192 uses sk[0,1,2], AES-256 uses all of them).
This is not the cryptographically secure way of doing things. We should almost certainly Exchange a single, massive 256 bit prime instead of four 64 bit ones, but for the sake of not needing to create our own 256 bit number classes, we just key exchange quadrice.

◆ input()

template<typename T = bool>
T util::input ( const std::string & title,
const T & error_ret = T() )
inline

std::cin can be a little difficult to use, particularly handling bad input. This sanitized it.

Template Parameters
TThe type of input to be returned.
Parameters
titleA title to be drawn for the input
error_retIf something causes an error, what we should return to let the caller know.
Returns
The user input, or the error return.
Remarks
This function does not re-prompt upon errors; it is the responsibility of the caller to check for the error return and act accordingly.
Warning
This function is blocking.

◆ prompt()

void util::prompt ( const std::string & message)
inline

Prompt the user and wait until they have confirmed it.

Parameters
messageThe message to display.
Warning
This function is blocking.

◆ receive_message()

void util::receive_message ( const std::array< uint64_t, 4 > & sk)

Receive an encrypted message from the peer.

Parameters
skThe shared key

◆ send_message()

void util::send_message ( const std::array< uint64_t, 4 > & sk)

Send an encrypted message to a peer.

Parameters
skThe shared key.