aboutsummaryrefslogtreecommitdiffstats
path: root/src/kasumi.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2007-05-31 03:25:19 +0000
committerlloyd <[email protected]>2007-05-31 03:25:19 +0000
commit55608e7dd1aa593944f967f2549564e4f42b654e (patch)
treeec2ec03a762a6dac82eb608487d5394370135624 /src/kasumi.cpp
parent22ecdc45a0efa4c444d0b7010b7cd743aeb68c57 (diff)
Write functions to handle loading and saving words a block at a time, taking into
account endian differences. The current code does not take advantage of the knowledge of which endianness we are running on; an optimization suggested by Yves Jerschow is to use (unsafe) casts to speed up the load/store operations. This turns out to provide large performance increases (30% or more) in some cases. Even without the unsafe casts, this version seems to average a few percent faster, probably because the longer loading loops have been partially or fully unrolled. This also makes the code implementing low-level algorithms like ciphers and hashes a bit more succint.
Diffstat (limited to 'src/kasumi.cpp')
-rw-r--r--src/kasumi.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/kasumi.cpp b/src/kasumi.cpp
index 8730c45fc..43eff7311 100644
--- a/src/kasumi.cpp
+++ b/src/kasumi.cpp
@@ -33,8 +33,10 @@ u16bit FI(u16bit I, u16bit K)
*************************************************/
void KASUMI::enc(const byte in[], byte out[]) const
{
- u16bit B0 = make_u16bit(in[0], in[1]), B1 = make_u16bit(in[2], in[3]),
- B2 = make_u16bit(in[4], in[5]), B3 = make_u16bit(in[6], in[7]);
+ u16bit B0 = load_be<u16bit>(in, 0);
+ u16bit B1 = load_be<u16bit>(in, 1);
+ u16bit B2 = load_be<u16bit>(in, 2);
+ u16bit B3 = load_be<u16bit>(in, 3);
for(u32bit j = 0; j != 8; j += 2)
{
@@ -61,10 +63,7 @@ void KASUMI::enc(const byte in[], byte out[]) const
B1 ^= R;
}
- out[0] = get_byte(0, B0); out[1] = get_byte(1, B0);
- out[2] = get_byte(0, B1); out[3] = get_byte(1, B1);
- out[4] = get_byte(0, B2); out[5] = get_byte(1, B2);
- out[6] = get_byte(0, B3); out[7] = get_byte(1, B3);
+ store_be(out, B0, B1, B2, B3);
}
/*************************************************
@@ -72,8 +71,10 @@ void KASUMI::enc(const byte in[], byte out[]) const
*************************************************/
void KASUMI::dec(const byte in[], byte out[]) const
{
- u16bit B0 = make_u16bit(in[0], in[1]), B1 = make_u16bit(in[2], in[3]),
- B2 = make_u16bit(in[4], in[5]), B3 = make_u16bit(in[6], in[7]);
+ u16bit B0 = load_be<u16bit>(in, 0);
+ u16bit B1 = load_be<u16bit>(in, 1);
+ u16bit B2 = load_be<u16bit>(in, 2);
+ u16bit B3 = load_be<u16bit>(in, 3);
for(u32bit j = 0; j != 8; j += 2)
{
@@ -102,10 +103,7 @@ void KASUMI::dec(const byte in[], byte out[]) const
B3 ^= R;
}
- out[0] = get_byte(0, B0); out[1] = get_byte(1, B0);
- out[2] = get_byte(0, B1); out[3] = get_byte(1, B1);
- out[4] = get_byte(0, B2); out[5] = get_byte(1, B2);
- out[6] = get_byte(0, B3); out[7] = get_byte(1, B3);
+ store_be(out, B0, B1, B2, B3);
}
/*************************************************
@@ -119,7 +117,7 @@ void KASUMI::key(const byte key[], u32bit)
SecureBuffer<u16bit, 16> K;
for(u32bit j = 0; j != 8; ++j)
{
- K[j] = make_u16bit(key[2*j], key[2*j+1]);
+ K[j] = load_be<u16bit>(key, j);
K[j+8] = K[j] ^ RC[j];
}