java.lang.Object
org.bouncycastle.crypto.digests.KeccakDigest
org.bouncycastle.crypto.digests.SHA3Digest
All Implemented Interfaces:
Digest, ExtendedDigest

public class SHA3Digestextends KeccakDigest
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.

  • Constructor Details

    • SHA3Digest

      public SHA3Digest()
      SHA3Digest.
    • SHA3Digest

      public SHA3Digest(CryptoServicePurpose purpose)
      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

      public SHA3Digest(int bitLength, CryptoServicePurpose purpose)
      SHA3Digest.
      Parameters:
      bitLength - the digest size in bits, one of 224, 256, 384 or 512
      purpose - the intended use of this digest, carried to the crypto services registrar when the digest is registered
    • SHA3Digest

      public SHA3Digest(SHA3Digest source)
      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

      public String getAlgorithmName()
      Names the digest by family and output size, e.g. "SHA3-256".
      Specified by:
      getAlgorithmName in interface Digest
      Overrides:
      getAlgorithmName in class KeccakDigest
      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:
      doFinal in interface Digest
      Overrides:
      doFinal in class KeccakDigest
      Parameters:
      out - the buffer to write the digest into
      outOff - 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:
      doFinal in class KeccakDigest
      Parameters:
      out - the buffer to write the digest into
      outOff - the offset into out at which to write the digest
      partialByte - a byte holding the final 1-7 bits of the message
      partialBits - how many bits of partialByte are message, 1 to 7, or 0 if none
      Returns:
      the number of bytes written to out