aboutsummaryrefslogtreecommitdiffstats
path: root/security/botan110/files/extra-patch-openssl11
blob: 584e7aa309e88894cca580d1be02eca4c8a641d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
--- src/engine/openssl/ossl_bc.cpp.orig 2017-10-02 06:00:00 UTC
+++ src/engine/openssl/ossl_bc.cpp
@@ -8,10 +8,6 @@
 #include <botan/internal/openssl_engine.h>
 #include <openssl/evp.h>
 
-#if OPENSSL_VERSION_NUMBER >= 0x10100000
-  #error "OpenSSL 1.1 API not supported in Botan 1.10, upgrade to 2.x"
-#endif
-
 namespace Botan {
 
 namespace {
@@ -44,7 +40,7 @@ class EVP_BlockCipher : public BlockCipher
       size_t block_sz;
       Key_Length_Specification cipher_key_spec;
       std::string cipher_name;
-      mutable EVP_CIPHER_CTX encrypt, decrypt;
+      mutable EVP_CIPHER_CTX *encrypt, *decrypt;
    };
 
 /*
@@ -59,14 +55,15 @@ EVP_BlockCipher::EVP_BlockCipher(const EVP_CIPHER* alg
    if(EVP_CIPHER_mode(algo) != EVP_CIPH_ECB_MODE)
       throw Invalid_Argument("EVP_BlockCipher: Non-ECB EVP was passed in");
 
-   EVP_CIPHER_CTX_init(&encrypt);
-   EVP_CIPHER_CTX_init(&decrypt);
+   if ((encrypt = EVP_CIPHER_CTX_new()) == NULL)
+      throw Invalid_Argument("EVP_BlockCipher: EVP_CIPHER_CTX_new failed");
+   EVP_EncryptInit_ex(encrypt, algo, 0, 0, 0);
+   EVP_CIPHER_CTX_set_padding(encrypt, 0);
 
-   EVP_EncryptInit_ex(&encrypt, algo, 0, 0, 0);
-   EVP_DecryptInit_ex(&decrypt, algo, 0, 0, 0);
-
-   EVP_CIPHER_CTX_set_padding(&encrypt, 0);
-   EVP_CIPHER_CTX_set_padding(&decrypt, 0);
+   if ((decrypt = EVP_CIPHER_CTX_new()) == NULL)
+      throw Invalid_Argument("EVP_BlockCipher: EVP_CIPHER_CTX_new failed");
+   EVP_DecryptInit_ex(decrypt, algo, 0, 0, 0);
+   EVP_CIPHER_CTX_set_padding(decrypt, 0);
    }
 
 /*
@@ -83,14 +80,15 @@ EVP_BlockCipher::EVP_BlockCipher(const EVP_CIPHER* alg
    if(EVP_CIPHER_mode(algo) != EVP_CIPH_ECB_MODE)
       throw Invalid_Argument("EVP_BlockCipher: Non-ECB EVP was passed in");
 
-   EVP_CIPHER_CTX_init(&encrypt);
-   EVP_CIPHER_CTX_init(&decrypt);
+   if ((encrypt = EVP_CIPHER_CTX_new()) == NULL)
+      throw Invalid_Argument("EVP_BlockCipher: EVP_CIPHER_CTX_new failed");
+   EVP_EncryptInit_ex(encrypt, algo, 0, 0, 0);
+   EVP_CIPHER_CTX_set_padding(encrypt, 0);
 
-   EVP_EncryptInit_ex(&encrypt, algo, 0, 0, 0);
-   EVP_DecryptInit_ex(&decrypt, algo, 0, 0, 0);
-
-   EVP_CIPHER_CTX_set_padding(&encrypt, 0);
-   EVP_CIPHER_CTX_set_padding(&decrypt, 0);
+   if ((decrypt = EVP_CIPHER_CTX_new()) == NULL)
+      throw Invalid_Argument("EVP_BlockCipher: EVP_CIPHER_CTX_new failed");
+   EVP_DecryptInit_ex(decrypt, algo, 0, 0, 0);
+   EVP_CIPHER_CTX_set_padding(decrypt, 0);
    }
 
 /*
@@ -98,8 +96,8 @@ EVP_BlockCipher::EVP_BlockCipher(const EVP_CIPHER* alg
 */
 EVP_BlockCipher::~EVP_BlockCipher()
    {
-   EVP_CIPHER_CTX_cleanup(&encrypt);
-   EVP_CIPHER_CTX_cleanup(&decrypt);
+   EVP_CIPHER_CTX_cleanup(encrypt);
+   EVP_CIPHER_CTX_cleanup(decrypt);
    }
 
 /*
@@ -109,7 +107,7 @@ void EVP_BlockCipher::encrypt_n(const byte in[], byte 
                                 size_t blocks) const
    {
    int out_len = 0;
-   EVP_EncryptUpdate(&encrypt, out, &out_len, in, blocks * block_sz);
+   EVP_EncryptUpdate(encrypt, out, &out_len, in, blocks * block_sz);
    }
 
 /*
@@ -119,7 +117,7 @@ void EVP_BlockCipher::decrypt_n(const byte in[], byte 
                                 size_t blocks) const
    {
    int out_len = 0;
-   EVP_DecryptUpdate(&decrypt, out, &out_len, in, blocks * block_sz);
+   EVP_DecryptUpdate(decrypt, out, &out_len, in, blocks * block_sz);
    }
 
 /*
@@ -134,19 +132,19 @@ void EVP_BlockCipher::key_schedule(const byte key[], s
       full_key += std::make_pair(key, 8);
       }
    else
-      if(EVP_CIPHER_CTX_set_key_length(&encrypt, length) == 0 ||
-         EVP_CIPHER_CTX_set_key_length(&decrypt, length) == 0)
+      if(EVP_CIPHER_CTX_set_key_length(encrypt, length) == 0 ||
+         EVP_CIPHER_CTX_set_key_length(decrypt, length) == 0)
          throw Invalid_Argument("EVP_BlockCipher: Bad key length for " +
                                 cipher_name);
 
    if(cipher_name == "RC2")
       {
-      EVP_CIPHER_CTX_ctrl(&encrypt, EVP_CTRL_SET_RC2_KEY_BITS, length*8, 0);
-      EVP_CIPHER_CTX_ctrl(&decrypt, EVP_CTRL_SET_RC2_KEY_BITS, length*8, 0);
+      EVP_CIPHER_CTX_ctrl(encrypt, EVP_CTRL_SET_RC2_KEY_BITS, length*8, 0);
+      EVP_CIPHER_CTX_ctrl(decrypt, EVP_CTRL_SET_RC2_KEY_BITS, length*8, 0);
       }
 
-   EVP_EncryptInit_ex(&encrypt, 0, 0, full_key.begin(), 0);
-   EVP_DecryptInit_ex(&decrypt, 0, 0, full_key.begin(), 0);
+   EVP_EncryptInit_ex(encrypt, 0, 0, full_key.begin(), 0);
+   EVP_DecryptInit_ex(decrypt, 0, 0, full_key.begin(), 0);
    }
 
 /*
@@ -154,7 +152,7 @@ void EVP_BlockCipher::key_schedule(const byte key[], s
 */
 BlockCipher* EVP_BlockCipher::clone() const
    {
-   return new EVP_BlockCipher(EVP_CIPHER_CTX_cipher(&encrypt),
+   return new EVP_BlockCipher(EVP_CIPHER_CTX_cipher(encrypt),
                               cipher_name,
                               cipher_key_spec.minimum_keylength(),
                               cipher_key_spec.maximum_keylength(),
@@ -166,16 +164,16 @@ BlockCipher* EVP_BlockCipher::clone() const
 */
 void EVP_BlockCipher::clear()
    {
-   const EVP_CIPHER* algo = EVP_CIPHER_CTX_cipher(&encrypt);
+   const EVP_CIPHER* algo = EVP_CIPHER_CTX_cipher(encrypt);
 
-   EVP_CIPHER_CTX_cleanup(&encrypt);
-   EVP_CIPHER_CTX_cleanup(&decrypt);
-   EVP_CIPHER_CTX_init(&encrypt);
-   EVP_CIPHER_CTX_init(&decrypt);
-   EVP_EncryptInit_ex(&encrypt, algo, 0, 0, 0);
-   EVP_DecryptInit_ex(&decrypt, algo, 0, 0, 0);
-   EVP_CIPHER_CTX_set_padding(&encrypt, 0);
-   EVP_CIPHER_CTX_set_padding(&decrypt, 0);
+   EVP_CIPHER_CTX_cleanup(encrypt);
+   EVP_CIPHER_CTX_cleanup(decrypt);
+   EVP_CIPHER_CTX_init(encrypt);
+   EVP_CIPHER_CTX_init(decrypt);
+   EVP_EncryptInit_ex(encrypt, algo, 0, 0, 0);
+   EVP_DecryptInit_ex(decrypt, algo, 0, 0, 0);
+   EVP_CIPHER_CTX_set_padding(encrypt, 0);
+   EVP_CIPHER_CTX_set_padding(decrypt, 0);
    }
 
 }
--- src/engine/openssl/ossl_md.cpp.orig 2017-10-02 06:00:00 UTC
+++ src/engine/openssl/ossl_md.cpp
@@ -8,10 +8,6 @@
 #include <botan/internal/openssl_engine.h>
 #include <openssl/evp.h>
 
-#if OPENSSL_VERSION_NUMBER >= 0x10100000
-  #error "OpenSSL 1.1 API not supported in Botan 1.10, upgrade to 2.x"
-#endif
-
 namespace Botan {
 
 namespace {
@@ -28,12 +24,12 @@ class EVP_HashFunction : public HashFunction
 
       size_t output_length() const
          {
-         return EVP_MD_size(EVP_MD_CTX_md(&md));
+         return EVP_MD_size(EVP_MD_CTX_md(md));
          }
 
       size_t hash_block_size() const
          {
-         return EVP_MD_block_size(EVP_MD_CTX_md(&md));
+         return EVP_MD_block_size(EVP_MD_CTX_md(md));
          }
 
       EVP_HashFunction(const EVP_MD*, const std::string&);
@@ -44,7 +40,7 @@ class EVP_HashFunction : public HashFunction
 
       size_t block_size;
       std::string algo_name;
-      EVP_MD_CTX md;
+      EVP_MD_CTX *md;
    };
 
 /*
@@ -52,7 +48,7 @@ class EVP_HashFunction : public HashFunction
 */
 void EVP_HashFunction::add_data(const byte input[], size_t length)
    {
-   EVP_DigestUpdate(&md, input, length);
+   EVP_DigestUpdate(md, input, length);
    }
 
 /*
@@ -60,9 +56,9 @@ void EVP_HashFunction::add_data(const byte input[], si
 */
 void EVP_HashFunction::final_result(byte output[])
    {
-   EVP_DigestFinal_ex(&md, output, 0);
-   const EVP_MD* algo = EVP_MD_CTX_md(&md);
-   EVP_DigestInit_ex(&md, algo, 0);
+   EVP_DigestFinal_ex(md, output, 0);
+   const EVP_MD* algo = EVP_MD_CTX_md(md);
+   EVP_DigestInit_ex(md, algo, 0);
    }
 
 /*
@@ -70,8 +66,8 @@ void EVP_HashFunction::final_result(byte output[])
 */
 void EVP_HashFunction::clear()
    {
-   const EVP_MD* algo = EVP_MD_CTX_md(&md);
-   EVP_DigestInit_ex(&md, algo, 0);
+   const EVP_MD* algo = EVP_MD_CTX_md(md);
+   EVP_DigestInit_ex(md, algo, 0);
    }
 
 /*
@@ -79,7 +75,7 @@ void EVP_HashFunction::clear()
 */
 HashFunction* EVP_HashFunction::clone() const
    {
-   const EVP_MD* algo = EVP_MD_CTX_md(&md);
+   const EVP_MD* algo = EVP_MD_CTX_md(md);
    return new EVP_HashFunction(algo, name());
    }
 
@@ -90,8 +86,9 @@ EVP_HashFunction::EVP_HashFunction(const EVP_MD* algo,
                                    const std::string& name) :
    algo_name(name)
    {
-   EVP_MD_CTX_init(&md);
-   EVP_DigestInit_ex(&md, algo, 0);
+   if ((md = EVP_MD_CTX_new()) == NULL)
+     throw Invalid_Argument("EVP_HashFunction: EVP_MD_CTX_new failed");
+   EVP_DigestInit_ex(md, algo, 0);
    }
 
 /*
@@ -99,7 +96,11 @@ EVP_HashFunction::EVP_HashFunction(const EVP_MD* algo,
 */
 EVP_HashFunction::~EVP_HashFunction()
    {
-   EVP_MD_CTX_cleanup(&md);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000
+   EVP_MD_CTX_free(md);
+#else
+   EVP_MD_CTX_cleanup(md);
+#endif
    }
 
 }