diff options
-rw-r--r-- | include/tiger.h | 3 | ||||
-rw-r--r-- | src/tiger.cpp | 76 |
2 files changed, 57 insertions, 22 deletions
diff --git a/include/tiger.h b/include/tiger.h index 393d411d0..dc99cf8d8 100644 --- a/include/tiger.h +++ b/include/tiger.h @@ -26,8 +26,9 @@ class Tiger : public MDx_HashFunction static void pass(u64bit&, u64bit&, u64bit&, u64bit[8], byte); static void mix(u64bit[8]); - static void round(u64bit&, u64bit&, u64bit&, u64bit, byte); + static const u64bit SBOX1[256], SBOX2[256], SBOX3[256], SBOX4[256]; + SecureBuffer<u64bit, 8> X; SecureBuffer<u64bit, 3> digest; const u32bit PASS; diff --git a/src/tiger.cpp b/src/tiger.cpp index d51fa4cc4..3df507853 100644 --- a/src/tiger.cpp +++ b/src/tiger.cpp @@ -48,14 +48,61 @@ void Tiger::copy_out(byte output[]) *************************************************/ void Tiger::pass(u64bit& A, u64bit& B, u64bit& C, u64bit X[8], byte mul) { - round(A, B, C, X[0], mul); - round(B, C, A, X[1], mul); - round(C, A, B, X[2], mul); - round(A, B, C, X[3], mul); - round(B, C, A, X[4], mul); - round(C, A, B, X[5], mul); - round(A, B, C, X[6], mul); - round(B, C, A, X[7], mul); + C ^= X[0]; + A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^ + SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)]; + B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^ + SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)]; + B *= mul; + + A ^= X[1]; + B -= SBOX1[get_byte(7, A)] ^ SBOX2[get_byte(5, A)] ^ + SBOX3[get_byte(3, A)] ^ SBOX4[get_byte(1, A)]; + C += SBOX1[get_byte(0, A)] ^ SBOX2[get_byte(2, A)] ^ + SBOX3[get_byte(4, A)] ^ SBOX4[get_byte(6, A)]; + C *= mul; + + B ^= X[2]; + C -= SBOX1[get_byte(7, B)] ^ SBOX2[get_byte(5, B)] ^ + SBOX3[get_byte(3, B)] ^ SBOX4[get_byte(1, B)]; + A += SBOX1[get_byte(0, B)] ^ SBOX2[get_byte(2, B)] ^ + SBOX3[get_byte(4, B)] ^ SBOX4[get_byte(6, B)]; + A *= mul; + + C ^= X[3]; + A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^ + SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)]; + B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^ + SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)]; + B *= mul; + + A ^= X[4]; + B -= SBOX1[get_byte(7, A)] ^ SBOX2[get_byte(5, A)] ^ + SBOX3[get_byte(3, A)] ^ SBOX4[get_byte(1, A)]; + C += SBOX1[get_byte(0, A)] ^ SBOX2[get_byte(2, A)] ^ + SBOX3[get_byte(4, A)] ^ SBOX4[get_byte(6, A)]; + C *= mul; + + B ^= X[5]; + C -= SBOX1[get_byte(7, B)] ^ SBOX2[get_byte(5, B)] ^ + SBOX3[get_byte(3, B)] ^ SBOX4[get_byte(1, B)]; + A += SBOX1[get_byte(0, B)] ^ SBOX2[get_byte(2, B)] ^ + SBOX3[get_byte(4, B)] ^ SBOX4[get_byte(6, B)]; + A *= mul; + + C ^= X[6]; + A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^ + SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)]; + B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^ + SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)]; + B *= mul; + + A ^= X[7]; + B -= SBOX1[get_byte(7, A)] ^ SBOX2[get_byte(5, A)] ^ + SBOX3[get_byte(3, A)] ^ SBOX4[get_byte(1, A)]; + C += SBOX1[get_byte(0, A)] ^ SBOX2[get_byte(2, A)] ^ + SBOX3[get_byte(4, A)] ^ SBOX4[get_byte(6, A)]; + C *= mul; } /************************************************* @@ -72,19 +119,6 @@ void Tiger::mix(u64bit X[8]) } /************************************************* -* Tiger Round * -*************************************************/ -void Tiger::round(u64bit& A, u64bit& B, u64bit& C, u64bit msg, byte mul) - { - C ^= msg; - A -= SBOX1[get_byte(7, C)] ^ SBOX2[get_byte(5, C)] ^ - SBOX3[get_byte(3, C)] ^ SBOX4[get_byte(1, C)]; - B += SBOX1[get_byte(0, C)] ^ SBOX2[get_byte(2, C)] ^ - SBOX3[get_byte(4, C)] ^ SBOX4[get_byte(6, C)]; - B *= mul; - } - -/************************************************* * Clear memory of sensitive data * *************************************************/ void Tiger::clear() throw() |