7 #if !defined(_AESKey_h_) 15 typedef uint8_t aes128_key_t[16];
27 void _readFromStream(std::istream &stream,
unsigned bytes, uint8_t *buffer)
const;
30 void _writeToStream(std::ostream &stream,
unsigned bytes,
const uint8_t *buffer)
const;
54 typedef uint8_t key_t[S / 8];
60 AESKey() { memset(m_key, 0,
sizeof(m_key)); }
62 AESKey(
const key_t &key) { memcpy(m_key, &key,
sizeof(m_key)); }
64 AESKey(
const key_t *key) { memcpy(m_key, key,
sizeof(m_key)); }
66 AESKey(std::istream &stream) { readFromStream(stream); }
72 ~AESKey() { memset(m_key, 0,
sizeof(m_key)); }
77 rng.generateBlock(m_key,
sizeof(m_key));
85 _writeToStream(stream, S / 8, reinterpret_cast<const uint8_t *>(&m_key));
90 inline const key_t &getKey()
const {
return m_key; }
91 inline void getKey(key_t *key)
const { memcpy(key, m_key,
sizeof(m_key)); }
92 inline void setKey(
const key_t &key) { memcpy(m_key, &key,
sizeof(m_key)); }
93 inline void setKey(
const key_t *key) { memcpy(m_key, key,
sizeof(m_key)); }
94 inline void setKey(
const AESKey<S> &key) { memcpy(m_key, key.
m_key,
sizeof(m_key)); }
104 const AESKey<S> &operator=(
const key_t &key)
109 const AESKey<S> &operator=(
const key_t *key)
115 operator const key_t &()
const {
return m_key; }
116 operator const key_t *()
const {
return m_key; }
117 friend std::ostream &operator<<(std::ostream &os, const AESKey<S> &key)
119 key.writeToStream(os);
AESKey(const AESKey< S > &other)
Copy constructor.
Definition: src/blfwk/AESKey.h:68
Definition: apps/elftosb/common/Random.h:37
AESKey(const key_t &key)
Constructor taking a key value reference.
Definition: src/blfwk/AESKey.h:62
void readFromStream(std::istream &stream)
Reads the key from a hex encoded data stream.
Definition: src/blfwk/AESKey.h:81
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: src/blfwk/AESKey.h:72
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: src/blfwk/AESKey.h:66
void randomize()
Set to the key to a randomly generated value.
Definition: src/blfwk/AESKey.h:74
Generic AES key class.
Definition: apps/elftosb/common/AESKey.h:51
AESKey()
Default constructor.
Definition: src/blfwk/AESKey.h:60
Base class for AESKey<S>.
Definition: apps/elftosb/common/AESKey.h:24
void writeToStream(std::ostream &stream) const
Writes the key to a data stream in hex encoded format.
Definition: src/blfwk/AESKey.h:83