gnu-crypto-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GNU Crypto] W.: RipeMD160 - Changing the initial value


From: Casey Marshall
Subject: Re: [GNU Crypto] W.: RipeMD160 - Changing the initial value
Date: Fri, 18 Nov 2005 20:23:21 -0800

On Nov 18, 2005, at 4:23 AM, address@hidden wrote:

Hello world,

I need some urgent help!

Due to some project purposes I cannot change I have to modify the initial value for the RIPEMD-160 algorithm
depending on another result from the RIPEMD-160 algorithm.

I am using Java 1.3.1 with gnu crypto 1.1
(The important class RipeMD160.java has not been changed compared to gnu crypto 2.0.1).

I want to do something like this:
(let newIV be an result of the RIPEMD-160 - e.g. "9c1185a5c5e9fc54612808977ee8f548b2258d31")

public void setIV(String newIV) {
        h0 = Integer.parseInt(newIV.substring(0, 8).toUpperCase(), 16);
        h1 = Integer.parseInt(newIV.substring(8, 16).toUpperCase(), 16);
        h2 = Integer.parseInt(newIV.substring(16, 24).toUpperCase(), 16);
        h3 = Integer.parseInt(newIV.substring(24, 32).toUpperCase(), 16);
        h4 = Integer.parseInt(newIV.substring(32, 40).toUpperCase(), 16);
}

In other words, I have to split the result in 5 4-byte-words and use them as new initial values for the next calculation.

In the current implementation of the RipeMD160-class, the initial value variables are declared as int.

It is possible that result.substring(0, 8) would be "FFFFFFFF" (greater than 7FFFFFFF - max value for JAVA int) for instance? In this case, this value would be greater than the max value of an JAVA int and I will get a problem!


The way to do that is to parse the inputs as longs, and cast them to ints:

  h0 = (int) Long.parseLong (newIV.substring (0, 8), 16);
  etc.

I'm fairly certain you don't need to call 'toUpperCase.' All you are doing there is creating yet another 8-character string unnecessarily.

But I'm curious why your 'newIV' value has to be a String. If you have just the byte array IV, converting that into five ints is a lot more efficient than splitting a string and parsing hex digits.

Hope this helps.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]