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 #elif (OPENSSL_VERSION_NUMBER >= 0x30000000L) 108 static __rte_always_inline void 109 set_dsa_sign(DSA_SIG *sign, BIGNUM *r, BIGNUM *s) 110 { 111 DSA_SIG_set0(sign, r, s); 112 } 113 114 static __rte_always_inline void 115 get_dsa_sign(DSA_SIG *sign, const BIGNUM **r, const BIGNUM **s) 116 { 117 DSA_SIG_get0(sign, r, s); 118 } 119 #else 120 121 static __rte_always_inline int 122 set_rsa_params(RSA *rsa, BIGNUM *p, BIGNUM *q) 123 { 124 return !(RSA_set0_factors(rsa, p, q)); 125 } 126 127 static __rte_always_inline int 128 set_rsa_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) 129 { 130 return !(RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp)); 131 } 132 133 /* n, e must be non-null, d can be NULL */ 134 135 static __rte_always_inline int 136 set_rsa_keys(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d) 137 { 138 return !(RSA_set0_key(rsa, n, e, d)); 139 } 140 141 static __rte_always_inline int 142 set_dh_params(DH *dh, BIGNUM *p, BIGNUM *g) 143 { 144 return !(DH_set0_pqg(dh, p, NULL, g)); 145 } 146 147 static __rte_always_inline int 148 set_dh_priv_key(DH *dh, BIGNUM *priv_key) 149 { 150 return !(DH_set0_key(dh, NULL, priv_key)); 151 } 152 153 static __rte_always_inline void 154 get_dh_pub_key(DH *dh_key, const BIGNUM **pub_key) 155 { 156 DH_get0_key(dh_key, pub_key, NULL); 157 } 158 159 static __rte_always_inline void 160 get_dh_priv_key(DH *dh_key, const BIGNUM **priv_key) 161 { 162 DH_get0_key(dh_key, NULL, priv_key); 163 } 164 165 static __rte_always_inline int 166 set_dsa_params(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g) 167 { 168 return !(DSA_set0_pqg(dsa, p, q, g)); 169 } 170 171 static __rte_always_inline void 172 set_dsa_priv_key(DSA *dsa, BIGNUM *priv_key) 173 { 174 DSA_set0_key(dsa, NULL, priv_key); 175 } 176 177 static __rte_always_inline void 178 set_dsa_sign(DSA_SIG *sign, BIGNUM *r, BIGNUM *s) 179 { 180 DSA_SIG_set0(sign, r, s); 181 } 182 183 static __rte_always_inline void 184 get_dsa_sign(DSA_SIG *sign, const BIGNUM **r, const BIGNUM **s) 185 { 186 DSA_SIG_get0(sign, r, s); 187 } 188 189 static __rte_always_inline int 190 set_dsa_keys(DSA *dsa, BIGNUM *pub, BIGNUM *priv) 191 { 192 return !(DSA_set0_key(dsa, pub, priv)); 193 } 194 195 static __rte_always_inline void 196 set_dsa_pub_key(DSA *dsa, BIGNUM *pub_key) 197 { 198 DSA_set0_key(dsa, pub_key, NULL); 199 } 200 201 static __rte_always_inline void 202 get_dsa_priv_key(DSA *dsa, const BIGNUM **priv_key) 203 { 204 DSA_get0_key(dsa, NULL, priv_key); 205 } 206 207 #endif /* version < 10100000 */ 208 209 #endif /* __RTA_COMPAT_H__ */ 210