Crypto++  5.6.3
Free C++ class library of cryptographic schemes
safer.h
Go to the documentation of this file.
1 // safer.h - written and placed in the public domain by Wei Dai
2 
3 //! \file safer.h
4 //! \brief Classes for the SAFER block cipher
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 //! \class SAFER
15 //! \brief SAFER base class
16 class SAFER
17 {
18 public:
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  class CRYPTOPP_NO_VTABLE Enc : public Base
34  {
35  public:
36  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
37  };
38 
39  class CRYPTOPP_NO_VTABLE Dec : public Base
40  {
41  public:
42  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
43  };
44 };
45 
46 template <class BASE, class INFO, bool STR>
47 class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
48 {
49 protected:
50  bool Strengthened() const {return STR;}
51 };
52 
53 //! \class SAFER_K_Info
54 //! \brief SAFER-K block cipher information
55 struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
56 {
57  static const char *StaticAlgorithmName() {return "SAFER-K";}
58 };
59 
60 //! \class SAFER_K
61 //! \brief SAFER-K block cipher
62 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-K">SAFER-K</a>
63 class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
64 {
65 public:
68 };
69 
70 //! \class SAFER_SK_Info
71 //! \brief SAFER-SK block cipher information
72 struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
73 {
74  static const char *StaticAlgorithmName() {return "SAFER-SK";}
75 };
76 
77 //! \class SAFER_SK
78 //! \brief SAFER-SK block cipher
79 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-SK">SAFER-SK</a>
80 class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
81 {
82 public:
85 };
86 
89 
92 
93 NAMESPACE_END
94 
95 #endif
SAFER-K block cipher.
Definition: safer.h:63
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:396
SecBlock typedef.
Definition: secblock.h:730
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1091
Classes and functions for secure memory allocations.
Inherited by algorithms with fixed block size.
Definition: seckey.h:34
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:60
SAFER base class.
Definition: safer.h:16
Classes and functions for implementing secret key algorithms.
Provides class member functions to key a block cipher.
Definition: seckey.h:316
SAFER-K block cipher information.
Definition: safer.h:55
SAFER-SK block cipher.
Definition: safer.h:80
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:157
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: safer.h:22
virtual void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const =0
Encrypt or decrypt a block.
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:303
Crypto++ library namespace.
SAFER-SK block cipher information.
Definition: safer.h:72
Interface for retrieving values given their names.
Definition: cryptlib.h:277