square.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // square.h - originally written and placed in the public domain by Wei Dai
  2. /// \file square.h
  3. /// \brief Classes for the Square block cipher
  4. #ifndef CRYPTOPP_SQUARE_H
  5. #define CRYPTOPP_SQUARE_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. /// \brief Square block cipher information
  10. /// \since Crypto++ 2.2
  11. struct Square_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, FixedRounds<8>
  12. {
  13. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Square";}
  14. };
  15. /// \brief Square block cipher
  16. /// \sa <a href="http://www.cryptopp.com/wiki/Square">Square</a>
  17. /// \since Crypto++ 2.2
  18. class Square : public Square_Info, public BlockCipherDocumentation
  19. {
  20. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Square_Info>
  21. {
  22. public:
  23. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  24. protected:
  25. FixedSizeSecBlock<word32, 4*(ROUNDS+1)> m_roundkeys;
  26. };
  27. class CRYPTOPP_NO_VTABLE Enc : public Base
  28. {
  29. public:
  30. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  31. private:
  32. static const byte Se[256];
  33. static const word32 Te[4][256];
  34. };
  35. class CRYPTOPP_NO_VTABLE Dec : public Base
  36. {
  37. public:
  38. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  39. private:
  40. static const byte Sd[256];
  41. static const word32 Td[4][256];
  42. };
  43. public:
  44. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  45. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  46. };
  47. typedef Square::Encryption SquareEncryption;
  48. typedef Square::Decryption SquareDecryption;
  49. NAMESPACE_END
  50. #endif