# HG changeset patch # User Matteo Croce # Date 1524922376 -7200 # Node ID 63b59e9dcbd7f9350d9372e8194e0d4e5f3890f4 # Parent 6b0fda728c9b59a8527da555c7580ac500c89b74 sha256sum: use kernel crypto API Use AF_ALG for sha224 and sha256 too Signed-off-by: Matteo Croce diff -r 6b0fda728c9b -r 63b59e9dcbd7 ChangeLog --- a/ChangeLog Sat Apr 28 15:32:55 2018 +0200 +++ b/ChangeLog Sat Apr 28 15:32:56 2018 +0200 @@ -1,3 +1,12 @@ +2018-04-28 Matteo Croce + + sha256sum: Use AF_ALG when available. + * lib/sha256.c: Include af_alg.h. + (sha256_stream, sha224_stream): Use afalg_stream when available. + * modules/crypto/sha256 (Files): Add the af_alg files. + (configure.ac): Invoke gl_LINUX_IF_ALG_H. + (Makefile.am): Add af_alg.c. + 2018-04-28 Matteo Croce sha1sum: Use AF_ALG when available. diff -r 6b0fda728c9b -r 63b59e9dcbd7 lib/sha256.c --- a/lib/sha256.c Sat Apr 28 15:32:55 2018 +0200 +++ b/lib/sha256.c Sat Apr 28 15:32:56 2018 +0200 @@ -32,6 +32,10 @@ #include #include +#ifdef HAVE_LINUX_IF_ALG_H +# include "af_alg.h" +#endif + #if USE_UNLOCKED_IO # include "unlocked-io.h" #endif @@ -177,8 +181,20 @@ { struct sha256_ctx ctx; size_t sum; + char *buffer; - char *buffer = malloc (BLOCKSIZE + 72); +#ifdef HAVE_LINUX_IF_ALG_H + int ret; + + ret = afalg_stream(stream, resblock, "sha256", SHA256_DIGEST_SIZE); + if (!ret) + return 0; + + if (ret == -EIO) + return 1; +#endif + + buffer = malloc (BLOCKSIZE + 72); if (!buffer) return 1; @@ -248,8 +264,20 @@ { struct sha256_ctx ctx; size_t sum; + char *buffer; - char *buffer = malloc (BLOCKSIZE + 72); +#ifdef HAVE_LINUX_IF_ALG_H + int ret; + + ret = afalg_stream(stream, resblock, "sha224", SHA224_DIGEST_SIZE); + if (!ret) + return 0; + + if (ret == -EIO) + return 1; +#endif + + buffer = malloc (BLOCKSIZE + 72); if (!buffer) return 1; diff -r 6b0fda728c9b -r 63b59e9dcbd7 modules/crypto/sha256 --- a/modules/crypto/sha256 Sat Apr 28 15:32:55 2018 +0200 +++ b/modules/crypto/sha256 Sat Apr 28 15:32:56 2018 +0200 @@ -5,8 +5,11 @@ lib/gl_openssl.h lib/sha256.h lib/sha256.c +lib/af_alg.h +lib/af_alg.c m4/gl-openssl.m4 m4/sha256.m4 +m4/linux-if-alg.m4 Depends-on: extern-inline @@ -15,9 +18,10 @@ configure.ac: gl_SHA256 +gl_LINUX_IF_ALG_H Makefile.am: -lib_SOURCES += sha256.c +lib_SOURCES += sha256.c af_alg.c Include: "sha256.h"