Use AF_ALG for sha224 and sha256 too Signed-off-by: Matteo Croce <mcr...@redhat.com> --- lib/sha256.c | 32 ++++++++++++++++++++++++++++++-- modules/crypto/sha256 | 6 +++++- 2 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/lib/sha256.c b/lib/sha256.c index 85405b20f..578f43e4d 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -32,6 +32,10 @@ #include <stdlib.h> #include <string.h> +#ifdef HAVE_LINUX_IF_ALG_H +# include "af_alg.h" +#endif + #if USE_UNLOCKED_IO # include "unlocked-io.h" #endif @@ -177,8 +181,20 @@ sha256_stream (FILE *stream, void *resblock) { struct sha256_ctx ctx; size_t sum; + char *buffer; + +#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 - char *buffer = malloc (BLOCKSIZE + 72); + buffer = malloc (BLOCKSIZE + 72); if (!buffer) return 1; @@ -248,8 +264,20 @@ sha224_stream (FILE *stream, void *resblock) { struct sha256_ctx ctx; size_t sum; + char *buffer; + +#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 - char *buffer = malloc (BLOCKSIZE + 72); + buffer = malloc (BLOCKSIZE + 72); if (!buffer) return 1; diff --git a/modules/crypto/sha256 b/modules/crypto/sha256 index 37fabfd90..9d4f11578 100644 --- a/modules/crypto/sha256 +++ b/modules/crypto/sha256 @@ -5,8 +5,11 @@ Files: 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 @@ stdint 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" -- 2.14.3