IBR-DTNSuite
0.12
|
#include <AES128Stream.h>
Public Member Functions | |
AES128Stream (const CipherMode mode, std::ostream &output, const unsigned char key[key_size_in_bytes], const uint32_t salt) | |
AES128Stream (const CipherMode mode, std::ostream &output, const unsigned char key[key_size_in_bytes], const uint32_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]) |
Public Member Functions inherited from ibrcommon::CipherStream | |
CipherStream (std::ostream &stream, const CipherMode mode=CIPHER_DECRYPT, const size_t buffer=2048) | |
virtual | ~CipherStream () |
void | encrypt (std::iostream &stream) |
void | decrypt (std::iostream &stream) |
Static Public Attributes | |
static const size_t | key_size_in_bytes = 16 |
static const size_t | salt_len = sizeof(uint32_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) |
Protected Member Functions inherited from ibrcommon::CipherStream | |
virtual void | encrypt_final () |
virtual void | decrypt_final () |
virtual int | sync () |
virtual std::char_traits< char > ::int_type | overflow (std::char_traits< char >::int_type=std::char_traits< char >::eof()) |
Additional Inherited Members | |
Public Types inherited from ibrcommon::CipherStream | |
enum | CipherMode { CIPHER_ENCRYPT = 0, CIPHER_DECRYPT = 1 } |
Protected Attributes inherited from ibrcommon::CipherStream | |
CipherMode | _mode |
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 42 of file AES128Stream.h.
ibrcommon::AES128Stream::AES128Stream | ( | const CipherMode | mode, |
std::ostream & | output, | ||
const unsigned char | key[key_size_in_bytes], | ||
const uint32_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 29 of file AES128Stream.cpp.
References ibrcommon::LogLevel::critical, gcm_init_and_key(), gcm_init_message(), IBRCOMMON_LOGGER_ENDL, IBRCOMMON_LOGGER_TAG, and iv_len.
ibrcommon::AES128Stream::AES128Stream | ( | const CipherMode | mode, |
std::ostream & | output, | ||
const unsigned char | key[key_size_in_bytes], | ||
const uint32_t | salt, | ||
const unsigned char | iv[iv_len] | ||
) |
Definition at line 51 of file AES128Stream.cpp.
References ibrcommon::LogLevel::critical, gcm_init_and_key(), gcm_init_message(), IBRCOMMON_LOGGER_ENDL, IBRCOMMON_LOGGER_TAG, and iv_len.
|
virtual |
cleans the output buffer and the context
Definition at line 72 of file AES128Stream.cpp.
References gcm_end().
|
protectedvirtual |
Implements ibrcommon::CipherStream.
Definition at line 110 of file AES128Stream.cpp.
References gcm_decrypt().
|
protectedvirtual |
Implements ibrcommon::CipherStream.
Definition at line 105 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 78 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 84 of file AES128Stream.cpp.
References gcm_compute_tag(), and RETURN_OK.
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 92 of file AES128Stream.cpp.
References getTag(), and tag_len.
Referenced by dtn::security::SecurityBlock::decryptBlock(), and dtn::security::PayloadConfidentialBlock::decryptPayload().
|
static |
the size of the buffer in which the data will be streamed
Definition at line 54 of file AES128Stream.h.
|
static |
the number of bytes of the initialisation vector
Definition at line 50 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().
|
static |
the number of bytes of 128 bit
Definition at line 46 of file AES128Stream.h.
Referenced by dtn::security::ExtensionSecurityBlock::decrypt(), dtn::security::PayloadConfidentialBlock::decrypt(), dtn::security::ExtensionSecurityBlock::encrypt(), and dtn::security::PayloadConfidentialBlock::encrypt().
|
static |
the number of bytes of the salt
Definition at line 48 of file AES128Stream.h.
|
static |
the number of bytes of the verification tag
Definition at line 52 of file AES128Stream.h.
Referenced by dtn::security::SecurityBlock::decryptBlock(), dtn::security::PayloadConfidentialBlock::decryptPayload(), dtn::security::PayloadConfidentialBlock::encrypt(), dtn::security::SecurityBlock::encryptBlock(), and verify().