java.lang.Object
org.bouncycastle.crypto.digests.LongDigest
- All Implemented Interfaces:
Digest, EncodableDigest, ExtendedDigest, Memoable
- Direct Known Subclasses:
SHA512Digest
Base class for SHA-384 and SHA-512.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intLength of the digest in bytes.private longByte counter for the length padding.private longHigh byte counter for the length padding.protected longHash working variables H1-H8.protected longHash working variables H1-H8.protected longHash working variables H1-H8.protected longHash working variables H1-H8.protected longHash working variables H1-H8.protected longHash working variables H1-H8.protected longHash working variables H1-H8.protected longHash 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 CryptoServicePurposeCrypto operation purpose.private long[]Schedule words of the compression.private intPosition in the schedule.private byte[]Buffer for the current eight byte block.private intPosition in the block buffer.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for variable length wordprotectedLongDigest(CryptoServicePurpose purpose) Constructor for variable length wordprotectedCopy constructor.Method Summary
Modifier and TypeMethodDescriptionprivate voidAdjust the byte counts so that byteCount2 represents the upper long (less 3 bits) word of the byte count.private longCh(long x, long y, long z) Choose function of the compression, for the long-word digests.protected voidcopyIn(LongDigest t) Takes over another digest's buffer and byte counts.protected abstract CryptoServicePropertiesReturns the properties for the crypto service.voidfinish()Pads the message to a block boundary and compresses the final block.intGets the digest length in bytes, 128 for a SHA-512 family digest.protected intReturns the size of the encoded state.private longMaj(long x, long y, long z) Majority function of the compression.protected voidpopulateState(byte[] state) Writes this digest's buffer, counts and chaining values into a byte array.protected voidExpands and mixes the 80-word schedule, then updates the chaining values.protected voidprocessLength(long lowW, long hiW) Process the bit length data.protected voidprocessWord(byte[] in, int inOff) Process a word of input data.voidreset()Clears the buffer, counts and chaining values to the initial state.protected voidrestoreState(byte[] encodedState) Reads back a state previously written bypopulateState(byte[]).private longSigma0(long x) Sigma zero schedule function.private longSigma1(long x) Sigma one schedule function.private longSum0(long x) Sigma zero rotation function.private longSum1(long x) Sigma one rotation function.voidupdate(byte in) Updates the digest with one byte.voidupdate(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, waitMethods inherited from interface Digest
doFinal, getAlgorithmName, getDigestSizeModifier and TypeMethodDescriptionintdoFinal(byte[] out, int outOff) close the digest, producing the final digest value.return the algorithm nameintreturn the size, in bytes, of the digest produced by this message digest.Methods inherited from interface EncodableDigest
getEncodedStateModifier and TypeMethodDescriptionbyte[]Return an encoded byte array for the digest's internal state
Field Details
BYTE_LENGTH
purpose
Crypto operation purpose.xBuf
private byte[] xBufBuffer for the current eight byte block.xBufOff
private int xBufOffPosition in the block buffer.byteCount1
private long byteCount1Byte counter for the length padding.byteCount2
private long byteCount2High byte counter for the length padding.H1
protected long H1Hash working variables H1-H8.H2
protected long H2Hash working variables H1-H8.H3
protected long H3Hash working variables H1-H8.H4
protected long H4Hash working variables H1-H8.H5
protected long H5Hash working variables H1-H8.H6
protected long H6Hash working variables H1-H8.H7
protected long H7Hash working variables H1-H8.H8
protected long H8Hash working variables H1-H8.W
private long[] WSchedule words of the compression.wOff
private int wOffPosition in the schedule.K
static final long[] KSHA-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 wordLongDigest
Constructor for variable length word- Parameters:
purpose- the crypto service purpose
LongDigest
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
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 bypopulateState(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
update
finish
public void finish()Pads the message to a block boundary and compresses the final block.reset
getByteLength
public int getByteLength()Gets the digest length in bytes, 128 for a SHA-512 family digest.- Specified by:
getByteLengthin interfaceExtendedDigest- 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 bytesinOff- 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 lengthhiW- 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 wordy- the second wordz- 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 wordy- the second wordz- 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
Returns the properties for the crypto service.- Returns:
- the crypto service properties