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

public Class Blake3Digest

extends Object
implements ExtendedDigest, Memoable, Xof
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.Xof, org.bouncycastle.crypto.ExtendedDigest, org.bouncycastle.crypto.Digest, org.bouncycastle.util.Memoable
Imports
java.util.Iterator, .Stack, org.bouncycastle.crypto.CryptoServicePurpose, .CryptoServicesRegistrar, .ExtendedDigest, .OutputLengthException, .Xof, org.bouncycastle.crypto.params.Blake3Parameters, org.bouncycastle.util.Arrays, .Integers, .Memoable, .Pack

Blake3 implementation.

Field Summary

Modifier and TypeField and Description
private static final int
BLOCKLEN

Buffer length.

private static final int
CHAINING0

Chaining0 State Locations.

private static final int
CHAINING1

Chaining1 State Location.

private static final int
CHAINING2

Chaining2 State Location.

private static final int
CHAINING3

Chaining3 State Location.

private static final int
CHAINING4

Chaining4 State Location.

private static final int
CHAINING5

Chaining5 State Location.

private static final int
CHAINING6

Chaining6 State Location.

private static final int
CHAINING7

Chaining7 State Location.

private static final int
CHUNKEND

ChunkEnd Flag.

private static final int
CHUNKLEN

Chunk length.

private static final int
CHUNKSTART

ChunkStart Flag.

private static final int
COUNT0

Count0 State Location.

private static final int
COUNT1

Count1 State Location.

private static final int
DATALEN

DataLen State Location.

private static final int
DERIVECONTEXT

DeriveContext Flag.

private static final int
DERIVEKEY

DeriveKey Flag.

private static final String
ERR_OUTPUTTING

Already outputting error.

private static final int
FLAGS

Flags State Location.

private static final int[]
IV

Blake3 Initialization Vector.

private static final int
IV0

IV0 State Locations.

private static final int
IV1

IV1 State Location.

private static final int
IV2

IV2 State Location.

private static final int
IV3

IV3 State Location.

private static final int
KEYEDHASH

KeyedHash Flag.

private static final int
NUMWORDS

Number of Words.

private long
outputAvailable

How many more bytes can we output?

private boolean
outputting

Are we outputting?

private static final int
PARENT

Parent Flag.

private final CryptoServicePurpose
private static final int
ROOT

Root Flag.

private static final int
ROUNDS

Number of Rounds.

private static final byte[]
SIGMA

Message word permutations.

private final byte[]
theBuffer

The byte input/output buffer.

private final int[]
theChaining

The chaining value.

private long
theCounter

The block counter.

private int
theCurrBytes

The # of bytes in the current block.

private final int
theDigestLen

The default digestLength.

private final byte[]
theIndices

The indices.

private final int[]
theK

The key.

private final int[]
theM

The message Buffer.

private int
theMode

The current mode.

private int
theOutputDataLen

The output dataLen.

private int
theOutputMode

The output mode.

private int
thePos

The position of the next byte in the buffer.

private final Stack<E>
theStack

The chainingStack.

private final int[]
theV

The state.

Constructor Summary

AccessConstructor and Description
public
Blake3Digest()

Constructor.

public
Blake3Digest(final int
the default digest size (in bits)
pDigestSize
)

Constructor.

public
Blake3Digest(final int
size of digest (in bits)
pDigestSize
,
CryptoServicePurpose
usage purpose.
purpose
)

Base constructor with purpose.

