Top Description Fields Constructors Methods
org.bouncycastle.crypto.digests

public Class Blake2sDigest

extends Object
implements ExtendedDigest
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.ExtendedDigest, org.bouncycastle.crypto.Digest
Imports
org.bouncycastle.crypto.CryptoServicePurpose, .CryptoServicesRegistrar, .ExtendedDigest, .OutputLengthException, org.bouncycastle.util.Arrays, .Integers, .Pack

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.

Field Summary

Modifier and TypeField and Description
private static final int[]
blake2s_IV

BLAKE2s Initialization Vector

private static final byte[][]
blake2s_sigma

Message word permutations

private static final int
private byte[]
buffer

Whenever this buffer overflows, it will be processed in the compress() function.

private int
bufferPos

Position of last inserted byte

private int[]
chainValue

State vector, in the BLAKE2 paper it is called h

private int
private int
private int
f0

finalization flag, for last block: ~0

private int
private int
private int
private int[]
internalState

Internal state, in the BLAKE2 paper it is called v

private boolean
private byte[]
private int
private int
private int
private long
private byte[]
private final CryptoServicePurpose
private static final int
private byte[]
private int
t0

holds least significant bits of counter

private int
t1

holds most significant bits of counter

Constructor Summary

AccessConstructor and Description
public
Blake2sDigest()

BLAKE2s-256 for hashing.

public
Blake2sDigest(int
size of digest (in bits)
digestSize
)

Basic sized constructor - size in bits.

public
public
Blake2sDigest(int
the desired digest length in bits. Must be a multiple of 8 and less than 256.
digestBits
,
CryptoServicePurpose
usage purpose.
purpose
)

BLAKE2s for hashing.

public
Blake2sDigest(byte[]
a key up to 32 bytes or null
key
)

BLAKE2s for authentication ("Prefix-MAC mode").

public
Blake2sDigest(byte[] key, CryptoServicePurpose purpose)

public
Blake2sDigest(byte[]
a key up to 32 bytes or null
key
,
int
from 1 up to 32 bytes
digestBytes
,
byte[]
8 bytes or null
salt
,
byte[]
8 bytes or null
personalization
)

BLAKE2s with key, required digest length, salt and personalization.

public
Blake2sDigest(byte[] key, int digestBytes, byte[] salt, byte[] personalization, CryptoServicePurpose purpose)

pack-priv
Blake2sDigest(int digestBytes, byte[] key, byte[] salt, byte[] personalization, long offset, CryptoServicePurpose purpose)

pack-priv
Blake2sDigest(int digestBytes, int hashLength, long offset)

pack-priv
Blake2sDigest(int digestBytes, int hashLength, long offset, CryptoServicePurpose purpose)

pack-priv
Blake2sDigest(byte[] key, byte[] param)

Method Summary

Modifier and TypeMethod and Description
public void
clearKey()

Overwrite the key if it is no longer used (zeroization).

public void
clearSalt()

Overwrite the salt (pepper) if it is secret and no longer used (zeroization).

private void
compress(byte[] message, int messagePos)

public int
doFinal(byte[]
the array the digest is to be copied into.
out
,
int
the offset into the out array the digest is to start at.
outOffset
)

Implements org.bouncycastle.crypto.Digest.doFinal.

Close the digest, producing the final digest value.
private void
G(int m1, int m2, int posA, int posB, int posC, int posD)

public String

Returns:

the algorithm name
getAlgorithmName
()

Implements org.bouncycastle.crypto.Digest.getAlgorithmName.

Return the algorithm name.
public int

Returns:

byte length of the digest's internal buffer.
getByteLength
()

Implements org.bouncycastle.crypto.ExtendedDigest.getByteLength.

Return the size in bytes of the internal buffer the digest applies its compression function to.
public int

Returns:

the size in bytes of the digest produced by this message digest.
getDigestSize
()

Implements org.bouncycastle.crypto.Digest.getDigestSize.

Return the size in bytes of the digest produced by this message digest.
private void
init(byte[] salt, byte[] personalization, byte[] key)

private void
public void
reset()

Implements org.bouncycastle.crypto.Digest.reset.

Reset the digest back to its initial state.
protected void
public void
update(byte
the input byte to be entered.
b
)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a single byte.
public void
update(byte[]
the byte array containing the data.
message
,
int
the offset into the byte array where the data starts.
offset
,
int
the length of the data.
len
)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a block of bytes.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blake2s_IVback to summary
private static final int[] blake2s_IV

BLAKE2s Initialization Vector

blake2s_sigmaback to summary
private static final byte[][] blake2s_sigma

Message word permutations

BLOCK_LENGTH_BYTESback to summary
private static final int BLOCK_LENGTH_BYTES
bufferback to summary
private byte[] buffer

Whenever this buffer overflows, it will be processed in the compress() function. For performance issues, long messages will not use this buffer.

