Crypto++  8.8
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:
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:
88 };
89 
92 
95 
96 NAMESPACE_END
97 
98 #endif
Provides class member functions to key a block cipher.
Definition: seckey.h:318
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1288
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:306
virtual void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const =0
Encrypt or decrypt a block.
Inherited by algorithms with fixed block size.
Definition: seckey.h:41
Interface for retrieving values given their names.
Definition: cryptlib.h:327
SAFER block cipher default operation.
Definition: safer.h:20
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: safer.h:22
SAFER block cipher decryption operation.
Definition: safer.h:42
SAFER block cipher encryption operation.
Definition: safer.h:35
SAFER block cipher default implementation.
Definition: safer.h:55
SAFER-K block cipher.
Definition: safer.h:69
SAFER-SK block cipher.
Definition: safer.h:84
SAFER block cipher.
Definition: safer.h:16
SecBlock<byte> typedef.
Definition: secblock.h:1226
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:166
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:65
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:399
SAFER-K block cipher information.
Definition: safer.h:62
SAFER-SK block cipher information.
Definition: safer.h:77