au.net.aba.crypto.provider
Class HMACwithAnyMD

java.lang.Object
  |
  +--javax.crypto.MacSpi
        |
        +--au.net.aba.crypto.provider.HMACwithAnyMD
Direct Known Subclasses:
HMACwithMD5, HMACwithSHA1

public class HMACwithAnyMD
extends MacSpi
implements java.lang.Cloneable

The specification for HMAC came from the HMAC Construction publication in RSA CryptoBytes, Spring of 1996. http://www.rsasecurity.com/rsalabs/cryptobytes.

The algorithm for the HMAC for a given key (K) and text (Text) is as follows: HMAC(K, Text) = H(K > Opad, H(K > IPad, Text))

Namely, 1) Append zeroes to the end of K to create a 64 byte string 2) XOR the 64-byte string computed in (1) with Ipad 3) Append the data stream Text to the 64-byte string computed in (2) 4) Apply H to the stream generated in (3) 5) XOR the 64-byte stringin (1) with Opad 6) Append the H result from (4) to the 64-byte string from (5) 7) Apply H to the stream generated in (6) and output result

NOTE:
Subclasses need to set the class variable _digest to an instance of the message digest they implement


Field Summary
protected  java.security.MessageDigest _digest
          The MD function.
 
Constructor Summary
HMACwithAnyMD()
           
 
Method Summary
protected  byte[] engineDoFinal()
          Completes the MAC computation and resets the MAC for further use, maintaining the secret key that the MAC was initialized with.
protected  int engineGetMacLength()
          Returns the length of the MAC in bytes.
protected  void engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec keyParams)
          Initializes the MAC with the given (secret) key and algorithm parameters.
protected  void engineReset()
          Resets the MAC for further use, maintaining the secret key that the MAC was initialized with.
protected  void engineUpdate(byte input)
          Processes the given byte
protected  void engineUpdate(byte[] input, int offset, int length)
          Processes the first len bytes in input, starting at offset inclusive.
 
Methods inherited from class javax.crypto.MacSpi
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_digest

protected java.security.MessageDigest _digest
The MD function. subclasses set this variable in their constructors.
Constructor Detail

HMACwithAnyMD

public HMACwithAnyMD()
Method Detail

engineInit

protected void engineInit(java.security.Key key,
                          java.security.spec.AlgorithmParameterSpec keyParams)
                   throws java.security.InvalidKeyException,
                          java.security.InvalidAlgorithmParameterException
Initializes the MAC with the given (secret) key and algorithm parameters.

Overrides:
engineInit in class MacSpi
Parameters:
key - the (secret) key
keyParams - the algorithm parameters

engineGetMacLength

protected int engineGetMacLength()
Description copied from class: MacSpi
Returns the length of the MAC in bytes.
Overrides:
engineGetMacLength in class MacSpi
Returns:
the length of the MAC in bytes

engineUpdate

protected void engineUpdate(byte input)
Processes the given byte

Overrides:
engineUpdate in class MacSpi
Parameters:
input - the input byte to process

engineUpdate

protected void engineUpdate(byte[] input,
                            int offset,
                            int length)
Processes the first len bytes in input, starting at offset inclusive.

Overrides:
engineUpdate in class MacSpi
Parameters:
input - the input buffer
offset - the offset in input where the input starts
len - the number of bytes to process

engineDoFinal

protected byte[] engineDoFinal()
Completes the MAC computation and resets the MAC for further use, maintaining the secret key that the MAC was initialized with.

Overrides:
engineDoFinal in class MacSpi
Returns:
the HMAC result as byte[]

engineReset

protected void engineReset()
Resets the MAC for further use, maintaining the secret key that the MAC was initialized with.
Overrides:
engineReset in class MacSpi