libutil++  1.9.3
 All Classes Functions Variables
Crypt.h
1 /*
2 ** libutil++
3 ** $Id: Crypt.h 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__util__Crypt_H__
10 #define __libutilxx__sella__util__Crypt_H__
11 
12 #include "../../common.h"
13 
14 #ifndef SKIP_CRYPT
15 
16 #include <mcrypt.h>
17 #include <string>
18 
19 #define CRYPT_ALGO_DEF "twofish"
20 #define CRYPT_MODE_DEF "cfb" /* Use a block mode */
21 #define CRYPT_KEYLEN_DEF 256
22 #define CRYPT_PASSWORD_DEF "q2enL5bsEmiP2laul8Lsii2uri7nMet3r4Ier7eSto3iDed7itr3llYSts9ni03nOnSlM"
23 #define CRYPT_SALT_DEF "Vine5l7xIc"
24 #define CRYPT_SERIAL_XOR 0xA5B65A69
25 
26 namespace sella {
27  namespace util {
28  class Crypt;
29  }
30 }
31 
33  public:
34  Crypt(const char *algo = CRYPT_ALGO_DEF, const char *mode = CRYPT_MODE_DEF, int bits = CRYPT_KEYLEN_DEF, uint32_t seed = 0);
35  Crypt(const Crypt &other);
36  virtual ~Crypt();
37  Crypt& operator=(const Crypt &other) throw ();
38 
39  void clear(void);
40 
41  void setSeed(uint32_t seed);
42  void setFlipSeed(uint32_t seed, uint32_t pattern = CRYPT_SERIAL_XOR);
43  uint32_t getSeed(void) const;
44 
45  bool setPassword(const char *password = CRYPT_PASSWORD_DEF, const char *salt = CRYPT_SALT_DEF);
46  const char* getPassword(void);
47  const unsigned char* getKey(void);
48 
49  void setKeyLen(int bits);
50  int getKeyLen(void) const;
51 
52  bool encrypt(char *plainetext, int len);
53  bool decrypt(char *ciphertext, int len);
54  bool check(const char *ciphertext, int len);
55 
56  protected:
57  private:
58  bool initialize(void);
59  bool deinitialize(void);
60  bool generateIV(void);
61 
62  bool init;
63  MCRYPT td;
64  uint32_t seed;
65  char *password;
66  char *salt;
67  unsigned char *key;
68  unsigned char *iv;
69  int keylen;
70 
71  std::string algo;
72  std::string mode;
73 };
74 
75 #endif
76 #endif
77 
78 /*
79 ** vim: noet ts=3 sw=3
80 */