00001
00002
00003
00004
00005
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
00015
00016
00017
00018
00019
00020
00021 class WvBlowfishEncoder :
public WvEncoder
00022 {
00023
public:
00024 enum Mode {
00025
ECBEncrypt,
00026
ECBDecrypt,
00027
CFBEncrypt,
00028
CFBDecrypt
00029 };
00030
00031
00032
00033
00034
00035
00036
00037
00038
WvBlowfishEncoder(Mode mode,
const void *key, size_t keysize);
00039
virtual ~WvBlowfishEncoder();
00040
00041
00042
00043
00044
00045
00046
00047
00048
void setkey(
const void *key, size_t keysize);
00049
00050
00051
00052
00053
00054
00055
void setiv(
const void *iv);
00056
00057
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();
00065
00066
00067 Mode mode;
00068 size_t
keysize;
00069 unsigned char *
key;
00070 struct bf_key_st *
bfkey;
00071 unsigned char ivec[8];
00072 int ivecoff;
00073
00074
void preparekey();
00075 };
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
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