00001 #ifndef CRYPTOPP_SAFER_H
00002 #define CRYPTOPP_SAFER_H
00003
00007 #include "cryptlib.h"
00008 #include "misc.h"
00009
00010 NAMESPACE_BEGIN(CryptoPP)
00011
00013 class SAFER : public FixedBlockSize<8>
00014 {
00015 public:
00016 enum {MAX_ROUNDS=13};
00017
00018 protected:
00019 SAFER(const byte *userkey_1, const byte *userkey_2, unsigned nof_rounds, bool strengthened);
00020
00021 void Encrypt(const byte *inBlock, byte *outBlock) const;
00022 void Decrypt(const byte *inBlock, byte *outBlock) const;
00023
00024 SecByteBlock keySchedule;
00025 static const byte exp_tab[256];
00026 static const byte log_tab[256];
00027 };
00028
00030 class SAFER_K64_Encryption : public SAFER, public FixedKeyLength<8>
00031 {
00032 public:
00033 enum {DEFAULT_ROUNDS=6};
00034 SAFER_K64_Encryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00035 : SAFER(userKey, userKey, rounds, false) {}
00036
00037 void ProcessBlock(byte * inoutBlock) const
00038 {SAFER::Encrypt(inoutBlock, inoutBlock);}
00039 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00040 {SAFER::Encrypt(inBlock, outBlock);}
00041 };
00042
00044 class SAFER_K64_Decryption : public SAFER, public FixedKeyLength<8>
00045 {
00046 public:
00047 enum {DEFAULT_ROUNDS=6};
00048 SAFER_K64_Decryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00049 : SAFER(userKey, userKey, rounds, false) {}
00050
00051 void ProcessBlock(byte * inoutBlock) const
00052 {SAFER::Decrypt(inoutBlock, inoutBlock);}
00053 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00054 {SAFER::Decrypt(inBlock, outBlock);}
00055 };
00056
00058 class SAFER_K128_Encryption : public SAFER, public FixedKeyLength<16>
00059 {
00060 public:
00061 enum {DEFAULT_ROUNDS=10};
00062 SAFER_K128_Encryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00063 : SAFER(userKey, userKey+8, rounds, false) {}
00064
00065 void ProcessBlock(byte * inoutBlock) const
00066 {SAFER::Encrypt(inoutBlock, inoutBlock);}
00067 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00068 {SAFER::Encrypt(inBlock, outBlock);}
00069 };
00070
00072 class SAFER_K128_Decryption : public SAFER, public FixedKeyLength<16>
00073 {
00074 public:
00075 enum {DEFAULT_ROUNDS=10};
00076 SAFER_K128_Decryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00077 : SAFER(userKey, userKey+8, rounds, false) {}
00078
00079 void ProcessBlock(byte * inoutBlock) const
00080 {SAFER::Decrypt(inoutBlock, inoutBlock);}
00081 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00082 {SAFER::Decrypt(inBlock, outBlock);}
00083 };
00084
00086 class SAFER_SK64_Encryption : public SAFER, public FixedKeyLength<8>
00087 {
00088 public:
00089 enum {DEFAULT_ROUNDS=8};
00090 SAFER_SK64_Encryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00091 : SAFER(userKey, userKey, rounds, true) {}
00092
00093 void ProcessBlock(byte * inoutBlock) const
00094 {SAFER::Encrypt(inoutBlock, inoutBlock);}
00095 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00096 {SAFER::Encrypt(inBlock, outBlock);}
00097 };
00098
00100 class SAFER_SK64_Decryption : public SAFER, public FixedKeyLength<8>
00101 {
00102 public:
00103 enum {DEFAULT_ROUNDS=8};
00104 SAFER_SK64_Decryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00105 : SAFER(userKey, userKey, rounds, true) {}
00106
00107 void ProcessBlock(byte * inoutBlock) const
00108 {SAFER::Decrypt(inoutBlock, inoutBlock);}
00109 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00110 {SAFER::Decrypt(inBlock, outBlock);}
00111 };
00112
00114 class SAFER_SK128_Encryption : public SAFER, public FixedKeyLength<16>
00115 {
00116 public:
00117 enum {DEFAULT_ROUNDS=10};
00118 SAFER_SK128_Encryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00119 : SAFER(userKey, userKey+8, rounds, true) {}
00120
00121 void ProcessBlock(byte * inoutBlock) const
00122 {SAFER::Encrypt(inoutBlock, inoutBlock);}
00123 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00124 {SAFER::Encrypt(inBlock, outBlock);}
00125 };
00126
00128 class SAFER_SK128_Decryption : public SAFER, public FixedKeyLength<16>
00129 {
00130 public:
00131 enum {DEFAULT_ROUNDS=10};
00132 SAFER_SK128_Decryption(const byte *userKey, unsigned int = 0, unsigned int rounds=DEFAULT_ROUNDS)
00133 : SAFER(userKey, userKey+8, rounds, true) {}
00134
00135 void ProcessBlock(byte * inoutBlock) const
00136 {SAFER::Decrypt(inoutBlock, inoutBlock);}
00137 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00138 {SAFER::Decrypt(inBlock, outBlock);}
00139 };
00140
00141 NAMESPACE_END
00142
00143 #endif