]> Savannah Git Hosting - gnulib.git/commit
sha1sum: use AF_ALG when available
authorMatteo Croce <mcroce@redhat.com>
Sat, 28 Apr 2018 13:32:55 +0000 (15:32 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 5 May 2018 12:36:16 +0000 (14:36 +0200)
commit7074a58633d332a4638b2794d16f594a7b888530
treef31e4bc1bb2ac9b2cbdae20ebd88a6aa30d04aea
parent0f3906631fa19caed9321cab02e2f4ba0a3bde72
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>
ChangeLog
lib/af_alg.c [new file with mode: 0644]
lib/af_alg.h [new file with mode: 0644]
lib/sha1.c
m4/linux-if-alg.m4 [new file with mode: 0644]
modules/crypto/sha1