2 * Worldvisions Tunnel Vision Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A 'counter mode' cryptography engine abstraction.
7 #ifndef __WVCOUNTERMODE_H
8 #define __WVCOUNTERMODE_H
10 #include "wvencoder.h"
12 /** A counter mode encryption encoder. */
13 class WvCounterModeEncoder
: public WvEncoder
19 * Create a new counter mode encoder / decoder.
20 * _keycrypt : the underlying encoder for generating the keystream
21 * (note: takes ownership of this encoder)
22 * _counter : the initial counter value
23 * _countersize : the counter size, must equal crypto block size
25 WvCounterModeEncoder(WvEncoder
*_keycrypt
,
26 const void *_counter
, size_t _countersize
);
27 virtual ~WvCounterModeEncoder();
30 * Sets the Counter mode auto-incrementing counter.
31 * counter : the counter
32 * countersize : the new counter size, must equal crypto block size
34 void setcounter(const void *counter
, size_t countersize
);
37 * Stores the current counter in the supplied buffer.
38 * counter : the array that receives the counter
40 void getcounter(void *counter
) const;
42 /** Returns the counter size. */
43 size_t getcountersize() const
44 { return countersize
; }
46 /** Increments the counter. */
47 virtual void incrcounter();
50 WvConstInPlaceBuf counterbuf
;
53 unsigned char *counter
; // auto-incrementing counter
54 size_t countersize
; // counter size in bytes
56 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
, bool flush
);
59 #endif // __WVCOUNTERMODE_H