From 7f267b20ca60727eeca7c4531f297eb82fbc10ee Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 8 Dec 2016 20:53:31 -0500 Subject: Inline Twofish::rs_mul into its only caller --- src/lib/block/twofish/twofish.cpp | 41 ++++++++++++++++++--------------------- src/lib/block/twofish/twofish.h | 2 -- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'src/lib/block/twofish') diff --git a/src/lib/block/twofish/twofish.cpp b/src/lib/block/twofish/twofish.cpp index a98ae8e70..0b30d4080 100644 --- a/src/lib/block/twofish/twofish.cpp +++ b/src/lib/block/twofish/twofish.cpp @@ -127,7 +127,25 @@ void Twofish::key_schedule(const byte key[], size_t length) secure_vector S(16); for(size_t i = 0; i != length; ++i) - rs_mul(&S[4*(i/8)], key[i], i); + { + /* + * Do one column of the RS matrix multiplcation + */ + if(key[i]) + { + byte X = POLY_TO_EXP[key[i] - 1]; + + byte RS1 = RS[(4*i ) % 32]; + byte RS2 = RS[(4*i+1) % 32]; + byte RS3 = RS[(4*i+2) % 32]; + byte RS4 = RS[(4*i+3) % 32]; + + S[4*(i/8) ] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS1 - 1]) % 255]; + S[4*(i/8)+1] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS2 - 1]) % 255]; + S[4*(i/8)+2] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS3 - 1]) % 255]; + S[4*(i/8)+3] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS4 - 1]) % 255]; + } + } if(length == 16) { @@ -212,27 +230,6 @@ void Twofish::key_schedule(const byte key[], size_t length) } } -/* -* Do one column of the RS matrix multiplcation -*/ -void Twofish::rs_mul(byte S[4], byte key, size_t offset) - { - if(key) - { - byte X = POLY_TO_EXP[key - 1]; - - byte RS1 = RS[(4*offset ) % 32]; - byte RS2 = RS[(4*offset+1) % 32]; - byte RS3 = RS[(4*offset+2) % 32]; - byte RS4 = RS[(4*offset+3) % 32]; - - S[0] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS1 - 1]) % 255]; - S[1] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS2 - 1]) % 255]; - S[2] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS3 - 1]) % 255]; - S[3] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS4 - 1]) % 255]; - } - } - /* * Clear memory of sensitive data */ diff --git a/src/lib/block/twofish/twofish.h b/src/lib/block/twofish/twofish.h index 42991e354..b8021263e 100644 --- a/src/lib/block/twofish/twofish.h +++ b/src/lib/block/twofish/twofish.h @@ -27,8 +27,6 @@ class BOTAN_DLL Twofish final : public Block_Cipher_Fixed_Params<16, 16, 32, 8> private: void key_schedule(const byte[], size_t) override; - static void rs_mul(byte[4], byte, size_t); - static const u32bit MDS0[256]; static const u32bit MDS1[256]; static const u32bit MDS2[256]; -- cgit v1.2.3