Blame SOURCES/0001-Add-support-for-computing-hashes-using-OpenSSL.patch

125681
From 11eab76046e2df31248d358ab85bdbcf366d2c78 Mon Sep 17 00:00:00 2001
125681
From: Nicola Sella <nsella@redhat.com>
125681
Date: Wed, 11 Nov 2020 14:52:14 +0100
125681
Subject: [PATCH 1/1] Add support for computing hashes using OpenSSL
6e36fb
96dd81
It adds WITH_OPENSSL build option.
96dd81
If it is ON, OpenSSL will be used instead of internal implementation
96dd81
of computing hashes (MD5, SHA1, SHA224, SHA256, SHA384, SHA512).
125681
125681
Rebase of https://github.com/openSUSE/libsolv/commit/9839a88e4fda23b46015170b201c98da7bcdd55e
6e36fb
---
125681
 CMakeLists.txt       | 13 +++++++++++--
96dd81
 src/CMakeLists.txt   | 16 +++++++++++-----
6e36fb
 src/chksum.c         | 32 ++++++++++++++++++++++++++++++++
6e36fb
 tools/CMakeLists.txt |  2 +-
125681
 4 files changed, 55 insertions(+), 8 deletions(-)
6e36fb
6e36fb
diff --git a/CMakeLists.txt b/CMakeLists.txt
125681
index 3541f496..e73dc552 100644
6e36fb
--- a/CMakeLists.txt
6e36fb
+++ b/CMakeLists.txt
47875b
@@ -40,6 +40,7 @@ OPTION (ENABLE_ZCHUNK_COMPRESSION "Build with zchunk compression support?" OFF)
6e36fb
 OPTION (WITH_SYSTEM_ZCHUNK "Use system zchunk library?" OFF)
6e36fb
 OPTION (WITH_LIBXML2  "Build with libxml2 instead of libexpat?" OFF)
96dd81
 OPTION (WITHOUT_COOKIEOPEN "Disable the use of stdio cookie opens?" OFF)
6e36fb
+OPTION (WITH_OPENSSL "Use OpenSSL instead of internal implementation of hashes?" OFF)
6e36fb
 
96dd81
 include (GNUInstallDirs)
96dd81
 message (STATUS "Libraries will be installed in ${CMAKE_INSTALL_FULL_LIBDIR}")
125681
@@ -164,6 +165,11 @@ INCLUDE_DIRECTORIES (${EXPAT_INCLUDE_DIRS})
6e36fb
 ENDIF (WITH_LIBXML2 )
6e36fb
 ENDIF (ENABLE_RPMMD OR ENABLE_SUSEREPO OR ENABLE_APPDATA OR ENABLE_COMPS OR ENABLE_HELIXREPO OR ENABLE_MDKREPO)
6e36fb
 
6e36fb
+IF (WITH_OPENSSL)
6e36fb
+FIND_PACKAGE (OpenSSL REQUIRED)
6e36fb
+INCLUDE_DIRECTORIES (${OPENSSL_INCLUDE_DIR})
6e36fb
+ENDIF(WITH_OPENSSL)
6e36fb
+
6e36fb
 IF (ENABLE_ZLIB_COMPRESSION)
6e36fb
 FIND_PACKAGE (ZLIB REQUIRED)
6e36fb
 INCLUDE_DIRECTORIES (${ZLIB_INCLUDE_DIRS})
125681
@@ -288,8 +294,8 @@ ENDIF (${CMAKE_MAJOR_VERSION} GREATER 2)
125681
 
6e36fb
 # should create config.h with #cmakedefine instead...
6e36fb
 FOREACH (VAR HAVE_STRCHRNUL HAVE_FOPENCOOKIE HAVE_FUNOPEN WORDS_BIGENDIAN
125681
-  HAVE_RPM_DB_H HAVE_RPMDBNEXTITERATORHEADERBLOB HAVE_RPMDBFSTAT
47875b
-  WITH_LIBXML2 WITHOUT_COOKIEOPEN)
125681
+  HAVE_RPM_DB_H HAVE_PGPDIGGETPARAMS HAVE_RPMDBNEXTITERATORHEADERBLOB HAVE_RPMDBFSTAT
47875b
+  WITH_LIBXML2 WITHOUT_COOKIEOPEN WITH_OPENSSL)
6e36fb
   IF(${VAR})
