simeck.h 5.8 KB

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