WvStreams
wvtripledes.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Tunnel Vision Software:
3  * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
4  *
5  * TripleDES cryptography abstractions.
6  */
7 #ifndef __WVTRIPLEDES_H
8 #define __WVTRIPLEDES_H
9 
10 #include "wvencoder.h"
11 #include "wvencoderstream.h"
12 #include "wvcrypto.h"
13 
14 #include <openssl/des.h>
15 
23 {
24 public:
25  enum Mode {
32  };
33 
34  /*
35  * Creates a new TripleDES cipher encoder.
36  *
37  * "mode" is the encryption mode
38  * "key[1-3]" are the initial keys
39  */
40  WvTripleDESEncoder(Mode mode, const void *key1, const void *key2,
41  const void *key3);
42 /* virtual ~WvTripleDESEncoder(); */
43 
44  /*
45  * Sets the current TripleDES keys and resets the initialization
46  * vector to all nulls.
47  *
48  * "key[1-3]" are the new keys
49  */
50  virtual void setkey(const void *key)
51  {
52  setkey(key, (unsigned char*)key+DES_KEY_SZ,
53  (unsigned char *)key+(DES_KEY_SZ*2));
54  return;
55  }
56  virtual void setkey(const void *_key1, const void *_key2,
57  const void *_key3);
58 
59  /*
60  * Sets the current TripleDES initialization vector.
61  *
62  * "iv" is the new IV must be 8 bytes
63  */
64  virtual void setiv(const void *iv);
65 
66 protected:
67  virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
68  virtual bool _reset(); // supported: restores most recently set
69  // key and initialization vector
70 
71 private:
72  Mode mode;
73  DES_cblock key;
74  DES_key_schedule deskey1;
75  DES_key_schedule deskey2;
76  DES_key_schedule deskey3;
77  DES_cblock ivec; // initialization vector
78  int ivecoff; // current offset into initvec
79 };
80 
81 
92 {
93 public:
94  WvTripleDESStream(WvStream *_cloned, const void *_key1,
95  const void *_key2, const void *_key3,
98  virtual ~WvTripleDESStream() { }
99 };
100 
101 #endif // __WVTRIPLEDES_H
WvEncoderStream
WvEncoderStream chains a series of encoders on the input and output ports of the underlying stream to...
Definition: wvencoderstream.h:37
WvTripleDESEncoder::CFBEncrypt
@ CFBEncrypt
Definition: wvtripledes.h:28
WvTripleDESEncoder::_encode
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
Definition: wvtripledes.cc:61
WvTripleDESEncoder::_reset
virtual bool _reset()
Template method implementation of reset().
Definition: wvtripledes.cc:30
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
WvTripleDESStream
A crypto stream implementing TripleDES encryption.
Definition: wvtripledes.h:91
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvTripleDESEncoder
An encoder implementing the TripleDES encryption method.
Definition: wvtripledes.h:22
WvCryptoEncoder
Definition: wvcrypto.h:21
WvEncoder::flush
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
Definition: wvencoder.h:163
WvTripleDESEncoder::ECBEncrypt
@ ECBEncrypt
Definition: wvtripledes.h:26
WvTripleDESEncoder::CFBDecrypt
@ CFBDecrypt
Definition: wvtripledes.h:29
WvTripleDESEncoder::CBCEncrypt
@ CBCEncrypt
Definition: wvtripledes.h:30
WvTripleDESEncoder::Mode
Mode
Definition: wvtripledes.h:25
WvTripleDESEncoder::ECBDecrypt
@ ECBDecrypt
Definition: wvtripledes.h:27
WvTripleDESEncoder::CBCDecrypt
@ CBCDecrypt
Definition: wvtripledes.h:31