IBR-DTNSuite  0.10
ibrcommon::AES128Stream Class Reference

#include <AES128Stream.h>

Inheritance diagram for ibrcommon::AES128Stream:
Inheritance graph
Collaboration diagram for ibrcommon::AES128Stream:
Collaboration graph

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
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
modetell the constructor wether this will be used for en- or decryption
outputthe stream in which will the cipher- or plaintext be serialized into
keythe AES128 key to use. Its size is key_size_in_bytes.
saltthe salt, which shall be the same for all data which belongs together
ivif used for decryption, this is the initialisation vector, which was created at encryption. The size of this array is iv_len.
tagif 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.

Here is the call graph for this function:

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.

Here is the call graph for this function:

ibrcommon::AES128Stream::~AES128Stream ( )
virtual

cleans the output buffer and the context

Definition at line 72 of file AES128Stream.cpp.

References gcm_end().

Here is the call graph for this function:

Member Function Documentation

void ibrcommon::AES128Stream::decrypt ( char *  buf,
const size_t  size 
)
protectedvirtual

Implements ibrcommon::CipherStream.

Definition at line 110 of file AES128Stream.cpp.

References gcm_decrypt().

Here is the call graph for this function:

void ibrcommon::AES128Stream::encrypt ( char *  buf,
const size_t  size 
)
protectedvirtual

Implements ibrcommon::CipherStream.

Definition at line 105 of file AES128Stream.cpp.

References gcm_encrypt().

Here is the call graph for this function:

void ibrcommon::AES128Stream::getIV ( unsigned char(&)  to_iv[iv_len]) const

Write the initialisation vector into an array, with length iv_len.

Parameters
to_ivthe 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.

Parameters
to_tagthe 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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

Member Data Documentation

const size_t ibrcommon::AES128Stream::BUFF_SIZE = 2048
static

the size of the buffer in which the data will be streamed

Definition at line 54 of file AES128Stream.h.

const size_t ibrcommon::AES128Stream::iv_len = 8
static
const size_t ibrcommon::AES128Stream::key_size_in_bytes = 16
static
const size_t ibrcommon::AES128Stream::salt_len = sizeof(uint32_t)
static

the number of bytes of the salt

Definition at line 48 of file AES128Stream.h.

const size_t ibrcommon::AES128Stream::tag_len = 16
static

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