File: openssl_compat.h

package info (click to toggle)
libpam-ssh 2.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,276 kB
  • sloc: ansic: 16,203; makefile: 93; sh: 38
file content (224 lines) | stat: -rw-r--r-- 3,696 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* Compatibility header for OpenSSL versions 1.0 and below */

#ifndef OPENSSL_COMPAT_H
#define OPENSSL_COMPAT_H

/* evp.h compat */
#ifdef HEADER_ENVELOPE_H

#ifndef HAVE_EVP_CIPHER_CTX_IV
static inline const unsigned char *
EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx) { return ctx->iv; }
#endif

#ifndef HAVE_EVP_CIPHER_CTX_IV_NOCONST
static inline unsigned char *
EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx) { return ctx->iv; }
#endif

#ifndef HAVE_EVP_CIPHER_IMPL_CTX_SIZE
static inline int
EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *e) { return e->ctx_size; }
#endif

#ifndef HAVE_EVP_CIPHER_CTX_GET_CIPHER_DATA
static inline void *
EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx) { return ctx->cipher_data; }
#endif

#endif /* HEADER_ENVELOPE_H */

/* rsa.h compat */
#ifdef HEADER_RSA_H

#ifndef HAVE_RSA_GET0_KEY
static inline void
RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
{
	if (n)
		*n = r->n;
	if (e)
		*e = r->e;
	if (d)
		*d = r->d;
}
#endif

#ifndef HAVE_RSA_SET0_KEY
static inline int
RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
{
	if (n) {
		BN_free(r->n);
		r->n = n;
	}
	if (e) {
		BN_free(r->e);
		r->e = e;
	}
	if (d) {
		BN_free(r->d);
		r->d = d;
	}
	return 1;
}
#endif

#ifndef HAVE_RSA_GET0_FACTORS
static inline void
RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
{
	if (p)
		*p = r->p;
	if (q)
		*q = r->q;
}
#endif

#ifndef HAVE_RSA_SET0_FACTORS
static inline int
RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
{
	if (p) {
		BN_free(r->p);
		r->p = p;
	}
	if (q) {
		BN_free(r->q);
		r->q = q;
	}
	return 1;
}
#endif

#ifndef HAVE_RSA_GET0_CRT_PARAMS
static inline void
RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1,
		    const BIGNUM **dmq1, const BIGNUM **iqmp)
{
	if (dmp1)
		*dmp1 = r->dmp1;
	if (dmq1)
		*dmq1 = r->dmq1;
	if (iqmp)
		*iqmp = r->iqmp;
}
#endif

#ifndef HAVE_RSA_SET0_CRT_PARAMS
static inline int
RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
{
	if (dmp1) {
		BN_free(r->dmp1);
		r->dmp1 = dmp1;
	}
	if (dmq1) {
		BN_free(r->dmq1);
		r->dmq1 = dmq1;
	}
	if (iqmp) {
		BN_free(r->iqmp);
		r->iqmp = iqmp;
	}
	return 1;
}
#endif

#endif /* HEADER_RSA_H */

/* ecdsa.h compat */
#ifdef HEADER_ECDSA_H

#ifndef HAVE_ECDSA_SIG_SET0
static inline int
ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
{
	BN_clear_free(sig->r);
	BN_clear_free(sig->s);
	sig->r = r;
	sig->s = s;
	return 1;
}
#endif

#endif /* HEADER_ECDSA_H */

/* dsa.h compat */
#ifdef HEADER_DSA_H

#ifndef HAVE_DSA_SIG_SET0
static inline int
DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s)
{
	BN_clear_free(sig->r);
	BN_clear_free(sig->s);
	sig->r = r;
	sig->s = s;
	return 1;
}
#endif

#ifndef HAVE_DSA_GET0_PQG
static inline void
DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
{
	if (p)
		*p = d->p;
	if (q)
		*q = d->q;
	if (g)
		*g = d->g;
}
#endif

#ifndef HAVE_DSA_SET0_PQG
static inline int
DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
{
	if (p) {
		BN_free(d->p);
		d->p = p;
	}
	if (q) {
		BN_free(d->q);
		d->q = q;
	}
	if (g) {
		BN_free(d->g);
		d->g = g;
	}
	return 1;
}
#endif

#ifndef HAVE_DSA_GET0_KEY
static inline void
DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key)
{
	if (pub_key)
		*pub_key = d->pub_key;
	if (priv_key)
		*priv_key = d->priv_key;
}
#endif

#ifndef HAVE_DSA_SET0_KEY
static inline int
DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
{
	if (pub_key) {
		BN_free(d->pub_key);
		d->pub_key = pub_key;
	}
	if (priv_key) {
		BN_free(d->priv_key);
		d->priv_key = priv_key;
	}
	return 1;
}
#endif

#endif /* HEADER_DSA_H */

#endif /* OPENSSL_COMPAT_H */