public final class SHA3_256
extends java.security.MessageDigest
NIST (FIPS PUB 202) specifies the Secure Hash Algorithm-3 (SHA-3) family of message digest algorithms as supplement of the SHA-1 and SHA-2 message digest algorithm family. SHA-3 is based on the KECCAK message digest algorithm but is not fully identical to KECCAK because it adds a suffix to the message to ensure domain separation between the SHA-3 hash function and the newly specified SHA-3 extendable-output function (XOF). The XOF allows the output to be extended to any desired length.
This class implements the SHA3-256 hash function that produces a 256-bit
hash-value of the given input data. Since SHA3-256 and KECCAK256 are not
identical a SHA3-256 MessageDigest engine will produce a different output
than a KECCAK256 MessageDigest engine. To ensure to use the NIST standardized
version, specify SHA3-256
as algorithm name when instantiating
a SHA3-256 MessageDigest engine:
MessageDigest sha3 = MessageDigest.getInstance("SHA3-256");After having created the MessageDigest engine, you can supply the data to be hashed by one or more calls to one of the
update
methods,
e.g:
sha3.update(m1); sha3.update(m2); ...Finally, the hash value can be computed using one of the
digest
methods:
byte[] hash_value = sha3.digest();There are several ways for combining
update
and
digest
methods for computing a message digest.
When the hash value successfully has been computed, the SHA-3 MessageDigest
object automatically resets for being able to be supplied with new data to be
hashed.MessageDigest
Constructor and Description |
---|
SHA3_256()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
protected void |
doPadding() |
protected void |
engineCompress(byte[] input,
int offset) |
protected byte[] |
engineDigest() |
protected void |
engineDigest(byte[] output,
int offset) |
protected int |
engineDigest(byte[] buf,
int offset,
int len)
Calculates the digest value and writes it to the given
output buffer.
|
protected int |
engineGetDigestLength() |
protected void |
engineReset() |
protected void |
engineUpdate(byte input) |
protected void |
engineUpdate(byte[] input,
int offset,
int len) |
protected int engineGetDigestLength()
engineGetDigestLength
in class java.security.MessageDigestSpi
protected void engineCompress(byte[] input, int offset)
protected void doPadding()
protected void engineDigest(byte[] output, int offset)
protected byte[] engineDigest()
engineDigest
in class java.security.MessageDigestSpi
protected int engineDigest(byte[] buf, int offset, int len) throws java.security.DigestException
engineDigest
in class java.security.MessageDigestSpi
buf
- the output buffer in which to write the digestoffset
- the start offset in the output bufferlen
- the length of the digest value.java.security.DigestException
- if an error occurs when calculating the digest value.protected void engineUpdate(byte input)
engineUpdate
in class java.security.MessageDigestSpi
protected void engineUpdate(byte[] input, int offset, int len)
engineUpdate
in class java.security.MessageDigestSpi
protected void engineReset()
engineReset
in class java.security.MessageDigestSpi
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.security.MessageDigest
java.lang.CloneNotSupportedException