Browse Source

Add support for Tiger with more than 3 passes

This fixes #632

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 1 year ago
parent
commit
c272d2264c
2 changed files with 27 additions and 2 deletions
  1. 25 1
      src/hashes/tiger.c
  2. 2 1
      src/headers/tomcrypt_hash.h

+ 25 - 1
src/hashes/tiger.c

@@ -601,7 +601,7 @@ static int ss_tiger_compress(hash_state *md, const unsigned char *buf)
 static int  s_tiger_compress(hash_state *md, const unsigned char *buf)
 #endif
 {
-    ulong64 a, b, c, x[8];
+    ulong64 a, b, c, x[8], t;
     unsigned long i;
 
     /* load words */
@@ -617,6 +617,11 @@ static int  s_tiger_compress(hash_state *md, const unsigned char *buf)
     s_pass(&c,&a,&b,x,7);
     s_key_schedule(x);
     s_pass(&b,&c,&a,x,9);
+    for (i = 3; i < md->tiger.passes; ++i) {
+       s_key_schedule(x);
+       s_pass(&a,&b,&c,x,9);
+       t = a; a = c; c = b; b = t;
+   }
 
     /* store state */
     md->tiger.state[0] = a ^ md->tiger.state[0];
@@ -649,6 +654,25 @@ int tiger_init(hash_state *md)
     md->tiger.state[2] = CONST64(0xF096A5B4C3B2E187);
     md->tiger.curlen = 0;
     md->tiger.length = 0;
+    md->tiger.passes = 3;
+    return CRYPT_OK;
+}
+
+/**
+   Initialize the hash state (extended version)
+   @param md       The hash state you wish to initialize
+   @param passes   The number of passes that should be executed
+                   when the compress function is called.
+   @return CRYPT_OK if successful
+*/
+int tiger_init_ex(hash_state *md, unsigned long passes)
+{
+    int err;
+    if ((err = tiger_init(md) != CRYPT_OK)) {
+        return err;
+    }
+    md->tiger.passes = passes;
+    return CRYPT_OK;
     return CRYPT_OK;
 }
 

+ 2 - 1
src/headers/tomcrypt_hash.h

@@ -57,7 +57,7 @@ struct md4_state {
 #ifdef LTC_TIGER
 struct tiger_state {
     ulong64 state[3], length;
-    unsigned long curlen;
+    unsigned long curlen, passes;
     unsigned char buf[64];
 };
 #endif
@@ -440,6 +440,7 @@ extern const struct ltc_hash_descriptor md2_desc;
 
 #ifdef LTC_TIGER
 int tiger_init(hash_state * md);
+int tiger_init_ex(hash_state *md, unsigned long passes);
 int tiger_process(hash_state * md, const unsigned char *in, unsigned long inlen);
 int tiger_done(hash_state * md, unsigned char *out);
 int tiger_test(void);