java.lang.Object
org.bouncycastle.crypto.digests.KeccakDigest
org.bouncycastle.crypto.digests.SHAKEDigest
- All Implemented Interfaces:
Digest, ExtendedDigest, Xof
Implementation of SHAKE based on following KeccakNISTInterface.c from keccak.team
Following the naming conventions used in the C source code to enable easy review of the implementation.
Field Summary
Fields inherited from class KeccakDigest
bitsInQueue, dataQueue, fixedOutputLength, purpose, rate, squeezing, stateModifier and TypeFieldDescriptionprotected intNumber of message bits currently held in dataQueue.protected byte[]Buffer holding message bits not yet absorbed into the state.protected intDigest capacity in bits, twice the output length.protected final CryptoServicePurposeCrypto service purpose this digest instance was created for.protected intSponge rate in bits, the number of message bits absorbed per permutation.protected booleanTrue once padding has been applied and output is being squeezed.protected long[]The sponge state, 25 lanes of 64 bits each.Constructor Summary
ConstructorsConstructorDescriptionCreates a SHAKE digest with 128 bits of security strength.SHAKEDigest(int bitStrength) Base constructor.SHAKEDigest(int bitStrength, CryptoServicePurpose purpose) Base constructor.SHAKEDigest(CryptoServicePurpose purpose) Creates a 128-bit SHAKE digest bound to a declared purpose.SHAKEDigest(SHAKEDigest source) Clone constructorMethod Summary
Modifier and TypeMethodDescriptionprivate static intcheckBitLength(int bitStrength) Rejects a bit strength that is not a multiple of 8.protected CryptoServicePropertiesReturns null, as SHAKE declares no crypto service properties.intdoFinal(byte[] out, int outOff) Squeezes the default digest size and resets the sponge.protected intdoFinal(byte[] out, int outOff, byte partialByte, int partialBits) Squeezes the default digest size after a partial trailing byte.intdoFinal(byte[] out, int outOff, int outLen) Squeezes outLen bytes, then resets the sponge.protected intdoFinal(byte[] out, int outOff, int outLen, byte partialByte, int partialBits) Squeezes outLen bytes after a partial trailing byte.intdoOutput(byte[] out, int outOff, int outLen) Squeezes outLen bytes without resetting, so output can be streamed.Names the algorithm as SHAKE followed by its bit strength.intGets the default output size in bytes, a quarter of the bit strength.Methods inherited from class KeccakDigest
absorb, absorb, absorbBits, getByteLength, reset, squeeze, update, updateModifier and TypeMethodDescriptionprotected voidabsorb(byte data) Absorb one byte into the sponge, permuting once the rate is reached.protected voidabsorb(byte[] data, int off, int len) Absorb a byte range into the sponge, permuting once per rate-sized block.protected voidabsorbBits(int data, int bits) Absorb the trailing 1-7 bits of a message, leaving the queue not a multiple of 8 so that no further absorbing is possible.intReturn the size of block that the compression function is applied to in bytes.voidreset()Clear all absorbed message and output state, making the instance ready for a fresh message at its existing capacity.protected voidsqueeze(byte[] output, int offset, long outputLength) Squeeze outputLength bits out of the sponge, padding first if the message has not been finished.voidupdate(byte in) Absorb one more byte of message.voidupdate(byte[] in, int inOff, int len) Absorb more message bytes.
Constructor Details
SHAKEDigest
public SHAKEDigest()Creates a SHAKE digest with 128 bits of security strength.SHAKEDigest
Creates a 128-bit SHAKE digest bound to a declared purpose.- Parameters:
purpose- the use the digest is declared to serve, which callers must match
SHAKEDigest
public SHAKEDigest(int bitStrength) Base constructor.- Parameters:
bitStrength- the security strength in bits of the XOF.
SHAKEDigest
Base constructor.- Parameters:
bitStrength- the security strength in bits of the XOF.purpose- the purpose of the digest will be used for.
SHAKEDigest
Clone constructor- Parameters:
source- the other digest to be copied.
Method Details
checkBitLength
private static int checkBitLength(int bitStrength) Rejects a bit strength that is not a multiple of 8.- Parameters:
bitStrength- the strength to check- Returns:
- the strength, if valid
getAlgorithmName
Names the algorithm as SHAKE followed by its bit strength.- Specified by:
getAlgorithmNamein interfaceDigest- Overrides:
getAlgorithmNamein classKeccakDigest- Returns:
- the digest length in bits, prefixed with "Keccak-"
getDigestSize
public int getDigestSize()Gets the default output size in bytes, a quarter of the bit strength.- Specified by:
getDigestSizein interfaceDigest- Overrides:
getDigestSizein classKeccakDigest- Returns:
- the digest length in bytes
doFinal
public int doFinal(byte[] out, int outOff) Squeezes the default digest size and resets the sponge.- Specified by:
doFinalin interfaceDigest- Overrides:
doFinalin classKeccakDigest- Parameters:
out- the buffer to write the digest intooutOff- the offset into out at which to write the digest- Returns:
- the number of bytes written to out
doFinal
public int doFinal(byte[] out, int outOff, int outLen) Squeezes outLen bytes, then resets the sponge.doOutput
public int doOutput(byte[] out, int outOff, int outLen) Squeezes outLen bytes without resetting, so output can be streamed.doFinal
protected int doFinal(byte[] out, int outOff, byte partialByte, int partialBits) Squeezes the default digest size after a partial trailing byte.- Overrides:
doFinalin classKeccakDigest- Parameters:
out- the buffer to write the digest intooutOff- the offset into out at which to write the digestpartialByte- a byte holding the final 1-7 bits of the messagepartialBits- how many bits of partialByte are message, 1 to 7, or 0 if none- Returns:
- the number of bytes written to out
doFinal
protected int doFinal(byte[] out, int outOff, int outLen, byte partialByte, int partialBits) Squeezes outLen bytes after a partial trailing byte.- Parameters:
out- the buffer the squeezed output is written tooutOff- the index in out at which output startsoutLen- the number of output bytes asked forpartialByte- the byte holding any bits not yet absorbedpartialBits- how many low bits of partialByte are data, 0 to 7- Returns:
- the number of bytes written to out, always outLen
cryptoServiceProperties
Returns null, as SHAKE declares no crypto service properties.- Overrides:
cryptoServicePropertiesin classKeccakDigest- Returns:
- the digest's service properties, or null if it declares none