xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/isc/openssl_shim.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1 /*	$NetBSD: openssl_shim.h,v 1.1 2024/02/18 20:57:49 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
26 void *
27 CRYPTO_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_CIPHER_CTX_NEW
35 EVP_CIPHER_CTX *
36 EVP_CIPHER_CTX_new(void);
37 #endif /* if !HAVE_EVP_CIPHER_CTX_NEW */
38 
39 #if !HAVE_EVP_CIPHER_CTX_FREE
40 void
41 EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx);
42 #endif /* if !HAVE_EVP_CIPHER_CTX_FREE */
43 
44 #if !HAVE_EVP_MD_CTX_NEW
45 EVP_MD_CTX *
46 EVP_MD_CTX_new(void);
47 #endif /* if !HAVE_EVP_MD_CTX_NEW */
48 
49 #if !HAVE_EVP_MD_CTX_FREE
50 void
51 EVP_MD_CTX_free(EVP_MD_CTX *ctx);
52 #endif /* if !HAVE_EVP_MD_CTX_FREE */
53 
54 #if !HAVE_EVP_MD_CTX_RESET
55 int
56 EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
57 #endif /* if !HAVE_EVP_MD_CTX_RESET */
58 
59 #if !HAVE_HMAC_CTX_NEW
60 HMAC_CTX *
61 HMAC_CTX_new(void);
62 #endif /* if !HAVE_HMAC_CTX_NEW */
63 
64 #if !HAVE_HMAC_CTX_FREE
65 void
66 HMAC_CTX_free(HMAC_CTX *ctx);
67 #endif /* if !HAVE_HMAC_CTX_FREE */
68 
69 #if !HAVE_HMAC_CTX_RESET
70 int
71 HMAC_CTX_reset(HMAC_CTX *ctx);
72 #endif /* if !HAVE_HMAC_CTX_RESET */
73 
74 #if !HAVE_HMAC_CTX_GET_MD
75 const EVP_MD *
76 HMAC_CTX_get_md(const HMAC_CTX *ctx);
77 #endif /* if !HAVE_HMAC_CTX_GET_MD */
78 
79 #if !HAVE_SSL_READ_EX
80 int
81 SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
82 #endif
83 
84 #if !HAVE_SSL_PEEK_EX
85 int
86 SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
87 #endif
88 
89 #if !HAVE_SSL_WRITE_EX
90 int
91 SSL_write_ex(SSL *ssl, const void *buf, size_t num, size_t *written);
92 #endif
93 
94 #if !HAVE_BIO_READ_EX
95 int
96 BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes);
97 #endif
98 
99 #if !HAVE_BIO_WRITE_EX
100 int
101 BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written);
102 #endif
103 
104 #if !HAVE_OPENSSL_INIT_CRYPTO
105 
106 #define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L
107 #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS    0x00000002L
108 #define OPENSSL_INIT_ADD_ALL_CIPHERS	    0x00000004L
109 #define OPENSSL_INIT_ADD_ALL_DIGESTS	    0x00000008L
110 #define OPENSSL_INIT_NO_ADD_ALL_CIPHERS	    0x00000010L
111 #define OPENSSL_INIT_NO_ADD_ALL_DIGESTS	    0x00000020L
112 
113 int
114 OPENSSL_init_crypto(uint64_t opts, const void *settings);
115 #endif
116 
117 #if !HAVE_OPENSSL_INIT_SSL
118 #define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L
119 #define OPENSSL_INIT_LOAD_SSL_STRINGS	 0x00200000L
120 
121 int
122 OPENSSL_init_ssl(uint64_t opts, const void *settings);
123 
124 #endif
125 
126 #if !HAVE_OPENSSL_CLEANUP
127 void
128 OPENSSL_cleanup(void);
129 #endif
130 
131 #if !HAVE_TLS_SERVER_METHOD
132 #define TLS_server_method SSLv23_server_method
133 #endif
134 
135 #if !HAVE_TLS_CLIENT_METHOD
136 #define TLS_client_method SSLv23_client_method
137 #endif
138