IBR-DTNSuite
0.8
|
#include <AES128Stream.h>
Classes | |
struct | gcm_iv |
Public Member Functions | |
AES128Stream (const CipherMode mode, std::ostream &output, const unsigned char key[key_size_in_bytes], const u_int32_t salt) | |
AES128Stream (const CipherMode mode, std::ostream &output, const unsigned char key[key_size_in_bytes], const u_int32_t salt, const unsigned char iv[iv_len]) | |
virtual | ~AES128Stream () |
void | getIV (unsigned char(&to_iv)[iv_len]) const |
void | getTag (unsigned char(&to_tag)[tag_len]) |
bool | verify (const unsigned char(&verify_tag)[tag_len]) |
Static Public Attributes | |
static const size_t | key_size_in_bytes = 16 |
static const size_t | salt_len = sizeof(u_int32_t) |
static const size_t | iv_len = 8 |
static const size_t | tag_len = 16 |
static const size_t | BUFF_SIZE = 2048 |
Protected Member Functions | |
virtual void | encrypt (char *buf, const size_t size) |
virtual void | decrypt (char *buf, const size_t size) |
Encrypts or decrypts an input stream using AES with a 128bit key using galois counter mode. In encryption mode initialisation vector and tag will be created and can be read with getIV() and getTag(). In decryption mode initialisation vector and tag have to be set at construction or via the decrypt()-Method. TODO test the gcm_iv structure on be and le systems
Definition at line 20 of file AES128Stream.h.
ibrcommon::AES128Stream::AES128Stream | ( | const CipherMode | mode, |
std::ostream & | output, | ||
const unsigned char | key[key_size_in_bytes], | ||
const u_int32_t | salt | ||
) |
Creates a AES128Stream object, either for encrypting or decrypting, which is controlled by mode. If this object is used for decryption iv and tag have to be set.
mode | tell the constructor wether this will be used for en- or decryption |
output | the stream in which will the cipher- or plaintext be serialized into |
key | the AES128 key to use. Its size is key_size_in_bytes. |
salt | the salt, which shall be the same for all data which belongs together |
iv | if used for decryption, this is the initialisation vector, which was created at encryption. The size of this array is iv_len. |
tag | if used for decryption, this is the authentication tag, which was created at encryption. The size of this array is tag_len. |
Definition at line 8 of file AES128Stream.cpp.
References gcm_init_and_key(), gcm_init_message(), IBRCOMMON_LOGGER, IBRCOMMON_LOGGER_ENDL, and iv_len.
ibrcommon::AES128Stream::AES128Stream | ( | const CipherMode | mode, |
std::ostream & | output, | ||
const unsigned char | key[key_size_in_bytes], | ||
const u_int32_t | salt, | ||
const unsigned char | iv[iv_len] | ||
) |
Definition at line 30 of file AES128Stream.cpp.
References gcm_init_and_key(), gcm_init_message(), IBRCOMMON_LOGGER, IBRCOMMON_LOGGER_ENDL, and iv_len.
ibrcommon::AES128Stream::~AES128Stream | ( | ) | [virtual] |
cleans the output buffer and the context
Definition at line 51 of file AES128Stream.cpp.
References gcm_end().
void ibrcommon::AES128Stream::decrypt | ( | char * | buf, |
const size_t | size | ||
) | [protected, virtual] |
Implements ibrcommon::CipherStream.
Definition at line 89 of file AES128Stream.cpp.
References gcm_decrypt().
void ibrcommon::AES128Stream::encrypt | ( | char * | buf, |
const size_t | size | ||
) | [protected, virtual] |
Implements ibrcommon::CipherStream.
Definition at line 84 of file AES128Stream.cpp.
References gcm_encrypt().
void ibrcommon::AES128Stream::getIV | ( | unsigned char(&) | to_iv[iv_len] | ) | const |
Write the initialisation vector into an array, with length iv_len.
to_iv | the array in which the vector will be written into |
Definition at line 57 of file AES128Stream.cpp.
References iv_len.
Referenced by dtn::security::PayloadConfidentialBlock::encrypt(), and dtn::security::SecurityBlock::encryptBlock().
void ibrcommon::AES128Stream::getTag | ( | unsigned char(&) | to_tag[tag_len] | ) |
Write the authentication tag into an array, with length tag_len.
to_tag | the array in which the tag will be written into |
Definition at line 63 of file AES128Stream.cpp.
References gcm_compute_tag().
Referenced by dtn::security::PayloadConfidentialBlock::encrypt(), dtn::security::SecurityBlock::encryptBlock(), and verify().
bool ibrcommon::AES128Stream::verify | ( | const unsigned char(&) | verify_tag[tag_len] | ) |
compares the given tag with the tag of the last en-/decryption
Definition at line 71 of file AES128Stream.cpp.
References getTag(), and tag_len.
Referenced by dtn::security::SecurityBlock::decryptBlock(), and dtn::security::PayloadConfidentialBlock::decryptPayload().
const size_t ibrcommon::AES128Stream::BUFF_SIZE = 2048 [static] |
the size of the buffer in which the data will be streamed
Definition at line 32 of file AES128Stream.h.
const size_t ibrcommon::AES128Stream::iv_len = 8 [static] |
the number of bytes of the initialisation vector
Definition at line 28 of file AES128Stream.h.
Referenced by AES128Stream(), dtn::security::SecurityBlock::decryptBlock(), dtn::security::PayloadConfidentialBlock::decryptPayload(), dtn::security::PayloadConfidentialBlock::encrypt(), dtn::security::SecurityBlock::encryptBlock(), and getIV().
const size_t ibrcommon::AES128Stream::key_size_in_bytes = 16 [static] |
the number of bytes of 128 bit
Definition at line 24 of file AES128Stream.h.
Referenced by dtn::security::ExtensionSecurityBlock::decrypt(), dtn::security::PayloadConfidentialBlock::decrypt(), dtn::security::ExtensionSecurityBlock::encrypt(), and dtn::security::PayloadConfidentialBlock::encrypt().
const size_t ibrcommon::AES128Stream::salt_len = sizeof(u_int32_t) [static] |
the number of bytes of the salt
Definition at line 26 of file AES128Stream.h.
const size_t ibrcommon::AES128Stream::tag_len = 16 [static] |
the number of bytes of the verification tag
Definition at line 30 of file AES128Stream.h.
Referenced by dtn::security::SecurityBlock::decryptBlock(), dtn::security::PayloadConfidentialBlock::decryptPayload(), dtn::security::PayloadConfidentialBlock::encrypt(), dtn::security::SecurityBlock::encryptBlock(), and verify().