00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__Crypt_H__
00010 #define __libutilxx__sella__util__Crypt_H__
00011
00012 #include "../../common.h"
00013
00014 #ifndef SKIP_CRYPT
00015
00016 #include <mcrypt.h>
00017 #include <string>
00018
00019 #define CRYPT_ALGO_DEF "twofish"
00020 #define CRYPT_MODE_DEF "cfb"
00021 #define CRYPT_KEYLEN_DEF 192
00022 #define CRYPT_PASSWORD_DEF "q2enL5bsEmiP2laul8Lsii2uri7nMet3r4Ier7eSto3iDed7itr3llYSts9ni03nOnSlM"
00023 #define CRYPT_SALT_DEF "Vine5l7xIc"
00024 #define CRYPT_SERIAL_XOR 0xA5B65A69
00025
00026 namespace sella {
00027 namespace util {
00028 class Crypt;
00029 }
00030 }
00031
00032 class sella::util::Crypt {
00033 public:
00034 Crypt(const char *algo = CRYPT_ALGO_DEF, const char *mode = CRYPT_MODE_DEF, int bits = CRYPT_KEYLEN_DEF);
00035 Crypt(const Crypt &other);
00036 virtual ~Crypt();
00037 Crypt& operator=(const Crypt &other) throw ();
00038
00039 void clear(void);
00040
00041 void setSeed(uint32_t seed);
00042 void setFlipSeed(uint32_t seed, uint32_t pattern = CRYPT_SERIAL_XOR);
00043 uint32_t getSeed(void) const;
00044
00045 bool setPassword(const char *password = CRYPT_PASSWORD_DEF, const char *salt = CRYPT_SALT_DEF);
00046 const char* getPassword(void);
00047 const unsigned char* getKey(void);
00048
00049 void setKeyLen(int bits);
00050 int getKeyLen(void) const;
00051
00052 bool encrypt(char *plainetext, int len);
00053 bool decrypt(char *ciphertext, int len);
00054 bool check(const char *ciphertext, int len);
00055
00056 protected:
00057 private:
00058 bool initialize(void);
00059 bool deinitialize(void);
00060 bool generateIV(void);
00061
00062 bool init;
00063 MCRYPT td;
00064 uint32_t seed;
00065 char *password;
00066 char *salt;
00067 unsigned char *key;
00068 unsigned char *iv;
00069 int keylen;
00070
00071 std::string algo;
00072 std::string mode;
00073 };
00074
00075 #endif
00076 #endif
00077
00078
00079
00080