00001 #ifndef CRYPTOPP_SAFER_H
00002 #define CRYPTOPP_SAFER_H
00003
00004
00005
00006
00007 #include "seckey.h"
00008 #include "secblock.h"
00009
00010 NAMESPACE_BEGIN(CryptoPP)
00011
00012
00013 class SAFER
00014 {
00015 public:
00016 class Base : public BlockCipher
00017 {
00018 public:
00019 unsigned int GetAlignment() const {return 1;}
00020 void UncheckedSetKey(CipherDir dir, const byte *userkey, unsigned int length, unsigned nof_rounds);
00021
00022 bool strengthened;
00023 SecByteBlock keySchedule;
00024 static const byte exp_tab[256];
00025 static const byte log_tab[256];
00026 };
00027
00028 class Enc : public Base
00029 {
00030 public:
00031 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00032 };
00033
00034 class Dec : public Base
00035 {
00036 public:
00037 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00038 };
00039 };
00040
00041 struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
00042 {
00043 static const char *StaticAlgorithmName() {return "SAFER-K";}
00044 static unsigned int DefaultRounds(unsigned int keylength) {return keylength == 8 ? 6 : 10;}
00045 };
00046
00047
00048 class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
00049 {
00050 class Enc : public BlockCipherBaseTemplate<SAFER_K_Info, SAFER::Enc>
00051 {
00052 public:
00053 Enc() {strengthened = false;}
00054 };
00055
00056 class Dec : public BlockCipherBaseTemplate<SAFER_K_Info, SAFER::Dec>
00057 {
00058 public:
00059 Dec() {strengthened = false;}
00060 };
00061
00062 public:
00063 typedef BlockCipherTemplate<ENCRYPTION, Enc> Encryption;
00064 typedef BlockCipherTemplate<DECRYPTION, Dec> Decryption;
00065 };
00066
00067 struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
00068 {
00069 static const char *StaticAlgorithmName() {return "SAFER-SK";}
00070 static unsigned int DefaultRounds(unsigned int keylength) {return keylength == 8 ? 8 : 10;}
00071 };
00072
00073
00074 class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
00075 {
00076 class Enc : public BlockCipherBaseTemplate<SAFER_SK_Info, SAFER::Enc>
00077 {
00078 public:
00079 Enc() {strengthened = true;}
00080 };
00081
00082 class Dec : public BlockCipherBaseTemplate<SAFER_SK_Info, SAFER::Dec>
00083 {
00084 public:
00085 Dec() {strengthened = true;}
00086 };
00087
00088 public:
00089 typedef BlockCipherTemplate<ENCRYPTION, Enc> Encryption;
00090 typedef BlockCipherTemplate<DECRYPTION, Dec> Decryption;
00091 };
00092
00093 typedef SAFER_K::Encryption SAFER_K_Encryption;
00094 typedef SAFER_K::Decryption SAFER_K_Decryption;
00095
00096 typedef SAFER_SK::Encryption SAFER_SK_Encryption;
00097 typedef SAFER_SK::Decryption SAFER_SK_Decryption;
00098
00099 NAMESPACE_END
00100
00101 #endif