summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/p_lib.c
diff options
context:
space:
mode:
authordjm <>2008-09-06 12:17:54 +0000
committerdjm <>2008-09-06 12:17:54 +0000
commit38ce604e3cc97706b876b0525ddff0121115456d (patch)
tree7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/evp/p_lib.c
parent12867252827c8efaa8ddd1fa3b3d6e321e2bcdef (diff)
downloadopenbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.gz
openbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.bz2
openbsd-38ce604e3cc97706b876b0525ddff0121115456d.zip
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/evp/p_lib.c')
-rw-r--r--src/lib/libcrypto/evp/p_lib.c177
1 files changed, 171 insertions, 6 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 215b94292a..22155ecf62 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -58,24 +58,60 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/err.h>
61#include <openssl/objects.h> 63#include <openssl/objects.h>
62#include <openssl/evp.h> 64#include <openssl/evp.h>
63#include <openssl/asn1_mac.h> 65#include <openssl/asn1_mac.h>
64#include <openssl/x509.h> 66#include <openssl/x509.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70#ifndef OPENSSL_NO_DSA
71#include <openssl/dsa.h>
72#endif
73#ifndef OPENSSL_NO_DH
74#include <openssl/dh.h>
75#endif
65 76
66static void EVP_PKEY_free_it(EVP_PKEY *x); 77static void EVP_PKEY_free_it(EVP_PKEY *x);
67 78
68int EVP_PKEY_bits(EVP_PKEY *pkey) 79int EVP_PKEY_bits(EVP_PKEY *pkey)
69 { 80 {
81 if (0)
82 return 0;
70#ifndef OPENSSL_NO_RSA 83#ifndef OPENSSL_NO_RSA
71 if (pkey->type == EVP_PKEY_RSA) 84 else if (pkey->type == EVP_PKEY_RSA)
72 return(BN_num_bits(pkey->pkey.rsa->n)); 85 return(BN_num_bits(pkey->pkey.rsa->n));
73 else
74#endif 86#endif
75#ifndef OPENSSL_NO_DSA 87#ifndef OPENSSL_NO_DSA
76 if (pkey->type == EVP_PKEY_DSA) 88 else if (pkey->type == EVP_PKEY_DSA)
77 return(BN_num_bits(pkey->pkey.dsa->p)); 89 return(BN_num_bits(pkey->pkey.dsa->p));
78#endif 90#endif
91#ifndef OPENSSL_NO_EC
92 else if (pkey->type == EVP_PKEY_EC)
93 {
94 BIGNUM *order = BN_new();
95 const EC_GROUP *group;
96 int ret;
97
98 if (!order)
99 {
100 ERR_clear_error();
101 return 0;
102 }
103 group = EC_KEY_get0_group(pkey->pkey.ec);
104 if (!EC_GROUP_get_order(group, order, NULL))
105 {
106 ERR_clear_error();
107 return 0;
108 }
109
110 ret = BN_num_bits(order);
111 BN_free(order);
112 return ret;
113 }
114#endif
79 return(0); 115 return(0);
80 } 116 }
81 117
@@ -92,6 +128,11 @@ int EVP_PKEY_size(EVP_PKEY *pkey)
92 if (pkey->type == EVP_PKEY_DSA) 128 if (pkey->type == EVP_PKEY_DSA)
93 return(DSA_size(pkey->pkey.dsa)); 129 return(DSA_size(pkey->pkey.dsa));
94#endif 130#endif
131#ifndef OPENSSL_NO_ECDSA
132 if (pkey->type == EVP_PKEY_EC)
133 return(ECDSA_size(pkey->pkey.ec));
134#endif
135
95 return(0); 136 return(0);
96 } 137 }
97 138
@@ -107,10 +148,20 @@ int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
107 return(ret); 148 return(ret);
108 } 149 }
109#endif 150#endif
151#ifndef OPENSSL_NO_EC
152 if (pkey->type == EVP_PKEY_EC)
153 {
154 int ret = pkey->save_parameters;
155
156 if (mode >= 0)
157 pkey->save_parameters = mode;
158 return(ret);
159 }
160#endif
110 return(0); 161 return(0);
111 } 162 }
112 163
113int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from) 164int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
114 { 165 {
115 if (to->type != from->type) 166 if (to->type != from->type)
116 { 167 {
@@ -141,12 +192,23 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
141 to->pkey.dsa->g=a; 192 to->pkey.dsa->g=a;
142 } 193 }
143#endif 194#endif
195#ifndef OPENSSL_NO_EC
196 if (to->type == EVP_PKEY_EC)
197 {
198 EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
199 if (group == NULL)
200 goto err;
201 if (EC_KEY_set_group(to->pkey.ec, group) == 0)
202 goto err;
203 EC_GROUP_free(group);
204 }
205#endif
144 return(1); 206 return(1);
145err: 207err:
146 return(0); 208 return(0);
147 } 209 }
148 210
149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey) 211int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)
150 { 212 {
151#ifndef OPENSSL_NO_DSA 213#ifndef OPENSSL_NO_DSA
152 if (pkey->type == EVP_PKEY_DSA) 214 if (pkey->type == EVP_PKEY_DSA)
@@ -158,10 +220,18 @@ int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
158 return(1); 220 return(1);
159 } 221 }
160#endif 222#endif
223#ifndef OPENSSL_NO_EC
224 if (pkey->type == EVP_PKEY_EC)
225 {
226 if (EC_KEY_get0_group(pkey->pkey.ec) == NULL)
227 return(1);
228 }
229#endif
230
161 return(0); 231 return(0);
162 } 232 }
163 233
164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b) 234int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
165 { 235 {
166#ifndef OPENSSL_NO_DSA 236#ifndef OPENSSL_NO_DSA
167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) 237 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
@@ -174,9 +244,72 @@ int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
174 return(1); 244 return(1);
175 } 245 }
176#endif 246#endif
247#ifndef OPENSSL_NO_EC
248 if (a->type == EVP_PKEY_EC && b->type == EVP_PKEY_EC)
249 {
250 const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
251 *group_b = EC_KEY_get0_group(b->pkey.ec);
252 if (EC_GROUP_cmp(group_a, group_b, NULL))
253 return 0;
254 else
255 return 1;
256 }
257#endif
177 return(-1); 258 return(-1);
178 } 259 }
179 260
261int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
262 {
263 if (a->type != b->type)
264 return -1;
265
266 if (EVP_PKEY_cmp_parameters(a, b) == 0)
267 return 0;
268
269 switch (a->type)
270 {
271#ifndef OPENSSL_NO_RSA
272 case EVP_PKEY_RSA:
273 if (BN_cmp(b->pkey.rsa->n,a->pkey.rsa->n) != 0
274 || BN_cmp(b->pkey.rsa->e,a->pkey.rsa->e) != 0)
275 return 0;
276 break;
277#endif
278#ifndef OPENSSL_NO_DSA
279 case EVP_PKEY_DSA:
280 if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0)
281 return 0;
282 break;
283#endif
284#ifndef OPENSSL_NO_EC
285 case EVP_PKEY_EC:
286 {
287 int r;
288 const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec);
289 const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec),
290 *pb = EC_KEY_get0_public_key(b->pkey.ec);
291 r = EC_POINT_cmp(group, pa, pb, NULL);
292 if (r != 0)
293 {
294 if (r == 1)
295 return 0;
296 else
297 return -2;
298 }
299 }
300 break;
301#endif
302#ifndef OPENSSL_NO_DH
303 case EVP_PKEY_DH:
304 return -2;
305#endif
306 default:
307 return -2;
308 }
309
310 return 1;
311 }
312
180EVP_PKEY *EVP_PKEY_new(void) 313EVP_PKEY *EVP_PKEY_new(void)
181 { 314 {
182 EVP_PKEY *ret; 315 EVP_PKEY *ret;
@@ -246,6 +379,29 @@ DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
246} 379}
247#endif 380#endif
248 381
382#ifndef OPENSSL_NO_EC
383
384int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
385{
386 int ret = EVP_PKEY_assign_EC_KEY(pkey,key);
387 if (ret)
388 EC_KEY_up_ref(key);
389 return ret;
390}
391
392EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
393{
394 if (pkey->type != EVP_PKEY_EC)
395 {
396 EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
397 return NULL;
398 }
399 EC_KEY_up_ref(pkey->pkey.ec);
400 return pkey->pkey.ec;
401}
402#endif
403
404
249#ifndef OPENSSL_NO_DH 405#ifndef OPENSSL_NO_DH
250 406
251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) 407int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
@@ -282,6 +438,8 @@ int EVP_PKEY_type(int type)
282 return(EVP_PKEY_DSA); 438 return(EVP_PKEY_DSA);
283 case EVP_PKEY_DH: 439 case EVP_PKEY_DH:
284 return(EVP_PKEY_DH); 440 return(EVP_PKEY_DH);
441 case EVP_PKEY_EC:
442 return(EVP_PKEY_EC);
285 default: 443 default:
286 return(NID_undef); 444 return(NID_undef);
287 } 445 }
@@ -306,6 +464,8 @@ void EVP_PKEY_free(EVP_PKEY *x)
306 } 464 }
307#endif 465#endif
308 EVP_PKEY_free_it(x); 466 EVP_PKEY_free_it(x);
467 if (x->attributes)
468 sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
309 OPENSSL_free(x); 469 OPENSSL_free(x);
310 } 470 }
311 471
@@ -327,6 +487,11 @@ static void EVP_PKEY_free_it(EVP_PKEY *x)
327 DSA_free(x->pkey.dsa); 487 DSA_free(x->pkey.dsa);
328 break; 488 break;
329#endif 489#endif
490#ifndef OPENSSL_NO_EC
491 case EVP_PKEY_EC:
492 EC_KEY_free(x->pkey.ec);
493 break;
494#endif
330#ifndef OPENSSL_NO_DH 495#ifndef OPENSSL_NO_DH
331 case EVP_PKEY_DH: 496 case EVP_PKEY_DH:
332 DH_free(x->pkey.dh); 497 DH_free(x->pkey.dh);