idea.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // idea.h - originally 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. /// \brief IDEA block cipher information
  10. /// \since Crypto++ 1.0
  11. struct IDEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public FixedRounds<8>
  12. {
  13. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "IDEA";}
  14. };
  15. /// \brief IDEA block cipher
  16. /// \sa <a href="http://www.cryptopp.com/wiki/IDEA">IDEA</a>
  17. /// \since Crypto++ 1.0
  18. class IDEA : public IDEA_Info, public BlockCipherDocumentation
  19. {
  20. public: // made public for internal purposes
  21. #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
  22. typedef word Word;
  23. #else
  24. typedef hword Word;
  25. #endif
  26. private:
  27. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<IDEA_Info>
  28. {
  29. public:
  30. unsigned int OptimalDataAlignment() const {return 2;}
  31. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  32. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  33. private:
  34. void EnKey(const byte *);
  35. void DeKey();
  36. FixedSizeSecBlock<Word, 6*ROUNDS+4> m_key;
  37. #ifdef IDEA_LARGECACHE
  38. static inline void LookupMUL(word &a, word b);
  39. void LookupKeyLogs();
  40. static void BuildLogTables();
  41. static volatile bool tablesBuilt;
  42. static word16 log[0x10000], antilog[0x10000];
  43. #endif
  44. };
  45. public:
  46. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  47. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  48. };
  49. typedef IDEA::Encryption IDEAEncryption;
  50. typedef IDEA::Decryption IDEADecryption;
  51. NAMESPACE_END
  52. #endif