|
Added
Link Here
|
| 0 |
- |
1 |
From 61399410964d61aec3609a1bc76fd260268b3ade Mon Sep 17 00:00:00 2001 |
|
|
2 |
From: Kurt Roeckx <kurt@roeckx.be> |
| 3 |
Date: Wed, 31 Aug 2016 23:00:39 +0200 |
| 4 |
Subject: [PATCH] Add OpenSSL 1.1.0 support |
| 5 |
|
| 6 |
--- |
| 7 |
configure.in | 6 +- |
| 8 |
lib/dns/openssl_link.c | 38 ++++--- |
| 9 |
lib/dns/openssldh_link.c | 255 +++++++++++++++++++++++++++++--------------- |
| 10 |
lib/dns/openssldsa_link.c | 170 +++++++++++++++++++++-------- |
| 11 |
lib/dns/opensslecdsa_link.c | 31 ++++-- |
| 12 |
lib/dns/opensslrsa_link.c | 246 ++++++++++++++++++++++++++++++------------ |
| 13 |
lib/isc/aes.c | 36 +++---- |
| 14 |
8 files changed, 554 insertions(+), 248 deletions(-) |
| 15 |
|
| 16 |
Index: bind9-9.10.3.dfsg.P4/configure.in |
| 17 |
=================================================================== |
| 18 |
--- configure.in.orig |
| 19 |
+++ configure.in |
| 20 |
@@ -1546,15 +1546,13 @@ shared library configuration (e.g., LD_L |
| 21 |
AC_MSG_CHECKING(whether linking with OpenSSL requires -ldl) |
| 22 |
AC_TRY_LINK([ |
| 23 |
#include <openssl/err.h> |
| 24 |
-#include <openssl/dso.h> |
| 25 |
], |
| 26 |
-[ DSO_METHOD_dlfcn(); ], |
| 27 |
+[ ERR_clear_error(); ], |
| 28 |
[AC_MSG_RESULT(no)], |
| 29 |
[LIBS="$LIBS -ldl" |
| 30 |
AC_TRY_LINK([ |
| 31 |
#include <openssl/err.h> |
| 32 |
-#include <openssl/dso.h> |
| 33 |
-],[ DSO_METHOD_dlfcn(); ], |
| 34 |
+],[ ERR_clear_error(); ], |
| 35 |
[AC_MSG_RESULT(yes) |
| 36 |
DST_OPENSSL_LIBS="$DST_OPENSSL_LIBS -ldl" |
| 37 |
], |
| 38 |
Index: bind9-9.10.3.dfsg.P4/lib/dns/openssl_link.c |
| 39 |
=================================================================== |
| 40 |
--- lib/dns/openssl_link.c.orig 2016-10-21 07:10:54.000000000 +0200 |
| 41 |
+++ lib/dns/openssl_link.c 2016-12-01 13:49:51.176571694 +0100 |
| 42 |
@@ -58,8 +58,10 @@ |
| 43 |
|
| 44 |
static RAND_METHOD *rm = NULL; |
| 45 |
|
| 46 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 47 |
static isc_mutex_t *locks = NULL; |
| 48 |
static int nlocks; |
| 49 |
+#endif |
| 50 |
|
| 51 |
#ifdef USE_ENGINE |
| 52 |
static ENGINE *e = NULL; |
| 53 |
@@ -111,6 +113,7 @@ |
| 54 |
} |
| 55 |
#endif |
| 56 |
|
| 57 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 58 |
static void |
| 59 |
lock_callback(int mode, int type, const char *file, int line) { |
| 60 |
UNUSED(file); |
| 61 |
@@ -120,6 +123,7 @@ |
| 62 |
else |
| 63 |
UNLOCK(&locks[type]); |
| 64 |
} |
| 65 |
+#endif |
| 66 |
|
| 67 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) |
| 68 |
static unsigned long |
| 69 |
@@ -129,7 +133,11 @@ |
| 70 |
#endif |
| 71 |
|
| 72 |
static void * |
| 73 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 74 |
mem_alloc(size_t size) { |
| 75 |
+#else |
| 76 |
+mem_alloc(size_t size, const char *file, int line) { |
| 77 |
+#endif |
| 78 |
#ifdef OPENSSL_LEAKS |
| 79 |
void *ptr; |
| 80 |
|
| 81 |
@@ -143,14 +151,22 @@ |
| 82 |
} |
| 83 |
|
| 84 |
static void |
| 85 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 86 |
mem_free(void *ptr) { |
| 87 |
+#else |
| 88 |
+mem_free(void *ptr, const char *file, int line) { |
| 89 |
+#endif |
| 90 |
INSIST(dst__memory_pool != NULL); |
| 91 |
if (ptr != NULL) |
| 92 |
isc_mem_free(dst__memory_pool, ptr); |
| 93 |
} |
| 94 |
|
| 95 |
static void * |
| 96 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 97 |
mem_realloc(void *ptr, size_t size) { |
| 98 |
+#else |
| 99 |
+mem_realloc(void *ptr, size_t size, const char *file, int line) { |
| 100 |
+#endif |
| 101 |
#ifdef OPENSSL_LEAKS |
| 102 |
void *rptr; |
| 103 |
|
| 104 |
@@ -179,6 +195,7 @@ |
| 105 |
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); |
| 106 |
#endif |
| 107 |
CRYPTO_set_mem_functions(mem_alloc, mem_realloc, mem_free); |
| 108 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 109 |
nlocks = CRYPTO_num_locks(); |
| 110 |
locks = mem_alloc(sizeof(isc_mutex_t) * nlocks); |
| 111 |
if (locks == NULL) |
| 112 |
@@ -187,13 +204,12 @@ |
| 113 |
if (result != ISC_R_SUCCESS) |
| 114 |
goto cleanup_mutexalloc; |
| 115 |
CRYPTO_set_locking_callback(lock_callback); |
| 116 |
-#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) |
| 117 |
CRYPTO_set_id_callback(id_callback); |
| 118 |
#endif |
| 119 |
|
| 120 |
ERR_load_crypto_strings(); |
| 121 |
|
| 122 |
- rm = mem_alloc(sizeof(RAND_METHOD)); |
| 123 |
+ rm = malloc(sizeof(RAND_METHOD)); |
| 124 |
if (rm == NULL) { |
| 125 |
result = ISC_R_NOMEMORY; |
| 126 |
goto cleanup_mutexinit; |
| 127 |
@@ -263,11 +279,13 @@ |
| 128 |
rm = NULL; |
| 129 |
#endif |
| 130 |
cleanup_mutexinit: |
| 131 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 132 |
CRYPTO_set_locking_callback(NULL); |
| 133 |
DESTROYMUTEXBLOCK(locks, nlocks); |
| 134 |
cleanup_mutexalloc: |
| 135 |
mem_free(locks); |
| 136 |
locks = NULL; |
| 137 |
+#endif |
| 138 |
return (result); |
| 139 |
} |
| 140 |
|
| 141 |
@@ -280,7 +298,7 @@ |
| 142 |
#if OPENSSL_VERSION_NUMBER >= 0x00907000L |
| 143 |
RAND_cleanup(); |
| 144 |
#endif |
| 145 |
- mem_free(rm); |
| 146 |
+ free(rm); |
| 147 |
rm = NULL; |
| 148 |
} |
| 149 |
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L) |
| 150 |
@@ -309,21 +327,20 @@ |
| 151 |
CRYPTO_mem_leaks_fp(stderr); |
| 152 |
#endif |
| 153 |
|
| 154 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 155 |
if (locks != NULL) { |
| 156 |
CRYPTO_set_locking_callback(NULL); |
| 157 |
DESTROYMUTEXBLOCK(locks, nlocks); |
| 158 |
mem_free(locks); |
| 159 |
locks = NULL; |
| 160 |
} |
| 161 |
+#endif |
| 162 |
} |
| 163 |
|
| 164 |
static isc_result_t |
| 165 |
toresult(isc_result_t fallback) { |
| 166 |
isc_result_t result = fallback; |
| 167 |
unsigned long err = ERR_get_error(); |
| 168 |
-#ifdef HAVE_OPENSSL_ECDSA |
| 169 |
- int lib = ERR_GET_LIB(err); |
| 170 |
-#endif |
| 171 |
int reason = ERR_GET_REASON(err); |
| 172 |
|
| 173 |
switch (reason) { |
| 174 |
@@ -335,13 +352,6 @@ |
| 175 |
result = ISC_R_NOMEMORY; |
| 176 |
break; |
| 177 |
default: |
| 178 |
-#ifdef HAVE_OPENSSL_ECDSA |
| 179 |
- if (lib == ERR_R_ECDSA_LIB && |
| 180 |
- reason == ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED) { |
| 181 |
- result = ISC_R_NOENTROPY; |
| 182 |
- break; |
| 183 |
- } |
| 184 |
-#endif |
| 185 |
break; |
| 186 |
} |
| 187 |
|
| 188 |
Index: bind9-9.10.3.dfsg.P4/lib/dns/openssldh_link.c |
| 189 |
=================================================================== |
| 190 |
--- lib/dns/openssldh_link.c.orig |
| 191 |
+++ lib/dns/openssldh_link.c |
| 192 |
@@ -81,6 +81,7 @@ openssldh_computesecret(const dst_key_t |
| 193 |
int ret; |
| 194 |
isc_region_t r; |
| 195 |
unsigned int len; |
| 196 |
+ const BIGNUM *pub_key; |
| 197 |
|
| 198 |
REQUIRE(pub->keydata.dh != NULL); |
| 199 |
REQUIRE(priv->keydata.dh != NULL); |
| 200 |
@@ -92,7 +93,12 @@ openssldh_computesecret(const dst_key_t |
| 201 |
isc_buffer_availableregion(secret, &r); |
| 202 |
if (r.length < len) |
| 203 |
return (ISC_R_NOSPACE); |
| 204 |
- ret = DH_compute_key(r.base, dhpub->pub_key, dhpriv); |
| 205 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 206 |
+ pub_key = dhpub->pub_key; |
| 207 |
+#else |
| 208 |
+ DH_get0_key(dhpub, &pub_key, NULL); |
| 209 |
+#endif |
| 210 |
+ ret = DH_compute_key(r.base, pub_key, dhpriv); |
| 211 |
if (ret <= 0) |
| 212 |
return (dst__openssl_toresult2("DH_compute_key", |
| 213 |
DST_R_COMPUTESECRETFAILURE)); |
| 214 |
@@ -104,6 +110,9 @@ static isc_boolean_t |
| 215 |
openssldh_compare(const dst_key_t *key1, const dst_key_t *key2) { |
| 216 |
int status; |
| 217 |
DH *dh1, *dh2; |
| 218 |
+ const BIGNUM *p1, *p2, *g1, *g2; |
| 219 |
+ const BIGNUM *pub_key1, *pub_key2; |
| 220 |
+ const BIGNUM *priv_key1, *priv_key2; |
| 221 |
|
| 222 |
dh1 = key1->keydata.dh; |
| 223 |
dh2 = key2->keydata.dh; |
| 224 |
@@ -113,17 +122,33 @@ openssldh_compare(const dst_key_t *key1, |
| 225 |
else if (dh1 == NULL || dh2 == NULL) |
| 226 |
return (ISC_FALSE); |
| 227 |
|
| 228 |
- status = BN_cmp(dh1->p, dh2->p) || |
| 229 |
- BN_cmp(dh1->g, dh2->g) || |
| 230 |
- BN_cmp(dh1->pub_key, dh2->pub_key); |
| 231 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 232 |
+ pub_key1 = dh1->pub_key; |
| 233 |
+ pub_key2 = dh2->pub_key; |
| 234 |
+ priv_key1 = dh1->priv_key; |
| 235 |
+ priv_key2 = dh2->priv_key; |
| 236 |
+ p1 = dh1->p; |
| 237 |
+ g1 = dh1->g; |
| 238 |
+ p2 = dh2->p; |
| 239 |
+ g2 = dh2->g; |
| 240 |
+#else |
| 241 |
+ DH_get0_key(dh1, &pub_key1, &priv_key1); |
| 242 |
+ DH_get0_key(dh2, &pub_key2, &priv_key2); |
| 243 |
+ DH_get0_pqg(dh1, &p1, NULL, &g1); |
| 244 |
+ DH_get0_pqg(dh2, &p2, NULL, &g2); |
| 245 |
+#endif |
| 246 |
+ |
| 247 |
+ status = BN_cmp(p1, p2) || |
| 248 |
+ BN_cmp(g1, g2) || |
| 249 |
+ BN_cmp(pub_key1, pub_key2); |
| 250 |
|
| 251 |
if (status != 0) |
| 252 |
return (ISC_FALSE); |
| 253 |
|
| 254 |
- if (dh1->priv_key != NULL || dh2->priv_key != NULL) { |
| 255 |
- if (dh1->priv_key == NULL || dh2->priv_key == NULL) |
| 256 |
+ if (priv_key1 != NULL || priv_key2 != NULL) { |
| 257 |
+ if (priv_key1 == NULL || priv_key2 == NULL) |
| 258 |
return (ISC_FALSE); |
| 259 |
- if (BN_cmp(dh1->priv_key, dh2->priv_key) != 0) |
| 260 |
+ if (BN_cmp(priv_key1, priv_key2) != 0) |
| 261 |
return (ISC_FALSE); |
| 262 |
} |
| 263 |
return (ISC_TRUE); |
| 264 |
@@ -133,6 +158,7 @@ static isc_boolean_t |
| 265 |
openssldh_paramcompare(const dst_key_t *key1, const dst_key_t *key2) { |
| 266 |
int status; |
| 267 |
DH *dh1, *dh2; |
| 268 |
+ const BIGNUM *p1, *p2, *g1, *g2; |
| 269 |
|
| 270 |
dh1 = key1->keydata.dh; |
| 271 |
dh2 = key2->keydata.dh; |
| 272 |
@@ -142,8 +168,18 @@ openssldh_paramcompare(const dst_key_t * |
| 273 |
else if (dh1 == NULL || dh2 == NULL) |
| 274 |
return (ISC_FALSE); |
| 275 |
|
| 276 |
- status = BN_cmp(dh1->p, dh2->p) || |
| 277 |
- BN_cmp(dh1->g, dh2->g); |
| 278 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 279 |
+ p1 = dh1->p; |
| 280 |
+ g1 = dh1->g; |
| 281 |
+ p2 = dh2->p; |
| 282 |
+ g2 = dh2->g; |
| 283 |
+#else |
| 284 |
+ DH_get0_pqg(dh1, &p1, NULL, &g1); |
| 285 |
+ DH_get0_pqg(dh2, &p2, NULL, &g2); |
| 286 |
+#endif |
| 287 |
+ |
| 288 |
+ status = BN_cmp(p1, p2) || |
| 289 |
+ BN_cmp(g1, g2); |
| 290 |
|
| 291 |
if (status != 0) |
| 292 |
return (ISC_FALSE); |
| 293 |
@@ -190,16 +226,29 @@ openssldh_generate(dst_key_t *key, int g |
| 294 |
key->key_size == 1024 || |
| 295 |
key->key_size == 1536) |
| 296 |
{ |
| 297 |
+ BIGNUM *p = NULL, *g = NULL; |
| 298 |
dh = DH_new(); |
| 299 |
if (dh == NULL) |
| 300 |
return (dst__openssl_toresult(ISC_R_NOMEMORY)); |
| 301 |
if (key->key_size == 768) |
| 302 |
- dh->p = bn768; |
| 303 |
+ p = BN_dup(bn768); |
| 304 |
else if (key->key_size == 1024) |
| 305 |
- dh->p = bn1024; |
| 306 |
+ p = BN_dup(bn1024); |
| 307 |
else |
| 308 |
- dh->p = bn1536; |
| 309 |
- dh->g = bn2; |
| 310 |
+ p = BN_dup(bn1536); |
| 311 |
+ g = BN_dup(bn2); |
| 312 |
+ if (p == NULL || g == NULL) { |
| 313 |
+ DH_free(dh); |
| 314 |
+ BN_free(p); |
| 315 |
+ BN_free(g); |
| 316 |
+ return (dst__openssl_toresult(ISC_R_NOMEMORY)); |
| 317 |
+ } |
| 318 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 319 |
+ dh->p = p; |
| 320 |
+ dh->g = g; |
| 321 |
+#else |
| 322 |
+ DH_set0_pqg(dh, p, NULL, g); |
| 323 |
+#endif |
| 324 |
} else |
| 325 |
generator = 2; |
| 326 |
} |
| 327 |
@@ -247,7 +296,11 @@ openssldh_generate(dst_key_t *key, int g |
| 328 |
return (dst__openssl_toresult2("DH_generate_key", |
| 329 |
DST_R_OPENSSLFAILURE)); |
| 330 |
} |
| 331 |
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L |
| 332 |
+ DH_clear_flags(dh, DH_FLAG_CACHE_MONT_P); |
| 333 |
+#else |
| 334 |
dh->flags &= ~DH_FLAG_CACHE_MONT_P; |
| 335 |
+#endif |
| 336 |
|
| 337 |
key->keydata.dh = dh; |
| 338 |
|
| 339 |
@@ -257,20 +310,23 @@ openssldh_generate(dst_key_t *key, int g |
| 340 |
static isc_boolean_t |
| 341 |
openssldh_isprivate(const dst_key_t *key) { |
| 342 |
DH *dh = key->keydata.dh; |
| 343 |
- return (ISC_TF(dh != NULL && dh->priv_key != NULL)); |
| 344 |
+ const BIGNUM *priv_key; |
| 345 |
+ |
| 346 |
+ if (dh == NULL) { |
| 347 |
+ return ISC_FALSE; |
| 348 |
+ } |
| 349 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 350 |
+ priv_key = dh->priv_key; |
| 351 |
+#else |
| 352 |
+ DH_get0_key(dh, NULL, &priv_key); |
| 353 |
+#endif |
| 354 |
+ return (ISC_TF(priv_key != NULL)); |
| 355 |
} |
| 356 |
|
| 357 |
static void |
| 358 |
openssldh_destroy(dst_key_t *key) { |
| 359 |
DH *dh = key->keydata.dh; |
| 360 |
|
| 361 |
- if (dh == NULL) |
| 362 |
- return; |
| 363 |
- |
| 364 |
- if (dh->p == bn768 || dh->p == bn1024 || dh->p == bn1536) |
| 365 |
- dh->p = NULL; |
| 366 |
- if (dh->g == bn2) |
| 367 |
- dh->g = NULL; |
| 368 |
DH_free(dh); |
| 369 |
key->keydata.dh = NULL; |
| 370 |
} |
| 371 |
@@ -301,47 +357,58 @@ openssldh_todns(const dst_key_t *key, is |
| 372 |
DH *dh; |
| 373 |
isc_region_t r; |
| 374 |
isc_uint16_t dnslen, plen, glen, publen; |
| 375 |
+ const BIGNUM *p, *g; |
| 376 |
+ const BIGNUM *pub_key; |
| 377 |
|
| 378 |
REQUIRE(key->keydata.dh != NULL); |
| 379 |
|
| 380 |
dh = key->keydata.dh; |
| 381 |
|
| 382 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 383 |
+ p = dh->p; |
| 384 |
+ g = dh->g; |
| 385 |
+ pub_key = dh->pub_key; |
| 386 |
+#else |
| 387 |
+ DH_get0_pqg(dh, &p, NULL, &g); |
| 388 |
+ DH_get0_key(dh, &pub_key, NULL); |
| 389 |
+#endif |
| 390 |
+ |
| 391 |
isc_buffer_availableregion(data, &r); |
| 392 |
|
| 393 |
- if (dh->g == bn2 && |
| 394 |
- (dh->p == bn768 || dh->p == bn1024 || dh->p == bn1536)) { |
| 395 |
+ if (BN_cmp(g, bn2) == 0 && |
| 396 |
+ (BN_cmp(p, bn768) == 0 || BN_cmp(p, bn1024) == 0 || BN_cmp(p, bn1536) == 0)) { |
| 397 |
plen = 1; |
| 398 |
glen = 0; |
| 399 |
} |
| 400 |
else { |
| 401 |
- plen = BN_num_bytes(dh->p); |
| 402 |
- glen = BN_num_bytes(dh->g); |
| 403 |
+ plen = BN_num_bytes(p); |
| 404 |
+ glen = BN_num_bytes(g); |
| 405 |
} |
| 406 |
- publen = BN_num_bytes(dh->pub_key); |
| 407 |
+ publen = BN_num_bytes(pub_key); |
| 408 |
dnslen = plen + glen + publen + 6; |
| 409 |
if (r.length < (unsigned int) dnslen) |
| 410 |
return (ISC_R_NOSPACE); |
| 411 |
|
| 412 |
uint16_toregion(plen, &r); |
| 413 |
if (plen == 1) { |
| 414 |
- if (dh->p == bn768) |
| 415 |
+ if (BN_cmp(p, bn768) == 0) |
| 416 |
*r.base = 1; |
| 417 |
- else if (dh->p == bn1024) |
| 418 |
+ else if (BN_cmp(p, bn1024) == 0) |
| 419 |
*r.base = 2; |
| 420 |
else |
| 421 |
*r.base = 3; |
| 422 |
} |
| 423 |
else |
| 424 |
- BN_bn2bin(dh->p, r.base); |
| 425 |
+ BN_bn2bin(p, r.base); |
| 426 |
isc_region_consume(&r, plen); |
| 427 |
|
| 428 |
uint16_toregion(glen, &r); |
| 429 |
if (glen > 0) |
| 430 |
- BN_bn2bin(dh->g, r.base); |
| 431 |
+ BN_bn2bin(g, r.base); |
| 432 |
isc_region_consume(&r, glen); |
| 433 |
|
| 434 |
uint16_toregion(publen, &r); |
| 435 |
- BN_bn2bin(dh->pub_key, r.base); |
| 436 |
+ BN_bn2bin(pub_key, r.base); |
| 437 |
isc_region_consume(&r, publen); |
| 438 |
|
| 439 |
isc_buffer_add(data, dnslen); |
| 440 |
@@ -355,6 +422,8 @@ openssldh_fromdns(dst_key_t *key, isc_bu |
| 441 |
isc_region_t r; |
| 442 |
isc_uint16_t plen, glen, publen; |
| 443 |
int special = 0; |
| 444 |
+ BIGNUM *p, *g; |
| 445 |
+ BIGNUM *pub_key; |
| 446 |
|
| 447 |
isc_buffer_remainingregion(data, &r); |
| 448 |
if (r.length == 0) |
| 449 |
@@ -363,7 +432,11 @@ openssldh_fromdns(dst_key_t *key, isc_bu |
| 450 |
dh = DH_new(); |
| 451 |
if (dh == NULL) |
| 452 |
return (dst__openssl_toresult(ISC_R_NOMEMORY)); |
| 453 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 454 |
dh->flags &= ~DH_FLAG_CACHE_MONT_P; |
| 455 |
+#else |
| 456 |
+ DH_clear_flags(dh, DH_FLAG_CACHE_MONT_P); |
| 457 |
+#endif |
| 458 |
|
| 459 |
/* |
| 460 |
* Read the prime length. 1 & 2 are table entries, > 16 means a |
| 461 |
@@ -391,20 +464,20 @@ openssldh_fromdns(dst_key_t *key, isc_bu |
| 462 |
} |
| 463 |
switch (special) { |
| 464 |
case 1: |
| 465 |
- dh->p = bn768; |
| 466 |
+ p = BN_dup(bn768); |
| 467 |
break; |
| 468 |
case 2: |
| 469 |
- dh->p = bn1024; |
| 470 |
+ p = BN_dup(bn1024); |
| 471 |
break; |
| 472 |
case 3: |
| 473 |
- dh->p = bn1536; |
| 474 |
+ p = BN_dup(bn1536); |
| 475 |
break; |
| 476 |
default: |
| 477 |
DH_free(dh); |
| 478 |
return (DST_R_INVALIDPUBLICKEY); |
| 479 |
} |
| 480 |
} else { |
| 481 |
- dh->p = BN_bin2bn(r.base, plen, NULL); |
| 482 |
+ p = BN_bin2bn(r.base, plen, NULL); |
| 483 |
isc_region_consume(&r, plen); |
| 484 |
} |
| 485 |
|
| 486 |
@@ -414,35 +487,42 @@ openssldh_fromdns(dst_key_t *key, isc_bu |
| 487 |
* special, we have a problem. |
| 488 |
*/ |
| 489 |
if (r.length < 2) { |
| 490 |
+ BN_free(p); |
| 491 |
DH_free(dh); |
| 492 |
return (DST_R_INVALIDPUBLICKEY); |
| 493 |
} |
| 494 |
glen = uint16_fromregion(&r); |
| 495 |
if (r.length < glen) { |
| 496 |
+ BN_free(p); |
| 497 |
DH_free(dh); |
| 498 |
return (DST_R_INVALIDPUBLICKEY); |
| 499 |
} |
| 500 |
if (special != 0) { |
| 501 |
if (glen == 0) |
| 502 |
- dh->g = bn2; |
| 503 |
+ g = BN_dup(bn2); |
| 504 |
else { |
| 505 |
- dh->g = BN_bin2bn(r.base, glen, NULL); |
| 506 |
- if (BN_cmp(dh->g, bn2) == 0) { |
| 507 |
- BN_free(dh->g); |
| 508 |
- dh->g = bn2; |
| 509 |
- } |
| 510 |
- else { |
| 511 |
+ g = BN_bin2bn(r.base, glen, NULL); |
| 512 |
+ if (BN_cmp(g, bn2) != 0) { |
| 513 |
+ BN_free(p); |
| 514 |
+ BN_free(g); |
| 515 |
DH_free(dh); |
| 516 |
return (DST_R_INVALIDPUBLICKEY); |
| 517 |
} |
| 518 |
} |
| 519 |
} else { |
| 520 |
if (glen == 0) { |
| 521 |
+ BN_free(p); |
| 522 |
DH_free(dh); |
| 523 |
return (DST_R_INVALIDPUBLICKEY); |
| 524 |
} |
| 525 |
- dh->g = BN_bin2bn(r.base, glen, NULL); |
| 526 |
+ g = BN_bin2bn(r.base, glen, NULL); |
| 527 |
} |
| 528 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 529 |
+ dh->p = p; |
| 530 |
+ dh->g = g; |
| 531 |
+#else |
| 532 |
+ DH_set0_pqg(dh, p, NULL, g); |
| 533 |
+#endif |
| 534 |
isc_region_consume(&r, glen); |
| 535 |
|
| 536 |
if (r.length < 2) { |
| 537 |
@@ -454,10 +534,15 @@ openssldh_fromdns(dst_key_t *key, isc_bu |
| 538 |
DH_free(dh); |
| 539 |
return (DST_R_INVALIDPUBLICKEY); |
| 540 |
} |
| 541 |
- dh->pub_key = BN_bin2bn(r.base, publen, NULL); |
| 542 |
+ pub_key = BN_bin2bn(r.base, publen, NULL); |
| 543 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 544 |
+ dh->pub_key = pub_key; |
| 545 |
+#else |
| 546 |
+ DH_set0_key(dh, pub_key, NULL); |
| 547 |
+#endif |
| 548 |
isc_region_consume(&r, publen); |
| 549 |
|
| 550 |
- key->key_size = BN_num_bits(dh->p); |
| 551 |
+ key->key_size = BN_num_bits(p); |
| 552 |
|
| 553 |
isc_buffer_forward(data, plen + glen + publen + 6); |
| 554 |
|
| 555 |
@@ -473,6 +558,8 @@ openssldh_tofile(const dst_key_t *key, c |
| 556 |
dst_private_t priv; |
| 557 |
unsigned char *bufs[4]; |
| 558 |
isc_result_t result; |
| 559 |
+ const BIGNUM *p, *g; |
| 560 |
+ const BIGNUM *pub_key, *priv_key; |
| 561 |
|
| 562 |
if (key->keydata.dh == NULL) |
| 563 |
return (DST_R_NULLKEY); |
| 564 |
@@ -481,10 +568,19 @@ openssldh_tofile(const dst_key_t *key, c |
| 565 |
return (DST_R_EXTERNALKEY); |
| 566 |
|
| 567 |
dh = key->keydata.dh; |
| 568 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 569 |
+ p = dh->p; |
| 570 |
+ g = dh->g; |
| 571 |
+ pub_key = dh->pub_key; |
| 572 |
+ priv_key = dh->priv_key; |
| 573 |
+#else |
| 574 |
+ DH_get0_pqg(dh, &p, NULL, &g); |
| 575 |
+ DH_get0_key(dh, &pub_key, &priv_key); |
| 576 |
+#endif |
| 577 |
|
| 578 |
memset(bufs, 0, sizeof(bufs)); |
| 579 |
for (i = 0; i < 4; i++) { |
| 580 |
- bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(dh->p)); |
| 581 |
+ bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(p)); |
| 582 |
if (bufs[i] == NULL) { |
| 583 |
result = ISC_R_NOMEMORY; |
| 584 |
goto fail; |
| 585 |
@@ -494,26 +590,26 @@ openssldh_tofile(const dst_key_t *key, c |
| 586 |
i = 0; |
| 587 |
|
| 588 |
priv.elements[i].tag = TAG_DH_PRIME; |
| 589 |
- priv.elements[i].length = BN_num_bytes(dh->p); |
| 590 |
- BN_bn2bin(dh->p, bufs[i]); |
| 591 |
+ priv.elements[i].length = BN_num_bytes(p); |
| 592 |
+ BN_bn2bin(p, bufs[i]); |
| 593 |
priv.elements[i].data = bufs[i]; |
| 594 |
i++; |
| 595 |
|
| 596 |
priv.elements[i].tag = TAG_DH_GENERATOR; |
| 597 |
- priv.elements[i].length = BN_num_bytes(dh->g); |
| 598 |
- BN_bn2bin(dh->g, bufs[i]); |
| 599 |
+ priv.elements[i].length = BN_num_bytes(g); |
| 600 |
+ BN_bn2bin(g, bufs[i]); |
| 601 |
priv.elements[i].data = bufs[i]; |
| 602 |
i++; |
| 603 |
|
| 604 |
priv.elements[i].tag = TAG_DH_PRIVATE; |
| 605 |
- priv.elements[i].length = BN_num_bytes(dh->priv_key); |
| 606 |
- BN_bn2bin(dh->priv_key, bufs[i]); |
| 607 |
+ priv.elements[i].length = BN_num_bytes(priv_key); |
| 608 |
+ BN_bn2bin(priv_key, bufs[i]); |
| 609 |
priv.elements[i].data = bufs[i]; |
| 610 |
i++; |
| 611 |
|
| 612 |
priv.elements[i].tag = TAG_DH_PUBLIC; |
| 613 |
- priv.elements[i].length = BN_num_bytes(dh->pub_key); |
| 614 |
- BN_bn2bin(dh->pub_key, bufs[i]); |
| 615 |
+ priv.elements[i].length = BN_num_bytes(pub_key); |
| 616 |
+ BN_bn2bin(pub_key, bufs[i]); |
| 617 |
priv.elements[i].data = bufs[i]; |
| 618 |
i++; |
| 619 |
|
| 620 |
@@ -523,7 +619,7 @@ openssldh_tofile(const dst_key_t *key, c |
| 621 |
for (i = 0; i < 4; i++) { |
| 622 |
if (bufs[i] == NULL) |
| 623 |
break; |
| 624 |
- isc_mem_put(key->mctx, bufs[i], BN_num_bytes(dh->p)); |
| 625 |
+ isc_mem_put(key->mctx, bufs[i], BN_num_bytes(p)); |
| 626 |
} |
| 627 |
return (result); |
| 628 |
} |
| 629 |
@@ -536,6 +632,7 @@ openssldh_parse(dst_key_t *key, isc_lex_ |
| 630 |
DH *dh = NULL; |
| 631 |
isc_mem_t *mctx; |
| 632 |
#define DST_RET(a) {ret = a; goto err;} |
| 633 |
+ BIGNUM *p = NULL, *g = NULL, *priv_key = NULL, *pub_key = NULL; |
| 634 |
|
| 635 |
UNUSED(pub); |
| 636 |
mctx = key->mctx; |
| 637 |
@@ -551,7 +648,11 @@ openssldh_parse(dst_key_t *key, isc_lex_ |
| 638 |
dh = DH_new(); |
| 639 |
if (dh == NULL) |
| 640 |
DST_RET(ISC_R_NOMEMORY); |
| 641 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 642 |
dh->flags &= ~DH_FLAG_CACHE_MONT_P; |
| 643 |
+#else |
| 644 |
+ DH_clear_flags(dh, DH_FLAG_CACHE_MONT_P); |
| 645 |
+#endif |
| 646 |
key->keydata.dh = dh; |
| 647 |
|
| 648 |
for (i = 0; i < priv.nelements; i++) { |
| 649 |
@@ -563,47 +664,31 @@ openssldh_parse(dst_key_t *key, isc_lex_ |
| 650 |
|
| 651 |
switch (priv.elements[i].tag) { |
| 652 |
case TAG_DH_PRIME: |
| 653 |
- dh->p = bn; |
| 654 |
+ p = bn; |
| 655 |
break; |
| 656 |
case TAG_DH_GENERATOR: |
| 657 |
- dh->g = bn; |
| 658 |
+ g = bn; |
| 659 |
break; |
| 660 |
case TAG_DH_PRIVATE: |
| 661 |
- dh->priv_key = bn; |
| 662 |
+ priv_key = bn; |
| 663 |
break; |
| 664 |
case TAG_DH_PUBLIC: |
| 665 |
- dh->pub_key = bn; |
| 666 |
+ pub_key = bn; |
| 667 |
break; |
| 668 |
} |
| 669 |
} |
| 670 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 671 |
+ dh->p = p; |
| 672 |
+ dh->g = g; |
| 673 |
+ dh->priv_key = priv_key; |
| 674 |
+ dh->pub_key = pub_key; |
| 675 |
+#else |
| 676 |
+ DH_set0_pqg(dh, p, NULL, g); |
| 677 |
+ DH_set0_key(dh, pub_key, priv_key); |
| 678 |
+#endif |
| 679 |
dst__privstruct_free(&priv, mctx); |
| 680 |
|
| 681 |
- key->key_size = BN_num_bits(dh->p); |
| 682 |
- |
| 683 |
- if ((key->key_size == 768 || |
| 684 |
- key->key_size == 1024 || |
| 685 |
- key->key_size == 1536) && |
| 686 |
- BN_cmp(dh->g, bn2) == 0) |
| 687 |
- { |
| 688 |
- if (key->key_size == 768 && BN_cmp(dh->p, bn768) == 0) { |
| 689 |
- BN_free(dh->p); |
| 690 |
- BN_free(dh->g); |
| 691 |
- dh->p = bn768; |
| 692 |
- dh->g = bn2; |
| 693 |
- } else if (key->key_size == 1024 && |
| 694 |
- BN_cmp(dh->p, bn1024) == 0) { |
| 695 |
- BN_free(dh->p); |
| 696 |
- BN_free(dh->g); |
| 697 |
- dh->p = bn1024; |
| 698 |
- dh->g = bn2; |
| 699 |
- } else if (key->key_size == 1536 && |
| 700 |
- BN_cmp(dh->p, bn1536) == 0) { |
| 701 |
- BN_free(dh->p); |
| 702 |
- BN_free(dh->g); |
| 703 |
- dh->p = bn1536; |
| 704 |
- dh->g = bn2; |
| 705 |
- } |
| 706 |
- } |
| 707 |
+ key->key_size = BN_num_bits(p); |
| 708 |
|
| 709 |
return (ISC_R_SUCCESS); |
| 710 |
|
| 711 |
Index: bind9-9.10.3.dfsg.P4/lib/dns/openssldsa_link.c |
| 712 |
=================================================================== |
| 713 |
--- lib/dns/openssldsa_link.c.orig |
| 714 |
+++ lib/dns/openssldsa_link.c |
| 715 |
@@ -53,6 +53,31 @@ |
| 716 |
|
| 717 |
static isc_result_t openssldsa_todns(const dst_key_t *key, isc_buffer_t *data); |
| 718 |
|
| 719 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 720 |
+static void |
| 721 |
+DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) { |
| 722 |
+ if (p != NULL) |
| 723 |
+ *p = d->p; |
| 724 |
+ if (q != NULL) |
| 725 |
+ *q = d->q; |
| 726 |
+ if (g != NULL) |
| 727 |
+ *g = d->g; |
| 728 |
+} |
| 729 |
+ |
| 730 |
+static void |
| 731 |
+DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) { |
| 732 |
+ if (pub_key != NULL) |
| 733 |
+ *pub_key = d->pub_key; |
| 734 |
+ if (priv_key != NULL) |
| 735 |
+ *priv_key = d->priv_key; |
| 736 |
+} |
| 737 |
+ |
| 738 |
+static void |
| 739 |
+DSA_clear_flags(DSA *d, int flags) { |
| 740 |
+ d->flags &= ~flags; |
| 741 |
+} |
| 742 |
+#endif |
| 743 |
+ |
| 744 |
static isc_result_t |
| 745 |
openssldsa_createctx(dst_key_t *key, dst_context_t *dctx) { |
| 746 |
#if USE_EVP |
| 747 |
@@ -64,7 +89,7 @@ openssldsa_createctx(dst_key_t *key, dst |
| 748 |
if (evp_md_ctx == NULL) |
| 749 |
return (ISC_R_NOMEMORY); |
| 750 |
|
| 751 |
- if (!EVP_DigestInit_ex(evp_md_ctx, EVP_dss1(), NULL)) { |
| 752 |
+ if (!EVP_DigestInit_ex(evp_md_ctx, EVP_sha1(), NULL)) { |
| 753 |
EVP_MD_CTX_destroy(evp_md_ctx); |
| 754 |
return (ISC_R_FAILURE); |
| 755 |
} |
| 756 |
@@ -121,7 +146,7 @@ openssldsa_adddata(dst_context_t *dctx, |
| 757 |
} |
| 758 |
|
| 759 |
static int |
| 760 |
-BN_bn2bin_fixed(BIGNUM *bn, unsigned char *buf, int size) { |
| 761 |
+BN_bn2bin_fixed(const BIGNUM *bn, unsigned char *buf, int size) { |
| 762 |
int bytes = size - BN_num_bytes(bn); |
| 763 |
while (bytes-- > 0) |
| 764 |
*buf++ = 0; |
| 765 |
@@ -136,6 +161,7 @@ openssldsa_sign(dst_context_t *dctx, isc |
| 766 |
isc_region_t r; |
| 767 |
DSA_SIG *dsasig; |
| 768 |
unsigned int klen; |
| 769 |
+ const BIGNUM *sig_r, *sig_s; |
| 770 |
#if USE_EVP |
| 771 |
EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx; |
| 772 |
EVP_PKEY *pkey; |
| 773 |
@@ -216,9 +242,15 @@ openssldsa_sign(dst_context_t *dctx, isc |
| 774 |
*r.base = klen; |
| 775 |
isc_region_consume(&r, 1); |
| 776 |
|
| 777 |
- BN_bn2bin_fixed(dsasig->r, r.base, ISC_SHA1_DIGESTLENGTH); |
| 778 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 779 |
+ sig_r = dsasig->r; |
| 780 |
+ sig_s = dsasig->s; |
| 781 |
+#else |
| 782 |
+ DSA_SIG_get0(dsasig, &sig_r, &sig_s); |
| 783 |
+#endif |
| 784 |
+ BN_bn2bin_fixed(sig_r, r.base, ISC_SHA1_DIGESTLENGTH); |
| 785 |
isc_region_consume(&r, ISC_SHA1_DIGESTLENGTH); |
| 786 |
- BN_bn2bin_fixed(dsasig->s, r.base, ISC_SHA1_DIGESTLENGTH); |
| 787 |
+ BN_bn2bin_fixed(sig_s, r.base, ISC_SHA1_DIGESTLENGTH); |
| 788 |
isc_region_consume(&r, ISC_SHA1_DIGESTLENGTH); |
| 789 |
DSA_SIG_free(dsasig); |
| 790 |
isc_buffer_add(sig, ISC_SHA1_DIGESTLENGTH * 2 + 1); |
| 791 |
@@ -233,6 +265,7 @@ openssldsa_verify(dst_context_t *dctx, c |
| 792 |
int status = 0; |
| 793 |
unsigned char *cp = sig->base; |
| 794 |
DSA_SIG *dsasig; |
| 795 |
+ BIGNUM *r, *s; |
| 796 |
#if USE_EVP |
| 797 |
EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx; |
| 798 |
#if 0 |
| 799 |
@@ -265,9 +298,15 @@ openssldsa_verify(dst_context_t *dctx, c |
| 800 |
dsasig = DSA_SIG_new(); |
| 801 |
if (dsasig == NULL) |
| 802 |
return (ISC_R_NOMEMORY); |
| 803 |
- dsasig->r = BN_bin2bn(cp, ISC_SHA1_DIGESTLENGTH, NULL); |
| 804 |
+ r = BN_bin2bn(cp, ISC_SHA1_DIGESTLENGTH, NULL); |
| 805 |
cp += ISC_SHA1_DIGESTLENGTH; |
| 806 |
- dsasig->s = BN_bin2bn(cp, ISC_SHA1_DIGESTLENGTH, NULL); |
| 807 |
+ s = BN_bin2bn(cp, ISC_SHA1_DIGESTLENGTH, NULL); |
| 808 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 809 |
+ dsasig->r = r; |
| 810 |
+ dsasig->s = s; |
| 811 |
+#else |
| 812 |
+ DSA_SIG_set0(dsasig, r, s); |
| 813 |
+#endif |
| 814 |
|
| 815 |
#if 0 |
| 816 |
pkey = EVP_PKEY_new(); |
| 817 |
@@ -308,6 +347,8 @@ static isc_boolean_t |
| 818 |
openssldsa_compare(const dst_key_t *key1, const dst_key_t *key2) { |
| 819 |
int status; |
| 820 |
DSA *dsa1, *dsa2; |
| 821 |
+ const BIGNUM *p1, *q1, *g1, *pub_key1, *priv_key1; |
| 822 |
+ const BIGNUM *p2, *q2, *g2, *pub_key2, *priv_key2; |
| 823 |
|
| 824 |
dsa1 = key1->keydata.dsa; |
| 825 |
dsa2 = key2->keydata.dsa; |
| 826 |
@@ -317,18 +358,23 @@ openssldsa_compare(const dst_key_t *key1 |
| 827 |
else if (dsa1 == NULL || dsa2 == NULL) |
| 828 |
return (ISC_FALSE); |
| 829 |
|
| 830 |
- status = BN_cmp(dsa1->p, dsa2->p) || |
| 831 |
- BN_cmp(dsa1->q, dsa2->q) || |
| 832 |
- BN_cmp(dsa1->g, dsa2->g) || |
| 833 |
- BN_cmp(dsa1->pub_key, dsa2->pub_key); |
| 834 |
+ DSA_get0_pqg(dsa1, &p1, &q1, &g1); |
| 835 |
+ DSA_get0_pqg(dsa2, &p2, &q2, &g2); |
| 836 |
+ DSA_get0_key(dsa1, &pub_key1, &priv_key1); |
| 837 |
+ DSA_get0_key(dsa2, &pub_key2, &priv_key2); |
| 838 |
+ |
| 839 |
+ status = BN_cmp(p1, p2) || |
| 840 |
+ BN_cmp(q1, q2) || |
| 841 |
+ BN_cmp(g1, g2) || |
| 842 |
+ BN_cmp(pub_key1, pub_key2); |
| 843 |
|
| 844 |
if (status != 0) |
| 845 |
return (ISC_FALSE); |
| 846 |
|
| 847 |
- if (dsa1->priv_key != NULL || dsa2->priv_key != NULL) { |
| 848 |
- if (dsa1->priv_key == NULL || dsa2->priv_key == NULL) |
| 849 |
+ if (priv_key1 != NULL || priv_key2 != NULL) { |
| 850 |
+ if (priv_key1 == NULL || priv_key2 == NULL) |
| 851 |
return (ISC_FALSE); |
| 852 |
- if (BN_cmp(dsa1->priv_key, dsa2->priv_key)) |
| 853 |
+ if (BN_cmp(priv_key1, priv_key2)) |
| 854 |
return (ISC_FALSE); |
| 855 |
} |
| 856 |
return (ISC_TRUE); |
| 857 |
@@ -420,7 +466,7 @@ openssldsa_generate(dst_key_t *key, int |
| 858 |
return (dst__openssl_toresult2("DSA_generate_key", |
| 859 |
DST_R_OPENSSLFAILURE)); |
| 860 |
} |
| 861 |
- dsa->flags &= ~DSA_FLAG_CACHE_MONT_P; |
| 862 |
+ DSA_clear_flags(dsa, DSA_FLAG_CACHE_MONT_P); |
| 863 |
|
| 864 |
key->keydata.dsa = dsa; |
| 865 |
|
| 866 |
@@ -430,7 +476,12 @@ openssldsa_generate(dst_key_t *key, int |
| 867 |
static isc_boolean_t |
| 868 |
openssldsa_isprivate(const dst_key_t *key) { |
| 869 |
DSA *dsa = key->keydata.dsa; |
| 870 |
- return (ISC_TF(dsa != NULL && dsa->priv_key != NULL)); |
| 871 |
+ const BIGNUM *priv_key; |
| 872 |
+ |
| 873 |
+ if (dsa == NULL) |
| 874 |
+ return (ISC_FALSE); |
| 875 |
+ DSA_get0_key(dsa, NULL, &priv_key); |
| 876 |
+ return (ISC_TF(priv_key != NULL)); |
| 877 |
} |
| 878 |
|
| 879 |
static void |
| 880 |
@@ -447,14 +498,18 @@ openssldsa_todns(const dst_key_t *key, i |
| 881 |
isc_region_t r; |
| 882 |
int dnslen; |
| 883 |
unsigned int t, p_bytes; |
| 884 |
+ const BIGNUM *p, *q, *g, *pub_key; |
| 885 |
|
| 886 |
REQUIRE(key->keydata.dsa != NULL); |
| 887 |
|
| 888 |
dsa = key->keydata.dsa; |
| 889 |
|
| 890 |
+ DSA_get0_pqg(dsa, &p, &q, &g); |
| 891 |
+ DSA_get0_key(dsa, &pub_key, NULL); |
| 892 |
+ |
| 893 |
isc_buffer_availableregion(data, &r); |
| 894 |
|
| 895 |
- t = (BN_num_bytes(dsa->p) - 64) / 8; |
| 896 |
+ t = (BN_num_bytes(p) - 64) / 8; |
| 897 |
if (t > 8) |
| 898 |
return (DST_R_INVALIDPUBLICKEY); |
| 899 |
p_bytes = 64 + 8 * t; |
| 900 |
@@ -465,13 +520,13 @@ openssldsa_todns(const dst_key_t *key, i |
| 901 |
|
| 902 |
*r.base = t; |
| 903 |
isc_region_consume(&r, 1); |
| 904 |
- BN_bn2bin_fixed(dsa->q, r.base, ISC_SHA1_DIGESTLENGTH); |
| 905 |
+ BN_bn2bin_fixed(q, r.base, ISC_SHA1_DIGESTLENGTH); |
| 906 |
isc_region_consume(&r, ISC_SHA1_DIGESTLENGTH); |
| 907 |
- BN_bn2bin_fixed(dsa->p, r.base, key->key_size/8); |
| 908 |
+ BN_bn2bin_fixed(p, r.base, key->key_size/8); |
| 909 |
isc_region_consume(&r, p_bytes); |
| 910 |
- BN_bn2bin_fixed(dsa->g, r.base, key->key_size/8); |
| 911 |
+ BN_bn2bin_fixed(g, r.base, key->key_size/8); |
| 912 |
isc_region_consume(&r, p_bytes); |
| 913 |
- BN_bn2bin_fixed(dsa->pub_key, r.base, key->key_size/8); |
| 914 |
+ BN_bn2bin_fixed(pub_key, r.base, key->key_size/8); |
| 915 |
isc_region_consume(&r, p_bytes); |
| 916 |
|
| 917 |
isc_buffer_add(data, dnslen); |
| 918 |
@@ -485,6 +540,7 @@ openssldsa_fromdns(dst_key_t *key, isc_b |
| 919 |
isc_region_t r; |
| 920 |
unsigned int t, p_bytes; |
| 921 |
isc_mem_t *mctx = key->mctx; |
| 922 |
+ BIGNUM *p, *q, *g, *pub_key; |
| 923 |
|
| 924 |
UNUSED(mctx); |
| 925 |
|
| 926 |
@@ -495,7 +551,7 @@ openssldsa_fromdns(dst_key_t *key, isc_b |
| 927 |
dsa = DSA_new(); |
| 928 |
if (dsa == NULL) |
| 929 |
return (ISC_R_NOMEMORY); |
| 930 |
- dsa->flags &= ~DSA_FLAG_CACHE_MONT_P; |
| 931 |
+ DSA_clear_flags(dsa, DSA_FLAG_CACHE_MONT_P); |
| 932 |
|
| 933 |
t = (unsigned int) *r.base; |
| 934 |
isc_region_consume(&r, 1); |
| 935 |
@@ -510,18 +566,32 @@ openssldsa_fromdns(dst_key_t *key, isc_b |
| 936 |
return (DST_R_INVALIDPUBLICKEY); |
| 937 |
} |
| 938 |
|
| 939 |
- dsa->q = BN_bin2bn(r.base, ISC_SHA1_DIGESTLENGTH, NULL); |
| 940 |
+ q = BN_bin2bn(r.base, ISC_SHA1_DIGESTLENGTH, NULL); |
| 941 |
isc_region_consume(&r, ISC_SHA1_DIGESTLENGTH); |
| 942 |
|
| 943 |
- dsa->p = BN_bin2bn(r.base, p_bytes, NULL); |
| 944 |
+ p = BN_bin2bn(r.base, p_bytes, NULL); |
| 945 |
isc_region_consume(&r, p_bytes); |
| 946 |
|
| 947 |
- dsa->g = BN_bin2bn(r.base, p_bytes, NULL); |
| 948 |
+ g = BN_bin2bn(r.base, p_bytes, NULL); |
| 949 |
isc_region_consume(&r, p_bytes); |
| 950 |
|
| 951 |
- dsa->pub_key = BN_bin2bn(r.base, p_bytes, NULL); |
| 952 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 953 |
+ dsa->p = p; |
| 954 |
+ dsa->q = q; |
| 955 |
+ dsa->g = g; |
| 956 |
+#else |
| 957 |
+ DSA_set0_pqg(dsa, p, q, g); |
| 958 |
+#endif |
| 959 |
+ |
| 960 |
+ pub_key = BN_bin2bn(r.base, p_bytes, NULL); |
| 961 |
isc_region_consume(&r, p_bytes); |
| 962 |
|
| 963 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 964 |
+ dsa->pub_key = pub_key; |
| 965 |
+#else |
| 966 |
+ DSA_set0_key(dsa, pub_key, NULL); |
| 967 |
+#endif |
| 968 |
+ |
| 969 |
key->key_size = p_bytes * 8; |
| 970 |
|
| 971 |
isc_buffer_forward(data, 1 + ISC_SHA1_DIGESTLENGTH + 3 * p_bytes); |
| 972 |
@@ -538,6 +608,7 @@ openssldsa_tofile(const dst_key_t *key, |
| 973 |
DSA *dsa; |
| 974 |
dst_private_t priv; |
| 975 |
unsigned char bufs[5][128]; |
| 976 |
+ const BIGNUM *p, *q, *g, *pub_key, *priv_key; |
| 977 |
|
| 978 |
if (key->keydata.dsa == NULL) |
| 979 |
return (DST_R_NULLKEY); |
| 980 |
@@ -549,33 +620,36 @@ openssldsa_tofile(const dst_key_t *key, |
| 981 |
|
| 982 |
dsa = key->keydata.dsa; |
| 983 |
|
| 984 |
+ DSA_get0_pqg(dsa, &p, &q, &g); |
| 985 |
+ DSA_get0_key(dsa, &pub_key, &priv_key); |
| 986 |
+ |
| 987 |
priv.elements[cnt].tag = TAG_DSA_PRIME; |
| 988 |
- priv.elements[cnt].length = BN_num_bytes(dsa->p); |
| 989 |
- BN_bn2bin(dsa->p, bufs[cnt]); |
| 990 |
+ priv.elements[cnt].length = BN_num_bytes(p); |
| 991 |
+ BN_bn2bin(p, bufs[cnt]); |
| 992 |
priv.elements[cnt].data = bufs[cnt]; |
| 993 |
cnt++; |
| 994 |
|
| 995 |
priv.elements[cnt].tag = TAG_DSA_SUBPRIME; |
| 996 |
- priv.elements[cnt].length = BN_num_bytes(dsa->q); |
| 997 |
- BN_bn2bin(dsa->q, bufs[cnt]); |
| 998 |
+ priv.elements[cnt].length = BN_num_bytes(q); |
| 999 |
+ BN_bn2bin(q, bufs[cnt]); |
| 1000 |
priv.elements[cnt].data = bufs[cnt]; |
| 1001 |
cnt++; |
| 1002 |
|
| 1003 |
priv.elements[cnt].tag = TAG_DSA_BASE; |
| 1004 |
- priv.elements[cnt].length = BN_num_bytes(dsa->g); |
| 1005 |
- BN_bn2bin(dsa->g, bufs[cnt]); |
| 1006 |
+ priv.elements[cnt].length = BN_num_bytes(g); |
| 1007 |
+ BN_bn2bin(g, bufs[cnt]); |
| 1008 |
priv.elements[cnt].data = bufs[cnt]; |
| 1009 |
cnt++; |
| 1010 |
|
| 1011 |
priv.elements[cnt].tag = TAG_DSA_PRIVATE; |
| 1012 |
- priv.elements[cnt].length = BN_num_bytes(dsa->priv_key); |
| 1013 |
- BN_bn2bin(dsa->priv_key, bufs[cnt]); |
| 1014 |
+ priv.elements[cnt].length = BN_num_bytes(priv_key); |
| 1015 |
+ BN_bn2bin(priv_key, bufs[cnt]); |
| 1016 |
priv.elements[cnt].data = bufs[cnt]; |
| 1017 |
cnt++; |
| 1018 |
|
| 1019 |
priv.elements[cnt].tag = TAG_DSA_PUBLIC; |
| 1020 |
- priv.elements[cnt].length = BN_num_bytes(dsa->pub_key); |
| 1021 |
- BN_bn2bin(dsa->pub_key, bufs[cnt]); |
| 1022 |
+ priv.elements[cnt].length = BN_num_bytes(pub_key); |
| 1023 |
+ BN_bn2bin(pub_key, bufs[cnt]); |
| 1024 |
priv.elements[cnt].data = bufs[cnt]; |
| 1025 |
cnt++; |
| 1026 |
|
| 1027 |
@@ -591,6 +665,7 @@ openssldsa_parse(dst_key_t *key, isc_lex |
| 1028 |
DSA *dsa = NULL; |
| 1029 |
isc_mem_t *mctx = key->mctx; |
| 1030 |
#define DST_RET(a) {ret = a; goto err;} |
| 1031 |
+ BIGNUM *p = NULL, *g = NULL, *q = NULL, *pub_key = NULL, *priv_key = NULL; |
| 1032 |
|
| 1033 |
/* read private key file */ |
| 1034 |
ret = dst__privstruct_parse(key, DST_ALG_DSA, lexer, mctx, &priv); |
| 1035 |
@@ -613,7 +688,7 @@ openssldsa_parse(dst_key_t *key, isc_lex |
| 1036 |
dsa = DSA_new(); |
| 1037 |
if (dsa == NULL) |
| 1038 |
DST_RET(ISC_R_NOMEMORY); |
| 1039 |
- dsa->flags &= ~DSA_FLAG_CACHE_MONT_P; |
| 1040 |
+ DSA_clear_flags(dsa, DSA_FLAG_CACHE_MONT_P); |
| 1041 |
key->keydata.dsa = dsa; |
| 1042 |
|
| 1043 |
for (i = 0; i < priv.nelements; i++) { |
| 1044 |
@@ -625,25 +700,36 @@ openssldsa_parse(dst_key_t *key, isc_lex |
| 1045 |
|
| 1046 |
switch (priv.elements[i].tag) { |
| 1047 |
case TAG_DSA_PRIME: |
| 1048 |
- dsa->p = bn; |
| 1049 |
+ p = bn; |
| 1050 |
break; |
| 1051 |
case TAG_DSA_SUBPRIME: |
| 1052 |
- dsa->q = bn; |
| 1053 |
+ q = bn; |
| 1054 |
break; |
| 1055 |
case TAG_DSA_BASE: |
| 1056 |
- dsa->g = bn; |
| 1057 |
+ g = bn; |
| 1058 |
break; |
| 1059 |
case TAG_DSA_PRIVATE: |
| 1060 |
- dsa->priv_key = bn; |
| 1061 |
+ priv_key = bn; |
| 1062 |
break; |
| 1063 |
case TAG_DSA_PUBLIC: |
| 1064 |
- dsa->pub_key = bn; |
| 1065 |
+ pub_key = bn; |
| 1066 |
break; |
| 1067 |
} |
| 1068 |
} |
| 1069 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1070 |
+ dsa->p = p; |
| 1071 |
+ dsa->q = q; |
| 1072 |
+ dsa->g = g; |
| 1073 |
+ dsa->pub_key = pub_key; |
| 1074 |
+ dsa->priv_key = priv_key; |
| 1075 |
+#else |
| 1076 |
+ DSA_set0_pqg(dsa, p, q, g); |
| 1077 |
+ DSA_set0_key(dsa, pub_key, priv_key); |
| 1078 |
+#endif |
| 1079 |
+ |
| 1080 |
dst__privstruct_free(&priv, mctx); |
| 1081 |
memset(&priv, 0, sizeof(priv)); |
| 1082 |
- key->key_size = BN_num_bits(dsa->p); |
| 1083 |
+ key->key_size = BN_num_bits(p); |
| 1084 |
return (ISC_R_SUCCESS); |
| 1085 |
|
| 1086 |
err: |
| 1087 |
Index: bind9-9.10.3.dfsg.P4/lib/dns/opensslecdsa_link.c |
| 1088 |
=================================================================== |
| 1089 |
--- lib/dns/opensslecdsa_link.c.orig |
| 1090 |
+++ lib/dns/opensslecdsa_link.c |
| 1091 |
@@ -110,7 +110,7 @@ opensslecdsa_adddata(dst_context_t *dctx |
| 1092 |
} |
| 1093 |
|
| 1094 |
static int |
| 1095 |
-BN_bn2bin_fixed(BIGNUM *bn, unsigned char *buf, int size) { |
| 1096 |
+BN_bn2bin_fixed(const BIGNUM *bn, unsigned char *buf, int size) { |
| 1097 |
int bytes = size - BN_num_bytes(bn); |
| 1098 |
|
| 1099 |
while (bytes-- > 0) |
| 1100 |
@@ -130,6 +130,7 @@ opensslecdsa_sign(dst_context_t *dctx, i |
| 1101 |
EC_KEY *eckey = EVP_PKEY_get1_EC_KEY(pkey); |
| 1102 |
unsigned int dgstlen, siglen; |
| 1103 |
unsigned char digest[EVP_MAX_MD_SIZE]; |
| 1104 |
+ const BIGNUM *sig_r, *sig_s; |
| 1105 |
|
| 1106 |
REQUIRE(key->key_alg == DST_ALG_ECDSA256 || |
| 1107 |
key->key_alg == DST_ALG_ECDSA384); |
| 1108 |
@@ -156,9 +157,17 @@ opensslecdsa_sign(dst_context_t *dctx, i |
| 1109 |
DST_RET(dst__openssl_toresult3(dctx->category, |
| 1110 |
"ECDSA_do_sign", |
| 1111 |
DST_R_SIGNFAILURE)); |
| 1112 |
- BN_bn2bin_fixed(ecdsasig->r, r.base, siglen / 2); |
| 1113 |
+ |
| 1114 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1115 |
+ sig_r = ecdsasig->r; |
| 1116 |
+ sig_s = ecdsasig->s; |
| 1117 |
+#else |
| 1118 |
+ ECDSA_SIG_get0(ecdsasig, &sig_r, &sig_s); |
| 1119 |
+#endif |
| 1120 |
+ |
| 1121 |
+ BN_bn2bin_fixed(sig_r, r.base, siglen / 2); |
| 1122 |
isc_region_consume(&r, siglen / 2); |
| 1123 |
- BN_bn2bin_fixed(ecdsasig->s, r.base, siglen / 2); |
| 1124 |
+ BN_bn2bin_fixed(sig_s, r.base, siglen / 2); |
| 1125 |
isc_region_consume(&r, siglen / 2); |
| 1126 |
ECDSA_SIG_free(ecdsasig); |
| 1127 |
isc_buffer_add(sig, siglen); |
| 1128 |
@@ -182,6 +191,7 @@ opensslecdsa_verify(dst_context_t *dctx, |
| 1129 |
EC_KEY *eckey = EVP_PKEY_get1_EC_KEY(pkey); |
| 1130 |
unsigned int dgstlen, siglen; |
| 1131 |
unsigned char digest[EVP_MAX_MD_SIZE]; |
| 1132 |
+ BIGNUM *r, *s; |
| 1133 |
|
| 1134 |
REQUIRE(key->key_alg == DST_ALG_ECDSA256 || |
| 1135 |
key->key_alg == DST_ALG_ECDSA384); |
| 1136 |
@@ -205,15 +215,18 @@ opensslecdsa_verify(dst_context_t *dctx, |
| 1137 |
ecdsasig = ECDSA_SIG_new(); |
| 1138 |
if (ecdsasig == NULL) |
| 1139 |
DST_RET (ISC_R_NOMEMORY); |
| 1140 |
- if (ecdsasig->r != NULL) |
| 1141 |
- BN_free(ecdsasig->r); |
| 1142 |
- ecdsasig->r = BN_bin2bn(cp, siglen / 2, NULL); |
| 1143 |
+ r = BN_bin2bn(cp, siglen / 2, NULL); |
| 1144 |
cp += siglen / 2; |
| 1145 |
- if (ecdsasig->s != NULL) |
| 1146 |
- BN_free(ecdsasig->s); |
| 1147 |
- ecdsasig->s = BN_bin2bn(cp, siglen / 2, NULL); |
| 1148 |
+ s = BN_bin2bn(cp, siglen / 2, NULL); |
| 1149 |
/* cp += siglen / 2; */ |
| 1150 |
|
| 1151 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1152 |
+ ecdsasig->r = r; |
| 1153 |
+ ecdsasig->s = s; |
| 1154 |
+#else |
| 1155 |
+ ECDSA_SIG_set0(ecdsasig, r, s); |
| 1156 |
+#endif |
| 1157 |
+ |
| 1158 |
status = ECDSA_do_verify(digest, dgstlen, ecdsasig, eckey); |
| 1159 |
switch (status) { |
| 1160 |
case 1: |
| 1161 |
Index: bind9-9.10.3.dfsg.P4/lib/dns/opensslrsa_link.c |
| 1162 |
=================================================================== |
| 1163 |
--- lib/dns/opensslrsa_link.c.orig |
| 1164 |
+++ lib/dns/opensslrsa_link.c |
| 1165 |
@@ -56,6 +56,42 @@ |
| 1166 |
#include <openssl/engine.h> |
| 1167 |
#endif |
| 1168 |
|
| 1169 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1170 |
+static void |
| 1171 |
+RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) { |
| 1172 |
+ if (n != NULL) |
| 1173 |
+ *n = r->n; |
| 1174 |
+ if (e != NULL) |
| 1175 |
+ *e = r->e; |
| 1176 |
+ if (d != NULL) |
| 1177 |
+ *d = r->d; |
| 1178 |
+} |
| 1179 |
+ |
| 1180 |
+static void |
| 1181 |
+RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) { |
| 1182 |
+ if (p != NULL) |
| 1183 |
+ *p = r->p; |
| 1184 |
+ if (q != NULL) |
| 1185 |
+ *q = r->q; |
| 1186 |
+} |
| 1187 |
+ |
| 1188 |
+static void |
| 1189 |
+RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp) { |
| 1190 |
+ if (dmp1 != NULL) |
| 1191 |
+ *dmp1 = r->dmp1; |
| 1192 |
+ if (dmq1 != NULL) |
| 1193 |
+ *dmq1 = r->dmq1; |
| 1194 |
+ if (iqmp != NULL) |
| 1195 |
+ *iqmp = r->iqmp; |
| 1196 |
+} |
| 1197 |
+ |
| 1198 |
+static int |
| 1199 |
+RSA_test_flags(const RSA *r, int flags) { |
| 1200 |
+ return r->flags & flags; |
| 1201 |
+} |
| 1202 |
+ |
| 1203 |
+#endif |
| 1204 |
+ |
| 1205 |
/* |
| 1206 |
* Limit the size of public exponents. |
| 1207 |
*/ |
| 1208 |
@@ -107,6 +143,7 @@ |
| 1209 |
(rsa)->flags &= ~RSA_FLAG_BLINDING; \ |
| 1210 |
} while (0) |
| 1211 |
#elif defined(RSA_FLAG_NO_BLINDING) |
| 1212 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1213 |
#define SET_FLAGS(rsa) \ |
| 1214 |
do { \ |
| 1215 |
(rsa)->flags &= ~RSA_FLAG_BLINDING; \ |
| 1216 |
@@ -115,6 +152,13 @@ |
| 1217 |
#else |
| 1218 |
#define SET_FLAGS(rsa) \ |
| 1219 |
do { \ |
| 1220 |
+ RSA_clear_flags(rsa, RSA_FLAG_BLINDING); \ |
| 1221 |
+ RSA_set_flags(rsa, RSA_FLAG_NO_BLINDING); \ |
| 1222 |
+ } while (0) |
| 1223 |
+#endif |
| 1224 |
+#else |
| 1225 |
+#define SET_FLAGS(rsa) \ |
| 1226 |
+ do { \ |
| 1227 |
(rsa)->flags &= ~RSA_FLAG_BLINDING; \ |
| 1228 |
} while (0) |
| 1229 |
#endif |
| 1230 |
@@ -521,6 +565,7 @@ opensslrsa_verify2(dst_context_t *dctx, |
| 1231 |
EVP_PKEY *pkey = key->keydata.pkey; |
| 1232 |
RSA *rsa; |
| 1233 |
int bits; |
| 1234 |
+ const BIGNUM *e; |
| 1235 |
#else |
| 1236 |
/* note: ISC_SHA512_DIGESTLENGTH >= ISC_*_DIGESTLENGTH */ |
| 1237 |
unsigned char digest[ISC_SHA512_DIGESTLENGTH]; |
| 1238 |
@@ -543,7 +588,9 @@ opensslrsa_verify2(dst_context_t *dctx, |
| 1239 |
rsa = EVP_PKEY_get1_RSA(pkey); |
| 1240 |
if (rsa == NULL) |
| 1241 |
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); |
| 1242 |
- bits = BN_num_bits(rsa->e); |
| 1243 |
+ |
| 1244 |
+ RSA_get0_key(rsa, NULL, &e, NULL); |
| 1245 |
+ bits = BN_num_bits(e); |
| 1246 |
RSA_free(rsa); |
| 1247 |
if (bits > maxbits && maxbits != 0) |
| 1248 |
return (DST_R_VERIFYFAILURE); |
| 1249 |
@@ -687,6 +734,7 @@ opensslrsa_compare(const dst_key_t *key1 |
| 1250 |
RSA *rsa1 = NULL, *rsa2 = NULL; |
| 1251 |
#if USE_EVP |
| 1252 |
EVP_PKEY *pkey1, *pkey2; |
| 1253 |
+ const BIGNUM *n1, *n2, *e1, *e2, *d1, *d2, *p1, *p2, *q1, *q2; |
| 1254 |
#endif |
| 1255 |
|
| 1256 |
#if USE_EVP |
| 1257 |
@@ -714,17 +762,22 @@ opensslrsa_compare(const dst_key_t *key1 |
| 1258 |
else if (rsa1 == NULL || rsa2 == NULL) |
| 1259 |
return (ISC_FALSE); |
| 1260 |
|
| 1261 |
- status = BN_cmp(rsa1->n, rsa2->n) || |
| 1262 |
- BN_cmp(rsa1->e, rsa2->e); |
| 1263 |
+ RSA_get0_key(rsa1, &n1, &e1, &d1); |
| 1264 |
+ RSA_get0_key(rsa2, &n2, &e2, &d2); |
| 1265 |
+ RSA_get0_factors(rsa1, &p1, &q1); |
| 1266 |
+ RSA_get0_factors(rsa2, &p2, &q2); |
| 1267 |
+ |
| 1268 |
+ status = BN_cmp(n1, n2) || |
| 1269 |
+ BN_cmp(e1, e2); |
| 1270 |
|
| 1271 |
if (status != 0) |
| 1272 |
return (ISC_FALSE); |
| 1273 |
|
| 1274 |
#if USE_EVP |
| 1275 |
- if ((rsa1->flags & RSA_FLAG_EXT_PKEY) != 0 || |
| 1276 |
- (rsa2->flags & RSA_FLAG_EXT_PKEY) != 0) { |
| 1277 |
- if ((rsa1->flags & RSA_FLAG_EXT_PKEY) == 0 || |
| 1278 |
- (rsa2->flags & RSA_FLAG_EXT_PKEY) == 0) |
| 1279 |
+ if (RSA_test_flags(rsa1, RSA_FLAG_EXT_PKEY) != 0 || |
| 1280 |
+ RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) != 0) { |
| 1281 |
+ if (RSA_test_flags(rsa1, RSA_FLAG_EXT_PKEY) == 0 || |
| 1282 |
+ RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) == 0) |
| 1283 |
return (ISC_FALSE); |
| 1284 |
/* |
| 1285 |
* Can't compare private parameters, BTW does it make sense? |
| 1286 |
@@ -733,12 +786,12 @@ opensslrsa_compare(const dst_key_t *key1 |
| 1287 |
} |
| 1288 |
#endif |
| 1289 |
|
| 1290 |
- if (rsa1->d != NULL || rsa2->d != NULL) { |
| 1291 |
- if (rsa1->d == NULL || rsa2->d == NULL) |
| 1292 |
+ if (d1 != NULL || d2 != NULL) { |
| 1293 |
+ if (d1 == NULL || d2 == NULL) |
| 1294 |
return (ISC_FALSE); |
| 1295 |
- status = BN_cmp(rsa1->d, rsa2->d) || |
| 1296 |
- BN_cmp(rsa1->p, rsa2->p) || |
| 1297 |
- BN_cmp(rsa1->q, rsa2->q); |
| 1298 |
+ status = BN_cmp(d1, d2) || |
| 1299 |
+ BN_cmp(p1, p2) || |
| 1300 |
+ BN_cmp(q1, q2); |
| 1301 |
|
| 1302 |
if (status != 0) |
| 1303 |
return (ISC_FALSE); |
| 1304 |
@@ -889,9 +942,15 @@ opensslrsa_isprivate(const dst_key_t *ke |
| 1305 |
#else |
| 1306 |
RSA *rsa = key->keydata.rsa; |
| 1307 |
#endif |
| 1308 |
- if (rsa != NULL && (rsa->flags & RSA_FLAG_EXT_PKEY) != 0) |
| 1309 |
+ const BIGNUM *d; |
| 1310 |
+ |
| 1311 |
+ if (rsa != NULL && RSA_test_flags(rsa, RSA_FLAG_EXT_PKEY) != 0) |
| 1312 |
return (ISC_TRUE); |
| 1313 |
- return (ISC_TF(rsa != NULL && rsa->d != NULL)); |
| 1314 |
+ if (rsa == NULL) |
| 1315 |
+ return (ISC_FALSE); |
| 1316 |
+ |
| 1317 |
+ RSA_get0_key(rsa, NULL, NULL, &d); |
| 1318 |
+ return (ISC_TF(d != NULL)); |
| 1319 |
} |
| 1320 |
|
| 1321 |
static void |
| 1322 |
@@ -918,6 +977,7 @@ opensslrsa_todns(const dst_key_t *key, i |
| 1323 |
#if USE_EVP |
| 1324 |
EVP_PKEY *pkey; |
| 1325 |
#endif |
| 1326 |
+ const BIGNUM *n, *e; |
| 1327 |
|
| 1328 |
#if USE_EVP |
| 1329 |
REQUIRE(key->keydata.pkey != NULL); |
| 1330 |
@@ -936,8 +996,9 @@ opensslrsa_todns(const dst_key_t *key, i |
| 1331 |
|
| 1332 |
isc_buffer_availableregion(data, &r); |
| 1333 |
|
| 1334 |
- e_bytes = BN_num_bytes(rsa->e); |
| 1335 |
- mod_bytes = BN_num_bytes(rsa->n); |
| 1336 |
+ RSA_get0_key(rsa, &n, &e, NULL); |
| 1337 |
+ e_bytes = BN_num_bytes(e); |
| 1338 |
+ mod_bytes = BN_num_bytes(n); |
| 1339 |
|
| 1340 |
if (e_bytes < 256) { /*%< key exponent is <= 2040 bits */ |
| 1341 |
if (r.length < 1) |
| 1342 |
@@ -955,9 +1016,9 @@ opensslrsa_todns(const dst_key_t *key, i |
| 1343 |
if (r.length < e_bytes + mod_bytes) |
| 1344 |
DST_RET(ISC_R_NOSPACE); |
| 1345 |
|
| 1346 |
- BN_bn2bin(rsa->e, r.base); |
| 1347 |
+ BN_bn2bin(e, r.base); |
| 1348 |
isc_region_consume(&r, e_bytes); |
| 1349 |
- BN_bn2bin(rsa->n, r.base); |
| 1350 |
+ BN_bn2bin(n, r.base); |
| 1351 |
|
| 1352 |
isc_buffer_add(data, e_bytes + mod_bytes); |
| 1353 |
|
| 1354 |
@@ -979,6 +1040,7 @@ opensslrsa_fromdns(dst_key_t *key, isc_b |
| 1355 |
#if USE_EVP |
| 1356 |
EVP_PKEY *pkey; |
| 1357 |
#endif |
| 1358 |
+ BIGNUM *n, *e; |
| 1359 |
|
| 1360 |
isc_buffer_remainingregion(data, &r); |
| 1361 |
if (r.length == 0) |
| 1362 |
@@ -1012,12 +1074,19 @@ opensslrsa_fromdns(dst_key_t *key, isc_b |
| 1363 |
RSA_free(rsa); |
| 1364 |
return (DST_R_INVALIDPUBLICKEY); |
| 1365 |
} |
| 1366 |
- rsa->e = BN_bin2bn(r.base, e_bytes, NULL); |
| 1367 |
+ e = BN_bin2bn(r.base, e_bytes, NULL); |
| 1368 |
isc_region_consume(&r, e_bytes); |
| 1369 |
|
| 1370 |
- rsa->n = BN_bin2bn(r.base, r.length, NULL); |
| 1371 |
+ n = BN_bin2bn(r.base, r.length, NULL); |
| 1372 |
+ |
| 1373 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1374 |
+ rsa->n = n; |
| 1375 |
+ rsa->e = e; |
| 1376 |
+#else |
| 1377 |
+ RSA_set0_key(rsa, n, e, NULL); |
| 1378 |
+#endif |
| 1379 |
|
| 1380 |
- key->key_size = BN_num_bits(rsa->n); |
| 1381 |
+ key->key_size = BN_num_bits(n); |
| 1382 |
|
| 1383 |
isc_buffer_forward(data, length); |
| 1384 |
|
| 1385 |
@@ -1048,6 +1117,8 @@ opensslrsa_tofile(const dst_key_t *key, |
| 1386 |
dst_private_t priv; |
| 1387 |
unsigned char *bufs[8]; |
| 1388 |
isc_result_t result; |
| 1389 |
+ const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp; |
| 1390 |
+ |
| 1391 |
|
| 1392 |
#if USE_EVP |
| 1393 |
if (key->keydata.pkey == NULL) |
| 1394 |
@@ -1068,8 +1139,12 @@ opensslrsa_tofile(const dst_key_t *key, |
| 1395 |
goto fail; |
| 1396 |
} |
| 1397 |
|
| 1398 |
+ RSA_get0_key(rsa, &n, &e, &d); |
| 1399 |
+ RSA_get0_factors(rsa, &p, &q); |
| 1400 |
+ RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); |
| 1401 |
+ |
| 1402 |
for (i = 0; i < 8; i++) { |
| 1403 |
- bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(rsa->n)); |
| 1404 |
+ bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(n)); |
| 1405 |
if (bufs[i] == NULL) { |
| 1406 |
result = ISC_R_NOMEMORY; |
| 1407 |
goto fail; |
| 1408 |
@@ -1079,61 +1154,61 @@ opensslrsa_tofile(const dst_key_t *key, |
| 1409 |
i = 0; |
| 1410 |
|
| 1411 |
priv.elements[i].tag = TAG_RSA_MODULUS; |
| 1412 |
- priv.elements[i].length = BN_num_bytes(rsa->n); |
| 1413 |
- BN_bn2bin(rsa->n, bufs[i]); |
| 1414 |
+ priv.elements[i].length = BN_num_bytes(n); |
| 1415 |
+ BN_bn2bin(n, bufs[i]); |
| 1416 |
priv.elements[i].data = bufs[i]; |
| 1417 |
i++; |
| 1418 |
|
| 1419 |
priv.elements[i].tag = TAG_RSA_PUBLICEXPONENT; |
| 1420 |
- priv.elements[i].length = BN_num_bytes(rsa->e); |
| 1421 |
- BN_bn2bin(rsa->e, bufs[i]); |
| 1422 |
+ priv.elements[i].length = BN_num_bytes(e); |
| 1423 |
+ BN_bn2bin(e, bufs[i]); |
| 1424 |
priv.elements[i].data = bufs[i]; |
| 1425 |
i++; |
| 1426 |
|
| 1427 |
- if (rsa->d != NULL) { |
| 1428 |
+ if (d != NULL) { |
| 1429 |
priv.elements[i].tag = TAG_RSA_PRIVATEEXPONENT; |
| 1430 |
- priv.elements[i].length = BN_num_bytes(rsa->d); |
| 1431 |
- BN_bn2bin(rsa->d, bufs[i]); |
| 1432 |
+ priv.elements[i].length = BN_num_bytes(d); |
| 1433 |
+ BN_bn2bin(d, bufs[i]); |
| 1434 |
priv.elements[i].data = bufs[i]; |
| 1435 |
i++; |
| 1436 |
} |
| 1437 |
|
| 1438 |
- if (rsa->p != NULL) { |
| 1439 |
+ if (p != NULL) { |
| 1440 |
priv.elements[i].tag = TAG_RSA_PRIME1; |
| 1441 |
- priv.elements[i].length = BN_num_bytes(rsa->p); |
| 1442 |
- BN_bn2bin(rsa->p, bufs[i]); |
| 1443 |
+ priv.elements[i].length = BN_num_bytes(p); |
| 1444 |
+ BN_bn2bin(p, bufs[i]); |
| 1445 |
priv.elements[i].data = bufs[i]; |
| 1446 |
i++; |
| 1447 |
} |
| 1448 |
|
| 1449 |
- if (rsa->q != NULL) { |
| 1450 |
+ if (q != NULL) { |
| 1451 |
priv.elements[i].tag = TAG_RSA_PRIME2; |
| 1452 |
- priv.elements[i].length = BN_num_bytes(rsa->q); |
| 1453 |
- BN_bn2bin(rsa->q, bufs[i]); |
| 1454 |
+ priv.elements[i].length = BN_num_bytes(q); |
| 1455 |
+ BN_bn2bin(q, bufs[i]); |
| 1456 |
priv.elements[i].data = bufs[i]; |
| 1457 |
i++; |
| 1458 |
} |
| 1459 |
|
| 1460 |
- if (rsa->dmp1 != NULL) { |
| 1461 |
+ if (dmp1 != NULL) { |
| 1462 |
priv.elements[i].tag = TAG_RSA_EXPONENT1; |
| 1463 |
- priv.elements[i].length = BN_num_bytes(rsa->dmp1); |
| 1464 |
- BN_bn2bin(rsa->dmp1, bufs[i]); |
| 1465 |
+ priv.elements[i].length = BN_num_bytes(dmp1); |
| 1466 |
+ BN_bn2bin(dmp1, bufs[i]); |
| 1467 |
priv.elements[i].data = bufs[i]; |
| 1468 |
i++; |
| 1469 |
} |
| 1470 |
|
| 1471 |
- if (rsa->dmq1 != NULL) { |
| 1472 |
+ if (dmq1 != NULL) { |
| 1473 |
priv.elements[i].tag = TAG_RSA_EXPONENT2; |
| 1474 |
- priv.elements[i].length = BN_num_bytes(rsa->dmq1); |
| 1475 |
- BN_bn2bin(rsa->dmq1, bufs[i]); |
| 1476 |
+ priv.elements[i].length = BN_num_bytes(dmq1); |
| 1477 |
+ BN_bn2bin(dmq1, bufs[i]); |
| 1478 |
priv.elements[i].data = bufs[i]; |
| 1479 |
i++; |
| 1480 |
} |
| 1481 |
|
| 1482 |
- if (rsa->iqmp != NULL) { |
| 1483 |
+ if (iqmp != NULL) { |
| 1484 |
priv.elements[i].tag = TAG_RSA_COEFFICIENT; |
| 1485 |
- priv.elements[i].length = BN_num_bytes(rsa->iqmp); |
| 1486 |
- BN_bn2bin(rsa->iqmp, bufs[i]); |
| 1487 |
+ priv.elements[i].length = BN_num_bytes(iqmp); |
| 1488 |
+ BN_bn2bin(iqmp, bufs[i]); |
| 1489 |
priv.elements[i].data = bufs[i]; |
| 1490 |
i++; |
| 1491 |
} |
| 1492 |
@@ -1162,7 +1237,7 @@ opensslrsa_tofile(const dst_key_t *key, |
| 1493 |
for (i = 0; i < 8; i++) { |
| 1494 |
if (bufs[i] == NULL) |
| 1495 |
break; |
| 1496 |
- isc_mem_put(key->mctx, bufs[i], BN_num_bytes(rsa->n)); |
| 1497 |
+ isc_mem_put(key->mctx, bufs[i], BN_num_bytes(n)); |
| 1498 |
} |
| 1499 |
return (result); |
| 1500 |
} |
| 1501 |
@@ -1170,25 +1245,37 @@ opensslrsa_tofile(const dst_key_t *key, |
| 1502 |
static isc_result_t |
| 1503 |
rsa_check(RSA *rsa, RSA *pub) |
| 1504 |
{ |
| 1505 |
+ const BIGNUM *rsa_n, *rsa_e, *pub_n, *pub_e; |
| 1506 |
+ |
| 1507 |
/* Public parameters should be the same but if they are not set |
| 1508 |
* copy them from the public key. */ |
| 1509 |
+ |
| 1510 |
+ RSA_get0_key(rsa, &rsa_n, &rsa_e, NULL); |
| 1511 |
+ |
| 1512 |
if (pub != NULL) { |
| 1513 |
- if (rsa->n != NULL) { |
| 1514 |
- if (BN_cmp(rsa->n, pub->n) != 0) |
| 1515 |
+ RSA_get0_key(pub, &pub_n, &pub_e, NULL); |
| 1516 |
+ |
| 1517 |
+ if (rsa_n != NULL && pub_n != NULL) { |
| 1518 |
+ if (BN_cmp(rsa_n, pub_n) != 0) |
| 1519 |
return (DST_R_INVALIDPRIVATEKEY); |
| 1520 |
- } else { |
| 1521 |
- rsa->n = pub->n; |
| 1522 |
- pub->n = NULL; |
| 1523 |
- } |
| 1524 |
- if (rsa->e != NULL) { |
| 1525 |
- if (BN_cmp(rsa->e, pub->e) != 0) |
| 1526 |
+ } else if (rsa_e != NULL && pub_e != NULL) { |
| 1527 |
+ if (BN_cmp(rsa_e, pub_e) != 0) |
| 1528 |
return (DST_R_INVALIDPRIVATEKEY); |
| 1529 |
- } else { |
| 1530 |
- rsa->e = pub->e; |
| 1531 |
- pub->e = NULL; |
| 1532 |
+ } else if (rsa_e == NULL || rsa_n == NULL) { |
| 1533 |
+ BIGNUM *new_n, *new_e; |
| 1534 |
+ if (pub_e == NULL || pub_n == NULL) |
| 1535 |
+ return (DST_R_INVALIDPRIVATEKEY); |
| 1536 |
+ rsa_n = new_n = BN_dup(pub_n); |
| 1537 |
+ rsa_e = new_e = BN_dup(pub_e); |
| 1538 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1539 |
+ rsa->n = new_n; |
| 1540 |
+ rsa->e = new_e; |
| 1541 |
+#else |
| 1542 |
+ RSA_set0_key(rsa, new_n, new_e, NULL); |
| 1543 |
+#endif |
| 1544 |
} |
| 1545 |
} |
| 1546 |
- if (rsa->n == NULL || rsa->e == NULL) |
| 1547 |
+ if (rsa_n == NULL || rsa_e == NULL) |
| 1548 |
return (DST_R_INVALIDPRIVATEKEY); |
| 1549 |
return (ISC_R_SUCCESS); |
| 1550 |
} |
| 1551 |
@@ -1200,13 +1287,14 @@ opensslrsa_parse(dst_key_t *key, isc_lex |
| 1552 |
int i; |
| 1553 |
RSA *rsa = NULL, *pubrsa = NULL; |
| 1554 |
#ifdef USE_ENGINE |
| 1555 |
- ENGINE *e = NULL; |
| 1556 |
+ ENGINE *eng = NULL; |
| 1557 |
#endif |
| 1558 |
isc_mem_t *mctx = key->mctx; |
| 1559 |
const char *engine = NULL, *label = NULL; |
| 1560 |
#if defined(USE_ENGINE) || USE_EVP |
| 1561 |
EVP_PKEY *pkey = NULL; |
| 1562 |
#endif |
| 1563 |
+ BIGNUM *n = NULL, *e = NULL, *d = NULL, *p = NULL, *q = NULL, *dmp1 = NULL, *dmq1 = NULL, *iqmp = NULL; |
| 1564 |
|
| 1565 |
/* read private key file */ |
| 1566 |
ret = dst__privstruct_parse(key, DST_ALG_RSA, lexer, mctx, &priv); |
| 1567 |
@@ -1257,10 +1345,10 @@ opensslrsa_parse(dst_key_t *key, isc_lex |
| 1568 |
#ifdef USE_ENGINE |
| 1569 |
if (engine == NULL) |
| 1570 |
DST_RET(DST_R_NOENGINE); |
| 1571 |
- e = dst__openssl_getengine(engine); |
| 1572 |
- if (e == NULL) |
| 1573 |
+ eng = dst__openssl_getengine(engine); |
| 1574 |
+ if (eng == NULL) |
| 1575 |
DST_RET(DST_R_NOENGINE); |
| 1576 |
- pkey = ENGINE_load_private_key(e, label, NULL, NULL); |
| 1577 |
+ pkey = ENGINE_load_private_key(eng, label, NULL, NULL); |
| 1578 |
if (pkey == NULL) |
| 1579 |
DST_RET(dst__openssl_toresult2( |
| 1580 |
"ENGINE_load_private_key", |
| 1581 |
@@ -1328,39 +1416,55 @@ opensslrsa_parse(dst_key_t *key, isc_lex |
| 1582 |
|
| 1583 |
switch (priv.elements[i].tag) { |
| 1584 |
case TAG_RSA_MODULUS: |
| 1585 |
- rsa->n = bn; |
| 1586 |
+ n = bn; |
| 1587 |
break; |
| 1588 |
case TAG_RSA_PUBLICEXPONENT: |
| 1589 |
- rsa->e = bn; |
| 1590 |
+ e = bn; |
| 1591 |
break; |
| 1592 |
case TAG_RSA_PRIVATEEXPONENT: |
| 1593 |
- rsa->d = bn; |
| 1594 |
+ d = bn; |
| 1595 |
break; |
| 1596 |
case TAG_RSA_PRIME1: |
| 1597 |
- rsa->p = bn; |
| 1598 |
+ p = bn; |
| 1599 |
break; |
| 1600 |
case TAG_RSA_PRIME2: |
| 1601 |
- rsa->q = bn; |
| 1602 |
+ q = bn; |
| 1603 |
break; |
| 1604 |
case TAG_RSA_EXPONENT1: |
| 1605 |
- rsa->dmp1 = bn; |
| 1606 |
+ dmp1 = bn; |
| 1607 |
break; |
| 1608 |
case TAG_RSA_EXPONENT2: |
| 1609 |
- rsa->dmq1 = bn; |
| 1610 |
+ dmq1 = bn; |
| 1611 |
break; |
| 1612 |
case TAG_RSA_COEFFICIENT: |
| 1613 |
- rsa->iqmp = bn; |
| 1614 |
+ iqmp = bn; |
| 1615 |
break; |
| 1616 |
} |
| 1617 |
} |
| 1618 |
+ |
| 1619 |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 1620 |
+ rsa->n = n; |
| 1621 |
+ rsa->e = e; |
| 1622 |
+ rsa->d = d; |
| 1623 |
+ rsa->p = p; |
| 1624 |
+ rsa->q = q; |
| 1625 |
+ rsa->dmp1 = dmp1; |
| 1626 |
+ rsa->dmq1 = dmq1; |
| 1627 |
+ rsa->iqmp = iqmp; |
| 1628 |
+#else |
| 1629 |
+ RSA_set0_key(rsa, n, e, d); |
| 1630 |
+ RSA_set0_factors(rsa, p, q); |
| 1631 |
+ RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp); |
| 1632 |
+#endif |
| 1633 |
+ |
| 1634 |
dst__privstruct_free(&priv, mctx); |
| 1635 |
memset(&priv, 0, sizeof(priv)); |
| 1636 |
|
| 1637 |
if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) |
| 1638 |
DST_RET(DST_R_INVALIDPRIVATEKEY); |
| 1639 |
- if (BN_num_bits(rsa->e) > RSA_MAX_PUBEXP_BITS) |
| 1640 |
+ if (BN_num_bits(e) > RSA_MAX_PUBEXP_BITS) |
| 1641 |
DST_RET(ISC_R_RANGE); |
| 1642 |
- key->key_size = BN_num_bits(rsa->n); |
| 1643 |
+ key->key_size = BN_num_bits(n); |
| 1644 |
if (pubrsa != NULL) |
| 1645 |
RSA_free(pubrsa); |
| 1646 |
#if USE_EVP |
| 1647 |
Index: bind9-9.10.3.dfsg.P4/lib/isc/aes.c |
| 1648 |
=================================================================== |
| 1649 |
--- lib/isc/aes.c.orig |
| 1650 |
+++ lib/isc/aes.c |
| 1651 |
@@ -36,48 +36,48 @@ void |
| 1652 |
isc_aes128_crypt(const unsigned char *key, const unsigned char *in, |
| 1653 |
unsigned char *out) |
| 1654 |
{ |
| 1655 |
- EVP_CIPHER_CTX c; |
| 1656 |
+ EVP_CIPHER_CTX *c = EVP_CIPHER_CTX_new(); |
| 1657 |
int len; |
| 1658 |
|
| 1659 |
- EVP_CIPHER_CTX_init(&c); |
| 1660 |
- RUNTIME_CHECK(EVP_EncryptInit(&c, EVP_aes_128_ecb(), key, NULL) == 1); |
| 1661 |
- EVP_CIPHER_CTX_set_padding(&c, 0); |
| 1662 |
- RUNTIME_CHECK(EVP_EncryptUpdate(&c, out, &len, in, |
| 1663 |
+ RUNTIME_CHECK(c != NULL); |
| 1664 |
+ RUNTIME_CHECK(EVP_EncryptInit(c, EVP_aes_128_ecb(), key, NULL) == 1); |
| 1665 |
+ EVP_CIPHER_CTX_set_padding(c, 0); |
| 1666 |
+ RUNTIME_CHECK(EVP_EncryptUpdate(c, out, &len, in, |
| 1667 |
ISC_AES_BLOCK_LENGTH) == 1); |
| 1668 |
RUNTIME_CHECK(len == ISC_AES_BLOCK_LENGTH); |
| 1669 |
- RUNTIME_CHECK(EVP_CIPHER_CTX_cleanup(&c) == 1); |
| 1670 |
+ EVP_CIPHER_CTX_free(c); |
| 1671 |
} |
| 1672 |
|
| 1673 |
void |
| 1674 |
isc_aes192_crypt(const unsigned char *key, const unsigned char *in, |
| 1675 |
unsigned char *out) |
| 1676 |
{ |
| 1677 |
- EVP_CIPHER_CTX c; |
| 1678 |
+ EVP_CIPHER_CTX *c = EVP_CIPHER_CTX_new(); |
| 1679 |
int len; |
| 1680 |
|
| 1681 |
- EVP_CIPHER_CTX_init(&c); |
| 1682 |
- RUNTIME_CHECK(EVP_EncryptInit(&c, EVP_aes_192_ecb(), key, NULL) == 1); |
| 1683 |
- EVP_CIPHER_CTX_set_padding(&c, 0); |
| 1684 |
- RUNTIME_CHECK(EVP_EncryptUpdate(&c, out, &len, in, |
| 1685 |
+ RUNTIME_CHECK(c != NULL); |
| 1686 |
+ RUNTIME_CHECK(EVP_EncryptInit(c, EVP_aes_192_ecb(), key, NULL) == 1); |
| 1687 |
+ EVP_CIPHER_CTX_set_padding(c, 0); |
| 1688 |
+ RUNTIME_CHECK(EVP_EncryptUpdate(c, out, &len, in, |
| 1689 |
ISC_AES_BLOCK_LENGTH) == 1); |
| 1690 |
RUNTIME_CHECK(len == ISC_AES_BLOCK_LENGTH); |
| 1691 |
- RUNTIME_CHECK(EVP_CIPHER_CTX_cleanup(&c) == 1); |
| 1692 |
+ EVP_CIPHER_CTX_free(c); |
| 1693 |
} |
| 1694 |
|
| 1695 |
void |
| 1696 |
isc_aes256_crypt(const unsigned char *key, const unsigned char *in, |
| 1697 |
unsigned char *out) |
| 1698 |
{ |
| 1699 |
- EVP_CIPHER_CTX c; |
| 1700 |
+ EVP_CIPHER_CTX *c = EVP_CIPHER_CTX_new(); |
| 1701 |
int len; |
| 1702 |
|
| 1703 |
- EVP_CIPHER_CTX_init(&c); |
| 1704 |
- RUNTIME_CHECK(EVP_EncryptInit(&c, EVP_aes_256_ecb(), key, NULL) == 1); |
| 1705 |
- EVP_CIPHER_CTX_set_padding(&c, 0); |
| 1706 |
- RUNTIME_CHECK(EVP_EncryptUpdate(&c, out, &len, in, |
| 1707 |
+ RUNTIME_CHECK(c != NULL); |
| 1708 |
+ RUNTIME_CHECK(EVP_EncryptInit(c, EVP_aes_256_ecb(), key, NULL) == 1); |
| 1709 |
+ EVP_CIPHER_CTX_set_padding(c, 0); |
| 1710 |
+ RUNTIME_CHECK(EVP_EncryptUpdate(c, out, &len, in, |
| 1711 |
ISC_AES_BLOCK_LENGTH) == 1); |
| 1712 |
RUNTIME_CHECK(len == ISC_AES_BLOCK_LENGTH); |
| 1713 |
- RUNTIME_CHECK(EVP_CIPHER_CTX_cleanup(&c) == 1); |
| 1714 |
+ EVP_CIPHER_CTX_free(c); |
| 1715 |
} |
| 1716 |
|
| 1717 |
#elif HAVE_OPENSSL_AES |