Mercurial > gnulib
view modules/crypto/sha1 @ 39313:6b0fda728c9b
sha1sum: use AF_ALG when available
Linux supports accessing kernel crypto API via AF_ALG since
version 2.6.38. Coreutils uses libcrypto when available and fallbacks to
generic C implementation of various hashing functions.
Add a generic afalg_stream() function which uses AF_ALG to calculate the
hash of a stream and use sendfile() when possible (regular file with size
less or equal than 0x7ffff000 (2,147,479,552) bytes, AKA MAX_RW_COUNT).
Use afalg_stream() only in sha1sum for now, but other hashes are possible.
The speed gain really depends on the CPU type, on systems which doesn't use
libcrypto ranges from ~10% to 320%.
This is a test on a Intel(R) Xeon(R) CPU E3-1265L V2 and Debian stretch:
$ truncate -s 2GB 2g.bin
$ time sha1sum 2g.bin
752ef2367f479e79e4f0cded9c270c2890506ab0 2g.bin
real 0m4.829s
user 0m4.437s
sys 0m0.391s
$ time ./sha1sum-afalg 2g.bin
752ef2367f479e79e4f0cded9c270c2890506ab0 2g.bin
real 0m3.164s
user 0m0.000s
sys 0m3.162s
Signed-off-by: Matteo Croce <mcroce@redhat.com>
author | Matteo Croce <mcroce@redhat.com> |
---|---|
date | Sat, 28 Apr 2018 15:32:55 +0200 |
parents | 135e82dafbea |
children | 8eac5062f218 |
line wrap: on
line source
Description: Compute SHA1 checksum. Files: lib/gl_openssl.h lib/sha1.h lib/sha1.c lib/af_alg.h lib/af_alg.c m4/gl-openssl.m4 m4/sha1.m4 m4/linux-if-alg.m4 Depends-on: extern-inline stdalign stdint configure.ac: gl_SHA1 gl_LINUX_IF_ALG_H Makefile.am: lib_SOURCES += sha1.c af_alg.c Include: "sha1.h" Link: $(LIB_CRYPTO) License: LGPLv2+ Maintainer: Jim Meyering