<< >>

SHA256 with function calls

The function-based SHA256 interface uses three functions. Call the function sha256BlockBegin() to start computing a new hash, the function sha256BlockUpdate() to incorporate some more data into the hash, and the function sha256BlockEnd() to obtain the hash.

Note that the current interface can only perform the computation on a byte stream. This can be changed to a bit stream, the hashing thread itself works on a bit stream already, it just requires a different set of functions.

API

void sha256BlockBegin(unsigned int hash[8])

This is one of three functions that comprise the function based interface to the SHA256 library.

It must be called to initialise the hash.

Parameters:
  • hash – an array of integers that holds the hash.
void sha256BlockUpdate(unsigned int hash[8], unsigned char message[], int n)

This is one of three functions that comprise the function based interface to the SHA256 library.

It is called to incorporate data into the hash. THe data is supplied as an array of unsigned characters (bytes).

Parameters:
  • hash – an array of integers that holds the hash.
  • message – an array of unsigned characters that contains the data to be incorporated into the hash
  • n – The number of bytes to incorporate into the hash.
void sha256BlockEnd(unsigned int hash[8])

This is one of three functions that comprise the function based interface to the SHA256 library.

It completes the hash by incorporating a trailing ‘1’, padding, and the length of the message. On return of this function the array passed as the first argument holds the hash.

Parameters:
  • hash – an array of integers in which the hash is returned.

Example

An example program is shown below:

int main(void) {
  unsigned int hash[8];
  sha256BlockStart(hash);
  sha256BlockUpdate(hash, "Hello", 5);
  sha256BlockEnd(hash);
  return 0;
}