summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/p_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/p_lib.c')
-rw-r--r--src/lib/libcrypto/evp/p_lib.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 62398ed74d..215b94292a 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -64,14 +64,15 @@
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66static void EVP_PKEY_free_it(EVP_PKEY *x); 66static void EVP_PKEY_free_it(EVP_PKEY *x);
67
67int EVP_PKEY_bits(EVP_PKEY *pkey) 68int EVP_PKEY_bits(EVP_PKEY *pkey)
68 { 69 {
69#ifndef NO_RSA 70#ifndef OPENSSL_NO_RSA
70 if (pkey->type == EVP_PKEY_RSA) 71 if (pkey->type == EVP_PKEY_RSA)
71 return(BN_num_bits(pkey->pkey.rsa->n)); 72 return(BN_num_bits(pkey->pkey.rsa->n));
72 else 73 else
73#endif 74#endif
74#ifndef NO_DSA 75#ifndef OPENSSL_NO_DSA
75 if (pkey->type == EVP_PKEY_DSA) 76 if (pkey->type == EVP_PKEY_DSA)
76 return(BN_num_bits(pkey->pkey.dsa->p)); 77 return(BN_num_bits(pkey->pkey.dsa->p));
77#endif 78#endif
@@ -82,12 +83,12 @@ int EVP_PKEY_size(EVP_PKEY *pkey)
82 { 83 {
83 if (pkey == NULL) 84 if (pkey == NULL)
84 return(0); 85 return(0);
85#ifndef NO_RSA 86#ifndef OPENSSL_NO_RSA
86 if (pkey->type == EVP_PKEY_RSA) 87 if (pkey->type == EVP_PKEY_RSA)
87 return(RSA_size(pkey->pkey.rsa)); 88 return(RSA_size(pkey->pkey.rsa));
88 else 89 else
89#endif 90#endif
90#ifndef NO_DSA 91#ifndef OPENSSL_NO_DSA
91 if (pkey->type == EVP_PKEY_DSA) 92 if (pkey->type == EVP_PKEY_DSA)
92 return(DSA_size(pkey->pkey.dsa)); 93 return(DSA_size(pkey->pkey.dsa));
93#endif 94#endif
@@ -96,10 +97,10 @@ int EVP_PKEY_size(EVP_PKEY *pkey)
96 97
97int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) 98int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
98 { 99 {
99#ifndef NO_DSA 100#ifndef OPENSSL_NO_DSA
100 if (pkey->type == EVP_PKEY_DSA) 101 if (pkey->type == EVP_PKEY_DSA)
101 { 102 {
102 int ret=pkey->save_parameters=mode; 103 int ret=pkey->save_parameters;
103 104
104 if (mode >= 0) 105 if (mode >= 0)
105 pkey->save_parameters=mode; 106 pkey->save_parameters=mode;
@@ -122,7 +123,7 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
122 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS); 123 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
123 goto err; 124 goto err;
124 } 125 }
125#ifndef NO_DSA 126#ifndef OPENSSL_NO_DSA
126 if (to->type == EVP_PKEY_DSA) 127 if (to->type == EVP_PKEY_DSA)
127 { 128 {
128 BIGNUM *a; 129 BIGNUM *a;
@@ -147,7 +148,7 @@ err:
147 148
148int EVP_PKEY_missing_parameters(EVP_PKEY *pkey) 149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
149 { 150 {
150#ifndef NO_DSA 151#ifndef OPENSSL_NO_DSA
151 if (pkey->type == EVP_PKEY_DSA) 152 if (pkey->type == EVP_PKEY_DSA)
152 { 153 {
153 DSA *dsa; 154 DSA *dsa;
@@ -162,7 +163,7 @@ int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
162 163
163int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b) 164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
164 { 165 {
165#ifndef NO_DSA 166#ifndef OPENSSL_NO_DSA
166 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) 167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
167 { 168 {
168 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) || 169 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
@@ -205,11 +206,12 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
205 return(key != NULL); 206 return(key != NULL);
206 } 207 }
207 208
208#ifndef NO_RSA 209#ifndef OPENSSL_NO_RSA
209int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) 210int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
210{ 211{
211 int ret = EVP_PKEY_assign_RSA(pkey, key); 212 int ret = EVP_PKEY_assign_RSA(pkey, key);
212 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_RSA); 213 if(ret)
214 RSA_up_ref(key);
213 return ret; 215 return ret;
214} 216}
215 217
@@ -219,16 +221,17 @@ RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
219 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY); 221 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
220 return NULL; 222 return NULL;
221 } 223 }
222 CRYPTO_add(&pkey->pkey.rsa->references, 1, CRYPTO_LOCK_RSA); 224 RSA_up_ref(pkey->pkey.rsa);
223 return pkey->pkey.rsa; 225 return pkey->pkey.rsa;
224} 226}
225#endif 227#endif
226 228
227#ifndef NO_DSA 229#ifndef OPENSSL_NO_DSA
228int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) 230int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
229{ 231{
230 int ret = EVP_PKEY_assign_DSA(pkey, key); 232 int ret = EVP_PKEY_assign_DSA(pkey, key);
231 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DSA); 233 if(ret)
234 DSA_up_ref(key);
232 return ret; 235 return ret;
233} 236}
234 237
@@ -238,17 +241,18 @@ DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
238 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY); 241 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
239 return NULL; 242 return NULL;
240 } 243 }
241 CRYPTO_add(&pkey->pkey.dsa->references, 1, CRYPTO_LOCK_DSA); 244 DSA_up_ref(pkey->pkey.dsa);
242 return pkey->pkey.dsa; 245 return pkey->pkey.dsa;
243} 246}
244#endif 247#endif
245 248
246#ifndef NO_DH 249#ifndef OPENSSL_NO_DH
247 250
248int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) 251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
249{ 252{
250 int ret = EVP_PKEY_assign_DH(pkey, key); 253 int ret = EVP_PKEY_assign_DH(pkey, key);
251 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DH); 254 if(ret)
255 DH_up_ref(key);
252 return ret; 256 return ret;
253} 257}
254 258
@@ -258,7 +262,7 @@ DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
258 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY); 262 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
259 return NULL; 263 return NULL;
260 } 264 }
261 CRYPTO_add(&pkey->pkey.dh->references, 1, CRYPTO_LOCK_DH); 265 DH_up_ref(pkey->pkey.dh);
262 return pkey->pkey.dh; 266 return pkey->pkey.dh;
263} 267}
264#endif 268#endif
@@ -309,13 +313,13 @@ static void EVP_PKEY_free_it(EVP_PKEY *x)
309 { 313 {
310 switch (x->type) 314 switch (x->type)
311 { 315 {
312#ifndef NO_RSA 316#ifndef OPENSSL_NO_RSA
313 case EVP_PKEY_RSA: 317 case EVP_PKEY_RSA:
314 case EVP_PKEY_RSA2: 318 case EVP_PKEY_RSA2:
315 RSA_free(x->pkey.rsa); 319 RSA_free(x->pkey.rsa);
316 break; 320 break;
317#endif 321#endif
318#ifndef NO_DSA 322#ifndef OPENSSL_NO_DSA
319 case EVP_PKEY_DSA: 323 case EVP_PKEY_DSA:
320 case EVP_PKEY_DSA2: 324 case EVP_PKEY_DSA2:
321 case EVP_PKEY_DSA3: 325 case EVP_PKEY_DSA3:
@@ -323,7 +327,7 @@ static void EVP_PKEY_free_it(EVP_PKEY *x)
323 DSA_free(x->pkey.dsa); 327 DSA_free(x->pkey.dsa);
324 break; 328 break;
325#endif 329#endif
326#ifndef NO_DH 330#ifndef OPENSSL_NO_DH
327 case EVP_PKEY_DH: 331 case EVP_PKEY_DH:
328 DH_free(x->pkey.dh); 332 DH_free(x->pkey.dh);
329 break; 333 break;