7 #if !defined(_AESCounter_h_) 15 typedef uint8_t aes128_counter_t[16];
27 void _readFromStream(std::istream &stream,
unsigned bytes, uint8_t *buffer);
30 void _writeToStream(std::ostream &stream,
unsigned bytes,
const uint8_t *buffer)
const;
54 typedef uint8_t counter_t[S / 8];
60 AESCounter() { memset(m_counter, 0,
sizeof(m_counter)); }
62 AESCounter(
const counter_t &counter) { memcpy(m_counter, &counter,
sizeof(m_counter)); }
64 AESCounter(
const counter_t *counter) { memcpy(m_counter, counter,
sizeof(m_counter)); }
66 AESCounter(std::istream &stream) { readFromStream(stream); }
77 rng.generateBlock(m_counter,
sizeof(m_counter));
83 _readFromStream(stream, S / 8, reinterpret_cast<uint8_t *>(&m_counter));
89 _writeToStream(stream, S / 8, reinterpret_cast<const uint8_t *>(&m_counter));
95 for (
unsigned j = 0; j < val; j++)
99 carry = !++m_counter[i];
106 inline const counter_t &getCounter()
const {
return m_counter; }
107 inline void getCounter(counter_t *counter)
const { memcpy(counter, m_counter,
sizeof(m_counter)); }
108 inline void setCounter(
const counter_t &counter) { memcpy(m_counter, &counter,
sizeof(m_counter)); }
109 inline void setCounter(
const counter_t *counter) { memcpy(m_counter, counter,
sizeof(m_counter)); }
110 inline void setCounter(
const AESCounter<S> &counter) { memcpy(m_counter, counter.
m_counter,
sizeof(m_counter)); }
131 operator const counter_t &()
const {
return m_counter; }
132 operator const counter_t *()
const {
return m_counter; }
133 friend std::ostream &operator<<(std::ostream &os, const AESCounter<S> &counter)
135 counter.writeToStream(os);
147 #endif // _AESCounter_h_ Definition: apps/elftosb/common/Random.h:37
void writeToStream(std::ostream &stream) const
Writes the counter to a data stream in hex encoded format.
Definition: apps/elftosb/common/AESCounter.h:87
AESCounter()
Default constructor.
Definition: apps/elftosb/common/AESCounter.h:60
Base class for AESCounter<S>.
Definition: apps/elftosb/common/AESCounter.h:23
Generic AES Counter class.
Definition: apps/elftosb/common/AESCounter.h:50
void incrementCounter(unsigned val)
Increments the counter by val.
Definition: apps/elftosb/common/AESCounter.h:93
AESCounter(const AESCounter< S > &other)
Copy constructor.
Definition: apps/elftosb/common/AESCounter.h:68
void _writeToStream(std::ostream &stream, unsigned bytes, const uint8_t *buffer) const
Writes hex encoded data to stream.
Definition: AESCounter.cpp:62
void _readFromStream(std::istream &stream, unsigned bytes, uint8_t *buffer)
Reads hex encoded data from stream.
Definition: AESCounter.cpp:30
AESCounter(const counter_t &counter)
Constructor taking a counter value reference.
Definition: apps/elftosb/common/AESCounter.h:62
void readFromStream(std::istream &stream)
Reads the counter from a hex encoded data stream.
Definition: apps/elftosb/common/AESCounter.h:81
void randomize()
Set to the counter to a randomly generated value.
Definition: apps/elftosb/common/AESCounter.h:74
AESCounter(std::istream &stream)
Constructor, reads counter from stream in hex format.
Definition: apps/elftosb/common/AESCounter.h:66
~AESCounter()
Destructor.
Definition: apps/elftosb/common/AESCounter.h:72
counter_t m_counter
The counter value.
Definition: apps/elftosb/common/AESCounter.h:141