aboutsummaryrefslogtreecommitdiffstats
path: root/src/rc6.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/rc6.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/rc6.cpp')
-rw-r--r--src/rc6.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/rc6.cpp b/src/rc6.cpp
index 622cb3f16..e7c8a4725 100644
--- a/src/rc6.cpp
+++ b/src/rc6.cpp
@@ -14,10 +14,10 @@ namespace Botan {
*************************************************/
void RC6::enc(const byte in[], byte out[]) const
{
- u32bit A = make_u32bit(in[ 3], in[ 2], in[ 1], in[ 0]),
- B = make_u32bit(in[ 7], in[ 6], in[ 5], in[ 4]),
- C = make_u32bit(in[11], in[10], in[ 9], in[ 8]),
- D = make_u32bit(in[15], in[14], in[13], in[12]);
+ u32bit A = load_le<u32bit>(in, 0);
+ u32bit B = load_le<u32bit>(in, 1);
+ u32bit C = load_le<u32bit>(in, 2);
+ u32bit D = load_le<u32bit>(in, 3);
B += S[0]; D += S[1];
@@ -48,14 +48,7 @@ void RC6::enc(const byte in[], byte out[]) const
A += S[42]; C += S[43];
- out[ 0] = get_byte(3, A); out[ 1] = get_byte(2, A);
- out[ 2] = get_byte(1, A); out[ 3] = get_byte(0, A);
- out[ 4] = get_byte(3, B); out[ 5] = get_byte(2, B);
- out[ 6] = get_byte(1, B); out[ 7] = get_byte(0, B);
- out[ 8] = get_byte(3, C); out[ 9] = get_byte(2, C);
- out[10] = get_byte(1, C); out[11] = get_byte(0, C);
- out[12] = get_byte(3, D); out[13] = get_byte(2, D);
- out[14] = get_byte(1, D); out[15] = get_byte(0, D);
+ store_le(out, A, B, C, D);
}
/*************************************************
@@ -63,10 +56,10 @@ void RC6::enc(const byte in[], byte out[]) const
*************************************************/
void RC6::dec(const byte in[], byte out[]) const
{
- u32bit A = make_u32bit(in[ 3], in[ 2], in[ 1], in[ 0]),
- B = make_u32bit(in[ 7], in[ 6], in[ 5], in[ 4]),
- C = make_u32bit(in[11], in[10], in[ 9], in[ 8]),
- D = make_u32bit(in[15], in[14], in[13], in[12]);
+ u32bit A = load_le<u32bit>(in, 0);
+ u32bit B = load_le<u32bit>(in, 1);
+ u32bit C = load_le<u32bit>(in, 2);
+ u32bit D = load_le<u32bit>(in, 3);
C -= S[43]; A -= S[42];
@@ -97,14 +90,7 @@ void RC6::dec(const byte in[], byte out[]) const
D -= S[1]; B -= S[0];
- out[ 0] = get_byte(3, A); out[ 1] = get_byte(2, A);
- out[ 2] = get_byte(1, A); out[ 3] = get_byte(0, A);
- out[ 4] = get_byte(3, B); out[ 5] = get_byte(2, B);
- out[ 6] = get_byte(1, B); out[ 7] = get_byte(0, B);
- out[ 8] = get_byte(3, C); out[ 9] = get_byte(2, C);
- out[10] = get_byte(1, C); out[11] = get_byte(0, C);
- out[12] = get_byte(3, D); out[13] = get_byte(2, D);
- out[14] = get_byte(1, D); out[15] = get_byte(0, D);
+ store_le(out, A, B, C, D);
}
/*************************************************