java.lang.Object
org.bouncycastle.crypto.digests.LongDigest
All Implemented Interfaces:
Digest, EncodableDigest, ExtendedDigest, Memoable
Direct Known Subclasses:
SHA512Digest

public abstract class LongDigestextends Object implements ExtendedDigest, Memoable, EncodableDigest
Base class for SHA-384 and SHA-512.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Length of the digest in bytes.
    private long
    Byte counter for the length padding.
    private long
    High byte counter for the length padding.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    protected long
    Hash working variables H1-H8.
    (package private) static final long[]
    SHA-384 and SHA-512 constants (first 64 bits of fractional parts of cube roots of first 64 primes)
    protected final CryptoServicePurpose
    Crypto operation purpose.
    private long[]
    Schedule words of the compression.
    private int
    Position in the schedule.
    private byte[]
    Buffer for the current eight byte block.
    private int
    Position in the block buffer.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for variable length word
    protected
    Constructor for variable length word
    protected
    Copy constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Adjust the byte counts so that byteCount2 represents the upper long (less 3 bits) word of the byte count.
    private long
    Ch(long x, long y, long z)
    Choose function of the compression, for the long-word digests.
    protected void
    Takes over another digest's buffer and byte counts.
    protected abstract CryptoServiceProperties
    Returns the properties for the crypto service.
    void
    Pads the message to a block boundary and compresses the final block.
    int
    Gets the digest length in bytes, 128 for a SHA-512 family digest.
    protected int
    Returns the size of the encoded state.
    private long
    Maj(long x, long y, long z)
    Majority function of the compression.
    protected void
    populateState(byte[] state)
    Writes this digest's buffer, counts and chaining values into a byte array.
    protected void
    Expands and mixes the 80-word schedule, then updates the chaining values.
    protected void
    processLength(long lowW, long hiW)
    Process the bit length data.
    protected void
    processWord(byte[] in, int inOff)
    Process a word of input data.
    void
    Clears the buffer, counts and chaining values to the initial state.
    protected void
    restoreState(byte[] encodedState)
    Reads back a state previously written by populateState(byte[]).
    private long
    Sigma0(long x)
    Sigma zero schedule function.
    private long
    Sigma1(long x)
    Sigma one schedule function.
    private long
    Sum0(long x)
    Sigma zero rotation function.
    private long
    Sum1(long x)
    Sigma one rotation function.
    void
    update(byte in)
    Updates the digest with one byte.
    void
    update(byte[] in, int inOff, int len)
    Updates the digest with the given bytes.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Digest

    doFinal, getAlgorithmName, getDigestSize
    Modifier and Type
    Method
    Description
    int
    doFinal(byte[] out, int outOff)
    close the digest, producing the final digest value.
    return the algorithm name
    int
    return the size, in bytes, of the digest produced by this message digest.

    Methods inherited from interface EncodableDigest

    getEncodedState
    Modifier and Type
    Method
    Description
    byte[]
    Return an encoded byte array for the digest's internal state

    Methods inherited from interface Memoable

    copy, reset
    Modifier and Type
    Method
    Description
    Produce a copy of this object with its configuration and in its current state.
    void
    reset(Memoable other)
    Restore a copied object state into this object.
  • Field Details

    • BYTE_LENGTH

      private static final int BYTE_LENGTH
      Length of the digest in bytes.
      See Also:
    • purpose

      protected final CryptoServicePurpose purpose
      Crypto operation purpose.
    • xBuf

      private byte[] xBuf
      Buffer for the current eight byte block.
    • xBufOff

      private int xBufOff
      Position in the block buffer.
    • byteCount1

      private long byteCount1
      Byte counter for the length padding.
    • byteCount2

      private long byteCount2
      High byte counter for the length padding.
    • H1

      protected long H1
      Hash working variables H1-H8.
    • H2

      protected long H2
      Hash working variables H1-H8.
    • H3

      protected long H3
      Hash working variables H1-H8.
    • H4

      protected long H4
      Hash working variables H1-H8.
    • H5

      protected long H5
      Hash working variables H1-H8.
    • H6

      protected long H6
      Hash working variables H1-H8.
    • H7

      protected long H7
      Hash working variables H1-H8.
    • H8

      protected long H8
      Hash working variables H1-H8.
    • W

      private long[] W
      Schedule words of the compression.
    • wOff

      private int wOff
      Position in the schedule.
    • K

      static final long[] K
      SHA-384 and SHA-512 constants (first 64 bits of fractional parts of cube roots of first 64 primes)
  • Constructor Details

    • LongDigest

      protected LongDigest()
      Constructor for variable length word
    • LongDigest

      protected LongDigest(CryptoServicePurpose purpose)
      Constructor for variable length word
      Parameters:
      purpose - the crypto service purpose
    • LongDigest

      protected LongDigest(LongDigest t)
      Copy constructor. We are using copy constructors in place of the Object.clone() interface as this interface is not supported by J2ME.
      Parameters:
      t - the digest to copy
  • Method Details

    • copyIn

      protected void copyIn(LongDigest t)
      Takes over another digest's buffer and byte counts.
      Parameters:
      t - the digest to copy state from
    • populateState

      protected void populateState(byte[] state)
      Writes this digest's buffer, counts and chaining values into a byte array.
      Parameters:
      state - the encoded state to populate from
    • restoreState

      protected void restoreState(byte[] encodedState)
      Reads back a state previously written by populateState(byte[]).
      Parameters:
      encodedState - the encoded state to restore from
    • getEncodedStateSize

      protected int getEncodedStateSize()
      Returns the size of the encoded state.
      Returns:
      the encoded state size in bytes
    • update

      public void update(byte in)
      Updates the digest with one byte.
      Specified by:
      update in interface Digest
      Parameters:
      in - the input byte
    • update

      public void update(byte[] in, int inOff, int len)
      Updates the digest with the given bytes.
      Specified by:
      update in interface Digest
      Parameters:
      in - the input bytes
      inOff - the offset into the byte array where the data starts.
      len - the length of the data.
    • finish

      public void finish()
      Pads the message to a block boundary and compresses the final block.
    • reset

      public void reset()
      Clears the buffer, counts and chaining values to the initial state.
      Specified by:
      reset in interface Digest
    • getByteLength

      public int getByteLength()
      Gets the digest length in bytes, 128 for a SHA-512 family digest.
      Specified by:
      getByteLength in interface ExtendedDigest
      Returns:
      byte length of the digests internal buffer.
    • processWord

      protected void processWord(byte[] in, int inOff)
      Process a word of input data.
      Parameters:
      in - the input bytes
      inOff - the offset into the input array
    • adjustByteCounts

      private void adjustByteCounts()
      Adjust the byte counts so that byteCount2 represents the upper long (less 3 bits) word of the byte count.
    • processLength

      protected void processLength(long lowW, long hiW)
      Process the bit length data.
      Parameters:
      lowW - low word of the bit length
      hiW - high word of the bit length
    • processBlock

      protected void processBlock()
      Expands and mixes the 80-word schedule, then updates the chaining values.
    • Ch

      private long Ch(long x, long y, long z)
      Choose function of the compression, for the long-word digests.
      Parameters:
      x - the first word
      y - the second word
      z - the third word
      Returns:
      the bits of z chosen by x
    • Maj

      private long Maj(long x, long y, long z)
      Majority function of the compression.
      Parameters:
      x - the first word
      y - the second word
      z - the third word
      Returns:
      the bits set in at least two words
    • Sum0

      private long Sum0(long x)
      Sigma zero rotation function.
      Parameters:
      x - the word to rotate
      Returns:
      the mixed rotations
    • Sum1

      private long Sum1(long x)
      Sigma one rotation function.
      Parameters:
      x - the word to rotate
      Returns:
      the mixed rotations
    • Sigma0

      private long Sigma0(long x)
      Sigma zero schedule function.
      Parameters:
      x - the schedule word
      Returns:
      the mixed rotations
    • Sigma1

      private long Sigma1(long x)
      Sigma one schedule function.
      Parameters:
      x - the schedule word
      Returns:
      the mixed rotations
    • cryptoServiceProperties

      protected abstract CryptoServiceProperties cryptoServiceProperties()
      Returns the properties for the crypto service.
      Returns:
      the crypto service properties