OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
openssl_compat.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef OPENSSL_COMPAT_H
18#define OPENSSL_COMPAT_H
19
20#include <openssl/opensslv.h>
21#include <openssl/pem.h>
22#include <openssl/rsa.h>
23
24#if !defined(HAVE_RSA_GET0_KEY) && defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
25#define HAVE_RSA_GET0_KEY
26#define HAVE_RSA_SET0_KEY
27#define EVP_MD_CTX_cleanup EVP_MD_CTX_free
28#endif
29
30#ifndef HAVE_RSA_GET0_KEY
39static inline void
40RSA_get0_key(const RSA *rsa, const BIGNUM **n,
41 const BIGNUM **e, const BIGNUM **d)
42{
43 if (n != NULL)
44 {
45 *n = rsa ? rsa->n : NULL;
46 }
47 if (e != NULL)
48 {
49 *e = rsa ? rsa->e : NULL;
50 }
51 if (d != NULL)
52 {
53 *d = rsa ? rsa->d : NULL;
54 }
55}
56#endif
57
58#ifndef HAVE_RSA_SET0_KEY
68static inline int
69RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
70{
71 if ((rsa->n == NULL && n == NULL)
72 || (rsa->e == NULL && e == NULL))
73 {
74 return 0;
75 }
76
77 if (n != NULL)
78 {
79 BN_free(rsa->n);
80 rsa->n = n;
81 }
82 if (e != NULL)
83 {
84 BN_free(rsa->e);
85 rsa->e = e;
86 }
87 if (d != NULL)
88 {
89 BN_free(rsa->d);
90 rsa->d = d;
91 }
92
93 return 1;
94}
95#endif
96
97#endif /* _OPENSSL_COMPAT_H */
98