--- configure.ac.orig 2021-07-02 02:31:51.000000000 -0600
+++ configure.ac 2021-07-07 19:53:46.145591253 -0600
@@ -269,15 +269,15 @@ AS_CASE([$with_hashlibrary],
AS_IF([test "x$with_hashlibrary" != xno],
[AC_MSG_CHECKING([whether hash-library headers and library are available])
- HASHLIBRARY_LIBS="-lsha256"
+ HASHLIBRARY_LIBS="-lcrypto"
#save_CPPFLAGS="$CPPFLAGS"
#save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
LIBS="$LIBS $HASHLIBRARY_LIBS"
AC_LINK_IFELSE(
- [AC_LANG_PROGRAM([[#include "hash-library/sha256.h"
+ [AC_LANG_PROGRAM([[#include <openssl/sha.h>
]],
- [[SHA256 dummy;
+ [[SHA256_CTX dummy;
]])],
[[have_hashlibrary=yes]
[CPPFLAGS="$CPPFLAGS $HASHLIBRARY_CPPFLAGS"]
--- source/libnormaliz/nmz_hash.cpp.orig 2021-07-02 02:31:51.000000000 -0600
+++ source/libnormaliz/nmz_hash.cpp 2021-07-07 20:24:50.109603050 -0600
@@ -1,5 +1,5 @@
#ifdef NMZ_HASHLIBRARY
-#include <hash-library/sha256.h>
+#include <openssl/sha.h>
#endif
#include <iostream>
@@ -18,8 +18,13 @@ using namespace std;
// return string of 32 zeros as default if hash-library is not present
string sha256str(const string& text, bool verbose) {
#ifdef NMZ_HASHLIBRARY
- SHA256 sha256;
- return sha256(text);
+ unsigned char rawHash[SHA256_DIGEST_LENGTH];
+ char hashstr[SHA256_DIGEST_LENGTH * 2 + 1];
+ SHA256(reinterpret_cast<const unsigned char *>(text.c_str()), text.size(), rawHash);
+ for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i)
+ sprintf(&hashstr[i * 2], "%02x", rawHash[i]);
+ hashstr[SHA256_DIGEST_LENGTH * 2] = '\0';
+ return hashstr;
#else
if(verbose)
verboseOutput() << "sha256str called but hash-library not present; "
@@ -34,10 +39,8 @@ string sha256str(const string& text, boo
// Return as vector<unsigned char> of size sha256.HashBytes (== 32)
vector<unsigned char> sha256hexvec(const string& text, bool verbose) {
#ifdef NMZ_HASHLIBRARY
- SHA256 sha256;
- sha256.add(text.c_str(), text.size());
- unsigned char rawHash[sha256.HashBytes];
- sha256.getHash(rawHash);
+ unsigned char rawHash[SHA256_DIGEST_LENGTH];
+ SHA256(reinterpret_cast<const unsigned char *>(text.c_str()), text.size(), rawHash);
int s = sizeof(rawHash)/sizeof(rawHash[0]);
// assuming sizeof(unsigned char) == 1, then s == sha256.HashBytes == 32
vector<unsigned char> v(rawHash, rawHash + s);
--- source/Makefile.configuration.orig 2021-07-02 02:31:51.000000000 -0600
+++ source/Makefile.configuration 2021-07-07 19:52:33.913496006 -0600
@@ -43,7 +43,7 @@ endif
ifeq ($(HASHLIBRARY),no)
else
CXXFLAGS += -DNMZ_HASHLIBRARY
- HASHLIBRARYFLAGS = $(OPT_LIB_ROOT)/lib/libsha256.a
+ HASHLIBRARYFLAGS = -lcrypto
endif
# development?