WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Tunnel Vision Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Blowfish cryptography abstractions. 00006 */ 00007 #ifndef __WVBLOWFISH_H 00008 #define __WVBLOWFISH_H 00009 00010 #include "wvencoder.h" 00011 #include "wvencoderstream.h" 00012 00013 struct bf_key_st; 00014 00021 class WvBlowfishEncoder : public WvEncoder 00022 { 00023 public: 00024 enum Mode { 00025 ECBEncrypt, 00026 ECBDecrypt, 00027 CFBEncrypt, 00028 CFBDecrypt 00029 }; 00030 00038 WvBlowfishEncoder(Mode mode, const void *key, size_t keysize); 00039 virtual ~WvBlowfishEncoder(); 00040 00048 void setkey(const void *key, size_t keysize); 00049 00055 void setiv(const void *iv); 00056 00058 bool is_encrypting() const { 00059 return (mode == ECBEncrypt || mode == CFBEncrypt); 00060 } 00061 00062 protected: 00063 virtual bool _encode(WvBuf &in, WvBuf &out, bool flush); 00064 virtual bool _reset(); // supported: restores most recently set 00065 // key and initialization vector 00066 00067 Mode mode; 00068 size_t keysize; 00069 unsigned char *key; 00070 struct bf_key_st *bfkey; 00071 unsigned char ivec[8]; // initialization vector 00072 int ivecoff; // current offset into initvec 00073 00074 void preparekey(); 00075 }; 00076 00077 00087 class WvBlowfishStream : public WvEncoderStream 00088 { 00089 public: 00090 WvBlowfishStream(WvStream *_cloned, 00091 const void *key, size_t _keysize, 00092 WvBlowfishEncoder::Mode readmode = WvBlowfishEncoder::CFBDecrypt, 00093 WvBlowfishEncoder::Mode writemode = WvBlowfishEncoder::CFBEncrypt); 00094 virtual ~WvBlowfishStream() { } 00095 }; 00096 00097 #endif // __WVBLOWFISH_H