diff options
author | lloyd <[email protected]> | 2007-05-31 03:25:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2007-05-31 03:25:19 +0000 |
commit | 55608e7dd1aa593944f967f2549564e4f42b654e (patch) | |
tree | ec2ec03a762a6dac82eb608487d5394370135624 /src/cast128.cpp | |
parent | 22ecdc45a0efa4c444d0b7010b7cd743aeb68c57 (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/cast128.cpp')
-rw-r--r-- | src/cast128.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/cast128.cpp b/src/cast128.cpp index ec87afb08..481897810 100644 --- a/src/cast128.cpp +++ b/src/cast128.cpp @@ -47,8 +47,8 @@ inline void R3(u32bit& L, u32bit R, u32bit MK, u32bit RK) *************************************************/ void CAST_128::enc(const byte in[], byte out[]) const { - u32bit L = make_u32bit(in[0], in[1], in[2], in[3]), - R = make_u32bit(in[4], in[5], in[6], in[7]); + u32bit L = load_be<u32bit>(in, 0); + u32bit R = load_be<u32bit>(in, 1); R1(L, R, MK[ 0], RK[ 0]); R2(R, L, MK[ 1], RK[ 1]); @@ -67,10 +67,7 @@ void CAST_128::enc(const byte in[], byte out[]) const R3(L, R, MK[14], RK[14]); R1(R, L, MK[15], RK[15]); - out[0] = get_byte(0, R); out[1] = get_byte(1, R); - out[2] = get_byte(2, R); out[3] = get_byte(3, R); - out[4] = get_byte(0, L); out[5] = get_byte(1, L); - out[6] = get_byte(2, L); out[7] = get_byte(3, L); + store_be(out, R, L); } /************************************************* @@ -78,8 +75,8 @@ void CAST_128::enc(const byte in[], byte out[]) const *************************************************/ void CAST_128::dec(const byte in[], byte out[]) const { - u32bit L = make_u32bit(in[0], in[1], in[2], in[3]), - R = make_u32bit(in[4], in[5], in[6], in[7]); + u32bit L = load_be<u32bit>(in, 0); + u32bit R = load_be<u32bit>(in, 1); R1(L, R, MK[15], RK[15]); R3(R, L, MK[14], RK[14]); @@ -98,10 +95,7 @@ void CAST_128::dec(const byte in[], byte out[]) const R2(L, R, MK[ 1], RK[ 1]); R1(R, L, MK[ 0], RK[ 0]); - out[0] = get_byte(0, R); out[1] = get_byte(1, R); - out[2] = get_byte(2, R); out[3] = get_byte(3, R); - out[4] = get_byte(0, L); out[5] = get_byte(1, L); - out[6] = get_byte(2, L); out[7] = get_byte(3, L); + store_be(out, R, L); } /************************************************* |