Crypto++ 7.0 Free C++ class library of cryptographic schemes

safer.h
Go to the documentation of this file.
1 // safer.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file safer.h
4 /// \brief Classes for the SAFER and SAFER-K block ciphers
5
6 #ifndef CRYPTOPP_SAFER_H
7 #define CRYPTOPP_SAFER_H
8
9 #include "seckey.h"
10 #include "secblock.h"
11
12 NAMESPACE_BEGIN(CryptoPP)
13
14 /// \brief SAFER block cipher
15 class SAFER
16 {
17 public:
18 /// \brief SAFER block cipher default operation
19 class CRYPTOPP_NO_VTABLE Base : public BlockCipher
20 {
21 public:
22 unsigned int OptimalDataAlignment() const {return 1;}
23 void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs &params);
24
25 protected:
26 virtual bool Strengthened() const =0;
27
28 SecByteBlock keySchedule;
29 static const byte exp_tab[256];
30 static const byte log_tab[256];
31 };
32
33 /// \brief SAFER block cipher encryption operation
34 class CRYPTOPP_NO_VTABLE Enc : public Base
35 {
36 public:
37 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
38 };
39
40 /// \brief SAFER block cipher decryption operation
41 class CRYPTOPP_NO_VTABLE Dec : public Base
42 {
43 public:
44 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
45 };
46 };
47
48 /// \brief SAFER block cipher default implementation
49 /// \tparam BASE SAFER::Enc or SAFER::Dec derived base class
50 /// \tparam INFO SAFER_Info derived class
51 /// \tparam STR flag indicating a strengthened implementation
52 /// \details SAFER-K is not strengthened; while SAFER-SK is strengthened.
53 template <class BASE, class INFO, bool STR>
54 class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
55 {
56 protected:
57 bool Strengthened() const {return STR;}
58 };
59
60 /// \brief SAFER-K block cipher information
61 struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
62 {
63 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SAFER-K";}
64 };
65
66 /// \brief SAFER-K block cipher
67 /// \sa <a href="http://www.cryptopp.com/wiki/SAFER-K">SAFER-K</a>
68 class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
69 {
70 public:
71 typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_K_Info, false> > Encryption;
72 typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_K_Info, false> > Decryption;
73 };
74
75 /// \brief SAFER-SK block cipher information
76 struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
77 {
78 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "SAFER-SK";}
79 };
80
81 /// \brief SAFER-SK block cipher
82 /// \sa <a href="http://www.cryptopp.com/wiki/SAFER-SK">SAFER-SK</a>
83 class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
84 {
85 public:
86 typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_SK_Info, true> > Encryption;
87 typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_SK_Info, true> > Decryption;
88 };
89
90 typedef SAFER_K::Encryption SAFER_K_Encryption;
91 typedef SAFER_K::Decryption SAFER_K_Decryption;
92
93 typedef SAFER_SK::Encryption SAFER_SK_Encryption;
94 typedef SAFER_SK::Decryption SAFER_SK_Decryption;
95
96 NAMESPACE_END
97
98 #endif
SAFER::Base::OptimalDataAlignment
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: safer.h:22
SAFER_K
SAFER-K block cipher.
Definition: safer.h:68
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:398
BlockTransformation::ProcessAndXorBlock
virtual void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const =0
Encrypt or decrypt a block.
SecByteBlock
SecBlock<byte> typedef.
Definition: secblock.h:1052
BlockCipher
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1248
SAFER::Dec
SAFER block cipher decryption operation.
Definition: safer.h:41
secblock.h
Classes and functions for secure memory allocations.
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
VariableRounds
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:64
SAFER::Base
SAFER block cipher default operation.
Definition: safer.h:19
SAFER
SAFER block cipher.
Definition: safer.h:15
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherFinal
Provides class member functions to key a block cipher.
Definition: seckey.h:317
SAFER_Impl
SAFER block cipher default implementation.
Definition: safer.h:54
SAFER_K_Info
SAFER-K block cipher information.
Definition: safer.h:61
SAFER_SK
SAFER-SK block cipher.
Definition: safer.h:83
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
CryptoPP
Crypto++ library namespace.
SAFER_SK_Info
SAFER-SK block cipher information.
Definition: safer.h:76
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293
SAFER::Enc
SAFER block cipher encryption operation.
Definition: safer.h:34