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

public Class KMAC

extends Object
implements Mac, Xof
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.Xof, org.bouncycastle.crypto.ExtendedDigest, org.bouncycastle.crypto.Digest, org.bouncycastle.crypto.Mac
Imports
org.bouncycastle.crypto.CipherParameters, .DataLengthException, .Mac, .Xof, org.bouncycastle.crypto.digests.CSHAKEDigest, .XofUtils, org.bouncycastle.crypto.params.KeyParameter, org.bouncycastle.util.Arrays, .Strings

KMAC - MAC with optional XOF mode.

From NIST Special Publication 800-185 - SHA-3 Derived Functions:cSHAKE, KMAC, TupleHash and ParallelHash

Field Summary

Modifier and TypeField and Description
private final int
private final CSHAKEDigest
private boolean
private boolean
private byte[]
private final int
private static final byte[]

Constructor Summary

AccessConstructor and Description
public
KMAC(int
bit length of the underlying SHAKE function, 128 or 256.
bitLength
,
byte[]
the customization string - available for local use.
S
)

Base constructor.

Method Summary

Modifier and TypeMethod and Description
private void
bytePad(byte[] X, int w)

public int
doFinal(byte[]
the array the MAC is to be output to.
out
,
int
the offset into the out buffer the output is to start at.
outOff
)

Implements org.bouncycastle.crypto.Mac.doFinal, org.bouncycastle.crypto.Digest.doFinal.

Compute the final stage of the MAC writing the output to the out parameter.
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.

Output the results of the final calculation for this digest to outLen number of bytes.
public int
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.
private static byte[]
encode(byte[] X)

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.
public int
getMacSize()

Implements org.bouncycastle.crypto.Mac.getMacSize.

Return the block size for this MAC (in bytes).
public void
init(CipherParameters
the key and other data required by the MAC.
params
)

Implements org.bouncycastle.crypto.Mac.init.

Initialise the MAC.
public void
public void
update(byte
the byte to be processed.
in
)

Implements org.bouncycastle.crypto.Mac.update, org.bouncycastle.crypto.Digest.update.

add a single byte to the mac for processing.
public void
update(byte[]
the array containing the input.
in
,
int
the index in the array the data begins at.
inOff
,
int
the length of the input starting at inOff.
len
)

Implements org.bouncycastle.crypto.Mac.update, org.bouncycastle.crypto.Digest.update.

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

Field Detail

bitLengthback to summary
private final int bitLength
cshakeback to summary
private final CSHAKEDigest cshake
firstOutputback to summary
private boolean firstOutput
initialisedback to summary
private boolean initialised
keyback to summary
private byte[] key
outputLengthback to summary
private final int outputLength
paddingback to summary
private static final byte[] padding

Constructor Detail

KMACback to summary
public KMAC(int bitLength, byte[] S)

Base constructor.

Parameters
bitLength:int

bit length of the underlying SHAKE function, 128 or 256.

S:byte[]

the customization string - available for local use.

Method Detail

bytePadback to summary
private void bytePad(byte[] X, int w)
doFinalback to summary
public int doFinal(byte[] out, int outOff) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.Mac.doFinal, org.bouncycastle.crypto.Digest.doFinal.

Doc from org.bouncycastle.crypto.Mac.doFinal.

Compute the final stage of the MAC writing the output to the out parameter.

doFinal leaves the MAC in the same state it was after the last init.

Parameters
out:byte[]

the array the MAC is to be output to.

outOff:int

the offset into the out buffer the output is to start at.

Exceptions
DataLengthException:
if there isn't enough space in out.
IllegalStateException:
if the MAC is not initialised.
doFinalback to summary
public int doFinal(byte[] out, int outOff, int outLen)

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
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

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

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
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

encodeback to summary
private static byte[] encode(byte[] X)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.Mac.getAlgorithmName, org.bouncycastle.crypto.Digest.getAlgorithmName.

Doc from org.bouncycastle.crypto.Mac.getAlgorithmName.

Return the name of the algorithm the MAC implements.

Returns:String

the name of the algorithm the MAC implements.

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.

getMacSizeback to summary
public int getMacSize()

Implements org.bouncycastle.crypto.Mac.getMacSize.

Doc from org.bouncycastle.crypto.Mac.getMacSize.

Return the block size for this MAC (in bytes).

Returns:int

the block size for this MAC in bytes.

initback to summary
public void init(CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.Mac.init.

Doc from org.bouncycastle.crypto.Mac.init.

Initialise the MAC.

Parameters
params:CipherParameters

the key and other data required by the MAC.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.Mac.reset, org.bouncycastle.crypto.Digest.reset.

Doc from org.bouncycastle.crypto.Mac.reset.

Reset the MAC. At the end of resetting the MAC should be in the in the same state it was after the last init (if there was one).

updateback to summary
public void update(byte in) throws IllegalStateException

Implements org.bouncycastle.crypto.Mac.update, org.bouncycastle.crypto.Digest.update.

Doc from org.bouncycastle.crypto.Mac.update.

add a single byte to the mac for processing.

Parameters
in:byte

the byte to be processed.

Exceptions
IllegalStateException:
if the MAC is not initialised.
updateback to summary
public void update(byte[] in, int inOff, int len) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.Mac.update, org.bouncycastle.crypto.Digest.update.

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

update the message digest with a block of bytes.

Parameters
in:byte[]

Doc from org.bouncycastle.crypto.Mac.update.

the array containing the input.

inOff:int

Doc from org.bouncycastle.crypto.Mac.update.

the index in the array the data begins at.

len:int

Doc from org.bouncycastle.crypto.Mac.update.

the length of the input starting at inOff.

Exceptions
DataLengthException:

Doc from org.bouncycastle.crypto.Mac.update.

if there isn't enough data in in.

IllegalStateException:

Doc from org.bouncycastle.crypto.Mac.update.

if the MAC is not initialised.