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.

67 lines
1.6 KiB

  1. // shark.h - written and placed in the public domain by Wei Dai
  2. //! \file shark.h
  3. //! \brief Classes for the SHARK block cipher
  4. #ifndef CRYPTOPP_SHARK_H
  5. #define CRYPTOPP_SHARK_H
  6. #include "config.h"
  7. #include "seckey.h"
  8. #include "secblock.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. //! _
  11. struct SHARK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 16>, public VariableRounds<6, 2>
  12. {
  13. static const char *StaticAlgorithmName() {return "SHARK-E";}
  14. };
  15. /// <a href="http://www.weidai.com/scan-mirror/cs.html#SHARK-E">SHARK-E</a>
  16. class SHARK : public SHARK_Info, public BlockCipherDocumentation
  17. {
  18. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
  19. {
  20. public:
  21. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &param);
  22. protected:
  23. unsigned int m_rounds;
  24. SecBlock<word64> m_roundKeys;
  25. };
  26. class CRYPTOPP_NO_VTABLE Enc : public Base
  27. {
  28. public:
  29. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  30. // used by Base to do key setup
  31. void InitForKeySetup();
  32. private:
  33. static const byte sbox[256];
  34. static const word64 cbox[8][256];
  35. };
  36. class CRYPTOPP_NO_VTABLE Dec : public Base
  37. {
  38. public:
  39. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  40. private:
  41. static const byte sbox[256];
  42. static const word64 cbox[8][256];
  43. };
  44. public:
  45. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  46. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  47. };
  48. typedef SHARK::Encryption SHARKEncryption;
  49. typedef SHARK::Decryption SHARKDecryption;
  50. NAMESPACE_END
  51. #endif