hash: add an SHA-256 implementation using OpenSSL
We already have OpenSSL routines available for SHA-1, so add routines for SHA-256 as well. On a Core i7-6600U, this SHA-256 implementation compares favorably to the SHA1DC SHA-1 implementation: SHA-1: 157 MiB/s (64 byte chunks); 337 MiB/s (16 KiB chunks) SHA-256: 165 MiB/s (64 byte chunks); 408 MiB/s (16 KiB chunks) Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Nov 14, 2018 at 04:09 UTC
4b4e2918099600c1eefe7b5a71bf647803905b7e
2 files changed
+9
Makefile
+7
@@ -183,6 +183,8 @@ all::
183
#
184
# Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.
185
#
186
+# Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.
187
+#
188
# Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin).
189
#
190
# Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
@@ -1638,6 +1640,10 @@ endif
1640
endif
1641
endif
1642
1643
+ifdef OPENSSL_SHA256
1644
+ EXTLIBS += $(LIB_4_CRYPTO)
1645
+ BASIC_CFLAGS += -DSHA256_OPENSSL
1646
+else
1647
ifdef GCRYPT_SHA256
1648
BASIC_CFLAGS += -DSHA256_GCRYPT
1649
EXTLIBS += -lgcrypt
@@ -1645,6 +1651,7 @@ else
1651
LIB_OBJS += sha256/block/sha256.o
1652
BASIC_CFLAGS += -DSHA256_BLK
1653
endif
1654
+endif
1655
1656
ifdef SHA1_MAX_BLOCK_SIZE
1657
LIB_OBJS += compat/sha1-chunked.o
hash.h
+2
@@ -17,6 +17,8 @@
17
18
#if defined(SHA256_GCRYPT)
19
#include "sha256/gcrypt.h"
20
+#elif defined(SHA256_OPENSSL)
21
+#include <openssl/sha.h>
22
#else
23
#include "sha256/block/sha256.h"
24
#endif