Crypto++ 7.0 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++ 7.1
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_CHAM_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_CHAM_ADVANCED_PROCESS_BLOCKS
26 #endif
27
28 NAMESPACE_BEGIN(CryptoPP)
29
30 /// \brief CHAM block cipher information
31 /// \since Crypto++ 7.1
32 struct CHAM64_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
33 {
34 /// \brief The algorithm name
35 /// \returns 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++ 7.1
47 struct CHAM128_Info : public FixedBlockSize<16>, public VariableKeyLength<16,16,32,16>
48 {
49 /// \brief The algorithm name
50 /// \returns 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++ 7.1
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++ 7.1
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 std::string AlgorithmProvider() const;
78
79 SecBlock<word16> m_rk;
80 mutable FixedSizeSecBlock<word16, 4> m_x;
81 unsigned int m_kw;
82 };
83
84 /// \brief Encryption transformation
85 /// \details Enc provides implementation for encryption transformation. All key and block
86 /// sizes are supported.
87 /// \since Crypto++ 7.1
88 class CRYPTOPP_NO_VTABLE Enc : public Base
89 {
90 public:
91 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
92
93 #if CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
94 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
95 #endif
96 };
97
98 /// \brief Encryption transformation
99 /// \details Dec provides implementation for decryption transformation. All key and block
100 /// sizes are supported.
101 /// \since Crypto++ 7.1
102 class CRYPTOPP_NO_VTABLE Dec : public Base
103 {
104 public:
105 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
106
107 #if CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
108 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
109 #endif
110 };
111
112 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
113 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
114 };
115
116 typedef CHAM64::Encryption CHAM64Encryption;
117 typedef CHAM64::Decryption CHAM64Decryption;
118
119 /// \brief CHAM 128-bit block cipher
120 /// \details CHAM128 provides 128-bit block size. The valid key size is 128-bit and 256-bit.
121 /// \note Crypto++ provides a byte oriented implementation
122 /// \sa CHAM64, <a href="http://www.cryptopp.com/wiki/CHAM">CHAM</a>,
123 /// <a href="https://pdfs.semanticscholar.org/2f57/61b5c2614cffd58a09cc83c375a2b32a2ed3.pdf">
124 /// CHAM: A Family of Lightweight Block Ciphers for Resource-Constrained Devices</a>
125 /// \since Crypto++ 7.1
126 class CRYPTOPP_NO_VTABLE CHAM128 : public CHAM128_Info, public BlockCipherDocumentation
127 {
128 public:
129 /// \brief CHAM block cipher transformation functions
130 /// \details Provides implementation common to encryption and decryption
131 /// \since Crypto++ 7.1
132 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<CHAM128_Info>
133 {
134 protected:
135 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
136 std::string AlgorithmProvider() const;
137
138 SecBlock<word32> m_rk;
139 mutable FixedSizeSecBlock<word32, 4> m_x;
140 unsigned int m_kw;
141 };
142
143 /// \brief Encryption transformation
144 /// \details Enc provides implementation for encryption transformation. All key and block
145 /// sizes are supported.
146 /// \since Crypto++ 7.1
147 class CRYPTOPP_NO_VTABLE Enc : public Base
148 {
149 public:
150 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
151
152 #if CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
153 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
154 #endif
155 };
156
157 /// \brief Encryption transformation
158 /// \details Dec provides implementation for decryption transformation. All key and block
159 /// sizes are supported.
160 /// \since Crypto++ 7.1
161 class CRYPTOPP_NO_VTABLE Dec : public Base
162 {
163 public:
164 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
165
166 #if CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
167 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
168 #endif
169 };
170
171 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
172 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
173 };
174
175 typedef CHAM128::Encryption CHAM128Encryption;
176 typedef CHAM128::Decryption CHAM128Decryption;
177
178 NAMESPACE_END
179
180 #endif // CRYPTOPP_CHAM_H
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:124
algparam.h
Classes for working with NameValuePairs.
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:398
CHAM128::Enc
Encryption transformation.
Definition: cham.h:147
SecBlock< word16 >
CHAM64::Dec
Encryption transformation.
Definition: cham.h:102
config.h
Library configuration file.
CHAM64_Info
CHAM block cipher information.
Definition: cham.h:32
CHAM128
CHAM 128-bit block cipher.
Definition: cham.h:126
secblock.h
Classes and functions for secure memory allocations.
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
CHAM128_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: cham.h:53
CHAM128_Info
CHAM block cipher information.
Definition: cham.h:47
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherFinal< ENCRYPTION, Enc >
CHAM64::Enc
Encryption transformation.
Definition: cham.h:88
FixedSizeSecBlock< word16, 4 >
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165
CHAM64
CHAM 64-bit block cipher.
Definition: cham.h:67
CHAM128::Base
CHAM block cipher transformation functions.
Definition: cham.h:132
CHAM64_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: cham.h:38
CHAM128::Dec
Encryption transformation.
Definition: cham.h:161
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
CryptoPP
Crypto++ library namespace.
CHAM64::Base
CHAM block cipher transformation functions.
Definition: cham.h:73
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293