Crypto++  8.6
Free C++ class library of cryptographic schemes
cham.h
Go to the documentation of this file.
1 // cham.h - written and placed in the public domain by Kim Sung Hee and Jeffrey Walton
2 // Based on "CHAM: A Family of Lightweight Block Ciphers for
3 // Resource-Constrained Devices" by Bonwook Koo, Dongyoung Roh,
4 // Hyeonjin Kim, Younghoon Jung, Dong-Geon Lee, and Daesung Kwon
5 
6 /// \file cham.h
7 /// \brief Classes for the CHAM block cipher
8 /// \since Crypto++ 8.0
9 
10 #ifndef CRYPTOPP_CHAM_H
11 #define CRYPTOPP_CHAM_H
12 
13 #include "config.h"
14 #include "seckey.h"
15 #include "secblock.h"
16 #include "algparam.h"
17 
18 #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86)
19 # define CRYPTOPP_CHAM128_ADVANCED_PROCESS_BLOCKS 1
20 #endif
21 
22 // Yet another SunStudio/SunCC workaround. Failed self tests
23 // in SSE code paths on i386 for SunStudio 12.3 and below.
24 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
25 # undef CRYPTOPP_CHAM128_ADVANCED_PROCESS_BLOCKS
26 #endif
27 
28 NAMESPACE_BEGIN(CryptoPP)
29 
30 /// \brief CHAM block cipher information
31 /// \since Crypto++ 8.0
32 struct CHAM64_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
33 {
34  /// \brief The algorithm name
35  /// \return the algorithm name
36  /// \details StaticAlgorithmName returns the algorithm's name as a static
37  /// member function.
38  static const std::string StaticAlgorithmName()
39  {
40  // Format is Cipher-Blocksize
41  return "CHAM-64";
42  }
43 };
44 
45 /// \brief CHAM block cipher information
46 /// \since Crypto++ 8.0
47 struct CHAM128_Info : public FixedBlockSize<16>, public VariableKeyLength<16,16,32,16>
48 {
49  /// \brief The algorithm name
50  /// \return the algorithm name
51  /// \details StaticAlgorithmName returns the algorithm's name as a static
52  /// member function.
53  static const std::string StaticAlgorithmName()
54  {
55  // Format is Cipher-Blocksize
56  return "CHAM-128";
57  }
58 };
59 
60 /// \brief CHAM 64-bit block cipher
61 /// \details CHAM64 provides 64-bit block size. The valid key size is 128-bit.
62 /// \note Crypto++ provides a byte oriented implementation
63 /// \sa CHAM128, <a href="http://www.cryptopp.com/wiki/CHAM">CHAM</a>,
64 /// <a href="https://pdfs.semanticscholar.org/2f57/61b5c2614cffd58a09cc83c375a2b32a2ed3.pdf">
65 /// CHAM: A Family of Lightweight Block Ciphers for Resource-Constrained Devices</a>
66 /// \since Crypto++ 8.0
67 class CRYPTOPP_NO_VTABLE CHAM64 : public CHAM64_Info, public BlockCipherDocumentation
68 {
69 public:
70  /// \brief CHAM block cipher transformation functions
71  /// \details Provides implementation common to encryption and decryption
72  /// \since Crypto++ 8.0
73  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<CHAM64_Info>
74  {
75  protected:
76  void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
77 
78  SecBlock<word16> m_rk;
79  mutable FixedSizeSecBlock<word16, 4> m_x;
80  unsigned int m_kw;
81  };
82 
83  /// \brief Encryption transformation
84  /// \details Enc provides implementation for encryption transformation. All key and block
85  /// sizes are supported.
86  /// \since Crypto++ 8.0
87  class CRYPTOPP_NO_VTABLE Enc : public Base
88  {
89  public:
90  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
91  };
92 
93  /// \brief Decryption transformation
94  /// \details Dec provides implementation for decryption transformation. All key and block
95  /// sizes are supported.
96  /// \since Crypto++ 8.0
97  class CRYPTOPP_NO_VTABLE Dec : public Base
98  {
99  public:
100  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
101  };
102 
103  /// \brief CHAM64 encryption
105  /// \brief CHAM64 decryption
107 };
108 
109 /// \brief CHAM64 encryption
111 /// \brief CHAM64 decryption
113 
114 /// \brief CHAM 128-bit block cipher
115 /// \details CHAM128 provides 128-bit block size. The valid key size is 128-bit and 256-bit.
116 /// \note Crypto++ provides a byte oriented implementation
117 /// \sa CHAM64, <a href="http://www.cryptopp.com/wiki/CHAM">CHAM</a>,
118 /// <a href="https://pdfs.semanticscholar.org/2f57/61b5c2614cffd58a09cc83c375a2b32a2ed3.pdf">
119 /// CHAM: A Family of Lightweight Block Ciphers for Resource-Constrained Devices</a>
120 /// \since Crypto++ 8.0
121 class CRYPTOPP_NO_VTABLE CHAM128 : public CHAM128_Info, public BlockCipherDocumentation
122 {
123 public:
124  /// \brief CHAM block cipher transformation functions
125  /// \details Provides implementation common to encryption and decryption
126  /// \since Crypto++ 8.0
127  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<CHAM128_Info>
128  {
129  protected:
130  void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
131  std::string AlgorithmProvider() const;
132 
133  SecBlock<word32> m_rk;
134  mutable FixedSizeSecBlock<word32, 4> m_x;
135  unsigned int m_kw;
136  };
137 
138  /// \brief Encryption transformation
139  /// \details Enc provides implementation for encryption transformation. All key and block
140  /// sizes are supported.
141  /// \since Crypto++ 8.0
142  class CRYPTOPP_NO_VTABLE Enc : public Base
143  {
144  public:
145  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
146 
147 #if CRYPTOPP_CHAM128_ADVANCED_PROCESS_BLOCKS
148  size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
149 #endif
150  };
151 
152  /// \brief Decryption transformation
153  /// \details Dec provides implementation for decryption transformation. All key and block
154  /// sizes are supported.
155  /// \since Crypto++ 8.0
156  class CRYPTOPP_NO_VTABLE Dec : public Base
157  {
158  public:
159  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
160 
161 #if CRYPTOPP_CHAM128_ADVANCED_PROCESS_BLOCKS
162  size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
163 #endif
164  };
165 
166  /// \brief CHAM128 encryption
168  /// \brief CHAM128 decryption
170 };
171 
172 /// \brief CHAM128 encryption
174 /// \brief CHAM128 decryption
176 
177 NAMESPACE_END
178 
179 #endif // CRYPTOPP_CHAM_H
CHAM128Encryption
CHAM128::Encryption CHAM128Encryption
CHAM128 encryption.
Definition: cham.h:173
CHAM128::Decryption
BlockCipherFinal< DECRYPTION, Dec > Decryption
CHAM128 decryption.
Definition: cham.h:169
CHAM128::Enc
Encryption transformation.
Definition: cham.h:142
CHAM128::Base
CHAM block cipher transformation functions.
Definition: cham.h:127
CHAM64Decryption
CHAM64::Decryption CHAM64Decryption
CHAM64 decryption.
Definition: cham.h:112
CHAM128::Dec
Decryption transformation.
Definition: cham.h:156
secblock.h
Classes and functions for secure memory allocations.
CHAM64Encryption
CHAM64::Encryption CHAM64Encryption
CHAM64 encryption.
Definition: cham.h:110
CHAM64_Info
CHAM block cipher information.
Definition: cham.h:32
CHAM128_Info
CHAM block cipher information.
Definition: cham.h:47
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
CHAM128
CHAM 128-bit block cipher.
Definition: cham.h:121
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:124
CHAM64::Encryption
BlockCipherFinal< ENCRYPTION, Enc > Encryption
CHAM64 encryption.
Definition: cham.h:104
CHAM128_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: cham.h:53
CHAM64::Enc
Encryption transformation.
Definition: cham.h:87
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:398
CHAM128::Encryption
BlockCipherFinal< ENCRYPTION, Enc > Encryption
CHAM128 encryption.
Definition: cham.h:167
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherFinal< ENCRYPTION, Enc >
FixedSizeSecBlock< word16, 4 >
CHAM64_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: cham.h:38
CHAM64::Base
CHAM block cipher transformation functions.
Definition: cham.h:73
CryptoPP
Crypto++ library namespace.
config.h
Library configuration file.
CHAM64
CHAM 64-bit block cipher.
Definition: cham.h:67
SecBlock< word16 >
CHAM64::Decryption
BlockCipherFinal< DECRYPTION, Dec > Decryption
CHAM64 decryption.
Definition: cham.h:106
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
CHAM64::Dec
Decryption transformation.
Definition: cham.h:97
algparam.h
Classes for working with NameValuePairs.
CHAM128Decryption
CHAM128::Decryption CHAM128Decryption
CHAM128 decryption.
Definition: cham.h:175
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165