[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 0/4] Use AF_ALG in checksum utilities
From: |
Matteo Croce |
Subject: |
[PATCH v3 0/4] Use AF_ALG in checksum utilities |
Date: |
Sat, 28 Apr 2018 15:32:54 +0200 |
Let md5sum and all sha*sum utilities use Linux kernel cryptographic API via the
AF_ALG address family.
Speed gain depends on the CPU type:
Xeon E3-1265L V2:
$ 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
Xeon E3-1240 v6:
$ time sha1sum disk.qcow2
47be301f86c71c20eae4ccc5bab4c02e09e729a4 disk.qcow2
real 0m28.390s
user 0m13.352s
sys 0m1.376s
$ time ./sha1sum-afalg disk.qcow2
47be301f86c71c20eae4ccc5bab4c02e09e729a4 disk.qcow2
real 0m8.373s
user 0m0.052s
sys 0m8.308s
Marvell Armada 8040 - MACCHIATOBin Dual shot:
$ dd if=/dev/zero bs=1G count=10 |time -p sha1sum
a0b6e2ca4e28360a929943e8eb966f703a69dc44 2g.bin
real 0m49.390s
user 0m46.852s
sys 0m2.076s
$ dd if=/dev/zero bs=1G count=10 |time -p ./sha1sum-afalg
a0b6e2ca4e28360a929943e8eb966f703a69dc44 2g.bin
real 0m15.104s
user 0m0.052s
sys 0m15.008s
Correctness of the implementation was tested with the following script:
algos='md5sum sha1sum sha224sum sha256sum sha384sum sha512sum'
dd='dd status=none if=/dev/zero'
for alg in $algos; do
echo -n "Checking $alg..."
for bs in 1 31 512 1K 4K 1M; do
for count in 0 1 1234 4096; do
hash1=$($dd bs=$bs count=$count |$alg)
hash2=$($dd bs=$bs count=$count |src/$alg)
[ "$hash1" = "$hash2" ] || \
exec echo "\n$alg: hash differs with bs=$bs count=$count"
done
truncate -s $bs /tmp/filechk-$$
hash1=$($alg /tmp/filechk-$$)
hash2=$(src/$alg /tmp/filechk-$$)
[ "$hash1" = "$hash2" ] || \
exec echo "\n$alg: hash differs reading '/tmp/filechk-$$'!"
rm -f /tmp/filechk-$$
hash1=$($alg /proc/version)
hash2=$(src/$alg /proc/version)
[ "$hash1" = "$hash2" ] || \
exec echo "\n$alg: hash differs reading from procfs!"
done
echo " ok"
done
Changes since v2:
* added m4 script to check for af_alg in configury
* more strict error checking in af_alg.c
* don't allocate temporary buffer if using sendfile
* adhere to GNU coding style
* don't include more headers than necessary
* don't use sendfile for empty files as it breaks reading from procfs
* use sendfile for shared memory objects too
Changes since v1:
* add copyright nore in af_alg.c
* check for AF_ALG in sys/socket.h to avoid build failures when unavailable
* don't include unneeded header files in af_alg.h
* revert wrong Include directive in module description
* revert unneeded 'Hey Emacs!' blocks
* use correct GNU indentation
* prefer size_t over int to denote memory segments
* avoid possible overflow by checking arguments size
* return -EIO if sendfile() returns a short read/write count
* fix a file descriptor leak when bind() returns error
Matteo Croce (4):
sha1sum: use AF_ALG when available
sha256sum: use kernel crypto API
sha512sum: use kernel crypto API
md5sum: use kernel crypto API
lib/af_alg.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/af_alg.h | 49 +++++++++++++++++++++
lib/md5.c | 18 +++++++-
lib/sha1.c | 17 +++++++-
lib/sha256.c | 32 +++++++++++++-
lib/sha512.c | 32 +++++++++++++-
m4/linux-if-alg.m4 | 29 +++++++++++++
modules/crypto/md5 | 6 ++-
modules/crypto/sha1 | 6 ++-
modules/crypto/sha256 | 6 ++-
modules/crypto/sha512 | 6 ++-
11 files changed, 306 insertions(+), 10 deletions(-)
create mode 100644 lib/af_alg.c
create mode 100644 lib/af_alg.h
create mode 100644 m4/linux-if-alg.m4
--
2.14.3
- [PATCH v3 0/4] Use AF_ALG in checksum utilities,
Matteo Croce <=