WvStreams
wvblowfish.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Tunnel Vision Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Blowfish cryptography abstractions.
6  */
7 #ifndef __WVBLOWFISH_H
8 #define __WVBLOWFISH_H
9 
10 #include "wvencoder.h"
11 #include "wvencoderstream.h"
12 
13 struct bf_key_st;
14 
22 {
23 public:
24  enum Mode {
29  };
30 
38  WvBlowfishEncoder(Mode mode, const void *key, size_t keysize);
39  virtual ~WvBlowfishEncoder();
40 
48  void setkey(const void *key, size_t keysize);
49 
55  void setiv(const void *iv);
56 
58  bool is_encrypting() const {
59  return (mode == ECBEncrypt || mode == CFBEncrypt);
60  }
61 
62 protected:
63  virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
64  virtual bool _reset(); // supported: restores most recently set
65  // key and initialization vector
66 
67  Mode mode;
68  size_t keysize;
69  unsigned char *key;
70  struct bf_key_st *bfkey;
71  unsigned char ivec[8]; // initialization vector
72  int ivecoff; // current offset into initvec
73 
74  void preparekey();
75 };
76 
77 
88 {
89 public:
90  WvBlowfishStream(WvStream *_cloned,
91  const void *key, size_t _keysize,
94  virtual ~WvBlowfishStream() { }
95 };
96 
97 #endif // __WVBLOWFISH_H
WvBlowfishEncoder::Mode
Mode
Definition: wvblowfish.h:24
WvEncoderStream
WvEncoderStream chains a series of encoders on the input and output ports of the underlying stream to...
Definition: wvencoderstream.h:37
WvBlowfishEncoder::_encode
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
Definition: wvblowfish.cc:63
WvEncoder
The base encoder class.
Definition: wvencoder.h:67
WvBlowfishEncoder::ECBDecrypt
@ ECBDecrypt
Definition: wvblowfish.h:26
WvBlowfishEncoder::setkey
void setkey(const void *key, size_t keysize)
Sets the current Blowfish key and resets the initialization vector to all nulls.
Definition: wvblowfish.cc:36
WvBlowfishEncoder
An encoder implementing the Blowfish encryption method.
Definition: wvblowfish.h:21
WvBlowfishEncoder::is_encrypting
bool is_encrypting() const
Return true if mode is encrypting or false if decrypting.
Definition: wvblowfish.h:58
WvBlowfishEncoder::_reset
virtual bool _reset()
Template method implementation of reset().
Definition: wvblowfish.cc:29
WvBlowfishEncoder::setiv
void setiv(const void *iv)
Sets the current Blowfish initialization vector.
Definition: wvblowfish.cc:46
WvBlowfishEncoder::WvBlowfishEncoder
WvBlowfishEncoder(Mode mode, const void *key, size_t keysize)
Creates a new Blowfish cipher encoder.
Definition: wvblowfish.cc:14
WvBlowfishEncoder::ECBEncrypt
@ ECBEncrypt
Definition: wvblowfish.h:25
WvBlowfishEncoder::CFBEncrypt
@ CFBEncrypt
Definition: wvblowfish.h:27
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvEncoder::flush
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
Definition: wvencoder.h:163
WvBlowfishEncoder::CFBDecrypt
@ CFBDecrypt
Definition: wvblowfish.h:28
WvBlowfishStream
A crypto stream implementing Blowfish encryption.
Definition: wvblowfish.h:87