aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
}