summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/drivers/crypto/openssl/compat.h
blob: eecb7d36989b91e6a31a10d2ee0ff52231baefa6 (plain)
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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Cavium Networks
 */

#ifndef __RTA_COMPAT_H__
#define __RTA_COMPAT_H__

#if (OPENSSL_VERSION_NUMBER < 0x10100000L)

static __rte_always_inline int
set_rsa_params(RSA *rsa, BIGNUM *p, BIGNUM *q)
{
	rsa->p = p;
	rsa->q = q;
	return 0;
}

static __rte_always_inline int
set_rsa_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
{
	rsa->dmp1 = dmp1;
	rsa->dmq1 = dmq1;
	rsa->iqmp = iqmp;
	return 0;
}

static __rte_always_inline int
set_rsa_keys(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
{
	rsa->n = n;
	rsa->e = e;
	rsa->d = d;
	return 0;
}

static __rte_always_inline int
set_dh_params(DH *dh, BIGNUM *p, BIGNUM *g)
{
	dh->p = p;
	dh->q = NULL;
	dh->g = g;
	return 0;
}

static __rte_always_inline int
set_dh_priv_key(DH *dh, BIGNUM *priv_key)
{
	dh->priv_key = priv_key;
	return 0;
}

static __rte_always_inline int
set_dsa_params(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
{
	dsa->p = p;
	dsa->q = q;
	dsa->g = g;
	return 0;
}

static __rte_always_inline void
get_dh_pub_key(DH *dh, const BIGNUM **pub_key)
{
	*pub_key = dh->pub_key;
}

static __rte_always_inline void
get_dh_priv_key(DH *dh, const BIGNUM **priv_key)
{
	*priv_key = dh->priv_key;
}

static __rte_always_inline void
set_dsa_sign(DSA_SIG *sign, BIGNUM *r, BIGNUM *s)
{
	sign->r = r;
	sign->s = s;
}

static __rte_always_inline void
get_dsa_sign(DSA_SIG *sign, const BIGNUM **r, const BIGNUM **s)
{
	*r = sign->r;
	*s = sign->s;
}

static __rte_always_inline int
set_dsa_keys(DSA *dsa, BIGNUM *pub, BIGNUM *priv)
{
	dsa->pub_key = pub;
	dsa->priv_key = priv;
	return 0;
}

static __rte_always_inline void
set_dsa_pub_key(DSA *dsa, BIGNUM *pub)
{
	dsa->pub_key = pub;
}

static __rte_always_inline void
get_dsa_priv_key(DSA *dsa, BIGNUM **priv_key)
{
	*priv_key = dsa->priv_key;
}

#else

static __rte_always_inline int
set_rsa_params(RSA *rsa, BIGNUM *p, BIGNUM *q)
{
	return !(RSA_set0_factors(rsa, p, q));
}

static __rte_always_inline int
set_rsa_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
{
	return !(RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp));
}

/* n, e must be non-null, d can be NULL */

static __rte_always_inline  int
set_rsa_keys(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
{
	return !(RSA_set0_key(rsa, n, e, d));
}

static __rte_always_inline int
set_dh_params(DH *dh, BIGNUM *p, BIGNUM *g)
{
	return !(DH_set0_pqg(dh, p, NULL, g));
}

static __rte_always_inline int
set_dh_priv_key(DH *dh, BIGNUM *priv_key)
{
	return !(DH_set0_key(dh, NULL, priv_key));
}

static __rte_always_inline void
get_dh_pub_key(DH *dh_key, const BIGNUM **pub_key)
{
	DH_get0_key(dh_key, pub_key, NULL);
}

static __rte_always_inline void
get_dh_priv_key(DH *dh_key, const BIGNUM **priv_key)
{
	DH_get0_key(dh_key, NULL, priv_key);
}

static __rte_always_inline int
set_dsa_params(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
{
	return !(DSA_set0_pqg(dsa, p, q, g));
}

static __rte_always_inline void
set_dsa_priv_key(DSA *dsa, BIGNUM *priv_key)
{
	DSA_set0_key(dsa, NULL, priv_key);
}

static __rte_always_inline void
set_dsa_sign(DSA_SIG *sign, BIGNUM *r, BIGNUM *s)
{
	DSA_SIG_set0(sign, r, s);
}

static __rte_always_inline void
get_dsa_sign(DSA_SIG *sign, const BIGNUM **r, const BIGNUM **s)
{
	DSA_SIG_get0(sign, r, s);
}

static __rte_always_inline int
set_dsa_keys(DSA *dsa, BIGNUM *pub, BIGNUM *priv)
{
	return !(DSA_set0_key(dsa, pub, priv));
}

static __rte_always_inline void
set_dsa_pub_key(DSA *dsa, BIGNUM *pub_key)
{
	DSA_set0_key(dsa, pub_key, NULL);
}

static __rte_always_inline void
get_dsa_priv_key(DSA *dsa, const BIGNUM **priv_key)
{
	DSA_get0_key(dsa, NULL, priv_key);
}

#endif /* version < 10100000 */

#endif /* __RTA_COMPAT_H__ */