1/*	$NetBSD: openssl_shim.h,v 1.7 2024/02/21 22:52:28 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/crypto.h>
19#include <openssl/engine.h>
20#include <openssl/evp.h>
21#include <openssl/hmac.h>
22#include <openssl/opensslv.h>
23#include <openssl/ssl.h>
24
25#if !HAVE_CRYPTO_ZALLOC
26void *
27CRYPTO_zalloc(size_t num, const char *file, int line);
28#endif /* if !HAVE_CRYPTO_ZALLOC */
29
30#if !defined(OPENSSL_zalloc)
31#define OPENSSL_zalloc(num) CRYPTO_zalloc(num, __FILE__, __LINE__)
32#endif
33
34#if !HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
35#define EVP_PKEY_new_raw_private_key(type, e, key, keylen) \
36	EVP_PKEY_new_mac_key(type, e, key, (int)(keylen))
37#endif /* if !HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY */
38
39#if !HAVE_EVP_CIPHER_CTX_NEW
40EVP_CIPHER_CTX *
41EVP_CIPHER_CTX_new(void);
42#endif /* if !HAVE_EVP_CIPHER_CTX_NEW */
43
44#if !HAVE_EVP_CIPHER_CTX_FREE
45void
46EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx);
47#endif /* if !HAVE_EVP_CIPHER_CTX_FREE */
48
49#if !HAVE_EVP_MD_CTX_NEW
50#define EVP_MD_CTX_new EVP_MD_CTX_create
51#endif /* if !HAVE_EVP_MD_CTX_NEW */
52
53#if !HAVE_EVP_MD_CTX_FREE
54#define EVP_MD_CTX_free EVP_MD_CTX_destroy
55#endif /* if !HAVE_EVP_MD_CTX_FREE */
56
57#if !HAVE_EVP_MD_CTX_RESET
58int
59EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
60#endif /* if !HAVE_EVP_MD_CTX_RESET */
61
62#if !HAVE_EVP_MD_CTX_GET0_MD
63#define EVP_MD_CTX_get0_md EVP_MD_CTX_md
64#endif /* if !HAVE_EVP_MD_CTX_GET0_MD */
65
66#if !HAVE_SSL_READ_EX
67int
68SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
69#endif
70
71#if !HAVE_SSL_PEEK_EX
72int
73SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
74#endif
75
76#if !HAVE_SSL_WRITE_EX
77int
78SSL_write_ex(SSL *ssl, const void *buf, size_t num, size_t *written);
79#endif
80
81#if !HAVE_BIO_READ_EX
82int
83BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes);
84#endif
85
86#if !HAVE_BIO_WRITE_EX
87int
88BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written);
89#endif
90
91#if !HAVE_OPENSSL_INIT_CRYPTO
92
93#define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L
94#define OPENSSL_INIT_LOAD_CRYPTO_STRINGS    0x00000002L
95#define OPENSSL_INIT_ADD_ALL_CIPHERS	    0x00000004L
96#define OPENSSL_INIT_ADD_ALL_DIGESTS	    0x00000008L
97#define OPENSSL_INIT_NO_ADD_ALL_CIPHERS	    0x00000010L
98#define OPENSSL_INIT_NO_ADD_ALL_DIGESTS	    0x00000020L
99
100int
101OPENSSL_init_crypto(uint64_t opts, const void *settings);
102#endif
103
104#if !HAVE_OPENSSL_INIT_SSL
105#define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L
106#define OPENSSL_INIT_LOAD_SSL_STRINGS	 0x00200000L
107
108int
109OPENSSL_init_ssl(uint64_t opts, const void *settings);
110
111#endif
112
113#if !HAVE_OPENSSL_CLEANUP
114void
115OPENSSL_cleanup(void);
116#endif
117
118#if !HAVE_TLS_SERVER_METHOD
119#define TLS_server_method SSLv23_server_method
120#endif
121
122#if !HAVE_TLS_CLIENT_METHOD
123#define TLS_client_method SSLv23_client_method
124#endif
125
126#if !HAVE_SSL_CTX_UP_REF
127int
128SSL_CTX_up_ref(SSL_CTX *store);
129#endif /* !HAVE_SSL_CTX_UP_REF */
130
131#if !HAVE_X509_STORE_UP_REF
132int
133X509_STORE_up_ref(X509_STORE *v);
134#endif /* !HAVE_OPENSSL_CLEANUP */
135
136#if !HAVE_SSL_CTX_SET1_CERT_STORE
137void
138SSL_CTX_set1_cert_store(SSL_CTX *ctx, X509_STORE *store);
139#endif /* !HAVE_SSL_CTX_SET1_CERT_STORE */
140