P10. Sha2 implementation

  Copyright (c) 2001, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.

  All rights reserved.

 

  TERMS

 

  Redistribution and use in source and binary forms, with or without modification, are permitted subject to the following conditions:

 

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

 

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

 

  3. The copyright holder's name must not be used to endorse or promote any products derived from this software without his specific prior written permission.

 

  This software is provided 'as is' with no express or implied warranties of correctness or fitness for purpose.

  -------------------------------------------------

 

  This is a byte oriented version of SHA256 that operates on arrays of bytes stored in memory. The operation uses a type 'sha256_ctx' to hold details of the current hash state and uses the following three calls:

 

  void sha256_begin(sha256_ctx ctx[])

  void sha256_hash(const unsigned char data[], unsigned long len, sha256_ctx ctx[])

  void sha256_end(unsigned char hval[], sha256_ctx ctx[])

 

  The first subroutine initialises a hash computation by setting up the context in the sha256_ctx context.

 

  The second subroutine hashes 8-bit bytes from array data[] into the hash state withinh sha256_ctx context, the number of bytes to be hashed being given by the the unsigned long integer len.

 

  The third subroutine completes the hash calculation and places the resulting digest value in the array of 8-bit bytes hval[]

 

  This implementation of SHA256 also supports SHA384 and SHA512 but these hash functions depend on the use of 64-bit long integers and are not very efficient on 32-bit machines. This code is NOT recommended for these hash functions.

 

  My thanks to Erik Andersen <andersen@codepoet-consulting.com> for testing this code on big-endian systems and for his assistance with corrections