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

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

index d529ec224f4ca8fc518c9d40a68aaf6cf5370c7d..d267347b9d3709bf9144bf3054b3a42210656b31 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-04-28  Matteo Croce  <mcroce@redhat.com>
+
+       sha512sum: Use AF_ALG when available.
+       * lib/sha512.c: Include af_alg.h.
+       (sha512_stream, sha384_stream): Use afalg_stream when available.
+       * modules/crypto/sha512 (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>
 
        sha256sum: Use AF_ALG when available.
index 8a6dd4e83ac18c66a9350fbf64355ad5ad6916b0..72e5fdd241cbccaa3243cdb2afba691688451672 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
@@ -185,8 +189,20 @@ sha512_stream (FILE *stream, void *resblock)
 {
   struct sha512_ctx ctx;
   size_t sum;
+  char *buffer;
+
+#ifdef HAVE_LINUX_IF_ALG_H
+  int ret;
+
+  ret = afalg_stream(stream, resblock, "sha512", SHA512_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;
 
@@ -256,8 +272,20 @@ sha384_stream (FILE *stream, void *resblock)
 {
   struct sha512_ctx ctx;
   size_t sum;
+  char *buffer;
+
+#ifdef HAVE_LINUX_IF_ALG_H
+  int ret;
+
+  ret = afalg_stream(stream, resblock, "sha384", SHA384_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 4c97604cdebad81f3231e354c2a6e571570a1ca5..6d0dd1019a799068b395bc5f4187a02138ed80eb 100644 (file)
@@ -5,8 +5,11 @@ Files:
 lib/gl_openssl.h
 lib/sha512.h
 lib/sha512.c
+lib/af_alg.h
+lib/af_alg.c
 m4/gl-openssl.m4
 m4/sha512.m4
+m4/linux-if-alg.m4
 
 Depends-on:
 extern-inline
@@ -16,9 +19,10 @@ u64
 
 configure.ac:
 gl_SHA512
+gl_LINUX_IF_ALG_H
 
 Makefile.am:
-lib_SOURCES += sha512.c
+lib_SOURCES += sha512.c af_alg.c
 
 Include:
 "sha512.h"