7 #include "wvcountermode.h" 11 const void *_counter,
size_t _countersize) :
12 keycrypt(_keycrypt), counter(NULL)
18 WvCounterModeEncoder::~WvCounterModeEncoder()
28 counter =
new unsigned char[_countersize];
29 countersize = _countersize;
30 memcpy(counter, _counter, countersize);
36 memcpy(_counter, counter, countersize);
42 for (
size_t i = 0; i < countersize && ! ++counter[i]; ++i);
50 size_t avail = inbuf.
used();
51 size_t offset = outbuf.
used();
55 for (len = avail; len >= countersize; len -= countersize)
57 counterbuf.reset(counter, countersize);
58 success = keycrypt->
encode(counterbuf, outbuf,
true);
62 if (flush && len != 0 && success)
64 counterbuf.reset(counter, countersize);
65 success = keycrypt->
encode(counterbuf, outbuf,
true);
68 outbuf.
unalloc(countersize - len);
80 len = outbuf.optpeekable(offset);
81 unsigned char *dataout = outbuf.
mutablepeek(offset, len);
85 const unsigned char *datain = inbuf.
get(len);
98 *(dataout++) ^= *(datain++);
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
size_t optgettable() const
Returns the optimal maximum number of elements in the buffer currently available for reading without ...
T * mutablepeek(int offset, size_t count)
Returns a non-const pointer info the buffer at the specified offset to the specified number of elemen...
void unalloc(size_t count)
Unallocates exactly the specified number of elements by removing them from the buffer and releasing t...
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Template method implementation of encode().
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers...
size_t used() const
Returns the number of elements in the buffer currently available for reading.
#define deletev
Remplacement for delete[].
void getcounter(void *counter) const
Stores the current counter in the supplied buffer.
void setcounter(const void *counter, size_t countersize)
Sets the Counter mode auto-incrementing counter.
virtual void incrcounter()
Increments the counter.
bool encode(WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false)
Reads data from the input buffer, encodes it, and writes the result to the output buffer...
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
WvCounterModeEncoder(WvEncoder *_keycrypt, const void *_counter, size_t _countersize)
Create a new counter mode encoder / decoder.