Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:09

0001 // simeck.h - written and placed in the public domain by Gangqiang Yang and Jeffrey Walton.

0002 //            Based on "The Simeck Family of Lightweight Block Ciphers" by Gangqiang Yang,

0003 //            Bo Zhu, Valentin Suder, Mark D. Aagaard, and Guang Gong

0004 
0005 /// \file simeck.h

0006 /// \brief Classes for the SIMECK block cipher

0007 /// \sa <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>,

0008 ///   <a href="https://eprint.iacr.org/2015/612.pdf">The Simeck

0009 ///   Family of Lightweight Block Ciphers</a>

0010 /// \since Crypto++ 8.0

0011 
0012 #ifndef CRYPTOPP_SIMECK_H
0013 #define CRYPTOPP_SIMECK_H
0014 
0015 #include "config.h"
0016 #include "seckey.h"
0017 #include "secblock.h"
0018 #include "algparam.h"
0019 
0020 NAMESPACE_BEGIN(CryptoPP)
0021 
0022 /// \brief SIMECK block cipher information

0023 /// \since Crypto++ 8.0

0024 struct SIMECK32_Info : public FixedBlockSize<4>, public FixedKeyLength<8>, public FixedRounds<32>
0025 {
0026     /// \brief The algorithm name

0027     /// \return the algorithm name

0028     /// \details StaticAlgorithmName returns the algorithm's name as a static

0029     ///   member function.

0030     static const std::string StaticAlgorithmName()
0031     {
0032         // Format is Cipher-Blocksize

0033         return "SIMECK-32";
0034     }
0035 };
0036 
0037 /// \brief SIMECK block cipher information

0038 /// \since Crypto++ 8.0

0039 struct SIMECK64_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<44>
0040 {
0041     /// \brief The algorithm name

0042     /// \return the algorithm name

0043     /// \details StaticAlgorithmName returns the algorithm's name as a static

0044     ///   member function.

0045     static const std::string StaticAlgorithmName()
0046     {
0047         // Format is Cipher-Blocksize

0048         return "SIMECK-64";
0049     }
0050 };
0051 
0052 /// \brief SIMECK 32-bit block cipher

0053 /// \details SIMECK32 provides 32-bit block size. The valid key size is 64-bit.

0054 /// \note Crypto++ provides a byte oriented implementation

0055 /// \sa SIMECK64, <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>,

0056 ///   <a href="https://eprint.iacr.org/2015/612.pdf">The Simeck Family of

0057 ///   Lightweight Block Ciphers</a>

0058 /// \since Crypto++ 8.0

0059 class CRYPTOPP_NO_VTABLE SIMECK32 : public SIMECK32_Info, public BlockCipherDocumentation
0060 {
0061 public:
0062     /// \brief SIMECK block cipher transformation functions

0063     /// \details Provides implementation common to encryption and decryption

0064     /// \since Crypto++ 8.0

0065     class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SIMECK32_Info>
0066     {
0067     protected:
0068         void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
0069         std::string AlgorithmProvider() const;
0070 
0071         FixedSizeSecBlock<word16, ROUNDS> m_rk;
0072         mutable FixedSizeSecBlock<word16, 5> m_t;
0073     };
0074 
0075     /// \brief Encryption transformation

0076     /// \details Enc provides implementation for encryption transformation. All key and block

0077     ///   sizes are supported.

0078     /// \since Crypto++ 8.0

0079     class CRYPTOPP_NO_VTABLE Enc : public Base
0080     {
0081     public:
0082         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0083     };
0084 
0085     /// \brief Decryption transformation

0086     /// \details Dec provides implementation for decryption transformation. All key and block

0087     ///   sizes are supported.

0088     /// \since Crypto++ 8.0

0089     class CRYPTOPP_NO_VTABLE Dec : public Base
0090     {
0091     public:
0092         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0093     };
0094 
0095     typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0096     typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0097 };
0098 
0099 typedef SIMECK32::Encryption SIMECK32Encryption;
0100 typedef SIMECK32::Decryption SIMECK32Decryption;
0101 
0102 /// \brief SIMECK 64-bit block cipher

0103 /// \details SIMECK64 provides 64-bit block size. The valid key size is 128-bit.

0104 /// \note Crypto++ provides a byte oriented implementation

0105 /// \sa SIMECK32, <a href="http://www.cryptopp.com/wiki/SIMECK">SIMECK</a>,

0106 ///   <a href= "https://eprint.iacr.org/2015/612.pdf">The Simeck Family of

0107 ///   Lightweight Block Ciphers</a>

0108 /// \since Crypto++ 8.0

0109 class CRYPTOPP_NO_VTABLE SIMECK64 : public SIMECK64_Info, public BlockCipherDocumentation
0110 {
0111 public:
0112     /// \brief SIMECK block cipher transformation functions

0113     /// \details Provides implementation common to encryption and decryption

0114     /// \since Crypto++ 8.0

0115     class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SIMECK64_Info>
0116     {
0117     protected:
0118         void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
0119         std::string AlgorithmProvider() const;
0120 
0121         FixedSizeSecBlock<word32, ROUNDS> m_rk;
0122         mutable FixedSizeSecBlock<word32, 5> m_t;
0123     };
0124 
0125     /// \brief Encryption transformation

0126     /// \details Enc provides implementation for encryption transformation. All key and block

0127     ///   sizes are supported.

0128     /// \since Crypto++ 8.0

0129     class CRYPTOPP_NO_VTABLE Enc : public Base
0130     {
0131     public:
0132         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0133 
0134 #if CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS
0135         size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
0136 #endif
0137     };
0138 
0139     /// \brief Decryption transformation

0140     /// \details Dec provides implementation for decryption transformation. All key and block

0141     ///   sizes are supported.

0142     /// \since Crypto++ 8.0

0143     class CRYPTOPP_NO_VTABLE Dec : public Base
0144     {
0145     public:
0146         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0147 
0148 #if CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS
0149         size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
0150 #endif
0151     };
0152 
0153     typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
0154     typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
0155 };
0156 
0157 typedef SIMECK64::Encryption SIMECK64Encryption;
0158 typedef SIMECK64::Decryption SIMECK64Decryption;
0159 
0160 NAMESPACE_END
0161 
0162 #endif  // CRYPTOPP_SIMECK_H