Crypto++ 8.1 Free C++ class library of cryptographic schemes

simeck.h
Go to the documentation of this file.
1 // simeck.h - written and placed in the public domain by Gangqiang Yang and Jeffrey Walton.
2 // Based on "The Simeck Family of Lightweight Block Ciphers" by Gangqiang Yang,
3 // Bo Zhu, Valentin Suder, Mark D. Aagaard, and Guang Gong
4
5 /// \file simeck.h
6 /// \brief Classes for the SIMECK block cipher
7 /// \sa <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>,
8 /// <a href="https://eprint.iacr.org/2015/612.pdf">The Simeck
9 /// Family of Lightweight Block Ciphers</a>
10 /// \since Crypto++ 8.0
11
12 #ifndef CRYPTOPP_SIMECK_H
13 #define CRYPTOPP_SIMECK_H
14
15 #include "config.h"
16 #include "seckey.h"
17 #include "secblock.h"
18 #include "algparam.h"
19
20 #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86)
21 # define CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS 1
22 #endif
23
24 // Yet another SunStudio/SunCC workaround. Failed self tests
25 // in SSE code paths on i386 for SunStudio 12.3 and below.
26 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
27 # undef CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS
28 #endif
29
30 NAMESPACE_BEGIN(CryptoPP)
31
32 /// \brief SIMECK block cipher information
33 /// \since Crypto++ 8.0
34 struct SIMECK32_Info : public FixedBlockSize<4>, public FixedKeyLength<8>, public FixedRounds<32>
35 {
36 /// \brief The algorithm name
37 /// \returns the algorithm name
38 /// \details StaticAlgorithmName returns the algorithm's name as a static
39 /// member function.
40 static const std::string StaticAlgorithmName()
41 {
42 // Format is Cipher-Blocksize
43 return "SIMECK-32";
44 }
45 };
46
47 /// \brief SIMECK block cipher information
48 /// \since Crypto++ 8.0
49 struct SIMECK64_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<44>
50 {
51 /// \brief The algorithm name
52 /// \returns the algorithm name
53 /// \details StaticAlgorithmName returns the algorithm's name as a static
54 /// member function.
55 static const std::string StaticAlgorithmName()
56 {
57 // Format is Cipher-Blocksize
58 return "SIMECK-64";
59 }
60 };
61
62 /// \brief SIMECK 32-bit block cipher
63 /// \details SIMECK32 provides 32-bit block size. The valid key size is 64-bit.
64 /// \note Crypto++ provides a byte oriented implementation
65 /// \sa SIMECK64, <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>,
66 /// <a href="https://eprint.iacr.org/2015/612.pdf">The Simeck Family of
67 /// Lightweight Block Ciphers</a>
68 /// \since Crypto++ 8.0
69 class CRYPTOPP_NO_VTABLE SIMECK32 : public SIMECK32_Info, public BlockCipherDocumentation
70 {
71 public:
72 /// \brief SIMECK block cipher transformation functions
73 /// \details Provides implementation common to encryption and decryption
74 /// \since Crypto++ 8.0
75 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SIMECK32_Info>
76 {
77 protected:
78 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
79 std::string AlgorithmProvider() const;
80
81 FixedSizeSecBlock<word16, ROUNDS> m_rk;
82 mutable FixedSizeSecBlock<word16, 5> m_t;
83 };
84
85 /// \brief Encryption transformation
86 /// \details Enc provides implementation for encryption transformation. All key and block
87 /// sizes are supported.
88 /// \since Crypto++ 8.0
89 class CRYPTOPP_NO_VTABLE Enc : public Base
90 {
91 public:
92 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
93 };
94
95 /// \brief Encryption transformation
96 /// \details Dec provides implementation for decryption transformation. All key and block
97 /// sizes are supported.
98 /// \since Crypto++ 8.0
99 class CRYPTOPP_NO_VTABLE Dec : public Base
100 {
101 public:
102 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
103 };
104
105 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
106 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
107 };
108
109 typedef SIMECK32::Encryption SIMECK32Encryption;
110 typedef SIMECK32::Decryption SIMECK32Decryption;
111
112 /// \brief SIMECK 64-bit block cipher
113 /// \details SIMECK64 provides 64-bit block size. The valid key size is 128-bit.
114 /// \note Crypto++ provides a byte oriented implementation
115 /// \sa SIMECK32, <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>,
116 /// <a href= "https://eprint.iacr.org/2015/612.pdf">The Simeck Family of
117 /// Lightweight Block Ciphers</a>
118 /// \since Crypto++ 8.0
119 class CRYPTOPP_NO_VTABLE SIMECK64 : public SIMECK64_Info, public BlockCipherDocumentation
120 {
121 public:
122 /// \brief SIMECK block cipher transformation functions
123 /// \details Provides implementation common to encryption and decryption
124 /// \since Crypto++ 8.0
125 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SIMECK64_Info>
126 {
127 protected:
128 void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
129 std::string AlgorithmProvider() const;
130
131 FixedSizeSecBlock<word32, ROUNDS> m_rk;
132 mutable FixedSizeSecBlock<word32, 5> m_t;
133 };
134
135 /// \brief Encryption transformation
136 /// \details Enc provides implementation for encryption transformation. All key and block
137 /// sizes are supported.
138 /// \since Crypto++ 8.0
139 class CRYPTOPP_NO_VTABLE Enc : public Base
140 {
141 public:
142 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
143
144 #if CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS
145 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
146 #endif
147 };
148
149 /// \brief Encryption transformation
150 /// \details Dec provides implementation for decryption transformation. All key and block
151 /// sizes are supported.
152 /// \since Crypto++ 8.0
153 class CRYPTOPP_NO_VTABLE Dec : public Base
154 {
155 public:
156 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
157
158 #if CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS
159 size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
160 #endif
161 };
162
163 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
164 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
165 };
166
167 typedef SIMECK64::Encryption SIMECK64Encryption;
168 typedef SIMECK64::Decryption SIMECK64Decryption;
169
170 NAMESPACE_END
171
172 #endif // CRYPTOPP_SIMECK_H
SIMECK64_Info
SIMECK block cipher information.
Definition: simeck.h:49
SIMECK64_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: simeck.h:55
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
SIMECK64::Dec
Encryption transformation.
Definition: simeck.h:153
SIMECK64::Base
SIMECK block cipher transformation functions.
Definition: simeck.h:125
SIMECK64::Enc
Encryption transformation.
Definition: simeck.h:139
config.h
Library configuration file.
SIMECK32_Info::StaticAlgorithmName
static const std::string StaticAlgorithmName()
The algorithm name.
Definition: simeck.h:40
BlockCipher
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1250
SIMECK32::Dec
Encryption transformation.
Definition: simeck.h:99
secblock.h
Classes and functions for secure memory allocations.
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
seckey.h
Classes and functions for implementing secret key algorithms.
SIMECK32::Enc
Encryption transformation.
Definition: simeck.h:89
BlockCipherFinal< ENCRYPTION, Enc >
SIMECK32::Base
SIMECK block cipher transformation functions.
Definition: simeck.h:75
FixedSizeSecBlock< word16, ROUNDS >
SIMECK32
SIMECK 32-bit block cipher.
Definition: simeck.h:69
FixedRounds
Inherited by algorithms with fixed number of rounds.
Definition: seckey.h:52
SIMECK64
SIMECK 64-bit block cipher.
Definition: simeck.h:119
SIMECK32_Info
SIMECK block cipher information.
Definition: simeck.h:34
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
CryptoPP
Crypto++ library namespace.
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293