From a720fab2ad613883a2b877b3c81c38e0ae6aca24 Mon Sep 17 00:00:00 2001 From: Matteo Croce Date: Sat, 28 Apr 2018 15:32:58 +0200 Subject: [PATCH] md5sum: use kernel crypto API Use AF_ALG for md5 too Signed-off-by: Matteo Croce --- ChangeLog | 9 +++++++++ lib/md5.c | 18 +++++++++++++++++- modules/crypto/md5 | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d267347b9d..00e809f918 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2018-04-28 Matteo Croce + + md5sum: Use AF_ALG when available. + * lib/md5.c: Include af_alg.h. + (md5_stream): Use afalg_stream when available. + * modules/crypto/md5 (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 sha512sum: Use AF_ALG when available. diff --git a/lib/md5.c b/lib/md5.c index 68d00a6c7e..307abbbe7a 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -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 @@ -142,8 +146,20 @@ md5_stream (FILE *stream, void *resblock) { struct md5_ctx ctx; size_t sum; + char *buffer; + +#ifdef HAVE_LINUX_IF_ALG_H + int ret; + + ret = afalg_stream(stream, resblock, "md5", MD5_DIGEST_SIZE); + if (!ret) + return 0; + + if (ret == -EIO) + return 1; +#endif - char *buffer = malloc (BLOCKSIZE + 72); + buffer = malloc (BLOCKSIZE + 72); if (!buffer) return 1; diff --git a/modules/crypto/md5 b/modules/crypto/md5 index e5fb39cedf..415cf0523a 100644 --- a/modules/crypto/md5 +++ b/modules/crypto/md5 @@ -5,8 +5,11 @@ Files: lib/gl_openssl.h lib/md5.h lib/md5.c +lib/af_alg.h +lib/af_alg.c m4/gl-openssl.m4 m4/md5.m4 +m4/linux-if-alg.m4 Depends-on: extern-inline @@ -15,9 +18,10 @@ stdint configure.ac: gl_MD5 +gl_LINUX_IF_ALG_H Makefile.am: -lib_SOURCES += md5.c +lib_SOURCES += md5.c af_alg.c Include: "md5.h" -- 2.39.5