bufferPosback to summary
private int bufferPos

Position of last inserted byte

chainValueback to summary
private int[] chainValue

State vector, in the BLAKE2 paper it is called h

depthback to summary
private int depth
digestLengthback to summary
private int digestLength
f0back to summary
private int f0

finalization flag, for last block: ~0

f1back to summary
private int f1
fanoutback to summary
private int fanout
innerHashLengthback to summary
private int innerHashLength
internalStateback to summary
private int[] internalState

Internal state, in the BLAKE2 paper it is called v

isLastNodeback to summary
private boolean isLastNode
keyback to summary
private byte[] key
keyLengthback to summary
private int keyLength
leafLengthback to summary
private int leafLength
nodeDepthback to summary
private int nodeDepth
nodeOffsetback to summary
private long nodeOffset
personalizationback to summary
private byte[] personalization
purposeback to summary
private final CryptoServicePurpose purpose
ROUNDSback to summary
private static final int ROUNDS
saltback to summary
private byte[] salt
t0back to summary
private int t0

holds least significant bits of counter

t1back to summary
private int t1

holds most significant bits of counter

Constructor Detail

Blake2sDigestback to summary
public Blake2sDigest()

BLAKE2s-256 for hashing.

Blake2sDigestback to summary
public Blake2sDigest(int digestSize)

Basic sized constructor - size in bits.

Parameters
digestSize:int

size of digest (in bits)

Blake2sDigestback to summary
public Blake2sDigest(Blake2sDigest digest)
Blake2sDigestback to summary
public Blake2sDigest(int digestBits, CryptoServicePurpose purpose)

BLAKE2s for hashing.

Parameters
digestBits:int

the desired digest length in bits. Must be a multiple of 8 and less than 256.

purpose:CryptoServicePurpose

usage purpose.

Blake2sDigestback to summary
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:byte[]

a key up to 32 bytes or null

Blake2sDigestback to summary
public Blake2sDigest(byte[] key, CryptoServicePurpose purpose)
Blake2sDigestback to summary
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:byte[]

a key up to 32 bytes or null

digestBytes:int

from 1 up to 32 bytes

salt:byte[]

8 bytes or null

personalization:byte[]

8 bytes or null

Blake2sDigestback to summary
public Blake2sDigest(byte[] key, int digestBytes, byte[] salt, byte[] personalization, CryptoServicePurpose purpose)
Blake2sDigestback to summary
pack-priv Blake2sDigest(int digestBytes, byte[] key, byte[] salt, byte[] personalization, long offset, CryptoServicePurpose purpose)
Blake2sDigestback to summary
pack-priv Blake2sDigest(int digestBytes, int hashLength, long offset)
Blake2sDigestback to summary
pack-priv Blake2sDigest(int digestBytes, int hashLength, long offset, CryptoServicePurpose purpose)
Blake2sDigestback to summary
pack-priv Blake2sDigest(byte[] key, byte[] param)

Method Detail

clearKeyback to summary
public void clearKey()

Overwrite the key if it is no longer used (zeroization).

clearSaltback to summary
public void clearSalt()

Overwrite the salt (pepper) if it is secret and no longer used (zeroization).

compressback to summary
private void compress(byte[] message, int messagePos)
doFinalback to summary
public int doFinal(byte[] out, int outOffset)

Implements org.bouncycastle.crypto.Digest.doFinal.

Close the digest, producing the final digest value. The doFinal() call leaves the digest reset. Key, salt and personal string remain.

Parameters
out:byte[]

the array the digest is to be copied into.

outOffset:int

the offset into the out array the digest is to start at.

Gback to summary
private void G(int m1, int m2, int posA, int posB, int posC, int posD)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.Digest.getAlgorithmName.

Return the algorithm name.

Returns:String

the algorithm name

getByteLengthback to summary
public int getByteLength()

Implements org.bouncycastle.crypto.ExtendedDigest.getByteLength.

Return the size in bytes of the internal buffer the digest applies its compression function to.

Returns:int

byte length of the digest's internal buffer.

getDigestSizeback to summary
public int getDigestSize()

Implements org.bouncycastle.crypto.Digest.getDigestSize.

Return the size in bytes of the digest produced by this message digest.

Returns:int

the size in bytes of the digest produced by this message digest.

initback to summary
private void init(byte[] salt, byte[] personalization, byte[] key)
initializeInternalStateback to summary
private void initializeInternalState()
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.Digest.reset.

Reset the digest back to its initial state. The key, the salt and the personal string will remain for further computations.

setAsLastNodeback to summary
protected void setAsLastNode()
updateback to summary
public void update(byte b)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a single byte.

Parameters
b:byte

the input byte to be entered.

updateback to summary
public void update(byte[] message, int offset, int len)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a block of bytes.

Parameters
message:byte[]

the byte array containing the data.

offset:int

the offset into the byte array where the data starts.

len:int

the length of the data.