Security Scol plugin
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
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
28NAMESPACE_BEGIN(CryptoPP)
29
30
32struct CHAM64_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
33{
38 static const std::string StaticAlgorithmName()
39 {
40 // Format is Cipher-Blocksize
41 return "CHAM-64";
42 }
43};
44
47struct CHAM128_Info : public FixedBlockSize<16>, public VariableKeyLength<16,16,32,16>
48{
53 static const std::string StaticAlgorithmName()
54 {
55 // Format is Cipher-Blocksize
56 return "CHAM-128";
57 }
58};
59
67class CRYPTOPP_NO_VTABLE CHAM64 : public CHAM64_Info, public BlockCipherDocumentation
68{
69public:
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
80 unsigned int m_kw;
81 };
82
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
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
107};
108
113
121class CRYPTOPP_NO_VTABLE CHAM128 : public CHAM128_Info, public BlockCipherDocumentation
122{
123public:
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;
135 unsigned int m_kw;
136 };
137
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
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
170};
171
176
177NAMESPACE_END
178
179#endif // CRYPTOPP_CHAM_H
Classes for working with NameValuePairs.
CHAM128::Encryption CHAM128Encryption
CHAM128 encryption.
Definition cham.h:173
CHAM64::Encryption CHAM64Encryption
CHAM64 encryption.
Definition cham.h:110
CHAM128::Decryption CHAM128Decryption
CHAM128 decryption.
Definition cham.h:175
CHAM64::Decryption CHAM64Decryption
CHAM64 decryption.
Definition cham.h:112
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:128
Decryption transformation.
Definition cham.h:157
Encryption transformation.
Definition cham.h:143
CHAM 128-bit block cipher.
Definition cham.h:122
BlockCipherFinal< DECRYPTION, Dec > Decryption
CHAM128 decryption.
Definition cham.h:169
BlockCipherFinal< ENCRYPTION, Enc > Encryption
CHAM128 encryption.
Definition cham.h:167
CHAM block cipher transformation functions.
Definition cham.h:74
Decryption transformation.
Definition cham.h:98
Encryption transformation.
Definition cham.h:88
CHAM 64-bit block cipher.
Definition cham.h:68
BlockCipherFinal< ENCRYPTION, Enc > Encryption
CHAM64 encryption.
Definition cham.h:104
BlockCipherFinal< DECRYPTION, Dec > Decryption
CHAM64 decryption.
Definition cham.h:106
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:1246
Interface for retrieving values given their names.
Definition cryptlib.h:322
Secure memory block with allocator and cleanup.
Definition secblock.h:731
Inherited by keyed algorithms with variable key length.
Definition seckey.h:166
Library configuration file.
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:62
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