SHA-224, SHA-256, SHA-384 and SHA-512

This is a fast software implementation in C of the FIPS 180-2 hash algorithms SHA-224, SHA-256, SHA-384 and SHA-512. The code is distributed under the BSD license. For each algorithm, the implementation has been verified with the NIST test vectors and with the additional vectors provided by Aaron D. Gifford.

News

February 2, 2007: Added new optimizations and a minor bug fix.

May 23, 2005: Added support for SHA-224.

April 30, 2005: First release.

Download

sha2.tar.gz

GitHub

https://github.com/ouah/sha2

Compilation options

There is an UNROLL_LOOPS option which is disabled by default. Depending on your system, enabling this option can make hashing faster or slower.

Performance

SHA-256 can achieve hashing at 27 cycles per byte for long data on a Pentium 4 with the Intel compiler. Data lengths in the tables below are in bytes and values are in cycles/byte.

Arch: Pentium 4 (Prescott), compiler: icc 8.1, compiler options: -O2 -xP -ip, software options: -DUNROLL_LOOPS

Data length110100 1,00010,000100,000
SHA-2242120212.841.20 27.8026.5626.66
SHA-2562128212.041.20 27.7926.5926.71
SHA-3848056807.280.56 60.8959.1258.44
SHA-5128088808.082.00 60.7159.2058.51

Arch: Pentium 4 (Prescott), compiler: gcc 3.3.4, compiler options: -O3 -march=pentium4 -fomit-frame-pointer, software options: none

Data length110100 1,00010,000100,000
SHA-2242440256.849.68 35.1433.4833.41
SHA-2562448257.649.44 35.1633.6633.40
SHA-384161361626.4162.40 126.40123.95122.70
SHA-512161601628.8162.64 126.52124.11122.75

Portability

The implementation has been tested on numerous UNIX systems and on both little-endian and big-endian platforms.


Olivier Gay - olivier.gay@a3.epfl.ch
Last updated: February 2, 2007