Crypto++  5.6.4
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 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 //! \class SAFER
15 //! \brief SAFER block cipher
16 class SAFER
17 {
18 public:
19  //! \class Base
20  //! \brief SAFER block cipher default operation
21  class CRYPTOPP_NO_VTABLE Base : public BlockCipher
22  {
23  public:
24  unsigned int OptimalDataAlignment() const {return 1;}
25  void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs &params);
26 
27  protected:
28  virtual bool Strengthened() const =0;
29 
30  SecByteBlock keySchedule;
31  static const byte exp_tab[256];
32  static const byte log_tab[256];
33  };
34 
35  //! \class Enc
36  //! \brief SAFER block cipher encryption operation
37  class CRYPTOPP_NO_VTABLE Enc : public Base
38  {
39  public:
40  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
41  };
42 
43  //! \class Dec
44  //! \brief SAFER block cipher decryption operation
45  class CRYPTOPP_NO_VTABLE Dec : public Base
46  {
47  public:
48  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
49  };
50 };
51 
52 //! \class SAFER_Impl
53 //! \brief SAFER block cipher default implementation
54 //! \tparam BASE SAFER::Enc or SAFER::Dec derived base class
55 //! \tparam INFO SAFER_Info derived class
56 //! \tparam STR flag indicating a strengthened implementation
57 //! \details SAFER-K is not strengthened; while SAFER-SK is strengthened.
58 template <class BASE, class INFO, bool STR>
59 class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
60 {
61 protected:
62  bool Strengthened() const {return STR;}
63 };
64 
65 //! \class SAFER_K_Info
66 //! \brief SAFER-K block cipher information
67 struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
68 {
69  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SAFER-K";}
70 };
71 
72 //! \class SAFER_K
73 //! \brief SAFER-K block cipher
74 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-K">SAFER-K</a>
75 class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
76 {
77 public:
80 };
81 
82 //! \class SAFER_SK_Info
83 //! \brief SAFER-SK block cipher information
84 struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
85 {
86  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SAFER-SK";}
87 };
88 
89 //! \class SAFER_SK
90 //! \brief SAFER-SK block cipher
91 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-SK">SAFER-SK</a>
92 class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
93 {
94 public:
97 };
98 
101 
104 
105 NAMESPACE_END
106 
107 #endif
SAFER-K block cipher.
Definition: safer.h:75
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:423
SecBlock typedef.
Definition: secblock.h:731
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1098
SAFER block cipher decryption operation.
Definition: safer.h:45
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 block cipher default operation.
Definition: safer.h:21
SAFER block cipher.
Definition: safer.h:16
Classes and functions for implementing secret key algorithms.
Provides class member functions to key a block cipher.
Definition: seckey.h:339
SAFER block cipher default implementation.
Definition: safer.h:59
SAFER-K block cipher information.
Definition: safer.h:67
SAFER-SK block cipher.
Definition: safer.h:92
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:177
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: safer.h:24
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:326
Crypto++ library namespace.
SAFER-SK block cipher information.
Definition: safer.h:84
Interface for retrieving values given their names.
Definition: cryptlib.h:282
SAFER block cipher encryption operation.
Definition: safer.h:37