java.lang.Object
org.bouncycastle.crypto.digests.KeccakDigest
org.bouncycastle.crypto.digests.SHA3Digest
- All Implemented Interfaces:
Digest, ExtendedDigest
Implementation of SHA-3 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
ConstructorsConstructorDescriptionSHA3Digest.SHA3Digest(int bitLength) SHA3Digest.SHA3Digest(int bitLength, CryptoServicePurpose purpose) SHA3Digest.SHA3Digest(CryptoServicePurpose purpose) SHA3Digest.SHA3Digest(SHA3Digest source) SHA3Digest.Method Summary
Modifier and TypeMethodDescriptionprivate static intcheckBitLength(int bitLength) Rejects a bit length that is not a multiple of 8.intdoFinal(byte[] out, int outOff) Pad the sponge and squeeze out the digest.protected intdoFinal(byte[] out, int outOff, byte partialByte, int partialBits) Pad and squeeze out the digest for a message ending mid-byte.Names the digest by family and output size, e.g.Methods inherited from class KeccakDigest
absorb, absorb, absorbBits, cryptoServiceProperties, getByteLength, getDigestSize, 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.protected CryptoServicePropertiesDescribe this digest's properties for the crypto services registrar.intReturn the size of block that the compression function is applied to in bytes.intGet the size of the digest this class produces.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
SHA3Digest
public SHA3Digest()SHA3Digest.SHA3Digest
SHA3Digest.- Parameters:
purpose- the intended use of this digest, carried to the crypto services registrar when the digest is registered
SHA3Digest
public SHA3Digest(int bitLength) SHA3Digest.- Parameters:
bitLength- the digest size in bits, one of 224, 256, 384 or 512
SHA3Digest
SHA3Digest.- Parameters:
bitLength- the digest size in bits, one of 224, 256, 384 or 512purpose- the intended use of this digest, carried to the crypto services registrar when the digest is registered
SHA3Digest
SHA3Digest.- Parameters:
source- the digest to copy the sponge state from, so a partially absorbed message can be continued in the new instance
Method Details
checkBitLength
private static int checkBitLength(int bitLength) Rejects a bit length that is not a multiple of 8.- Parameters:
bitLength- the length to check- Returns:
- the length, if valid
getAlgorithmName
Names the digest by family and output size, e.g. "SHA3-256".- Specified by:
getAlgorithmNamein interfaceDigest- Overrides:
getAlgorithmNamein classKeccakDigest- Returns:
- the digest length in bits, prefixed with "Keccak-"
doFinal
public int doFinal(byte[] out, int outOff) Pad the sponge and squeeze out the digest.- 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
protected int doFinal(byte[] out, int outOff, byte partialByte, int partialBits) Pad and squeeze out the digest for a message ending mid-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