Package org.bouncycastle.crypto.digests
Class Blake2sDigest
- java.lang.Object
-
- org.bouncycastle.crypto.digests.Blake2sDigest
-
- All Implemented Interfaces:
Digest
,ExtendedDigest
public class Blake2sDigest extends java.lang.Object implements ExtendedDigest
Implementation of the cryptographic hash function BLAKE2s. BLAKE2s offers a built-in keying mechanism to be used directly for authentication ("Prefix-MAC") rather than a HMAC construction. BLAKE2s offers a built-in support for a salt for randomized hashing and a personal string for defining a unique hash function for each application. BLAKE2s is optimized for 32-bit platforms and produces digests of any size between 1 and 32 bytes.
-
-
Constructor Summary
Constructors Constructor Description Blake2sDigest()
BLAKE2s-256 for hashing.Blake2sDigest(byte[] key)
BLAKE2s for authentication ("Prefix-MAC mode").Blake2sDigest(byte[] key, int digestBytes, byte[] salt, byte[] personalization)
BLAKE2s with key, required digest length, salt and personalization.Blake2sDigest(int digestBits)
BLAKE2s for hashing.Blake2sDigest(Blake2sDigest digest)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearKey()
Overwrite the key if it is no longer used (zeroization).void
clearSalt()
Overwrite the salt (pepper) if it is secret and no longer used (zeroization).int
doFinal(byte[] out, int outOffset)
Close the digest, producing the final digest value.java.lang.String
getAlgorithmName()
Return the algorithm name.int
getByteLength()
Return the size in bytes of the internal buffer the digest applies its compression function to.int
getDigestSize()
Return the size in bytes of the digest produced by this message digest.void
reset()
Reset the digest back to its initial state.void
update(byte b)
Update the message digest with a single byte.void
update(byte[] message, int offset, int len)
Update the message digest with a block of bytes.
-
-
-
Constructor Detail
-
Blake2sDigest
public Blake2sDigest()
BLAKE2s-256 for hashing.
-
Blake2sDigest
public Blake2sDigest(Blake2sDigest digest)
-
Blake2sDigest
public Blake2sDigest(int digestBits)
BLAKE2s for hashing.- Parameters:
digestBits
- the desired digest length in bits. Must be a multiple of 8 and less than 256.
-
Blake2sDigest
public Blake2sDigest(byte[] key)
BLAKE2s for authentication ("Prefix-MAC mode"). After calling the doFinal() method, the key will remain to be used for further computations of this instance. The key can be overwritten using the clearKey() method.- Parameters:
key
- a key up to 32 bytes or null
-
Blake2sDigest
public Blake2sDigest(byte[] key, int digestBytes, byte[] salt, byte[] personalization)
BLAKE2s with key, required digest length, salt and personalization. After calling the doFinal() method, the key, the salt and the personal string will remain and might be used for further computations with this instance. The key can be overwritten using the clearKey() method, the salt (pepper) can be overwritten using the clearSalt() method.- Parameters:
key
- a key up to 32 bytes or nulldigestBytes
- from 1 up to 32 bytessalt
- 8 bytes or nullpersonalization
- 8 bytes or null
-
-
Method Detail
-
update
public void update(byte b)
Update the message digest with a single byte.
-
update
public void update(byte[] message, int offset, int len)
Update the message digest with a block of bytes.
-
doFinal
public int doFinal(byte[] out, int outOffset)
Close the digest, producing the final digest value. The doFinal() call leaves the digest reset. Key, salt and personal string remain.
-
reset
public void reset()
Reset the digest back to its initial state. The key, the salt and the personal string will remain for further computations.
-
getAlgorithmName
public java.lang.String getAlgorithmName()
Return the algorithm name.- Specified by:
getAlgorithmName
in interfaceDigest
- Returns:
- the algorithm name
-
getDigestSize
public int getDigestSize()
Return the size in bytes of the digest produced by this message digest.- Specified by:
getDigestSize
in interfaceDigest
- Returns:
- the size in bytes of the digest produced by this message digest.
-
getByteLength
public int getByteLength()
Return the size in bytes of the internal buffer the digest applies its compression function to.- Specified by:
getByteLength
in interfaceExtendedDigest
- Returns:
- byte length of the digest's internal buffer.
-
clearKey
public void clearKey()
Overwrite the key if it is no longer used (zeroization).
-
clearSalt
public void clearSalt()
Overwrite the salt (pepper) if it is secret and no longer used (zeroization).
-
-