New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / crypto / openssl / compat.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium Networks
3  */
4
5 #ifndef __RTA_COMPAT_H__
6 #define __RTA_COMPAT_H__
7
8 #if (OPENSSL_VERSION_NUMBER < 0x10100000L)
9
10 static __rte_always_inline int
11 set_rsa_params(RSA *rsa, BIGNUM *p, BIGNUM *q)
12 {
13         rsa->p = p;
14         rsa->q = q;
15         return 0;
16 }
17
18 static __rte_always_inline int
19 set_rsa_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
20 {
21         rsa->dmp1 = dmp1;
22         rsa->dmq1 = dmq1;
23         rsa->iqmp = iqmp;
24         return 0;
25 }
26
27 static __rte_always_inline int
28 set_rsa_keys(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
29 {
30         rsa->n = n;
31         rsa->e = e;
32         rsa->d = d;
33         return 0;
34 }
35
36 static __rte_always_inline int
37 set_dh_params(DH *dh, BIGNUM *p, BIGNUM *g)
38 {
39         dh->p = p;
40         dh->q = NULL;
41         dh->g = g;
42         return 0;
43 }
44
45 static __rte_always_inline int
46 set_dh_priv_key(DH *dh, BIGNUM *priv_key)
47 {
48         dh->priv_key = priv_key;
49         return 0;
50 }
51
52 static __rte_always_inline int
53 set_dsa_params(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
54 {
55         dsa->p = p;
56         dsa->q = q;
57         dsa->g = g;
58         return 0;
59 }
60
61 static __rte_always_inline void
62 get_dh_pub_key(DH *dh, const BIGNUM **pub_key)
63 {
64         *pub_key = dh->pub_key;
65 }
66
67 static __rte_always_inline void
68 get_dh_priv_key(DH *dh, const BIGNUM **priv_key)
69 {
70         *priv_key = dh->priv_key;
71 }
72
73 static __rte_always_inline void
74 set_dsa_sign(DSA_SIG *sign, BIGNUM *r, BIGNUM *s)
75 {
76         sign->r = r;
77         sign->s = s;
78 }
79
80 static __rte_always_inline void
81 get_dsa_sign(DSA_SIG *sign, const BIGNUM **r, const BIGNUM **s)
82 {
83         *r = sign->r;
84         *s = sign->s;
85 }
86
87 static __rte_always_inline int
88 set_dsa_keys(DSA *dsa, BIGNUM *pub, BIGNUM *priv)
89 {
90         dsa->pub_key = pub;
91         dsa->priv_key = priv;
92         return 0;
93 }
94
95 static __rte_always_inline void
96 set_dsa_pub_key(DSA *dsa, BIGNUM *pub)
97 {
98         dsa->pub_key = pub;
99 }
100
101 static __rte_always_inline void
102 get_dsa_priv_key(DSA *dsa, BIGNUM **priv_key)
103 {
104         *priv_key = dsa->priv_key;
105 }
106
107 #else
108
109 static __rte_always_inline int
110 set_rsa_params(RSA *rsa, BIGNUM *p, BIGNUM *q)
111 {
112         return !(RSA_set0_factors(rsa, p, q));
113 }
114
115 static __rte_always_inline int
116 set_rsa_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
117 {
118         return !(RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp));
119 }
120
121 /* n, e must be non-null, d can be NULL */
122
123 static __rte_always_inline  int
124 set_rsa_keys(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
125 {
126         return !(RSA_set0_key(rsa, n, e, d));
127 }
128
129 static __rte_always_inline int
130 set_dh_params(DH *dh, BIGNUM *p, BIGNUM *g)
131 {
132         return !(DH_set0_pqg(dh, p, NULL, g));
133 }
134
135 static __rte_always_inline int
136 set_dh_priv_key(DH *dh, BIGNUM *priv_key)
137 {
138         return !(DH_set0_key(dh, NULL, priv_key));
139 }
140
141 static __rte_always_inline void
142 get_dh_pub_key(DH *dh_key, const BIGNUM **pub_key)
143 {
144         DH_get0_key(dh_key, pub_key, NULL);
145 }
146
147 static __rte_always_inline void
148 get_dh_priv_key(DH *dh_key, const BIGNUM **priv_key)
149 {
150         DH_get0_key(dh_key, NULL, priv_key);
151 }
152
153 static __rte_always_inline int
154 set_dsa_params(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
155 {
156         return !(DSA_set0_pqg(dsa, p, q, g));
157 }
158
159 static __rte_always_inline void
160 set_dsa_priv_key(DSA *dsa, BIGNUM *priv_key)
161 {
162         DSA_set0_key(dsa, NULL, priv_key);
163 }
164
165 static __rte_always_inline void
166 set_dsa_sign(DSA_SIG *sign, BIGNUM *r, BIGNUM *s)
167 {
168         DSA_SIG_set0(sign, r, s);
169 }
170
171 static __rte_always_inline void
172 get_dsa_sign(DSA_SIG *sign, const BIGNUM **r, const BIGNUM **s)
173 {
174         DSA_SIG_get0(sign, r, s);
175 }
176
177 static __rte_always_inline int
178 set_dsa_keys(DSA *dsa, BIGNUM *pub, BIGNUM *priv)
179 {
180         return !(DSA_set0_key(dsa, pub, priv));
181 }
182
183 static __rte_always_inline void
184 set_dsa_pub_key(DSA *dsa, BIGNUM *pub_key)
185 {
186         DSA_set0_key(dsa, pub_key, NULL);
187 }
188
189 static __rte_always_inline void
190 get_dsa_priv_key(DSA *dsa, const BIGNUM **priv_key)
191 {
192         DSA_get0_key(dsa, NULL, priv_key);
193 }
194
195 #endif /* version < 10100000 */
196
197 #endif /* __RTA_COMPAT_H__ */