public
Blake3Digest(final Blake3Digest
the source digest.
pSource
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
adjustChaining()

Adjust Chaining after compression.

private void
adjustStack()

Adjust the stack.

private void
compress()

Perform compression.

private void
compressBlock(final byte[]
the message buffer
pMessage
,
final int
the position within the message buffer
pMsgPos
)

Compress next block of the message.

private void
compressFinalBlock(final int
the data length
pDataLen
)

Compress final block.

public Memoable
copy()

Implements org.bouncycastle.util.Memoable.copy.

Produce a copy of this object with its configuration and in its current state.
public int
doFinal(final byte[]
the array the digest is to be copied into.
pOutput
,
final int
the offset into the out array the digest is to start at.
pOutOffset
)

Implements org.bouncycastle.crypto.Digest.doFinal.

close the digest, producing the final digest value.
public int
doFinal(final byte[]
output array to write the output bytes to.
pOut
,
final int
offset to start writing the bytes at.
pOutOffset
,
final int
the number of output bytes requested.
pOutLen
)

Implements org.bouncycastle.crypto.Xof.doFinal.

Output the results of the final calculation for this digest to outLen number of bytes.
public int
doOutput(final byte[]
output array to write the output bytes to.
pOut
,
final int
offset to start writing the bytes at.
pOutOffset
,
final int
the number of output bytes requested.
pOutLen
)

Implements org.bouncycastle.crypto.Xof.doOutput.

Start outputting the results of the final calculation for this digest.
public String
public int
getByteLength()

Implements org.bouncycastle.crypto.ExtendedDigest.getByteLength.

Return the size in bytes of the internal buffer the digest applies it's compression function to.
public int
getDigestSize()

Implements org.bouncycastle.crypto.Digest.getDigestSize.

return the size, in bytes, of the digest produced by this message digest.
private void
incrementBlockCount()

IncrementBlockCount.

public void
init(final Blake3Parameters
the parameters.
pParams
)

Initialise.

private void
initChunkBlock(final int
the dataLength
pDataLen
,
final boolean
is this the final chunk?
pFinal
)

Initialise chunk block.

private void
initIndices()

initialise the indices.

private void
initKey(final byte[]
the keyBytes
pKey
)

Initialise key.

private void
initKeyFromContext()

Initialise key from context.

private void
initM(final byte[]
the source message
pMessage
,
final int
the message position
pMsgPos
)

Initialise M from message.

private void
initNullKey()

Initialise null key.

private void
initParentBlock()

Initialise parent block.

private void
mixG(final int
the message index
msgIdx
,
final int
position A in V
posA
,
final int
position B in V
posB
,
final int
position C in V
posC
,
final int
poistion D in V
posD
)

Mix function G.

private void
nextOutputBlock()

Initialise output block.

private void
performRound()

Perform a round.

private void
permuteIndices()

PermuteIndices.

private void
processStack()

Process the stack.

public void
reset()

Implements org.bouncycastle.crypto.Digest.reset.

reset the digest back to it's initial state.
public void
reset(final Memoable
an object originally copied from an object of the same type as this instance.
pSource
)

Implements org.bouncycastle.util.Memoable.reset.

Restore a copied object state into this object.
private void
resetBlockCount()

ResetBlockCount.

private void
setRoot()

Set root indication.

public void
update(final 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(final byte[]
the byte array containing the data.
pMessage
,
final int
the offset into the byte array where the data starts.
pOffset
,
final int
the length of the data.
pLen
)

Implements org.bouncycastle.crypto.Digest.update.

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

Field Detail

BLOCKLENback to summary
private static final int BLOCKLEN

Buffer length.

CHAINING0back to summary
private static final int CHAINING0

Chaining0 State Locations.

CHAINING1back to summary
private static final int CHAINING1

Chaining1 State Location.

CHAINING2back to summary
private static final int CHAINING2

Chaining2 State Location.

CHAINING3back to summary
private static final int CHAINING3

Chaining3 State Location.

CHAINING4back to summary
private static final int CHAINING4

Chaining4 State Location.

CHAINING5back to summary
private static final int CHAINING5

Chaining5 State Location.

CHAINING6back to summary
private static final int CHAINING6

Chaining6 State Location.

CHAINING7back to summary
private static final int CHAINING7

Chaining7 State Location.

CHUNKENDback to summary
private static final int CHUNKEND

ChunkEnd Flag.

CHUNKLENback to summary
private static final int CHUNKLEN

Chunk length.

CHUNKSTARTback to summary
private static final int CHUNKSTART

ChunkStart Flag.

COUNT0back to summary
private static final int COUNT0

Count0 State Location.

COUNT1back to summary
private static final int COUNT1

Count1 State Location.

DATALENback to summary
private static final int DATALEN

DataLen State Location.

DERIVECONTEXTback to summary
private static final int DERIVECONTEXT

DeriveContext Flag.

DERIVEKEYback to summary
private static final int DERIVEKEY

DeriveKey Flag.

ERR_OUTPUTTINGback to summary
private static final String ERR_OUTPUTTING

Already outputting error.

FLAGSback to summary
private static final int FLAGS

Flags State Location.

IVback to summary
private static final int[] IV

Blake3 Initialization Vector.

IV0back to summary
private static final int IV0

IV0 State Locations.

IV1back to summary
private static final int IV1

IV1 State Location.

IV2back to summary
private static final int IV2

IV2 State Location.

IV3back to summary
private static final int IV3

IV3 State Location.

KEYEDHASHback to summary
private static final int KEYEDHASH

KeyedHash Flag.

NUMWORDSback to summary
private static final int NUMWORDS

Number of Words.

outputAvailableback to summary
private long outputAvailable

How many more bytes can we output?

outputtingback to summary
private boolean outputting

Are we outputting?

PARENTback to summary
private static final int PARENT

Parent Flag.

purposeback to summary
private final CryptoServicePurpose purpose
ROOTback to summary
private static final int ROOT

Root Flag.

ROUNDSback to summary
private static final int ROUNDS

Number of Rounds.

SIGMAback to summary
private static final byte[] SIGMA

Message word permutations.

theBufferback to summary
private final byte[] theBuffer

The byte input/output buffer.

theChainingback to summary
private final int[] theChaining

The chaining value.

theCounterback to summary
private long theCounter

The block counter.

theCurrBytesback to summary
private int theCurrBytes

The # of bytes in the current block.

theDigestLenback to summary
private final int theDigestLen

The default digestLength.

theIndicesback to summary
private final byte[] theIndices

The indices.

theKback to summary
private final int[] theK

The key.

theMback to summary
private final int[] theM

The message Buffer.

theModeback to summary
private int theMode

The current mode.

theOutputDataLenback to summary
private int theOutputDataLen

The output dataLen.

theOutputModeback to summary
private int theOutputMode

The output mode.

thePosback to summary
private int thePos

The position of the next byte in the buffer.

theStackback to summary
private final Stack<E> theStack

The chainingStack.

theVback to summary
private final int[] theV

The state.

Constructor Detail

Blake3Digestback to summary
public Blake3Digest()

Constructor.

Blake3Digestback to summary
public Blake3Digest(final int pDigestSize)

Constructor.

Parameters
pDigestSize:int

the default digest size (in bits)

Blake3Digestback to summary
public Blake3Digest(final int pDigestSize, CryptoServicePurpose purpose)

Base constructor with purpose.

Parameters
pDigestSize:int

size of digest (in bits)

purpose:CryptoServicePurpose

usage purpose.

Blake3Digestback to summary
public Blake3Digest(final Blake3Digest pSource)

Constructor.

Parameters
pSource:Blake3Digest

the source digest.

Method Detail

adjustChainingback to summary
private void adjustChaining()

Adjust Chaining after compression.

adjustStackback to summary
private void adjustStack()

Adjust the stack.

compressback to summary
private void compress()

Perform compression.

compressBlockback to summary
private void compressBlock(final byte[] pMessage, final int pMsgPos)

Compress next block of the message.

Parameters
pMessage:byte[]

the message buffer

pMsgPos:int

the position within the message buffer

compressFinalBlockback to summary
private void compressFinalBlock(final int pDataLen)

Compress final block.

Parameters
pDataLen:int

the data length

copyback to summary
public Memoable copy()

Implements org.bouncycastle.util.Memoable.copy.

Doc from org.bouncycastle.util.Memoable.copy.

Produce a copy of this object with its configuration and in its current state.

The returned object may be used simply to store the state, or may be used as a similar object starting from the copied state.

doFinalback to summary
public int doFinal(final byte[] pOutput, final int pOutOffset)

Implements org.bouncycastle.crypto.Digest.doFinal.

Doc from org.bouncycastle.crypto.Digest.doFinal.

close the digest, producing the final digest value. The doFinal call leaves the digest reset.

Parameters
pOutput:byte[]

the array the digest is to be copied into.

pOutOffset:int

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

doFinalback to summary
public int doFinal(final byte[] pOut, final int pOutOffset, final int pOutLen)

Implements org.bouncycastle.crypto.Xof.doFinal.

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

Output the results of the final calculation for this digest to outLen number of bytes.

Parameters
pOut:byte[]

output array to write the output bytes to.

pOutOffset:int

offset to start writing the bytes at.

pOutLen:int

the number of output bytes requested.

Returns:int

the number of bytes written

doOutputback to summary
public int doOutput(final byte[] pOut, final int pOutOffset, final int pOutLen)

Implements org.bouncycastle.crypto.Xof.doOutput.

Doc from 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
pOut:byte[]

output array to write the output bytes to.

pOutOffset:int

offset to start writing the bytes at.

pOutLen: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.

Doc from 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.

Doc from org.bouncycastle.crypto.ExtendedDigest.getByteLength.

Return the size in bytes of the internal buffer the digest applies it's compression function to.

Returns:int

byte length of the digests internal buffer.

getDigestSizeback to summary
public int getDigestSize()

Implements org.bouncycastle.crypto.Digest.getDigestSize.

Doc from 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.

incrementBlockCountback to summary
private void incrementBlockCount()

IncrementBlockCount.

initback to summary
public void init(final Blake3Parameters pParams)

Initialise.

Parameters
pParams:Blake3Parameters

the parameters.

initChunkBlockback to summary
private void initChunkBlock(final int pDataLen, final boolean pFinal)

Initialise chunk block.

Parameters
pDataLen:int

the dataLength

pFinal:boolean

is this the final chunk?

initIndicesback to summary
private void initIndices()

initialise the indices.

initKeyback to summary
private void initKey(final byte[] pKey)

Initialise key.

Parameters
pKey:byte[]

the keyBytes

initKeyFromContextback to summary
private void initKeyFromContext()

Initialise key from context.

initMback to summary
private void initM(final byte[] pMessage, final int pMsgPos)

Initialise M from message.

Parameters
pMessage:byte[]

the source message

pMsgPos:int

the message position

initNullKeyback to summary
private void initNullKey()

Initialise null key.

initParentBlockback to summary
private void initParentBlock()

Initialise parent block.

mixGback to summary
private void mixG(final int msgIdx, final int posA, final int posB, final int posC, final int posD)

Mix function G.

Parameters
msgIdx:int

the message index

posA:int

position A in V

posB:int

position B in V

posC:int

position C in V

posD:int

poistion D in V

nextOutputBlockback to summary
private void nextOutputBlock()

Initialise output block.

performRoundback to summary
private void performRound()

Perform a round.

permuteIndicesback to summary
private void permuteIndices()

PermuteIndices.

processStackback to summary
private void processStack()

Process the stack.

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.Digest.reset.

Doc from org.bouncycastle.crypto.Digest.reset.

reset the digest back to it's initial state.

resetback to summary
public void reset(final Memoable pSource)

Implements org.bouncycastle.util.Memoable.reset.

Doc from org.bouncycastle.util.Memoable.reset.

Restore a copied object state into this object.

Implementations of this method should try to avoid or minimise memory allocation to perform the reset.

Parameters
pSource:Memoable

an object originally copied from an object of the same type as this instance.

resetBlockCountback to summary
private void resetBlockCount()

ResetBlockCount.

setRootback to summary
private void setRoot()

Set root indication.

updateback to summary
public void update(final byte b)

Implements org.bouncycastle.crypto.Digest.update.

Doc from 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(final byte[] pMessage, final int pOffset, final int pLen)

Implements org.bouncycastle.crypto.Digest.update.

Doc from org.bouncycastle.crypto.Digest.update.

update the message digest with a block of bytes.

Parameters
pMessage:byte[]

the byte array containing the data.

pOffset:int

the offset into the byte array where the data starts.

pLen:int

the length of the data.