xref: /netbsd-src/external/mpl/bind/dist/lib/dns/openssl_shim.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: openssl_shim.h,v 1.3 2025/01/26 16:25:23 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 #pragma once
17 
18 #include <openssl/bn.h>
19 #include <openssl/dh.h>
20 #include <openssl/ecdsa.h>
21 #include <openssl/err.h>
22 #include <openssl/evp.h>
23 #include <openssl/opensslv.h>
24 #include <openssl/rsa.h>
25 
26 /*
27  * Limit the size of public exponents.
28  */
29 #ifndef RSA_MAX_PUBEXP_BITS
30 #define RSA_MAX_PUBEXP_BITS 35
31 #endif /* ifndef RSA_MAX_PUBEXP_BITS */
32 
33 #if !HAVE_BN_GENCB_NEW
34 /* These are new in OpenSSL 1.1.0. */
35 static inline BN_GENCB *
36 BN_GENCB_new(void) {
37 	return OPENSSL_malloc(sizeof(BN_GENCB));
38 }
39 
40 static inline void
41 BN_GENCB_free(BN_GENCB *cb) {
42 	if (cb == NULL) {
43 		return;
44 	}
45 	OPENSSL_free(cb);
46 }
47 
48 static inline void *
49 BN_GENCB_get_arg(BN_GENCB *cb) {
50 	return cb->arg;
51 }
52 #endif /* !HAVE_BN_GENCB_NEW */
53 
54 #if !HAVE_EVP_PKEY_GET0_RSA && OPENSSL_VERSION_NUMBER < 0x10100000L
55 static inline const RSA *
56 EVP_PKEY_get0_RSA(const EVP_PKEY *pkey) {
57 	return pkey->type == EVP_PKEY_RSA ? pkey->pkey.rsa : NULL;
58 }
59 #endif
60 
61 #if !HAVE_EVP_PKEY_GET0_EC_KEY && OPENSSL_VERSION_NUMBER < 0x10100000L
62 static inline const EC_KEY *
63 EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey) {
64 	return pkey->type == EVP_PKEY_EC ? pkey->pkey.ec : NULL;
65 }
66 #endif
67 
68 #if !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L
69 int
70 RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
71 
72 int
73 RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
74 
75 int
76 RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
77 
78 void
79 RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
80 	     const BIGNUM **d);
81 
82 void
83 RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
84 
85 void
86 RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
87 		    const BIGNUM **iqmp);
88 
89 int
90 RSA_test_flags(const RSA *r, int flags);
91 #endif /* !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L */
92 
93 #if !HAVE_ECDSA_SIG_GET0
94 void
95 ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
96 
97 int
98 ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
99 #endif /* !HAVE_ECDSA_SIG_GET0 */
100 
101 #if !HAVE_ERR_GET_ERROR_ALL
102 unsigned long
103 ERR_get_error_all(const char **file, int *line, const char **func,
104 		  const char **data, int *flags);
105 #endif /* if !HAVE_ERR_GET_ERROR_ALL */
106 
107 #if !HAVE_EVP_PKEY_EQ
108 #define EVP_PKEY_eq EVP_PKEY_cmp
109 #endif
110