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