Fawkes API
Fawkes Development Version
|
#include <>>
Public Member Functions | |
MessageEncryptor (const unsigned char *key, const unsigned char *iv) | |
Constructor. More... | |
~MessageEncryptor () | |
Empty destructor. More... | |
void | set_plain_buffer (void *buffer, size_t buffer_length) |
Set plain buffer. More... | |
void | set_crypt_buffer (void *buffer, size_t buffer_length) |
Set crypted buffer. More... | |
size_t | recommended_crypt_buffer_size () |
Get recommended crypted buffer size. More... | |
size_t | encrypt () |
Encrypt. More... | |
Message encryptor.
This class is used to encrypt world info message before they are sent over the network.
The used encryption is AES (128 bit) with a supplied key and initialisation vector that both sides have to agree on. The encryption is used in the less safe Electronic Code Book (ECB) mode. It is prefered over Cipher Block Chaining (CBC) mode since we expect a very unreliable transport medium (wifi in a totally crowded and signal-hostile environment) where we could have severe packet loss. In CBC mode if you loose a single packet you can not only not decrypt this packet that you didn't get, but also not the directly following packages. In this case it can already cause severe problems if about half of the packes are lost.
We are merely interested in some kind of child-proof blinds that is just used to make cheating too much work to be interesting. We actually don't care if someone can decrypt our traffic with enough time, we just don't want other teams to be able to decrypt our traffic during the game. Otherwise teams could cheat and just read the network messages to know where the opponents are instead of really detecting them using sensors.
This implementation uses OpenSSL for the AES encryption (in fact it uses the accompanying libcrypto that comes with OpenSSL, not libopenssl itself). It is almost everywhere available and easy to use.
fawkes::MessageEncryptor::MessageEncryptor | ( | const unsigned char * | key, |
const unsigned char * | iv | ||
) |
Constructor.
key | encryption key |
iv | initialisation vector |
Definition at line 85 of file encrypt.cpp.
fawkes::MessageEncryptor::~MessageEncryptor | ( | ) |
Empty destructor.
Definition at line 98 of file encrypt.cpp.
size_t fawkes::MessageEncryptor::encrypt | ( | ) |
Encrypt.
Do the encryption.
Definition at line 167 of file encrypt.cpp.
References fawkes::Exception::Exception(), and fawkes::MessageEncryptionException::MessageEncryptionException().
size_t fawkes::MessageEncryptor::recommended_crypt_buffer_size | ( | ) |
Get recommended crypted buffer size.
The cryto text is in most cases longer than the plain text. This is because we use a block cipher. This block cipher encrypts block of certain sizes (in case of AES128 a block has a size of 16 bytes). If our data does not align to this block size padding at the end is required to fill up the last block to the requested size. Since this padding depends on the used cipher this convenience method is provided to get the recommended minimum size depending on the plain text buffer (that you have to set before you call this method.
MissingParameterException | thrown, if set_plain_buffer() has not been called or if the supplied buffer had zero size. |
Definition at line 131 of file encrypt.cpp.
void fawkes::MessageEncryptor::set_crypt_buffer | ( | void * | buffer, |
size_t | buffer_length | ||
) |
Set crypted buffer.
This set the destination buffer to which the encrypted message is written.
buffer | crypted buffer |
buffer_length | crypted buffer length |
Definition at line 155 of file encrypt.cpp.
void fawkes::MessageEncryptor::set_plain_buffer | ( | void * | buffer, |
size_t | buffer_length | ||
) |
Set plain buffer.
This set the source buffer that is encrypted.
buffer | plain buffer |
buffer_length | plain buffer length |
Definition at line 111 of file encrypt.cpp.