edu.harvard.deas.hyperenc
Class HyperMAC

java.lang.Object
  extended by edu.harvard.deas.hyperenc.HyperMAC
All Implemented Interfaces:
Serializable

public class HyperMAC
extends Object
implements Serializable

Represents a MAC computed with the Hyper-Encryption Message Authentication Code (HEMAC) algorithm. Also includes methods to compute and verify HEMACs.

HEMAC makes use of HMAC, specified in RFC 2104. HEMAC makes use of a cryptographic hash function h with output length L, and a secret key K of length 2L. The HEMAC of a message x is computed as follows:

HEMAC(K, x) = K[0:L] ^ HMACh(K[L:2L], x)
where ^ represents the XOR operation, and K[i:j] represents the ith through jth bits of K (including i, but excluding j).

HEMAC uses a similar naming scheme as HMAC: for example, if the underlying hash function h is SHA1, then the resulting HEMAC is called HEMAC-SHA1.

See Also:
Serialized Form

Constructor Summary
HyperMAC(List<Integer> blockList, byte[] mac)
          Constructs a new HEMAC blob.
 
Method Summary
static byte[] computeMac(Mac hmac, byte[] key, byte[] msg)
          Computes the HEMAC of msg using the given secret key and HMAC instance.
 List<Integer> getBlockList()
          Returns the list of IDs that identify the encryption blocks used for the key to this HEMAC.
 byte[] getMac()
          Returns the HEMAC value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HyperMAC

public HyperMAC(List<Integer> blockList,
                byte[] mac)
Constructs a new HEMAC blob.

Parameters:
blockList - List of encryption block IDs used as the HEMAC key.
mac - The HEMAC value itself.
Method Detail

getBlockList

public List<Integer> getBlockList()
Returns the list of IDs that identify the encryption blocks used for the key to this HEMAC.

Returns:
the encryption block ID list

getMac

public byte[] getMac()
Returns the HEMAC value.

Returns:
the HEMAC value, computed as described in this class

computeMac

public static final byte[] computeMac(Mac hmac,
                                      byte[] key,
                                      byte[] msg)
                               throws InvalidKeyException
Computes the HEMAC of msg using the given secret key and HMAC instance.

Parameters:
hmac - A Mac instance representing the HMAC to be used by this HEMAC. This Mac object will be initialized using Mac.init(Key), so any state it currently holds will be lost.
key - The secret key for this HEMAC. Must be exactly twice the length of the length of the output of hmac.
msg - The message for which to compute the HEMAC.
Returns:
the HEMAC of msg, using the specified HMAC and key.
Throws:
InvalidKeyException - if the provided key has incorrect length