For the latest news and information visit
The GNU Crypto project

gnu.crypto.mac
Class HMac

java.lang.Object
  extended bygnu.crypto.mac.BaseMac
      extended bygnu.crypto.mac.HMac
All Implemented Interfaces:
java.lang.Cloneable, IMac

public class HMac
extends BaseMac

The implementation of the HMAC (Keyed-Hash Message Authentication Code).

HMAC can be used in combination with any iterated cryptographic hash function. HMAC also uses a secret key for calculation and verification of the message authentication values. The main goals behind this construction are

References:

  1. RFC 2104HMAC: Keyed-Hashing for Message Authentication.
    H. Krawczyk, M. Bellare, and R. Canetti.

Version:
$Revision: 1.2 $

Field Summary
protected  int blockSize
           
protected  byte[] ipad
           
protected  IMessageDigest ipadHash
           
protected  int macSize
           
protected  IMessageDigest opadHash
           
static java.lang.String USE_WITH_PKCS5_V2
           
 
Fields inherited from class gnu.crypto.mac.BaseMac
name, truncatedSize, underlyingHash
 
Fields inherited from interface gnu.crypto.mac.IMac
MAC_KEY_MATERIAL, TRUNCATED_SIZE
 
Constructor Summary
protected HMac(IMessageDigest underlyingHash)
          Trivial constructor for use by concrete subclasses.
 
Method Summary
 java.lang.Object clone()
          Returns a clone copy of this instance.
 byte[] digest()
          Completes the MAC by performing final operations such as padding and resetting the instance.
 void init(java.util.Map attributes)
          Initialises the algorithm with designated attributes.
 void reset()
          Resets the algorithm instance for re-initialisation and use with other characteristics.
 boolean selfTest()
          A basic test.
 
Methods inherited from class gnu.crypto.mac.BaseMac
macSize, name, update, update
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_WITH_PKCS5_V2

public static final java.lang.String USE_WITH_PKCS5_V2
See Also:
Constant Field Values

macSize

protected int macSize

blockSize

protected int blockSize

ipadHash

protected IMessageDigest ipadHash

opadHash

protected IMessageDigest opadHash

ipad

protected byte[] ipad
Constructor Detail

HMac

protected HMac(IMessageDigest underlyingHash)

Trivial constructor for use by concrete subclasses.

Parameters:
underlyingHash - the underlying hash algorithm instance.
Method Detail

clone

public java.lang.Object clone()
Description copied from interface: IMac

Returns a clone copy of this instance.

Specified by:
clone in interface IMac
Specified by:
clone in class BaseMac

init

public void init(java.util.Map attributes)
          throws java.security.InvalidKeyException,
                 java.lang.IllegalStateException
Description copied from interface: IMac

Initialises the algorithm with designated attributes. Permissible names and values are described in the class documentation above.

Specified by:
init in interface IMac
Specified by:
init in class BaseMac
Throws:
java.security.InvalidKeyException
java.lang.IllegalStateException

reset

public void reset()
Description copied from interface: IMac

Resets the algorithm instance for re-initialisation and use with other characteristics. This method always succeeds.

Specified by:
reset in interface IMac
Overrides:
reset in class BaseMac

digest

public byte[] digest()
Description copied from interface: IMac

Completes the MAC by performing final operations such as padding and resetting the instance.

Specified by:
digest in interface IMac
Specified by:
digest in class BaseMac

selfTest

public boolean selfTest()
Description copied from interface: IMac

A basic test. Ensures that the MAC of a pre-determined message is equal to a known pre-computed value.

Specified by:
selfTest in interface IMac
Specified by:
selfTest in class BaseMac

For the latest news and information visit
The GNU Crypto project

Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.