aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2007-11-11 19:25:56 +0000
committerlloyd <[email protected]>2007-11-11 19:25:56 +0000
commit0a668e05218bd55ba52c26a7641ac502cd9e8b6d (patch)
tree015ee0562c308fdf53a263fdc8e9e82e42dfdaf6 /src
parenta85553fecdaf6dc6165c7bdcb17dd96588d76067 (diff)
Have IDEA's mul() return the result instead of altering a reference value.
Split up some lines for readability. Benchmarks somewhat slower than the previous version (34.3 vs 32.0 on my Core2, gcc 4.1.2), will need to investigate.
Diffstat (limited to 'src')
-rw-r--r--src/idea.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/idea.cpp b/src/idea.cpp
index 267a14504..49c064073 100644
--- a/src/idea.cpp
+++ b/src/idea.cpp
@@ -13,17 +13,17 @@ namespace {
/*************************************************
* Multiplication modulo 65537 *
*************************************************/
-inline void mul(u16bit& a, u16bit b)
+inline u16bit mul(u16bit a, u16bit b)
{
if(a && b)
{
u32bit temp = static_cast<u32bit>(a) * b;
a = static_cast<u16bit>(temp >> 16);
b = static_cast<u16bit>(temp & 0xFFFF);
- a = static_cast<u16bit>(b - a + ((b < a) ? 1 : 0));
+ return static_cast<u16bit>(b - a + ((b < a) ? 1 : 0));
}
else
- a = static_cast<u16bit>(1 - a - b);
+ return static_cast<u16bit>(1 - a - b);
}
}
@@ -40,24 +40,30 @@ void IDEA::enc(const byte in[], byte out[]) const
for(u32bit j = 0; j != 8; ++j)
{
- mul(X1, EK[6*j+0]);
+ X1 = mul(X1, EK[6*j+0]);
X2 += EK[6*j+1];
X3 += EK[6*j+2];
- mul(X4, EK[6*j+3]);
+ X4 = mul(X4, EK[6*j+3]);
+
u16bit T0 = X3;
X3 ^= X1;
- mul(X3, EK[6*j+4]);
+ X3 = mul(X3, EK[6*j+4]);
+
u16bit T1 = X2;
X2 = static_cast<u16bit>((X2 ^ X4) + X3);
- mul(X2, EK[6*j+5]);
+ X2 = mul(X2, EK[6*j+5]);
X3 += X2;
+
X1 ^= X2;
X4 ^= X3;
X2 ^= T0;
X3 ^= T1;
}
- mul(X1, EK[48]); X2 += EK[50]; X3 += EK[49]; mul(X4, EK[51]);
+ X1 = mul(X1, EK[48]);
+ X2 += EK[50];
+ X3 += EK[49];
+ X4 = mul(X4, EK[51]);
store_be(out, X1, X3, X2, X4);
}
@@ -74,24 +80,30 @@ void IDEA::dec(const byte in[], byte out[]) const
for(u32bit j = 0; j != 8; ++j)
{
- mul(X1, DK[6*j+0]);
+ X1 = mul(X1, DK[6*j+0]);
X2 += DK[6*j+1];
X3 += DK[6*j+2];
- mul(X4, DK[6*j+3]);
+ X4 = mul(X4, DK[6*j+3]);
+
u16bit T0 = X3;
X3 ^= X1;
- mul(X3, DK[6*j+4]);
+ X3 = mul(X3, DK[6*j+4]);
+
u16bit T1 = X2;
X2 = static_cast<u16bit>((X2 ^ X4) + X3);
- mul(X2, DK[6*j+5]);
+ X2 = mul(X2, DK[6*j+5]);
X3 += X2;
+
X1 ^= X2;
X4 ^= X3;
X2 ^= T0;
X3 ^= T1;
}
- mul(X1, DK[48]); X2 += DK[50]; X3 += DK[49]; mul(X4, DK[51]);
+ X1 = mul(X1, DK[48]);
+ X2 += DK[50];
+ X3 += DK[49];
+ X4 = mul(X4, DK[51]);
store_be(out, X1, X3, X2, X4);
}