tools: cmake: import another upstream commit for OpenSSL backwards compatibility
[openwrt/openwrt.git] / tools / cmake / patches / 130-upstream-libarchive-openssl-compat-headers.patch
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
5
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.
10 ---
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
20
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
26 archive_hmac.c
27 archive_hmac_private.h
28 archive_match.c
29 + archive_openssl_evp_private.h
30 + archive_openssl_hmac_private.h
31 archive_options.c
32 archive_options_private.h
33 archive_pack_dev.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 {
39 } archive_crypto_ctx;
40
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
46
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
51 @@ -134,7 +134,7 @@
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"
57 #endif
58
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;
66
67 #elif defined(HAVE_LIBCRYPTO)
68 -#include <openssl/hmac.h>
69 +#include "archive_openssl_hmac_private.h"
70
71 typedef HMAC_CTX archive_hmac_sha1_ctx;
72
73 diff --git a/Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h b/Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h
74 new file mode 100644
75 index 0000000..0e97e27
76 --- /dev/null
77 +++ b/Utilities/cmlibarchive/libarchive/archive_openssl_evp_private.h
78 @@ -0,0 +1,51 @@
79 +/*-
80 + * Copyright (c) 2003-2007 Tim Kientzle
81 + * All rights reserved.
82 + *
83 + * Redistribution and use in source and binary forms, with or without
84 + * modification, are permitted provided that the following conditions
85 + * are met:
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.
91 + *
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.
102 + */
103 +#ifndef ARCHIVE_OPENSSL_EVP_PRIVATE_H_INCLUDED
104 +#define ARCHIVE_OPENSSL_EVP_PRIVATE_H_INCLUDED
105 +
106 +#include <openssl/evp.h>
107 +#include <openssl/opensslv.h>
108 +
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)
113 +{
114 + EVP_MD_CTX *ctx = (EVP_MD_CTX *)malloc(sizeof(EVP_MD_CTX));
115 + if (ctx != NULL) {
116 + memset(ctx, 0, sizeof(*ctx));
117 + }
118 + return ctx;
119 +}
120 +
121 +static inline void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
122 +{
123 + EVP_MD_CTX_cleanup(ctx);
124 + memset(ctx, 0, sizeof(*ctx));
125 + free(ctx);
126 +}
127 +#endif
128 +
129 +#endif
130 diff --git a/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
131 new file mode 100644
132 index 0000000..d4ae0d1
133 --- /dev/null
134 +++ b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
135 @@ -0,0 +1,52 @@
136 +/*-
137 + * Copyright (c) 2003-2007 Tim Kientzle
138 + * All rights reserved.
139 + *
140 + * Redistribution and use in source and binary forms, with or without
141 + * modification, are permitted provided that the following conditions
142 + * are met:
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.
148 + *
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.
159 + */
160 +#ifndef ARCHIVE_OPENSSL_HMAC_PRIVATE_H_INCLUDED
161 +#define ARCHIVE_OPENSSL_HMAC_PRIVATE_H_INCLUDED
162 +
163 +#include <openssl/hmac.h>
164 +#include <openssl/opensslv.h>
165 +
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)
170 +{
171 + HMAC_CTX *ctx = (HMAC_CTX *)malloc(sizeof(HMAC_CTX));
172 + if (ctx != NULL) {
173 + memset(ctx, 0, sizeof(*ctx));
174 + HMAC_CTX_init(ctx);
175 + }
176 + return ctx;
177 +}
178 +
179 +static inline void HMAC_CTX_free(HMAC_CTX *ctx)
180 +{
181 + HMAC_CTX_cleanup(ctx);
182 + memset(ctx, 0, sizeof(*ctx));
183 + free(ctx);
184 +}
185 +#endif
186 +
187 +#endif
188 --
189 libgit2 0.24.0
190