Line | Count | Source |
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 | | NAMESPACE_BEGIN(CryptoPP) |
21 | | |
22 | | /// \brief SIMECK block cipher information |
23 | | /// \since Crypto++ 8.0 |
24 | | struct SIMECK32_Info : public FixedBlockSize<4>, public FixedKeyLength<8>, public FixedRounds<32> |
25 | | { |
26 | | /// \brief The algorithm name |
27 | | /// \return the algorithm name |
28 | | /// \details StaticAlgorithmName returns the algorithm's name as a static |
29 | | /// member function. |
30 | | static const std::string StaticAlgorithmName() |
31 | 13 | { |
32 | | // Format is Cipher-Blocksize |
33 | 13 | return "SIMECK-32"; |
34 | 13 | } |
35 | | }; |
36 | | |
37 | | /// \brief SIMECK block cipher information |
38 | | /// \since Crypto++ 8.0 |
39 | | struct SIMECK64_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<44> |
40 | | { |
41 | | /// \brief The algorithm name |
42 | | /// \return the algorithm name |
43 | | /// \details StaticAlgorithmName returns the algorithm's name as a static |
44 | | /// member function. |
45 | | static const std::string StaticAlgorithmName() |
46 | 14 | { |
47 | | // Format is Cipher-Blocksize |
48 | 14 | return "SIMECK-64"; |
49 | 14 | } |
50 | | }; |
51 | | |
52 | | /// \brief SIMECK 32-bit block cipher |
53 | | /// \details SIMECK32 provides 32-bit block size. The valid key size is 64-bit. |
54 | | /// \note Crypto++ provides a byte oriented implementation |
55 | | /// \sa SIMECK64, <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>, |
56 | | /// <a href="https://eprint.iacr.org/2015/612.pdf">The Simeck Family of |
57 | | /// Lightweight Block Ciphers</a> |
58 | | /// \since Crypto++ 8.0 |
59 | | class CRYPTOPP_NO_VTABLE SIMECK32 : public SIMECK32_Info, public BlockCipherDocumentation |
60 | | { |
61 | | public: |
62 | | /// \brief SIMECK block cipher transformation functions |
63 | | /// \details Provides implementation common to encryption and decryption |
64 | | /// \since Crypto++ 8.0 |
65 | | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SIMECK32_Info> |
66 | | { |
67 | | protected: |
68 | | void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms); |
69 | | std::string AlgorithmProvider() const; |
70 | | |
71 | | FixedSizeSecBlock<word16, ROUNDS> m_rk; |
72 | | mutable FixedSizeSecBlock<word16, 5> m_t; |
73 | | }; |
74 | | |
75 | | /// \brief Encryption transformation |
76 | | /// \details Enc provides implementation for encryption transformation. All key and block |
77 | | /// sizes are supported. |
78 | | /// \since Crypto++ 8.0 |
79 | | class CRYPTOPP_NO_VTABLE Enc : public Base |
80 | | { |
81 | | public: |
82 | | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
83 | | }; |
84 | | |
85 | | /// \brief Decryption transformation |
86 | | /// \details Dec provides implementation for decryption transformation. All key and block |
87 | | /// sizes are supported. |
88 | | /// \since Crypto++ 8.0 |
89 | | class CRYPTOPP_NO_VTABLE Dec : public Base |
90 | | { |
91 | | public: |
92 | | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
93 | | }; |
94 | | |
95 | | typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption; |
96 | | typedef BlockCipherFinal<DECRYPTION, Dec> Decryption; |
97 | | }; |
98 | | |
99 | | typedef SIMECK32::Encryption SIMECK32Encryption; |
100 | | typedef SIMECK32::Decryption SIMECK32Decryption; |
101 | | |
102 | | /// \brief SIMECK 64-bit block cipher |
103 | | /// \details SIMECK64 provides 64-bit block size. The valid key size is 128-bit. |
104 | | /// \note Crypto++ provides a byte oriented implementation |
105 | | /// \sa SIMECK32, <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>, |
106 | | /// <a href= "https://eprint.iacr.org/2015/612.pdf">The Simeck Family of |
107 | | /// Lightweight Block Ciphers</a> |
108 | | /// \since Crypto++ 8.0 |
109 | | class CRYPTOPP_NO_VTABLE SIMECK64 : public SIMECK64_Info, public BlockCipherDocumentation |
110 | | { |
111 | | public: |
112 | | /// \brief SIMECK block cipher transformation functions |
113 | | /// \details Provides implementation common to encryption and decryption |
114 | | /// \since Crypto++ 8.0 |
115 | | class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SIMECK64_Info> |
116 | | { |
117 | | protected: |
118 | | void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs ¶ms); |
119 | | std::string AlgorithmProvider() const; |
120 | | |
121 | | FixedSizeSecBlock<word32, ROUNDS> m_rk; |
122 | | mutable FixedSizeSecBlock<word32, 5> m_t; |
123 | | }; |
124 | | |
125 | | /// \brief Encryption transformation |
126 | | /// \details Enc provides implementation for encryption transformation. All key and block |
127 | | /// sizes are supported. |
128 | | /// \since Crypto++ 8.0 |
129 | | class CRYPTOPP_NO_VTABLE Enc : public Base |
130 | | { |
131 | | public: |
132 | | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
133 | | |
134 | | #if CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS |
135 | | size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; |
136 | | #endif |
137 | | }; |
138 | | |
139 | | /// \brief Decryption transformation |
140 | | /// \details Dec provides implementation for decryption transformation. All key and block |
141 | | /// sizes are supported. |
142 | | /// \since Crypto++ 8.0 |
143 | | class CRYPTOPP_NO_VTABLE Dec : public Base |
144 | | { |
145 | | public: |
146 | | void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
147 | | |
148 | | #if CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS |
149 | | size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const; |
150 | | #endif |
151 | | }; |
152 | | |
153 | | typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption; |
154 | | typedef BlockCipherFinal<DECRYPTION, Dec> Decryption; |
155 | | }; |
156 | | |
157 | | typedef SIMECK64::Encryption SIMECK64Encryption; |
158 | | typedef SIMECK64::Decryption SIMECK64Decryption; |
159 | | |
160 | | NAMESPACE_END |
161 | | |
162 | | #endif // CRYPTOPP_SIMECK_H |