SHA Class Reference

#include <sha.h>

Inheritance diagram for SHA:

Inheritance graph
Collaboration diagram for SHA:

Collaboration graph

Detailed Description

Implementation of the NIST Secure Hash Algorithm (SHA/SHA-1), FIPS 180-1.

Usage flow:
  SHA()      // construct a new SHA object
  add()      // call as many times as necessary to process data
  final()    // finalize message digest computation
  result()   // obtain resulting hash value

Recommendations for strict FIPS 140-1 compliance:
  As long as you do not use SHA-0, all public data members and methods of
  class SHA can be used by an application requiring FIPS 140-1 compliance.

Sample code illustrating the use of this class appears in the Cookbook section Using the Message Digest Functions.

References

SHA-1 is specified in:


Public Member Functions

 SHA (int version=1)
 Constructor used to create an initialized SHA object for SHA (i.e., SHA-0) or SHA-1.
 ~SHA ()
 Destructor. Calls clear();.
int add (char c)
 Update message digest computation with a single byte.
int add (int bytes, const char *buf)
 Update message digest computation with a buffer.
int add (int nbits, int b)
 Update message digest computation with a specified number of bits.
int final (void)
 Finalize the message digest computation.
void finalstore (void)
 finalstore:
const char * result (void) const
 Get a pointer to the final message digest.
int length () const
 Get the length in bytes of a message digest.
int blocksize () const
 Get the algorithm block size.
double count64 () const
 Get the number of bytes hashed so far.
template<class T>
to () const
 Get a type T representation of the message digest.
str tostr () const
 Get a str representation of the message digest.
void reset (int version=1)
 Reset this SHA object. Calls clear().
void resetk (void)
 resetk:
void clear (void)
 Clear this object, zeroizing and/or reinitializing all internal data.


Constructor & Destructor Documentation

SHA ( int  version = 1  )  [inline, explicit]

Constructor used to create an initialized SHA object for SHA (i.e., SHA-0) or SHA-1.

Parameters:
version indicator: 0 for SHA-0, 1 for SHA-1
Remarks:
SHA-1 is the default, if no version is specified. SHA-0 should not be used!


Member Function Documentation

int add ( int  nbits,
int  b 
)

Update message digest computation with a specified number of bits.

Parameters:
nbits the number of bits in b to be hashed
b an int containing the bits to be hashed
Returns:
0 (success)
CDK_ERROR_STATE
Remarks:
This function MUST BE CALLED LAST AND ONLY ONCE when hashing a long bit string. Call add(char) or add(int, const char*) on your data until you have less than one byte remaining. Then call this function. Example: add(4,0x50) causes '0x0101' to be hashed.
Note:
FIPS 140-1 testing of the CDK was performed for SHA-1 in BYTE mode, but not in BIT mode.

int add ( int  bytes,
const char *  buf 
)

Update message digest computation with a buffer.

Parameters:
bytes the number of bytes in the input buffer
buf a pointer to the input buffer
Returns:
0 (success)
CDK_ERROR_STATE
CDK_INVALID_PTR

int add ( char  c  ) 

Update message digest computation with a single byte.

Parameters:
c the byte to be hashed
Returns:
0 (success)
CDK_ERROR_STATE

int blocksize (  )  const [inline]

Get the algorithm block size.

Returns:
64.

double count64 (  )  const [inline]

Get the number of bytes hashed so far.

Returns:
the number of bytes processed by an add() function since the last clear.

int final ( void   ) 

Finalize the message digest computation.

Returns:
0 (success)
CDK_ERROR_STATE

void finalstore ( void   ) 

finalstore:

Note:
This function is intended for internal use only. It does not return a final message digest, but rather an intermediate value required by class PRNG.
Returns:
0 (success)
CDK_ERROR_STATE

int length (  )  const [inline]

Get the length in bytes of a message digest.

Returns:
20

void reset ( int  version = 1  ) 

Reset this SHA object. Calls clear().

Parameters:
version indicates which version of SHA to perform: <= 0 for SHA, >= 1 for SHA-1

void resetk ( void   ) 

resetk:

Remarks:
This function is provided for internal DSA use only.

const char* result ( void   )  const

Get a pointer to the final message digest.

Returns:
a pointer to the 16-byte message digest
(NULL, if the CDK is in its hard error state)

T to (  )  const [inline]

Get a type T representation of the message digest.

Returns:
an object of type T representating the message digest

str tostr (  )  const

Get a str representation of the message digest.

Returns:
a str containing the string representation of the message digest.


The documentation for this class was generated from the following file:
ISC Cryptographic Development Kit - User's Guide
ISC website
Questions? E-mail ISC technical support
Copyright© 2002-2006 Information Security Corp. All rights reserved.