aboutsummaryrefslogtreecommitdiffstats
path: root/src/idea.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2007-07-23 15:44:04 +0000
committerlloyd <[email protected]>2007-07-23 15:44:04 +0000
commite2f1f734277146d817ab284dea21e4013cb5b937 (patch)
tree21ad6ee775e36aa7fb24a504077200c22b1f15b8 /src/idea.cpp
parent211c4929ae92106794984d872a0cae1a873baa29 (diff)
Avoid C-style casts (as detected by GCC's -Wold-style-cast) and instead use
static_cast or reinterpret_cast, as needed.
Diffstat (limited to 'src/idea.cpp')
-rw-r--r--src/idea.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/idea.cpp b/src/idea.cpp
index ed142ca9b..c12f7b5b9 100644
--- a/src/idea.cpp
+++ b/src/idea.cpp
@@ -17,13 +17,13 @@ inline void mul(u16bit& a, u16bit b)
{
if(a && b)
{
- u32bit temp = (u32bit)a * b;
- a = (u16bit)(temp >> 16);
- b = (u16bit)(temp & 0xFFFF);
- a = (u16bit)(b - a + ((b < a) ? 1 : 0));
+ 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));
}
else
- a = (u16bit)(1 - a - b);
+ a = static_cast<u16bit>(1 - a - b);
}
}
@@ -48,7 +48,7 @@ void IDEA::enc(const byte in[], byte out[]) const
X3 ^= X1;
mul(X3, EK[6*j+4]);
u16bit T1 = X2;
- X2 = (u16bit)((X2 ^ X4) + X3);
+ X2 = static_cast<u16bit>((X2 ^ X4) + X3);
mul(X2, EK[6*j+5]);
X3 += X2;
X1 ^= X2;
@@ -82,7 +82,7 @@ void IDEA::dec(const byte in[], byte out[]) const
X3 ^= X1;
mul(X3, DK[6*j+4]);
u16bit T1 = X2;
- X2 = (u16bit)((X2 ^ X4) + X3);
+ X2 = static_cast<u16bit>((X2 ^ X4) + X3);
mul(X2, DK[6*j+5]);
X3 += X2;
X1 ^= X2;
@@ -103,19 +103,22 @@ u16bit IDEA::mul_inv(u16bit x)
{
if(x <= 1)
return x;
- u16bit t0 = (u16bit)(65537 / x), t1 = 1, y = (u16bit)(65537 % x);
+
+ u16bit t0 = static_cast<u16bit>(65537 / x), t1 = 1;
+ u16bit y = static_cast<u16bit>(65537 % x);
+
while(y != 1)
{
- u16bit q = (u16bit)(x / y);
+ u16bit q = static_cast<u16bit>(x / y);
x %= y;
- t1 += (u16bit)(q * t0);
+ t1 += static_cast<u16bit>(q * t0);
if(x == 1)
return t1;
- q = (u16bit)(y / x);
+ q = static_cast<u16bit>(y / x);
y %= x;
- t0 += (u16bit)(q * t1);
+ t0 += static_cast<u16bit>(q * t1);
}
- return (u16bit)(1 - t0);
+ return static_cast<u16bit>(1 - t0);
}
/*************************************************
@@ -128,14 +131,14 @@ void IDEA::key(const byte key[], u32bit)
for(u32bit j = 1, k = 8, offset = 0; k != 52; j %= 8, ++j, ++k)
{
- EK[j+7+offset] = (u16bit)((EK[(j % 8) + offset] << 9) |
- (EK[((j+1) % 8) + offset] >> 7));
+ EK[j+7+offset] = static_cast<u16bit>((EK[(j % 8) + offset] << 9) |
+ (EK[((j+1) % 8) + offset] >> 7));
offset += (j == 8) ? 8 : 0;
}
DK[51] = mul_inv(EK[3]);
- DK[50] = (u16bit)-EK[2];
- DK[49] = (u16bit)-EK[1];
+ DK[50] = -EK[2];
+ DK[49] = -EK[1];
DK[48] = mul_inv(EK[0]);
for(u32bit j = 1, k = 4, counter = 47; j != 8; ++j, k += 6)
@@ -143,16 +146,16 @@ void IDEA::key(const byte key[], u32bit)
DK[counter--] = EK[k+1];
DK[counter--] = EK[k];
DK[counter--] = mul_inv(EK[k+5]);
- DK[counter--] = (u16bit)-EK[k+3];
- DK[counter--] = (u16bit)-EK[k+4];
+ DK[counter--] = -EK[k+3];
+ DK[counter--] = -EK[k+4];
DK[counter--] = mul_inv(EK[k+2]);
}
DK[5] = EK[47];
DK[4] = EK[46];
DK[3] = mul_inv(EK[51]);
- DK[2] = (u16bit)-EK[50];
- DK[1] = (u16bit)-EK[49];
+ DK[2] = -EK[50];
+ DK[1] = -EK[49];
DK[0] = mul_inv(EK[48]);
}