Class SHAKEDigest

java.lang.Object
org.bouncycastle.crypto.digests.KeccakDigest
org.bouncycastle.crypto.digests.SHAKEDigest
All Implemented Interfaces:
Digest, EncodableDigest, EncodableService, ExtendedDigest, SavableDigestXof, Xof, Memoable
Direct Known Subclasses:
CSHAKEDigest

public class SHAKEDigest extends KeccakDigest implements SavableDigestXof
implementation of SHAKE based on following KeccakNISTInterface.c from https://keccak.noekeon.org/

Following the naming conventions used in the C source code to enable easy review of the implementation.

  • Constructor Details

    • SHAKEDigest

      public SHAKEDigest()
    • SHAKEDigest

      public SHAKEDigest(CryptoServicePurpose purpose)
    • SHAKEDigest

      public SHAKEDigest(int bitStrength)
      Base constructor.
      Parameters:
      bitStrength - the security strength in bits of the XOF.
    • SHAKEDigest

      public SHAKEDigest(int bitStrength, CryptoServicePurpose purpose)
      Base constructor.
      Parameters:
      bitStrength - the security strength in bits of the XOF.
      purpose - the purpose of the digest will be used for.
    • SHAKEDigest

      public SHAKEDigest(byte[] encoded, CryptoServicePurpose purpose)
    • SHAKEDigest

      public SHAKEDigest(SHAKEDigest source)
      Clone constructor
      Parameters:
      source - the other digest to be copied.
    • SHAKEDigest

      public SHAKEDigest(byte[] encodedState)
  • Method Details

    • newInstance

      public static SavableDigestXof newInstance()
    • newInstance

      public static SavableDigestXof newInstance(CryptoServicePurpose purpose)
    • newInstance

      public static SavableDigestXof newInstance(int bitStrength)
    • newInstance

      public static SavableDigestXof newInstance(int bitStrength, CryptoServicePurpose purpose)
    • newInstance

      public static SavableDigestXof newInstance(byte[] encoded, CryptoServicePurpose purpose)
    • newInstance

      public static SavableDigestXof newInstance(Digest digest)
    • getAlgorithmName

      public String getAlgorithmName()
      Description copied from interface: Digest
      return the algorithm name
      Specified by:
      getAlgorithmName in interface Digest
      Overrides:
      getAlgorithmName in class KeccakDigest
      Returns:
      the algorithm name
    • getDigestSize

      public int getDigestSize()
      Description copied from interface: Digest
      return the size, in bytes, of the digest produced by this message digest.
      Specified by:
      getDigestSize in interface Digest
      Overrides:
      getDigestSize in class KeccakDigest
      Returns:
      the size, in bytes, of the digest produced by this message digest.
    • doFinal

      public int doFinal(byte[] out, int outOff)
      Description copied from interface: Digest
      close the digest, producing the final digest value. The doFinal call leaves the digest reset.
      Specified by:
      doFinal in interface Digest
      Overrides:
      doFinal in class KeccakDigest
      Parameters:
      out - the array the digest is to be copied into.
      outOff - the offset into the out array the digest is to start at.
    • doFinal

      public int doFinal(byte[] out, int outOff, int outLen)
      Description copied from interface: Xof
      Output the results of the final calculation for this digest to outLen number of bytes.
      Specified by:
      doFinal in interface Xof
      Parameters:
      out - output array to write the output bytes to.
      outOff - offset to start writing the bytes at.
      outLen - the number of output bytes requested.
      Returns:
      the number of bytes written
    • doOutput

      public int doOutput(byte[] out, int outOff, int outLen)
      Description copied from interface: Xof
      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.
      Specified by:
      doOutput in interface Xof
      Parameters:
      out - output array to write the output bytes to.
      outOff - offset to start writing the bytes at.
      outLen - the number of output bytes requested.
      Returns:
      the number of bytes written
    • doFinal

      protected int doFinal(byte[] out, int outOff, byte partialByte, int partialBits)
      Overrides:
      doFinal in class KeccakDigest
    • doFinal

      protected int doFinal(byte[] out, int outOff, int outLen, byte partialByte, int partialBits)
    • cryptoServiceProperties

      protected CryptoServiceProperties cryptoServiceProperties()
      Overrides:
      cryptoServiceProperties in class KeccakDigest
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getEncodedState

      public byte[] getEncodedState()
      Description copied from interface: EncodableDigest
      Return an encoded byte array for the digest's internal state
      Specified by:
      getEncodedState in interface EncodableDigest
      Specified by:
      getEncodedState in interface EncodableService
      Returns:
      an encoding of the digests internal state.
    • copy

      public Memoable copy()
      Description copied from interface: Memoable
      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.

      Specified by:
      copy in interface Memoable
    • reset

      public void reset(Memoable other)
      Description copied from interface: Memoable
      Restore a copied object state into this object.

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

      Specified by:
      reset in interface Memoable
      Parameters:
      other - an object originally copied from an object of the same type as this instance.