6e36fb
     ADD_DEFINITIONS (-D${VAR}=1)
6e36fb
     SET (SWIG_FLAGS ${SWIG_FLAGS} -D${VAR})
125681
@@ -426,6 +432,9 @@ ENDIF (ENABLE_ZSTD_COMPRESSION)
6e36fb
 IF (WITH_SYSTEM_ZCHUNK)
6e36fb
 SET (SYSTEM_LIBRARIES ${SYSTEM_LIBRARIES} ${ZCHUNK_LIBRARIES})
6e36fb
 ENDIF (WITH_SYSTEM_ZCHUNK)
6e36fb
+IF (WITH_OPENSSL)
6e36fb
+SET (SYSTEM_LIBRARIES ${SYSTEM_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
6e36fb
+ENDIF (WITH_OPENSSL)
6e36fb
 IF (ENABLE_RPMDB)
6e36fb
 SET (SYSTEM_LIBRARIES ${RPMDB_LIBRARY} ${SYSTEM_LIBRARIES})
6e36fb
 ENDIF (ENABLE_RPMDB)
6e36fb
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
125681
index bbf30bac..ece870ee 100644
6e36fb
--- a/src/CMakeLists.txt
6e36fb
+++ b/src/CMakeLists.txt
6e36fb
@@ -18,9 +18,8 @@ SET (libsolv_SRCS
6e36fb
     solver.c solverdebug.c repo_solv.c repo_write.c evr.c pool.c
6e36fb
     queue.c repo.c repodata.c repopage.c util.c policy.c solvable.c
6e36fb
     transaction.c order.c rules.c problems.c linkedpkg.c cplxdeps.c
6e36fb
-    chksum.c md5.c sha1.c sha2.c solvversion.c selection.c
6e36fb
-    fileprovides.c diskusage.c suse.c solver_util.c cleandeps.c
6e36fb
-    userinstalled.c filelistfilter.c)
6e36fb
+    chksum.c solvversion.c selection.c fileprovides.c diskusage.c
6e36fb
+    suse.c solver_util.c cleandeps.c userinstalled.c filelistfilter.c)
6e36fb
 
6e36fb
 SET (libsolv_HEADERS
6e36fb
     bitmap.h evr.h hash.h policy.h poolarch.h poolvendor.h pool.h
96dd81
@@ -43,14 +42,21 @@ IF (WIN32)
96dd81
     LIST (APPEND libsolv_SRCS ${WIN32_COMPAT_SOURCES})
96dd81
 ENDIF (WIN32)
6e36fb
 
6e36fb
+IF (NOT WITH_OPENSSL)
6e36fb
+  SET (libsolv_SRCS ${libsolv_SRCS} md5.c sha1.c sha2.c)
6e36fb
+ENDIF (NOT WITH_OPENSSL)
96dd81
+
6e36fb
 IF (HAVE_LINKER_VERSION_SCRIPT)
6e36fb
 SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINK_FLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/src/libsolv.ver")
6e36fb
 ENDIF (HAVE_LINKER_VERSION_SCRIPT)
6e36fb
 
6e36fb
 IF (DISABLE_SHARED)
125681
-    ADD_LIBRARY (libsolv STATIC ${libsolv_SRCS})
6e36fb
+  ADD_LIBRARY (libsolv STATIC ${libsolv_SRCS})
6e36fb
 ELSE (DISABLE_SHARED)
125681
-    ADD_LIBRARY (libsolv SHARED ${libsolv_SRCS})
6e36fb
+  ADD_LIBRARY (libsolv SHARED ${libsolv_SRCS})
6e36fb
+  IF (WITH_OPENSSL)
6e36fb
+    TARGET_LINK_LIBRARIES (libsolv ${OPENSSL_CRYPTO_LIBRARY})
6e36fb
+  ENDIF (WITH_OPENSSL)
6e36fb
 ENDIF (DISABLE_SHARED)
6e36fb
 
125681
 IF (WIN32)
6e36fb
diff --git a/src/chksum.c b/src/chksum.c
96dd81
index 1f8ab471..9189b744 100644
6e36fb
--- a/src/chksum.c
6e36fb
+++ b/src/chksum.c
6e36fb
@@ -15,10 +15,42 @@
6e36fb
 #include "util.h"
6e36fb
 #include "chksum.h"
6e36fb
 
6e36fb
+#ifdef WITH_OPENSSL
6e36fb
+
6e36fb
+#include <openssl/md5.h>
6e36fb
+#include <openssl/sha.h>
6e36fb
+
6e36fb
+typedef SHA_CTX SHA1_CTX;
6e36fb
+typedef SHA256_CTX SHA224_CTX;
6e36fb
+typedef SHA512_CTX SHA384_CTX;
6e36fb
+
6e36fb
+#define solv_MD5_Init(ctx) MD5_Init(ctx)
6e36fb
+#define solv_MD5_Update(ctx, data, len) MD5_Update(ctx, data, len)
6e36fb
+#define solv_MD5_Final(md, ctx) MD5_Final(md, ctx)
6e36fb
+#define solv_SHA1_Init(ctx) SHA1_Init(ctx)
6e36fb
+#define solv_SHA1_Update(ctx, data, len) SHA1_Update(ctx, data, len)
6e36fb
+#define solv_SHA1_Final(ctx, md) SHA1_Final(md, ctx)
6e36fb
+#define solv_SHA224_Init(ctx) SHA224_Init(ctx)
6e36fb
+#define solv_SHA224_Update(ctx, data, len) SHA224_Update(ctx, data, len)
6e36fb
+#define solv_SHA224_Final(md, ctx) SHA224_Final(md, ctx)
6e36fb
+#define solv_SHA256_Init(ctx) SHA256_Init(ctx)
6e36fb
+#define solv_SHA256_Update(ctx, data, len) SHA256_Update(ctx, data, len)
6e36fb
+#define solv_SHA256_Final(md, ctx) SHA256_Final(md, ctx)
6e36fb
+#define solv_SHA384_Init(ctx) SHA384_Init(ctx)
6e36fb
+#define solv_SHA384_Update(ctx, data, len) SHA384_Update(ctx, data, len)
6e36fb
+#define solv_SHA384_Final(md, ctx) SHA384_Final(md, ctx)
6e36fb
+#define solv_SHA512_Init(ctx) SHA512_Init(ctx)
6e36fb
+#define solv_SHA512_Update(ctx, data, len) SHA512_Update(ctx, data, len)
6e36fb
+#define solv_SHA512_Final(md, ctx) SHA512_Final(md, ctx)
6e36fb
+
6e36fb
+#else
6e36fb
+
6e36fb
 #include "md5.h"
6e36fb
 #include "sha1.h"
6e36fb
 #include "sha2.h"
6e36fb
 
6e36fb
+#endif
6e36fb
+
96dd81
 #ifdef _WIN32
96dd81
   #include "strfncs.h"
96dd81
 #endif
6e36fb
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
96dd81
index f19030eb..d477e195 100644
6e36fb
--- a/tools/CMakeLists.txt
6e36fb
+++ b/tools/CMakeLists.txt
96dd81
@@ -116,7 +116,7 @@ SET(tools_list ${tools_list} repo2solv)
96dd81
 ENDIF (NOT WIN32)
6e36fb
 
6e36fb
 ADD_EXECUTABLE (dumpsolv dumpsolv.c )
6e36fb
-TARGET_LINK_LIBRARIES (dumpsolv libsolv)
6e36fb
+TARGET_LINK_LIBRARIES (dumpsolv libsolv ${SYSTEM_LIBRARIES})
6e36fb
 
6e36fb
 ADD_EXECUTABLE (mergesolv mergesolv.c )
6e36fb
 TARGET_LINK_LIBRARIES (mergesolv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES})
47875b
-- 
125681
2.26.2
47875b