kz.gamma.vista
Class VistaSHA1

java.lang.Object
  extended by kz.gamma.vista.VistaSHA1

public class VistaSHA1
extends java.lang.Object

SHA1 Java sample. Ported from http://tools.ietf.org/html/rfc3174#section-7

Author:
Renat Karimov Date: 06.02.13 Time: 15:17

Field Summary
static int SHA1HashSize
           
static int shaInputTooLong
           
static int shaNull
           
static int shaStateError
           
static int shaSuccess
           
 
Constructor Summary
VistaSHA1()
           
 
Method Summary
static void DigestPrint(byte[] digest)
          Prints a message digest in hexadecimal.
static int SHA1CircularShift(int bits, int word)
           
 int SHA1Input(VistaSha1Context context, byte[] message_array, int length)
          SHA1Input

Description: This function accepts an array of octets as the next portion of the message.

 void SHA1PadMessage(VistaSha1Context context)
          SHA1PadMessage

Description: According to the standard, the message must be padded to an even 512 bits.

 void SHA1ProcessMessageBlock(VistaSha1Context context)
          SHA1ProcessMessageBlock

Description: This function will process the next 512 bits of the message stored in the Message_Block array.

 int SHA1Reset(VistaSha1Context context)
          SHA1Reset

Description: This function will initialize the SHA1Context in preparation for computing a new SHA1 message digest.

 int SHA1Result(VistaSha1Context context, byte[] Message_Digest)
          SHA1Result

Description: This function will return the 160-bit message digest into the Message_Digest array provided by the caller.

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHA1HashSize

public static final int SHA1HashSize
See Also:
Constant Field Values

shaSuccess

public static final int shaSuccess
See Also:
Constant Field Values

shaNull

public static final int shaNull
See Also:
Constant Field Values

shaInputTooLong

public static final int shaInputTooLong
See Also:
Constant Field Values

shaStateError

public static final int shaStateError
See Also:
Constant Field Values
Constructor Detail

VistaSHA1

public VistaSHA1()
Method Detail

DigestPrint

public static void DigestPrint(byte[] digest)
Prints a message digest in hexadecimal.


SHA1Reset

public int SHA1Reset(VistaSha1Context context)
SHA1Reset

Description: This function will initialize the SHA1Context in preparation for computing a new SHA1 message digest.

Parameters: context: [in/out] The context to reset.

Returns: sha Error Code.


SHA1Input

public int SHA1Input(VistaSha1Context context,
                     byte[] message_array,
                     int length)
SHA1Input

Description: This function accepts an array of octets as the next portion of the message.

Parameters: context: [in/out] The SHA context to update message_array: [in] An array of characters representing the next portion of the message. length: [in] The length of the message in message_array

Returns: sha Error Code.


SHA1ProcessMessageBlock

public void SHA1ProcessMessageBlock(VistaSha1Context context)
SHA1ProcessMessageBlock

Description: This function will process the next 512 bits of the message stored in the Message_Block array.

Parameters: None.

Returns: Nothing.

Comments: Many of the variable names in this code, especially the single character names, were used because those were the names used in the publication.


SHA1CircularShift

public static int SHA1CircularShift(int bits,
                                    int word)

SHA1Result

public int SHA1Result(VistaSha1Context context,
                      byte[] Message_Digest)
SHA1Result

Description: This function will return the 160-bit message digest into the Message_Digest array provided by the caller. NOTE: The first octet of hash is stored in the 0th element, the last octet of hash in the 19th element.

Parameters: context: [in/out] The context to use to calculate the SHA-1 hash. Message_Digest: [out] Where the digest is returned.

Returns: sha Error Code.


SHA1PadMessage

public void SHA1PadMessage(VistaSha1Context context)
SHA1PadMessage

Description: According to the standard, the message must be padded to an even 512 bits. The first padding bit must be a '1'. The last 64 bits represent the length of the original message. All bits in between should be 0. This function will pad the message according to those rules by filling the Message_Block array accordingly. It will also call the ProcessMessageBlock function provided appropriately. When it returns, it can be assumed that the message digest has been computed.

Parameters: context: [in/out] The context to pad ProcessMessageBlock: [in] The appropriate SHA*ProcessMessageBlock function Returns: Nothing.



Copyright © 1998-2014 Gamma Technologies. All Rights Reserved.