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.

63 lines
1.5 KiB

  1. // idea.h - written and placed in the public domain by Wei Dai
  2. //! \file idea.h
  3. //! \brief Classes for the IDEA block cipher
  4. #ifndef CRYPTOPP_IDEA_H
  5. #define CRYPTOPP_IDEA_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! _
  10. struct IDEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<8>
  11. {
  12. static const char *StaticAlgorithmName() {return "IDEA";}
  13. };
  14. /// <a href="http://www.weidai.com/scan-mirror/cs.html#IDEA">IDEA</a>
  15. class IDEA : public IDEA_Info, public BlockCipherDocumentation
  16. {
  17. public: // made public for internal purposes
  18. #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
  19. typedef word Word;
  20. #else
  21. typedef hword Word;
  22. #endif
  23. private:
  24. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<IDEA_Info>
  25. {
  26. public:
  27. unsigned int OptimalDataAlignment() const {return 2;}
  28. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  29. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  30. private:
  31. void EnKey(const byte *);
  32. void DeKey();
  33. FixedSizeSecBlock<Word, 6*ROUNDS+4> m_key;
  34. #ifdef IDEA_LARGECACHE
  35. static inline void LookupMUL(word &a, word b);
  36. void LookupKeyLogs();
  37. static void BuildLogTables();
  38. static volatile bool tablesBuilt;
  39. static word16 log[0x10000], antilog[0x10000];
  40. #endif
  41. };
  42. public:
  43. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  44. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  45. };
  46. typedef IDEA::Encryption IDEAEncryption;
  47. typedef IDEA::Decryption IDEADecryption;
  48. NAMESPACE_END
  49. #endif