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:
name, truncatedSize, underlyingHash
MAC_KEY_MATERIAL, TRUNCATED_SIZE
Constructor and Description |
---|
UHash32()
Trivial 0-arguments constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
public java.lang.Object clone()
IMac
Returns a clone copy of this instance.
public int macSize()
IMac
Returns the output length in bytes of this MAC algorithm.
public void init(java.util.Map attributes) throws java.security.InvalidKeyException, java.lang.IllegalStateException
IMac
Initialises the algorithm with designated attributes. Permissible names and values are described in the class documentation above.
init
in interface IMac
init
in class BaseMac
attributes
- a set of name-value pairs that describe the desired
future instance behaviour.java.security.InvalidKeyException
- if the key data is invalid.java.lang.IllegalStateException
- if the instance is already initialised.IMac.MAC_KEY_MATERIAL
public void update(byte b)
IMac
Continues a MAC operation using the input byte.
public void update(byte[] b, int offset, int len)
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.
public byte[] digest()
IMac
Completes the MAC by performing final operations such as padding and resetting the instance.
public void reset()
IMac
Resets the algorithm instance for re-initialisation and use with other characteristics. This method always succeeds.
public boolean selfTest()
IMac
A basic test. Ensures that the MAC of a pre-determined message is equal to a known pre-computed value.
Copyright © 2025. All rights reserved.