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

public Class Blake2xsDigest

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

Implementation of the eXtendable Output Function (XOF) BLAKE2xs.

BLAKE2xs offers a built-in keying mechanism to be used directly for authentication ("Prefix-MAC") rather than a HMAC construction.

BLAKE2xs offers a built-in support for a salt for randomized hashing and a personal string for defining a unique hash function for each application.

BLAKE2xs is optimized for 32-bit platforms and produces digests of any size between 1 and 2^16-2 bytes. The length can also be unknown and then the maximum length will be 2^32 blocks of 32 bytes.

Field Summary

Modifier and TypeField and Description
private long
blockPos

Keep track of the round number to detect the end of the digest after 2^32 blocks of 32 bytes.

private byte[]
buf

Digest of each round of the XOF

private int
bufPos

Current position for a round

private static final int
private int
digestLength

Expected digest length for the xof.

private int
digestPos

Overall position of the digest.

private byte[]
h0

Digest of the root hash

private Blake2sDigest
hash

Root hash that will take the updates

private static final long
private long
nodeOffset

Current node offset incremented by 1 every round.

private final CryptoServicePurpose
public static final int
UNKNOWN_DIGEST_LENGTH

Magic number to indicate an unknown length of digest

Constructor Summary

AccessConstructor and Description
public
Blake2xsDigest()

BLAKE2xs for hashing with unknown digest length

public
Blake2xsDigest(int
The desired digest length in bytes. Must be above 1 and less than 2^16-1
digestBytes
,
CryptoServicePurpose purpose)

BLAKE2xs for hashing

public
Blake2xsDigest(int digestBytes)

public
Blake2xsDigest(int
The desired digest length in bytes. Must be above 1 and less than 2^16-1
digestBytes
,
byte[]
A key up to 32 bytes or null
key
)

BLAKE2xs with key

public
Blake2xsDigest(int
The desired digest length in bytes. Must be above 1 and less than 2^16-1
digestBytes
,
byte[]
A key up to 32 bytes or null
key
,
byte[]
8 bytes or null
salt
,
byte[]
8 bytes or null
personalization
,
CryptoServicePurpose purpose)

BLAKE2xs with key, salt and personalization

public

Method Summary

Modifier and TypeMethod and Description
private long
private int
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.

public int
doFinal(byte[]
output array to write the output bytes to.
out
,
int
offset to start writing the bytes at.
outOff
,
int
the number of output bytes requested.
outLen
)

Implements org.bouncycastle.crypto.Xof.doFinal.

Close the digest, producing the final digest value.

public int

Returns:

the number of bytes written
doOutput
(byte[]
output array to write the output bytes to.
out
,
int
offset to start writing the bytes at.
outOff
,
int
the number of output bytes requested.
outLen
)

Implements org.bouncycastle.crypto.Xof.doOutput.

Start outputting the results of the final calculation for this digest.

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.

public long

Returns:

byte length of the largest digest with unknown length
getUnknownMaxLength
()

Return the maximum size in bytes the digest can produce when the length is unknown

public void
reset()

Implements org.bouncycastle.crypto.Digest.reset.

Reset the digest back to its initial state.

public void
update(byte
the input byte to be entered.
in
)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a single byte.

public void
update(byte[]
the byte array containing the data.
in
,
int
the offset into the byte array where the data starts.
inOff
,
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

blockPosback to summary
private long blockPos

Keep track of the round number to detect the end of the digest after 2^32 blocks of 32 bytes.

bufback to summary
private byte[] buf

Digest of each round of the XOF

bufPosback to summary
private int bufPos

Current position for a round

DIGEST_LENGTHback to summary
private static final int DIGEST_LENGTH
digestLengthback to summary
private int digestLength

Expected digest length for the xof. It can be unknown.

digestPosback to summary
private int digestPos

Overall position of the digest. It is useful when the length is known in advance to get last block length.

h0back to summary
private byte[] h0

Digest of the root hash

hashback to summary
private Blake2sDigest hash

Root hash that will take the updates

MAX_NUMBER_BLOCKSback to summary
private static final long MAX_NUMBER_BLOCKS
nodeOffsetback to summary
private long nodeOffset

Current node offset incremented by 1 every round.

purposeback to summary
private final CryptoServicePurpose purpose
UNKNOWN_DIGEST_LENGTHback to summary
public static final int UNKNOWN_DIGEST_LENGTH

Magic number to indicate an unknown length of digest

Constructor Detail

Blake2xsDigestback to summary
public Blake2xsDigest()

BLAKE2xs for hashing with unknown digest length

Blake2xsDigestback to summary
public Blake2xsDigest(int digestBytes, CryptoServicePurpose purpose)

BLAKE2xs for hashing

Parameters
digestBytes:int

The desired digest length in bytes. Must be above 1 and less than 2^16-1

Blake2xsDigestback to summary
public Blake2xsDigest(int digestBytes)
Blake2xsDigestback to summary
public Blake2xsDigest(int digestBytes, byte[] key)

BLAKE2xs with key

Parameters
digestBytes:int

The desired digest length in bytes. Must be above 1 and less than 2^16-1

key:byte[]

A key up to 32 bytes or null

Blake2xsDigestback to summary
public Blake2xsDigest(int digestBytes, byte[] key, byte[] salt, byte[] personalization, CryptoServicePurpose purpose)

BLAKE2xs with key, salt and personalization

Parameters
digestBytes:int

The desired digest length in bytes. Must be above 1 and less than 2^16-1

key:byte[]

A key up to 32 bytes or null

salt:byte[]

8 bytes or null

personalization:byte[]

8 bytes or null

Blake2xsDigestback to summary
public Blake2xsDigest(Blake2xsDigest digest)

Method Detail

computeNodeOffsetback to summary
private long computeNodeOffset()
computeStepLengthback to summary
private int computeStepLength()
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.

doFinalback to summary
public int doFinal(byte[] out, int outOff, int outLen)

Implements org.bouncycastle.crypto.Xof.doFinal.

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

Parameters
out:byte[]

output array to write the output bytes to.

outOff:int

offset to start writing the bytes at.

outLen:int

the number of output bytes requested.

Returns:int

Doc from org.bouncycastle.crypto.Xof.doFinal.

the number of bytes written

doOutputback to summary
public int doOutput(byte[] out, int outOff, int outLen)

Implements org.bouncycastle.crypto.Xof.doOutput.

Start outputting the results of the final calculation for this digest. Unlike doFinal, this method will continue producing output until the Xof is explicitly reset, or signals otherwise.

Parameters
out:byte[]

output array to write the output bytes to.

outOff:int

offset to start writing the bytes at.

outLen:int

the number of output bytes requested.

Returns:int

the number of bytes written

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.

getUnknownMaxLengthback to summary
public long getUnknownMaxLength()

Return the maximum size in bytes the digest can produce when the length is unknown

Returns:long

byte length of the largest digest with unknown length

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.

updateback to summary
public void update(byte in)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a single byte.

Parameters
in:byte

the input byte to be entered.

updateback to summary
public void update(byte[] in, int inOff, int len)

Implements org.bouncycastle.crypto.Digest.update.

Update the message digest with a block of bytes.

Parameters
in:byte[]

the byte array containing the data.

inOff:int

the offset into the byte array where the data starts.

len:int

the length of the data.