public class CmpRfc4210CompliantHasher
extends java.lang.Object
| Constructor and Description |
|---|
CmpRfc4210CompliantHasher(java.security.MessageDigest messageDigest)
A constructor; creates and initializes an
CMP4210Hasher
object that uses the provided MessageDigest to do the
hashing. |
CmpRfc4210CompliantHasher(java.security.MessageDigest messageDigest,
byte[] input)
A constructor; creates and initializes an
CMP4210Hasher
object that uses the provided MessageDigest to do the
hashing. |
CmpRfc4210CompliantHasher(java.lang.String algorithm)
A constructor; creates and initializes an
ExtendedHasher
object that uses the specified hashing algorithm to do the hashing. |
CmpRfc4210CompliantHasher(java.lang.String algorithm,
byte[] input)
A constructor; creates and initializes an
ExtendedHasher
object that uses the specified hashing algorithm to do the hashing. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getOutput(int nIterations)
Hashes the input byte array the specified number of times.
|
byte[] |
getOutput(int requiredKeySize,
int nIterations)
Hashes the input byte array the specified number of times and returns the
requested number of bytes (requiredKeySize), truncating or stretching the key as required.
|
void |
setInput(byte[] input)
Sets the input byte array to be used by the extended hasher, and resets
all internal data in preparation for a new hashing session.
|
void |
wipe()
Wipes all internal data.
|
public CmpRfc4210CompliantHasher(java.lang.String algorithm)
throws java.security.NoSuchAlgorithmException
ExtendedHasher
object that uses the specified hashing algorithm to do the hashing.algorithm - the hashing algorithmjava.security.NoSuchAlgorithmException - thrown if the hashing algorithm
is not recognizedpublic CmpRfc4210CompliantHasher(java.lang.String algorithm,
byte[] input)
throws java.security.NoSuchAlgorithmException
ExtendedHasher
object that uses the specified hashing algorithm to do the hashing.algorithm - the hashing algorithminput - data to hashjava.security.NoSuchAlgorithmException - thrown if the hashing algorithm
is not recognizedpublic CmpRfc4210CompliantHasher(java.security.MessageDigest messageDigest,
byte[] input)
throws java.lang.IllegalArgumentException
CMP4210Hasher
object that uses the provided MessageDigest to do the
hashing.messageDigest - a MessageDigest that
will be used for all hashinginput - data to hashjava.lang.IllegalArgumentException - thrown if either parameter is
null or the input is empty.public CmpRfc4210CompliantHasher(java.security.MessageDigest messageDigest)
CMP4210Hasher
object that uses the provided MessageDigest to do the
hashing.messageDigest - a MessageDigest that
will be used for all hashingjava.lang.IllegalArgumentException - thrown if either parameter is
null or the input is empty.public void setInput(byte[] input)
throws java.lang.IllegalArgumentException
input - the input byte arrayjava.lang.IllegalArgumentException - thrown if the input byte array is
nullpublic byte[] getOutput(int nIterations)
throws java.lang.IllegalArgumentException,
java.lang.NullPointerException
nIterations - the number of times to hash the inputjava.lang.IllegalArgumentException - thrown if the requested number
of bytes is less than zero, or if the requested number of
iterations is less than one (at least one hashing round
must be done)java.lang.NullPointerException - thrown if the input data has not been set yetpublic byte[] getOutput(int requiredKeySize,
int nIterations)
throws java.lang.IllegalArgumentException,
java.lang.NullPointerException
The input is hashed nIterations times. The output of the final iteration (called "BASEKEY" for ease of reference, with a size of "H") is what is used to form the symmetric key. If the MAC algorithm requires a K-bit key and K <= H: the most significant K bits of BASEKEY are used. K > H: all of BASEKEY is used for the most significant H bits of the key, OWF("1" || BASEKEY) is used for the next most significant H bits of the key, OWF("2" || BASEKEY) is used for the next most significant H bits of the key, and so on, until all K bits have been derived.
requiredKeySize - the required key size, in bytes, or 0 if a specific key size isn't required. See RFC 4210 section 5.1.3.1 where this corresponds to 'K' but in bytes instead of bits.nIterations - the number of times to hash the inputjava.lang.IllegalArgumentException - thrown if the requested number
of bytes is less than zero, or if the requested number of
iterations is less than one (at least one hashing round
must be done)java.lang.NullPointerException - thrown if the input data has not been set yetpublic final void wipe()