From 55608e7dd1aa593944f967f2549564e4f42b654e Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 31 May 2007 03:25:19 +0000 Subject: 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. --- src/gost.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/gost.cpp') diff --git a/src/gost.cpp b/src/gost.cpp index a8a295c4b..d999d0d2d 100644 --- a/src/gost.cpp +++ b/src/gost.cpp @@ -13,8 +13,7 @@ namespace Botan { *************************************************/ void GOST::enc(const byte in[], byte out[]) const { - u32bit N1 = make_u32bit(in[3], in[2], in[1], in[0]), - N2 = make_u32bit(in[7], in[6], in[5], in[4]); + u32bit N1 = load_le(in, 0), N2 = load_le(in, 1); for(u32bit j = 0; j != 32; j += 2) { @@ -29,10 +28,7 @@ void GOST::enc(const byte in[], byte out[]) const SBOX3[get_byte(2, T0)] | SBOX4[get_byte(3, T0)]; } - out[0] = get_byte(3, N2); out[1] = get_byte(2, N2); - out[2] = get_byte(1, N2); out[3] = get_byte(0, N2); - out[4] = get_byte(3, N1); out[5] = get_byte(2, N1); - out[6] = get_byte(1, N1); out[7] = get_byte(0, N1); + store_le(out, N2, N1); } /************************************************* @@ -40,8 +36,7 @@ void GOST::enc(const byte in[], byte out[]) const *************************************************/ void GOST::dec(const byte in[], byte out[]) const { - u32bit N1 = make_u32bit(in[3], in[2], in[1], in[0]), - N2 = make_u32bit(in[7], in[6], in[5], in[4]); + u32bit N1 = load_le(in, 0), N2 = load_le(in, 1); for(u32bit j = 0; j != 32; j += 2) { @@ -56,10 +51,7 @@ void GOST::dec(const byte in[], byte out[]) const SBOX3[get_byte(2, T0)] | SBOX4[get_byte(3, T0)]; } - out[0] = get_byte(3, N2); out[1] = get_byte(2, N2); - out[2] = get_byte(1, N2); out[3] = get_byte(0, N2); - out[4] = get_byte(3, N1); out[5] = get_byte(2, N1); - out[6] = get_byte(1, N1); out[7] = get_byte(0, N1); + store_le(out, N2, N1); } /************************************************* @@ -69,7 +61,7 @@ void GOST::key(const byte key[], u32bit) { for(u32bit j = 0; j != 8; ++j) { - u32bit K = make_u32bit(key[4*j+3], key[4*j+2], key[4*j+1], key[4*j]); + u32bit K = load_le(key, j); EK[j] = EK[j+8] = EK[j+16] = K; } -- cgit v1.2.3