aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/idea
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-23 16:51:24 +0000
committerlloyd <[email protected]>2009-12-23 16:51:24 +0000
commit92a851901ea42398c221a608348d1336b5529b09 (patch)
tree22dab44199d116f1de2ede8a03b5ffc3a5bc6247 /src/block/idea
parent3a652cd28ec554267be414d69ed14b46956f84d7 (diff)
Add last nights project, an SSE2 implementation of IDEA. Right about 4x
faster than the scalar version on a Core2.
Diffstat (limited to 'src/block/idea')
-rw-r--r--src/block/idea/idea.cpp78
-rw-r--r--src/block/idea/idea.h2
2 files changed, 27 insertions, 53 deletions
diff --git a/src/block/idea/idea.cpp b/src/block/idea/idea.cpp
index fb5fe83f1..15ff7c0ec 100644
--- a/src/block/idea/idea.cpp
+++ b/src/block/idea/idea.cpp
@@ -55,13 +55,13 @@ u16bit mul_inv(u16bit x)
return (1 - t0);
}
-}
-
-/*
-* IDEA Encryption
+/**
+* IDEA is involutional, depending only on the key schedule
*/
-void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
+void idea_op(const byte in[], byte out[], u32bit blocks, const u16bit K[52])
{
+ const u32bit BLOCK_SIZE = 8;
+
for(u32bit i = 0; i != blocks; ++i)
{
u16bit X1 = load_be<u16bit>(in, 0);
@@ -71,16 +71,16 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
for(u32bit j = 0; j != 8; ++j)
{
- X1 = mul(X1, EK[6*j+0]);
- X2 += EK[6*j+1];
- X3 += EK[6*j+2];
- X4 = mul(X4, EK[6*j+3]);
+ X1 = mul(X1, K[6*j+0]);
+ X2 += K[6*j+1];
+ X3 += K[6*j+2];
+ X4 = mul(X4, K[6*j+3]);
u16bit T0 = X3;
- X3 = mul(X3 ^ X1, EK[6*j+4]);
+ X3 = mul(X3 ^ X1, K[6*j+4]);
u16bit T1 = X2;
- X2 = mul((X2 ^ X4) + X3, EK[6*j+5]);
+ X2 = mul((X2 ^ X4) + X3, K[6*j+5]);
X3 += X2;
X1 ^= X2;
@@ -89,10 +89,10 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
X3 ^= T1;
}
- X1 = mul(X1, EK[48]);
- X2 += EK[50];
- X3 += EK[49];
- X4 = mul(X4, EK[51]);
+ X1 = mul(X1, K[48]);
+ X2 += K[50];
+ X3 += K[49];
+ X4 = mul(X4, K[51]);
store_be(out, X1, X3, X2, X4);
@@ -101,48 +101,22 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
}
}
+}
+
+/*
+* IDEA Encryption
+*/
+void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const
+ {
+ idea_op(in, out, blocks, EK);
+ }
+
/*
* IDEA Decryption
*/
void IDEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const
{
- for(u32bit i = 0; i != blocks; ++i)
- {
- u16bit X1 = load_be<u16bit>(in, 0);
- u16bit X2 = load_be<u16bit>(in, 1);
- u16bit X3 = load_be<u16bit>(in, 2);
- u16bit X4 = load_be<u16bit>(in, 3);
-
- for(u32bit j = 0; j != 8; ++j)
- {
- X1 = mul(X1, DK[6*j+0]);
- X2 += DK[6*j+1];
- X3 += DK[6*j+2];
- X4 = mul(X4, DK[6*j+3]);
-
- u16bit T0 = X3;
- X3 = mul(X3 ^ X1, DK[6*j+4]);
-
- u16bit T1 = X2;
- X2 = mul((X2 ^ X4) + X3, DK[6*j+5]);
- X3 += X2;
-
- X1 ^= X2;
- X4 ^= X3;
- X2 ^= T0;
- X3 ^= T1;
- }
-
- X1 = mul(X1, DK[48]);
- X2 += DK[50];
- X3 += DK[49];
- X4 = mul(X4, DK[51]);
-
- store_be(out, X1, X3, X2, X4);
-
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
- }
+ idea_op(in, out, blocks, DK);
}
/*
diff --git a/src/block/idea/idea.h b/src/block/idea/idea.h
index c1a79f423..89ec117e3 100644
--- a/src/block/idea/idea.h
+++ b/src/block/idea/idea.h
@@ -26,7 +26,7 @@ class BOTAN_DLL IDEA : public BlockCipher
BlockCipher* clone() const { return new IDEA; }
IDEA() : BlockCipher(8, 16) {}
- private:
+ protected:
void key_schedule(const byte[], u32bit);
SecureBuffer<u16bit, 52> EK, DK;
};