SHA-256 hashing algorithm
Introduction
In 1996, the National Institute of Standards and Technology approved the FIPS 180-2, a Secure Hash Standard, which bears the specification for the Secure Hash Algorithms (SHA-1, SHA-256, SHA-384, and SHA-512). However in February 2005, a successful attack on the SHA-1 algorithm was announced by researchers. Due to the advances in computer power, NIST planned to phase out SHA-1 in favor of larger and stronger hash functions (SHA-224, SHA-256, SHA-384 and SHA-512).
The following source code contains implementation for SHA-256 only. It is based on the reference implementation available at http://www.cr0.net:8040/.
I replaced types to match that of Symbian. Please include the GNU General Public License if you intend to use this code in your application. This optimized SHA-256 implementation conforms to FIPS-180-2.
SHA256.h
#ifndef _SHA256_H
#define _SHA256_H
#include <e32std.h>
#include <s32file.h>
namespace SHA256 {
typedef struct
{
TUint32 total[2];
TUint32 state[8];
TUint8 buffer[64];
}
sha256_context;
void sha256_starts( sha256_context *ctx );
void sha256_update( sha256_context *ctx, TUint8 *input, TUint32 length );
void sha256_finish( sha256_context *ctx, TUint8 digest[32] );
} // namespace SHA256 end
#endif /* sha256.h */
Sample Usage
TUint8 sha256sum[32]; // for hash storage
TBuf8<256> tMyBuffer8(_L8("Find hash of this string"));
TUint8* ptrMyBuffer = new (ELeave) TUint8[tMyBuffer8.Length()];
CleanupArrayDeletePushL(ptrMyBuffer);
Mem::Copy(ptrMyBuffer, tMyBuffer8.Ptr(), tMyBuffer8.Length() );
sha256_starts( &ctx );
sha256_update( &ctx, buf, tMyBuffer8.Length() );
sha256_finish( &ctx, sha256sum );
CleanupStack::PopAndDestroy();
Vinay
SE NSS
http://xms.za.net/web.html





