SHA2 Class Reference

#include <sha.h>

Inheritance diagram for SHA2:

Inheritance graph
Collaboration diagram for SHA2:

Collaboration graph

Detailed Description

Implementation of the Extended NIST Secure Hash Algorithms (SHA-256/-384/-512), FIPS 180-2.

Usage flow:
  SHA2()     // construct a new SHA2 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:
  All public data members and methods of the SHA2 class 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-256/-384/-512 are specified in:


Public Member Functions

 SHA2 (int version)
 Constructor used to create a new object initialized for SHA-256, -384 or -512.
 ~SHA2 ()
 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 final (void)
 Finalize the message digest computation.
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.
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 clear (void)
 clear


Constructor & Destructor Documentation

SHA2 ( int  version  )  [inline, explicit]

Constructor used to create a new object initialized for SHA-256, -384 or -512.

Parameters:
version indicator: 2 for SHA-256, 3 for SHA-384, 5 (or any other value) for SHA-512


Member Function Documentation

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  )  [inline]

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:
the algorithm's block size in bytes (64 or 128)

void clear ( void   ) 

clear

Remarks:
Modifies: clear() called to initialize the object. vers doesn't change.

int final ( void   ) 

Finalize the message digest computation.

Returns:
0 (success)
CDK_ERROR_STATE

int length (  )  const

Get the length in bytes of a message digest.

Returns:
the expected number of output bytes (32, 48, or 64)

const char* result ( void   )  const

Get a pointer to the final message digest.

Returns:
a pointer to the 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.