Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

  1. // square.h - 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. //! _
  10. struct Square_Info : public FixedBlockSize<16>, public FixedKeyLength<16>, FixedRounds<8>
  11. {
  12. static const char *StaticAlgorithmName() {return "Square";}
  13. };
  14. /// <a href="http://www.weidai.com/scan-mirror/cs.html#Square">Square</a>
  15. class Square : public Square_Info, public BlockCipherDocumentation
  16. {
  17. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Square_Info>
  18. {
  19. public:
  20. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  21. protected:
  22. FixedSizeSecBlock<word32, 4*(ROUNDS+1)> m_roundkeys;
  23. };
  24. class CRYPTOPP_NO_VTABLE Enc : public Base
  25. {
  26. public:
  27. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  28. private:
  29. static const byte Se[256];
  30. static const word32 Te[4][256];
  31. };
  32. class CRYPTOPP_NO_VTABLE Dec : public Base
  33. {
  34. public:
  35. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  36. private:
  37. static const byte Sd[256];
  38. static const word32 Td[4][256];
  39. };
  40. public:
  41. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  42. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  43. };
  44. typedef Square::Encryption SquareEncryption;
  45. typedef Square::Decryption SquareDecryption;
  46. NAMESPACE_END
  47. #endif