[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] sha256sum: use kernel crypto API
From: |
Matteo Croce |
Subject: |
[PATCH 2/4] sha256sum: use kernel crypto API |
Date: |
Mon, 23 Apr 2018 13:17:17 +0200 |
Use AF_ALG for sha224 and sha256 too
Signed-off-by: Matteo Croce <address@hidden>
---
lib/sha256.c | 26 ++++++++++++++++++++++++--
modules/crypto/sha256 | 5 ++++-
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/lib/sha256.c b/lib/sha256.c
index 85405b20f..566c24a43 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -36,6 +36,8 @@
# include "unlocked-io.h"
#endif
+#include "af_alg.h"
+
#ifdef WORDS_BIGENDIAN
# define SWAP(n) (n)
#else
@@ -178,7 +180,17 @@ sha256_stream (FILE *stream, void *resblock)
struct sha256_ctx ctx;
size_t sum;
- char *buffer = malloc (BLOCKSIZE + 72);
+ int ret;
+ char *buffer;
+
+ ret = afalg_stream(stream, resblock, "sha256", SHA256_DIGEST_SIZE);
+ if (!ret)
+ return 0;
+
+ if (ret == -EIO)
+ return 1;
+
+ buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
return 1;
@@ -249,7 +261,17 @@ sha224_stream (FILE *stream, void *resblock)
struct sha256_ctx ctx;
size_t sum;
- char *buffer = malloc (BLOCKSIZE + 72);
+ int ret;
+ char *buffer;
+
+ ret = afalg_stream(stream, resblock, "sha224", SHA224_DIGEST_SIZE);
+ if (!ret)
+ return 0;
+
+ if (ret == -EIO)
+ return 1;
+
+ buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
return 1;
diff --git a/modules/crypto/sha256 b/modules/crypto/sha256
index 37fabfd90..e27f88d79 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,10 +19,11 @@ configure.ac:
gl_SHA256
Makefile.am:
-lib_SOURCES += sha256.c
+lib_SOURCES += sha256.c af_alg.c
Include:
"sha256.h"
+"af_alg.h"
Link:
$(LIB_CRYPTO)
--
2.14.3