bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/4] sha512sum: use kernel crypto API


From: Matteo Croce
Subject: [PATCH 3/4] sha512sum: use kernel crypto API
Date: Mon, 23 Apr 2018 13:17:18 +0200

Use AF_ALG for sha384 and sha512 too

Signed-off-by: Matteo Croce <address@hidden>
---
 lib/sha512.c          | 26 ++++++++++++++++++++++++--
 modules/crypto/sha512 |  5 ++++-
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/lib/sha512.c b/lib/sha512.c
index 8a6dd4e83..1ba3342bb 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -36,6 +36,8 @@
 # include "unlocked-io.h"
 #endif
 
+#include "af_alg.h"
+
 #ifdef WORDS_BIGENDIAN
 # define SWAP(n) (n)
 #else
@@ -186,7 +188,17 @@ sha512_stream (FILE *stream, void *resblock)
   struct sha512_ctx ctx;
   size_t sum;
 
-  char *buffer = malloc (BLOCKSIZE + 72);
+  int ret;
+  char *buffer;
+
+  ret = afalg_stream(stream, resblock, "sha512", SHA512_DIGEST_SIZE);
+  if (!ret)
+      return 0;
+
+  if (ret == -EIO)
+      return 1;
+
+  buffer = malloc (BLOCKSIZE + 72);
   if (!buffer)
     return 1;
 
@@ -257,7 +269,17 @@ sha384_stream (FILE *stream, void *resblock)
   struct sha512_ctx ctx;
   size_t sum;
 
-  char *buffer = malloc (BLOCKSIZE + 72);
+  int ret;
+  char *buffer;
+
+  ret = afalg_stream(stream, resblock, "sha384", SHA384_DIGEST_SIZE);
+  if (!ret)
+      return 0;
+
+  if (ret == -EIO)
+      return 1;
+
+  buffer = malloc (BLOCKSIZE + 72);
   if (!buffer)
     return 1;
 
diff --git a/modules/crypto/sha512 b/modules/crypto/sha512
index 4c97604cd..d3a40fc7d 100644
--- a/modules/crypto/sha512
+++ b/modules/crypto/sha512
@@ -5,6 +5,8 @@ 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
 
@@ -18,10 +20,11 @@ configure.ac:
 gl_SHA512
 
 Makefile.am:
-lib_SOURCES += sha512.c
+lib_SOURCES += sha512.c af_alg.c
 
 Include:
 "sha512.h"
+"af_alg.h"
 
 Link:
 $(LIB_CRYPTO)
-- 
2.14.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]