Cryptography Reference
In-Depth Information
//Compute the new digest value for H
H=prevH.xor(H).or(A).modPow(exp,modulus).mod(twon).xor(prevH);
}
//Process the t+1 block
prevH=H;
H=BigInteger.valueOf(0);
//Process the 4 bit nybbles
BigInteger rem;
for (int j=n/2-4;j>=0;j-=4) {
//Each byte in last block begins with 1010B
H=H.shiftLeft(4).or(ten);
//Shift b to right and keep last 4 bits
rem=b.shiftRight(j).mod(sixteen);
//Append this remainder to H
H=H.shiftLeft(4).or(rem);
}
//Compute the final digest value as a BigInteger
H=prevH.xor(H).or(A).modPow(exp,modulus).mod(twon).xor(prevH);
//Convert to a byte array and return-call helper method getBytes().
return getBytes(H);
}
//Converting BigInteger to a byte array may force an extra byte for a sign bit.
//We remove this byte if it is produced
private static byte[] getBytes(BigInteger big) {
byte[] bigBytes=big.toByteArray();
if (big.bitLength()%8!=0) return bigBytes;
else {
byte[] smallerBytes=new byte[big.bitLength()/8];
System.arraycopy(bigBytes,1,smallerBytes,0,smallerBytes.length);
return smallerBytes;
}
}
}
TestMASH2Applet is an applet on the topic's website you can use to view the behavior
of MASH-2. A modulus about 1024 bits in length is generated. You enter a message, then
press a button to see its digest. The digest is displayed as a base 10 integer. (See Figure
16.8.)
One of the drawbacks of MASH-2 is that the digest it produces can be rather large. To
be secure, the size of the modulus should be at least 1024 bits, which implies that the digest
will likewise be 1024 bits, or 128 bytes long. For most applications, digests should be around
128 bits long.
Search WWH ::




Custom Search