7 #if !defined(_AESKey_h_) 16 typedef uint8_t aes128_key_t[16];
28 void _readFromStream(std::istream &stream,
unsigned bytes, uint8_t *buffer);
31 void _writeToStream(std::ostream &stream,
unsigned bytes,
const uint8_t *buffer);
55 typedef uint8_t key_t[S / 8];
61 AESKey() { memset(m_key, 0,
sizeof(m_key)); }
63 AESKey(
const key_t &key) { memcpy(m_key, &key,
sizeof(m_key)); }
65 AESKey(
const key_t *key) { memcpy(m_key, key,
sizeof(m_key)); }
67 AESKey(std::istream &stream) { readFromStream(stream); }
73 ~AESKey() { memset(m_key, 0,
sizeof(m_key)); }
78 rng.generateBlock(m_key,
sizeof(m_key));
87 inline const key_t &getKey()
const {
return m_key; }
88 inline void getKey(key_t *key)
const { memcpy(key, m_key,
sizeof(m_key)); }
89 inline void setKey(
const key_t &key) { memcpy(m_key, &key,
sizeof(m_key)); }
90 inline void setKey(
const key_t *key) { memcpy(m_key, key,
sizeof(m_key)); }
91 inline void setKey(
const AESKey<S> &key) { memcpy(m_key, key.
m_key,
sizeof(m_key)); }
101 const AESKey<S> &operator=(
const key_t &key)
106 const AESKey<S> &operator=(
const key_t *key)
112 operator const key_t &()
const {
return m_key; }
113 operator const key_t *()
const {
return m_key; }
AESKey(const AESKey< S > &other)
Copy constructor.
Definition: apps/elftosb/common/AESKey.h:69
Definition: apps/elftosb/common/Random.h:37
AESKey(const key_t &key)
Constructor taking a key value reference.
Definition: apps/elftosb/common/AESKey.h:63
void readFromStream(std::istream &stream)
Reads the key from a hex encoded data stream.
Definition: apps/elftosb/common/AESKey.h:82
void _writeToStream(std::ostream &stream, unsigned bytes, const uint8_t *buffer)
Writes hex encoded data to stream.
Definition: apps/elftosb/common/AESKey.cpp:62
~AESKey()
Destructor.
Definition: apps/elftosb/common/AESKey.h:73
void _readFromStream(std::istream &stream, unsigned bytes, uint8_t *buffer)
Reads hex encoded data from stream.
Definition: apps/elftosb/common/AESKey.cpp:30
key_t m_key
The key value.
Definition: apps/elftosb/common/AESKey.h:117
AESKey(std::istream &stream)
Constructor, reads key from stream in hex format.
Definition: apps/elftosb/common/AESKey.h:67
void randomize()
Set to the key to a randomly generated value.
Definition: apps/elftosb/common/AESKey.h:75
Generic AES key class.
Definition: apps/elftosb/common/AESKey.h:51
AESKey()
Default constructor.
Definition: apps/elftosb/common/AESKey.h:61
Base class for AESKey<S>.
Definition: apps/elftosb/common/AESKey.h:24
void writeToStream(std::ostream &stream)
Writes the key to a data stream in hex encoded format.
Definition: apps/elftosb/common/AESKey.h:84