1 From 7d433206cf7de8f28aa2d169ed25cd401fcfc413 Mon Sep 17 00:00:00 2001
2 From: Brad King <brad.king@kitware.com>
3 Date: Thu, 17 Nov 2016 15:26:41 -0500
4 Subject: [PATCH] libarchive: Add headers to adapt between OpenSSL 1.1 and older versions
6 Add private forwarding headers for `openssl/{evp,hmac}.h` to give us a
7 central place to add adaptation code to work across multiple
8 incompatible OpenSSL versions. Provide compatibility implementations of
9 some OpenSSL 1.1 APIs when using older OpenSSL versions.
11 Utilities/cmlibarchive/libarchive/CMakeLists.txt | 2 ++
12 Utilities/cmlibarchive/libarchive/archive_cryptor_private.h | 2 +-
13 Utilities/cmlibarchive/libarchive/archive_digest_private.h | 2 +-
14 Utilities/cmlibarchive/libarchive/archive_hmac_private.h | 2 +-
15 Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
16 Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
17 6 files changed, 108 insertions(+), 3 deletions(-)
18 create mode 100644 Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h
19 create mode 100644 Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
21 diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
22 index 4eeb5e3..eaa7b20 100644
23 --- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt
24 +++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
25 @@ -38,6 +38,8 @@ SET(libarchive_SOURCES
27 archive_hmac_private.h
29 + archive_openssl_evp_private.h
30 + archive_openssl_hmac_private.h
32 archive_options_private.h
34 diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
35 index 37eaad3..1c1a8c0 100644
36 --- a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
37 +++ b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
38 @@ -99,7 +99,7 @@ typedef struct {
41 #elif defined(HAVE_LIBCRYPTO)
42 -#include <openssl/evp.h>
43 +#include "archive_openssl_evp_private.h"
44 #define AES_BLOCK_SIZE 16
45 #define AES_MAX_KEY_SIZE 32
47 diff --git a/Utilities/cmlibarchive/libarchive/archive_digest_private.h b/Utilities/cmlibarchive/libarchive/archive_digest_private.h
48 index 77fad58..00697ae 100644
49 --- a/Utilities/cmlibarchive/libarchive/archive_digest_private.h
50 +++ b/Utilities/cmlibarchive/libarchive/archive_digest_private.h
52 defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) ||\
53 defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
54 #define ARCHIVE_CRYPTO_OPENSSL 1
55 -#include <openssl/evp.h>
56 +#include "archive_openssl_evp_private.h"
59 /* Windows crypto headers */
60 diff --git a/Utilities/cmlibarchive/libarchive/archive_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
61 index 64de743..f36d694 100644
62 --- a/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
63 +++ b/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
64 @@ -70,7 +70,7 @@ typedef struct {
65 typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx;
67 #elif defined(HAVE_LIBCRYPTO)
68 -#include <openssl/hmac.h>
69 +#include "archive_openssl_hmac_private.h"
71 typedef HMAC_CTX archive_hmac_sha1_ctx;
73 diff --git a/Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h b/Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h
75 index 0000000..0e97e27
77 +++ b/Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h
80 + * Copyright (c) 2003-2007 Tim Kientzle
81 + * All rights reserved.
83 + * Redistribution and use in source and binary forms, with or without
84 + * modification, are permitted provided that the following conditions
86 + * 1. Redistributions of source code must retain the above copyright
87 + * notice, this list of conditions and the following disclaimer.
88 + * 2. Redistributions in binary form must reproduce the above copyright
89 + * notice, this list of conditions and the following disclaimer in the
90 + * documentation and/or other materials provided with the distribution.
92 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
93 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
94 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
95 + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
96 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
98 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
99 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103 +#ifndef ARCHIVE_OPENSSL_EVP_PRIVATE_H_INCLUDED
104 +#define ARCHIVE_OPENSSL_EVP_PRIVATE_H_INCLUDED
106 +#include <openssl/evp.h>
107 +#include <openssl/opensslv.h>
109 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
110 +#include <stdlib.h> /* malloc, free */
111 +#include <string.h> /* memset */
112 +static inline EVP_MD_CTX *EVP_MD_CTX_new(void)
114 + EVP_MD_CTX *ctx = (EVP_MD_CTX *)malloc(sizeof(EVP_MD_CTX));
116 + memset(ctx, 0, sizeof(*ctx));
121 +static inline void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
123 + EVP_MD_CTX_cleanup(ctx);
124 + memset(ctx, 0, sizeof(*ctx));
130 diff --git a/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
132 index 0000000..d4ae0d1
134 +++ b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
137 + * Copyright (c) 2003-2007 Tim Kientzle
138 + * All rights reserved.
140 + * Redistribution and use in source and binary forms, with or without
141 + * modification, are permitted provided that the following conditions
143 + * 1. Redistributions of source code must retain the above copyright
144 + * notice, this list of conditions and the following disclaimer.
145 + * 2. Redistributions in binary form must reproduce the above copyright
146 + * notice, this list of conditions and the following disclaimer in the
147 + * documentation and/or other materials provided with the distribution.
149 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
150 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
151 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
152 + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
153 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
154 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
155 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
156 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
157 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
158 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
160 +#ifndef ARCHIVE_OPENSSL_HMAC_PRIVATE_H_INCLUDED
161 +#define ARCHIVE_OPENSSL_HMAC_PRIVATE_H_INCLUDED
163 +#include <openssl/hmac.h>
164 +#include <openssl/opensslv.h>
166 +#if OPENSSL_VERSION_NUMBER < 0x10100000L
167 +#include <stdlib.h> /* malloc, free */
168 +#include <string.h> /* memset */
169 +static inline HMAC_CTX *HMAC_CTX_new(void)
171 + HMAC_CTX *ctx = (HMAC_CTX *)malloc(sizeof(HMAC_CTX));
173 + memset(ctx, 0, sizeof(*ctx));
174 + HMAC_CTX_init(ctx);
179 +static inline void HMAC_CTX_free(HMAC_CTX *ctx)
181 + HMAC_CTX_cleanup(ctx);
182 + memset(ctx, 0, sizeof(*ctx));