File indexing completed on 2025-01-18 09:55:08
0001
0002
0003
0004
0005
0006 #ifndef CRYPTOPP_SAFER_H
0007 #define CRYPTOPP_SAFER_H
0008
0009 #include "seckey.h"
0010 #include "secblock.h"
0011
0012 NAMESPACE_BEGIN(CryptoPP)
0013
0014
0015 class SAFER
0016 {
0017 public:
0018
0019 class CRYPTOPP_NO_VTABLE Base : public BlockCipher
0020 {
0021 public:
0022 unsigned int OptimalDataAlignment() const {return 1;}
0023 void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs ¶ms);
0024
0025 protected:
0026 virtual bool Strengthened() const =0;
0027
0028 SecByteBlock keySchedule;
0029 static const byte exp_tab[256];
0030 static const byte log_tab[256];
0031 };
0032
0033
0034 class CRYPTOPP_NO_VTABLE Enc : public Base
0035 {
0036 public:
0037 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0038 };
0039
0040
0041 class CRYPTOPP_NO_VTABLE Dec : public Base
0042 {
0043 public:
0044 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0045 };
0046 };
0047
0048
0049
0050
0051
0052
0053 template <class BASE, class INFO, bool STR>
0054 class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
0055 {
0056 protected:
0057 bool Strengthened() const {return STR;}
0058 };
0059
0060
0061 struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
0062 {
0063 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SAFER-K";}
0064 };
0065
0066
0067
0068 class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
0069 {
0070 public:
0071 typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_K_Info, false> > Encryption;
0072 typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_K_Info, false> > Decryption;
0073 };
0074
0075
0076 struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
0077 {
0078 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SAFER-SK";}
0079 };
0080
0081
0082
0083 class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
0084 {
0085 public:
0086 typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_SK_Info, true> > Encryption;
0087 typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_SK_Info, true> > Decryption;
0088 };
0089
0090 typedef SAFER_K::Encryption SAFER_K_Encryption;
0091 typedef SAFER_K::Decryption SAFER_K_Decryption;
0092
0093 typedef SAFER_SK::Encryption SAFER_SK_Encryption;
0094 typedef SAFER_SK::Decryption SAFER_SK_Decryption;
0095
0096 NAMESPACE_END
0097
0098 #endif