Skip to content

Commit 4b4e291

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 27dc04c commit 4b4e291

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ all::
183183
#
184184
# Define GCRYPT_SHA256 to use the SHA-256 routines in libgcrypt.
185185
#
186+
# Define OPENSSL_SHA256 to use the SHA-256 routines in OpenSSL.
187+
#
186188
# Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin).
187189
#
188190
# Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
@@ -1638,13 +1640,18 @@ endif
16381640
endif
16391641
endif
16401642

1643+
ifdef OPENSSL_SHA256
1644+
EXTLIBS += $(LIB_4_CRYPTO)
1645+
BASIC_CFLAGS += -DSHA256_OPENSSL
1646+
else
16411647
ifdef GCRYPT_SHA256
16421648
BASIC_CFLAGS += -DSHA256_GCRYPT
16431649
EXTLIBS += -lgcrypt
16441650
else
16451651
LIB_OBJS += sha256/block/sha256.o
16461652
BASIC_CFLAGS += -DSHA256_BLK
16471653
endif
1654+
endif
16481655

16491656
ifdef SHA1_MAX_BLOCK_SIZE
16501657
LIB_OBJS += compat/sha1-chunked.o

hash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#if defined(SHA256_GCRYPT)
1919
#include "sha256/gcrypt.h"
20+
#elif defined(SHA256_OPENSSL)
21+
#include <openssl/sha.h>
2022
#else
2123
#include "sha256/block/sha256.h"
2224
#endif

0 commit comments

Comments
 (0)