For the latest news and information visit
The GNU Crypto project

gnu.crypto.mac
Class UHash32

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

public class UHash32
extends BaseMac

UHASH is a keyed hash function, which takes as input a string of arbitrary length, and produces as output a string of fixed length (such as 8 bytes). The actual output length depends on the parameter UMAC-OUTPUT-LEN.

UHASH has been shown to be epsilon-ASU ("Almost Strongly Universal"), where epsilon is a small (parameter-dependent) real number. Informally, saying that a keyed hash function is epsilon-ASU means that for any two distinct fixed input strings, the two outputs of the hash function with a random key "look almost like a pair of random strings". The number epsilon measures how non-random the output strings may be.

UHASH has been designed to be fast by exploiting several architectural features of modern commodity processors. It was specifically designed for use in UMAC. But UHASH is useful beyond that domain, and can be easily adopted for other purposes.

UHASH does its work in three layers. First, a hash function called NH is used to compress input messages into strings which are typically many times smaller than the input message. Second, the compressed message is hashed with an optimized polynomial hash function into a fixed-length 16-byte string. Finally, the 16-byte string is hashed using an inner-product hash into a string of length WORD-LEN bytes. These three layers are repeated (with a modified key) until the outputs total UMAC-OUTPUT-LEN bytes.

References:

  1. UMAC: Message Authentication Code using Universal Hashing.
    T. Krovetz, J. Black, S. Halevi, A. Hevia, H. Krawczyk, and P. Rogaway.

Version:
$Revision: 1.2 $

Nested Class Summary
(package private)  class UHash32.L1Hash32
          First hash stage of the UHash32 algorithm.
(package private)  class UHash32.L2Hash32
          Second hash stage of the UHash32 algorithm.
(package private)  class UHash32.L3Hash32
          Third hash stage of the UHash32 algorithm.
 
Field Summary
(package private) static byte[] ALL_ZEROES
           
(package private) static long BOUNDARY
           
(package private)  UHash32.L1Hash32[] l1hash
           
(package private) static java.math.BigInteger LOWER_RANGE
           
(package private)  int streams
           
(package private) static java.math.BigInteger TWO
           
(package private) static java.math.BigInteger UPPER_RANGE
           
 
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
UHash32()
          Trivial 0-arguments constructor.
 
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.
 int macSize()
          Returns the output length in bytes of this MAC algorithm.
(package private) static java.math.BigInteger prime(int n)
          The prime numbers used in UMAC are: +-----+--------------------+---------------------------------------+ | x | prime(x) [Decimal] | prime(x) [Hexadecimal] | +-----+--------------------+---------------------------------------+ | 19 | 2^19 - 1 | 0x0007FFFF | | 32 | 2^32 - 5 | 0xFFFFFFFB | | 36 | 2^36 - 5 | 0x0000000F FFFFFFFB | | 64 | 2^64 - 59 | 0xFFFFFFFF FFFFFFC5 | | 128 | 2^128 - 159 | 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFF61 | +-----+--------------------+---------------------------------------+
 void reset()
          Resets the algorithm instance for re-initialisation and use with other characteristics.
 boolean selfTest()
          A basic test.
 void update(byte b)
          Continues a MAC operation using the input byte.
 void update(byte[] b, int offset, int len)
          Continues a MAC operation, by filling the buffer, processing data in the algorithm's MAC_SIZE-bit block(s), updating the context and count, and buffering the remaining bytes in buffer for the next operation.
 
Methods inherited from class gnu.crypto.mac.BaseMac
name
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TWO

static final java.math.BigInteger TWO

BOUNDARY

static final long BOUNDARY

LOWER_RANGE

static final java.math.BigInteger LOWER_RANGE

UPPER_RANGE

static final java.math.BigInteger UPPER_RANGE

ALL_ZEROES

static final byte[] ALL_ZEROES

streams

int streams

l1hash

UHash32.L1Hash32[] l1hash
Constructor Detail

UHash32

public UHash32()
Trivial 0-arguments constructor.

Method Detail

prime

static final java.math.BigInteger prime(int n)

The prime numbers used in UMAC are:

   +-----+--------------------+---------------------------------------+
   |  x  | prime(x) [Decimal] | prime(x) [Hexadecimal]                |
   +-----+--------------------+---------------------------------------+
   | 19  | 2^19  - 1          | 0x0007FFFF                            |
   | 32  | 2^32  - 5          | 0xFFFFFFFB                            |
   | 36  | 2^36  - 5          | 0x0000000F FFFFFFFB                   |
   | 64  | 2^64  - 59         | 0xFFFFFFFF FFFFFFC5                   |
   | 128 | 2^128 - 159        | 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFF61 |
   +-----+--------------------+---------------------------------------+

Parameters:
n - a number of bits.
Returns:
the largest prime number less than 2**n.

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

macSize

public int macSize()
Description copied from interface: IMac

Returns the output length in bytes of this MAC algorithm.

Specified by:
macSize in interface IMac
Overrides:
macSize 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

update

public void update(byte b)
Description copied from interface: IMac

Continues a MAC operation using the input byte.

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

update

public void update(byte[] b,
                   int offset,
                   int len)
Description copied from interface: IMac

Continues a MAC operation, by filling the buffer, processing data in the algorithm's MAC_SIZE-bit block(s), updating the context and count, and buffering the remaining bytes in buffer for the next operation.

Specified by:
update in interface IMac
Overrides:
update 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

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

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.