bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH v2 2/4] sha256sum: use kernel crypto API


From: Matteo Croce
Subject: [PATCH v2 2/4] sha256sum: use kernel crypto API
Date: Wed, 25 Apr 2018 13:27:02 +0200

Use AF_ALG for sha224 and sha256 too

Signed-off-by: Matteo Croce <address@hidden>
---
 lib/sha256.c          | 34 ++++++++++++++++++++++++++++++++--
 modules/crypto/sha256 |  4 +++-
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/lib/sha256.c b/lib/sha256.c
index 85405b20f..7924040cd 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -32,6 +32,12 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <sys/socket.h>
+
+#ifdef AF_ALG
+# include "af_alg.h"
+#endif
+
 #if USE_UNLOCKED_IO
 # include "unlocked-io.h"
 #endif
@@ -177,8 +183,20 @@ sha256_stream (FILE *stream, void *resblock)
 {
   struct sha256_ctx ctx;
   size_t sum;
+  char *buffer;
 
-  char *buffer = malloc (BLOCKSIZE + 72);
+#ifdef AF_ALG
+  int ret;
+
+  ret = afalg_stream(stream, resblock, "sha256", SHA256_DIGEST_SIZE);
+  if (!ret)
+      return 0;
+
+  if (ret == -EIO)
+      return 1;
+#endif
+
+  buffer = malloc (BLOCKSIZE + 72);
   if (!buffer)
     return 1;
 
@@ -248,8 +266,20 @@ sha224_stream (FILE *stream, void *resblock)
 {
   struct sha256_ctx ctx;
   size_t sum;
+  char *buffer;
+
+#ifdef AF_ALG
+  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..412cbabfd 100644
--- a/modules/crypto/sha256
+++ b/modules/crypto/sha256
@@ -5,6 +5,8 @@ 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
 
@@ -17,7 +19,7 @@ configure.ac:
 gl_SHA256
 
 Makefile.am:
-lib_SOURCES += sha256.c
+lib_SOURCES += sha256.c af_alg.c
 
 Include:
 "sha256.h"
-- 
2.14.3




reply via email to

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