org.openuat.util
Class Hash

java.lang.Object
  extended by org.openuat.util.Hash

public class Hash
extends java.lang.Object

This is a small helper class that implements SHAd-256, a double execution of SHA256 to counter extension attacks. It is defined in Niels Ferguson, Bruce Schneier: Practical Cryptography, Wiley 2003

Version:
1.0
Author:
Rene Mayrhofer

Constructor Summary
Hash()
           
 
Method Summary
static byte[] doubleSHA256(byte[] text, boolean useJSSE)
          This is a small utility function for computing a secure hash from the shared key.
static byte[] hmacSHA256(byte[] text, byte[] key, boolean useJSSE)
          This is a small utility function for computing HMAC-SHA256 in its standard definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hash

public Hash()
Method Detail

doubleSHA256

public static byte[] doubleSHA256(byte[] text,
                                  boolean useJSSE)
                           throws InternalApplicationException
This is a small utility function for computing a secure hash from the shared key.

Parameters:
text - The text to hash, it may be of arbitrary length.
useJSSE - If set to true, the JSSE API with the default JCE provider of the JVM will be used for cryptographic operations. If set to false, an internal copy of the Bouncycastle Lightweight API classes will be used.
Returns:
The SHAd-256 hash over text.
Throws:
InternalApplicationException

hmacSHA256

public static byte[] hmacSHA256(byte[] text,
                                byte[] key,
                                boolean useJSSE)
                         throws InternalApplicationException
This is a small utility function for computing HMAC-SHA256 in its standard definition. HMAC-SHA256 is defined as \mathrm{HMAC}_K(m) = h\bigg((K \oplus \mathrm{opad}) \| h\big((K \oplus \mathrm{ipad}) \| m\big)\bigg)

Parameters:
text - The text to hash, it may be of arbitrary length.
key - The key for the HMAC. It should conform to the block size of the underlying hash function, i.e. 256 Bits / 32 Bytes, but will be hashed if longer or zero-padded if shorter. For a guaranteed security level of 128 Bits, you must use a 256 Bit key. To fulfill the security assumptions of HMAC, this key must be kept secret.
useJSSE - If set to true, the JSSE API with the default JCE provider of the JVM will be used for cryptographic operations. If set to false, an internal copy of the Bouncycastle Lightweight API classes will be used.
Returns:
The HMAC-SHA256 value.
Throws:
InternalApplicationException


2005-2009, Rene Mayrhofer.