1. initialize the hash value
2. a for-loop sha1_update, which each add 512-bit to the hash pool
3. finally do padding, appending extra 1 bit and appending the length of the message
Someone from Intel did SSSE3 acceleration Improving the Performance of the Secure Hash Algorithm (SHA-1) , which improves about 50%. For my workstation (i3-2100) , according to my OpenSSL CVS, the speed of SHA1 is around ~600MB.
In order to use original patch from the article (nearly the same mirror), just replace your step (2) with
void sha1_update_intel(int *hash, const char* input, size_t num_blocks );Then compile the attached Assembly source using
nasm -f elf64 -o sha1sum sha1sum.c #ORand link the .o to your program
yasm -f elf64 -o sha1sum sha1sum.c
Actually it ported to OpenSSL and was porting to kernel crypto:
OpenSSL CVS - Check-in [20937]
[PATCH v3 0/2] crypto, x86: assembler implementation of SHA1
Little benchmark using "openssl speed sha1"
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
i3-2100, 3.1G, Ubuntu 11.04-amd64
sha1-noasm 41509.80k 102830.17k 192025.60k 246080.17k 272615.51k
sha1-0.9.8 42963.77k 119563.82k 245913.69k 347327.44k 380286.29k
sha1-cvs 92259.92k 222029.44k 416805.07k 537374.38k 586825.73k
i5-760, 2.8G, CentOS 5.6-amd64
sha1-0.9.8 34189.42k 102558.96k 227312.78k 326800.38k 373721.22k
sha1-cvs 86948.28k 212469.37k 382940.36k 478658.76k 515970.81k
Xeon W3520, 2.67G, Ubuntu 10.10-amd64
sha1-0.9.8 37745.02k 107145.20k 227622.96k 315530.95k 358102.73k
sha1-cvs 83978.67k 199786.96k 365259.25k 459923.91k 493331.01k
Core2 Quad, CentOS 5.5-amd64
sha1-0.9.8 33646.27k 100451.23k 227755.21k 332412.51k 385859.58k
sha1-cvs 74688.70k 173850.00k 317574.97k 401208.30k 436905.76k
Core2 Duo E7400, CentOS 5.6 i386
sha1-0.9.8 26966.17k 84344.87k 202065.04k 312690.22k 368893.56k
sha1-cvs 54377.91k 141416.44k 271153.15k 353743.53k 390078.93k
C7-M 1.2G, Ubuntu 10.04
sha1-98k 4767.11k 13917.20k 30128.64k 42823.41k 48589.48k
sha1-cvs 9774.71k 22950.89k 40949.16k 51051.52k 55009.28k
sha1-98b_p 3616.33k 13747.16k 47283.20k 121266.52k 224901.91k
Nano 1.6G, src
sha1-no 20057.60k 51514.05k 99721.39k 130167.81k 142811.14k
sha1-padlock 37713.77k 114562.71k 259637.33k 379907.41k 438818.13k
sha1-noasm, sha1-cvs: OpenSSL Snapshot 20110918
sha1-0.9.8, Ubuntu 11.04: OpenSSL 0.9.8o 01 Jun 2010
sha1-0.9.8, CentOS 5.6: OpenSSL 0.9.8e-fips-rhel5
sha1-98b_p, OpenSSL 0.9.8b with patch