Crypto++ 8.2
Free C&
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_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
28NAMESPACE_BEGIN(CryptoPP)
29
30/// \brief CHAM block cipher information
31/// \since Crypto++ 8.0
32struct 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++ 8.0
47struct 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++ 8.0
67class CRYPTOPP_NO_VTABLE CHAM64 : public CHAM64_Info, public BlockCipherDocumentation
68{
69public:
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 std::string AlgorithmProvider() const;
78
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++ 8.0
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 Decryption transformation
99 /// \details Dec provides implementation for decryption transformation. All key and block
100 /// sizes are supported.
101 /// \since Crypto++ 8.0
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 /// \brief CHAM64 encryption
114 /// \brief CHAM64 decryption
116};
117
118/// \brief CHAM64 encryption
120/// \brief CHAM64 decryption
122
123/// \brief CHAM 128-bit block cipher
124/// \details CHAM128 provides 128-bit block size. The valid key size is 128-bit and 256-bit.
125/// \note Crypto++ provides a byte oriented implementation
126/// \sa CHAM64, <a href="http://www.cryptopp.com/wiki/CHAM">CHAM</a>,
127/// <a href="https://pdfs.semanticscholar.org/2f57/61b5c2614cffd58a09cc83c375a2b32a2ed3.pdf">
128/// CHAM: A Family of Lightweight Block Ciphers for Resource-Constrained Devices</a>
129/// \since Crypto++ 8.0
130class CRYPTOPP_NO_VTABLE CHAM128 : public CHAM128_Info, public BlockCipherDocumentation
131{
132public:
133 /// \brief CHAM block cipher transformation functions
134 /// \details Provides implementation common to encryption and decryption
135 /// \since Crypto++ 8.0
136 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<CHAM128_Info>
137 {
138 protected:
139 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
140 std::string AlgorithmProvider() const;
141
142 SecBlock<word32> m_rk;
144 unsigned int m_kw;
145 };
146
147 /// \brief Encryption transformation
148 /// \details Enc provides implementation for encryption transformation. All key and block
149 /// sizes are supported.
150 /// \since Crypto++ 8.0
151 class CRYPTOPP_NO_VTABLE Enc : public Base
152 {
153 public:
154 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
155
156#if CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
157 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
158#endif
159 };
160
161 /// \brief Decryption transformation
162 /// \details Dec provides implementation for decryption transformation. All key and block
163 /// sizes are supported.
164 /// \since Crypto++ 8.0
165 class CRYPTOPP_NO_VTABLE Dec : public Base
166 {
167 public:
168 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
169
170#if CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
171 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
172#endif
173 };
174
175 /// \brief CHAM128 encryption
177 /// \brief CHAM128 decryption
179};
180
181/// \brief CHAM128 encryption
183/// \brief CHAM128 decryption
185
186NAMESPACE_END
187
188#endif // CRYPTOPP_CHAM_H
Classes for working with NameValuePairs.
CHAM128::Encryption CHAM128Encryption
CHAM128 encryption.
Definition: cham.h:182
CHAM64::Encryption CHAM64Encryption
CHAM64 encryption.
Definition: cham.h:119
CHAM128::Decryption CHAM128Decryption
CHAM128 decryption.
Definition: cham.h:184
CHAM64::Decryption CHAM64Decryption
CHAM64 decryption.
Definition: cham.h:121
Provides class member functions to key a block cipher.
Definition: seckey.h:318
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:306
CHAM block cipher transformation functions.
Definition: cham.h:137
Decryption transformation.
Definition: cham.h:166
Encryption transformation.
Definition: cham.h:152
CHAM 128-bit block cipher.
Definition: cham.h:131
BlockCipherFinal< DECRYPTION, Dec > Decryption
CHAM128 decryption.
Definition: cham.h:178
BlockCipherFinal< ENCRYPTION, Enc > Encryption
CHAM128 encryption.
Definition: cham.h:176
CHAM block cipher transformation functions.
Definition: cham.h:74
Decryption transformation.
Definition: cham.h:103
Encryption transformation.
Definition: cham.h:89
CHAM 64-bit block cipher.
Definition: cham.h:68
BlockCipherFinal< ENCRYPTION, Enc > Encryption
CHAM64 encryption.
Definition: cham.h:113
BlockCipherFinal< DECRYPTION, Dec > Decryption
CHAM64 decryption.
Definition: cham.h:115
Inherited by algorithms with fixed block size.
Definition: seckey.h:41
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:125
Fixed size stack-based SecBlock.
Definition: secblock.h:1078
Interface for retrieving values given their names.
Definition: cryptlib.h:294
Secure memory block with allocator and cleanup.
Definition: secblock.h:689
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:166
Library configuration file.
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
CHAM block cipher information.
Definition: cham.h:48
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: cham.h:53
CHAM block cipher information.
Definition: cham.h:33
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: cham.h:38