10 static const
int IDEA_KEYLEN=(6*
IDEA::ROUNDS+4);
12 #define low16(x) ((x)&0xffff) // compiler should be able to optimize this away if word is 16 bits 13 #define high16(x) ((x)>>16) 18 #define DirectMUL(a,b) \ 20 word32 p=(word32)low16(a)*b; \ 24 p = low16(p) - high16(p); \ 25 a = (IDEA::Word)p - (IDEA::Word)high16(p); \ 31 #ifdef IDEA_LARGECACHE 32 volatile bool IDEA::Base::tablesBuilt =
false;
33 word16 IDEA::Base::log[0x10000];
34 word16 IDEA::Base::antilog[0x10000];
36 void IDEA::Base::BuildLogTables()
47 for (i=0; i<0x10000; i++)
53 for (i=0; i<0x10000; i++)
54 log[antilog[i]] = (
word16)i;
58 void IDEA::Base::LookupKeyLogs()
78 #endif // IDEA_LARGECACHE 84 #ifdef IDEA_LARGECACHE 93 #ifdef IDEA_LARGECACHE 105 for (; i<IDEA_KEYLEN; i++)
115 for (
unsigned i=0; i<15; i++)
133 for (i=0; i<ROUNDS; i++)
135 tempkey[i*6+0] = MulInv(
m_key[(ROUNDS-i)*6+0]);
136 tempkey[i*6+1] = AddInv(
m_key[(ROUNDS-i)*6+1+(i>0)]);
137 tempkey[i*6+2] = AddInv(
m_key[(ROUNDS-i)*6+2-(i>0)]);
138 tempkey[i*6+3] = MulInv(
m_key[(ROUNDS-i)*6+3]);
139 tempkey[i*6+4] =
m_key[(ROUNDS-1-i)*6+4];
140 tempkey[i*6+5] =
m_key[(ROUNDS-1-i)*6+5];
143 tempkey[i*6+0] = MulInv(
m_key[(ROUNDS-i)*6+0]);
144 tempkey[i*6+1] = AddInv(
m_key[(ROUNDS-i)*6+1]);
145 tempkey[i*6+2] = AddInv(
m_key[(ROUNDS-i)*6+2]);
146 tempkey[i*6+3] = MulInv(
m_key[(ROUNDS-i)*6+3]);
151 #ifdef IDEA_LARGECACHE 152 #define MUL(a,b) LookupMUL(a,b) 154 #define MUL(a,b) DirectMUL(a,b) 165 for (
unsigned int i=0; i<ROUNDS; i++)
183 MUL(x0, key[ROUNDS*6+0]);
184 x2 += key[ROUNDS*6+1];
185 x1 += key[ROUNDS*6+2];
186 MUL(x3, key[ROUNDS*6+3]);
188 Block::Put(xorBlock, outBlock)(x0)(x2)(x1)(x3);
Utility functions for the Crypto++ library.
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
Encrypt or decrypt a block.
#define NAMESPACE_BEGIN(x)
static GetBlock< T, B, GA > Get(const void *block)
CRYPTOPP_COMPILE_ASSERT(sizeof(IDEA::Word) >=2)
Access a block of memory.
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
FixedSizeSecBlock< Word, 6 *ROUNDS+4 > m_key
Classes and functions for secure memory allocations.
BlockGetAndPut< word32, BigEndian > Block
void AssertValidKeyLength(size_t length) const
Validates the key length.
Fixed size stack-based SecBlock.
T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
Rounds a value down to a multiple of a second value.
Classes for the IDEA block cipher.
Interface for retrieving values given their names.