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

161 lines
5.9 KiB
Diff
Raw Normal View History

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