]> Savannah Git Hosting - gnulib.git/commitdiff
sha256sum: use kernel crypto API
authorMatteo Croce <mcroce@redhat.com>
Sat, 28 Apr 2018 13:32:56 +0000 (15:32 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 5 May 2018 12:36:26 +0000 (14:36 +0200)
Use AF_ALG for sha224 and sha256 too

Signed-off-by: Matteo Croce <mcroce@redhat.com>
ChangeLog
lib/sha256.c
modules/crypto/sha256

index acec47a18c008fee9db8d5da61855aae5c58bb68..d529ec224f4ca8fc518c9d40a68aaf6cf5370c7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-04-28  Matteo Croce  <mcroce@redhat.com>
+
+       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  <mcroce@redhat.com>
 
        sha1sum: Use AF_ALG when available.
index 85405b20fdf481f4255ee6689a52be389517274f..578f43e4df9313abe71d4109444b24a2c4743d62 100644 (file)
 #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;
 
index 37fabfd905fca35b8a10ead90199e39624c16c91..9d4f115786211063164aa54d94e3ce9827fe920e 100644 (file)
@@ -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"