diff options
author | Jack Lloyd <[email protected]> | 2016-12-08 20:53:31 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-08 20:53:31 -0500 |
commit | 7f267b20ca60727eeca7c4531f297eb82fbc10ee (patch) | |
tree | af3cff256433b22e4452896223061638ceb00499 | |
parent | 34525707f18a78b2d451e787f058792409595df2 (diff) |
Inline Twofish::rs_mul into its only caller
-rw-r--r-- | src/lib/block/twofish/twofish.cpp | 41 | ||||
-rw-r--r-- | src/lib/block/twofish/twofish.h | 2 |
2 files changed, 19 insertions, 24 deletions
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<byte> 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) { @@ -213,27 +231,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 */ void Twofish::clear() 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]; |