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