summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/p_lib.c
diff options
context:
space:
mode:
authormarkus <>2002-09-05 12:51:50 +0000
committermarkus <>2002-09-05 12:51:50 +0000
commit15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch)
treebf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/evp/p_lib.c
parent027351f729b9e837200dae6e1520cda6577ab930 (diff)
downloadopenbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/evp/p_lib.c')
-rw-r--r--src/lib/libcrypto/evp/p_lib.c145
1 files changed, 94 insertions, 51 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 395351b373..215b94292a 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -58,58 +58,49 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "asn1_mac.h" 63#include <openssl/asn1_mac.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66/* EVPerr(EVP_F_D2I_PKEY,EVP_R_UNSUPPORTED_CIPHER); */
67/* EVPerr(EVP_F_D2I_PKEY,EVP_R_IV_TOO_LARGE); */
68
69#ifndef NOPROTO
70static void EVP_PKEY_free_it(EVP_PKEY *x); 66static void EVP_PKEY_free_it(EVP_PKEY *x);
71#else
72static void EVP_PKEY_free_it();
73#endif
74 67
75int EVP_PKEY_bits(pkey) 68int EVP_PKEY_bits(EVP_PKEY *pkey)
76EVP_PKEY *pkey;
77 { 69 {
78#ifndef NO_RSA 70#ifndef OPENSSL_NO_RSA
79 if (pkey->type == EVP_PKEY_RSA) 71 if (pkey->type == EVP_PKEY_RSA)
80 return(BN_num_bits(pkey->pkey.rsa->n)); 72 return(BN_num_bits(pkey->pkey.rsa->n));
81 else 73 else
82#endif 74#endif
83#ifndef NO_DSA 75#ifndef OPENSSL_NO_DSA
84 if (pkey->type == EVP_PKEY_DSA) 76 if (pkey->type == EVP_PKEY_DSA)
85 return(BN_num_bits(pkey->pkey.dsa->p)); 77 return(BN_num_bits(pkey->pkey.dsa->p));
86#endif 78#endif
87 return(0); 79 return(0);
88 } 80 }
89 81
90int EVP_PKEY_size(pkey) 82int EVP_PKEY_size(EVP_PKEY *pkey)
91EVP_PKEY *pkey;
92 { 83 {
93#ifndef NO_RSA 84 if (pkey == NULL)
85 return(0);
86#ifndef OPENSSL_NO_RSA
94 if (pkey->type == EVP_PKEY_RSA) 87 if (pkey->type == EVP_PKEY_RSA)
95 return(RSA_size(pkey->pkey.rsa)); 88 return(RSA_size(pkey->pkey.rsa));
96 else 89 else
97#endif 90#endif
98#ifndef NO_DSA 91#ifndef OPENSSL_NO_DSA
99 if (pkey->type == EVP_PKEY_DSA) 92 if (pkey->type == EVP_PKEY_DSA)
100 return(DSA_size(pkey->pkey.dsa)); 93 return(DSA_size(pkey->pkey.dsa));
101#endif 94#endif
102 return(0); 95 return(0);
103 } 96 }
104 97
105int EVP_PKEY_save_parameters(pkey,mode) 98int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
106EVP_PKEY *pkey;
107int mode;
108 { 99 {
109#ifndef NO_DSA 100#ifndef OPENSSL_NO_DSA
110 if (pkey->type == EVP_PKEY_DSA) 101 if (pkey->type == EVP_PKEY_DSA)
111 { 102 {
112 int ret=pkey->save_parameters=mode; 103 int ret=pkey->save_parameters;
113 104
114 if (mode >= 0) 105 if (mode >= 0)
115 pkey->save_parameters=mode; 106 pkey->save_parameters=mode;
@@ -119,8 +110,7 @@ int mode;
119 return(0); 110 return(0);
120 } 111 }
121 112
122int EVP_PKEY_copy_parameters(to,from) 113int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
123EVP_PKEY *to,*from;
124 { 114 {
125 if (to->type != from->type) 115 if (to->type != from->type)
126 { 116 {
@@ -130,10 +120,10 @@ EVP_PKEY *to,*from;
130 120
131 if (EVP_PKEY_missing_parameters(from)) 121 if (EVP_PKEY_missing_parameters(from))
132 { 122 {
133 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS); 123 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
134 goto err; 124 goto err;
135 } 125 }
136#ifndef NO_DSA 126#ifndef OPENSSL_NO_DSA
137 if (to->type == EVP_PKEY_DSA) 127 if (to->type == EVP_PKEY_DSA)
138 { 128 {
139 BIGNUM *a; 129 BIGNUM *a;
@@ -156,10 +146,9 @@ err:
156 return(0); 146 return(0);
157 } 147 }
158 148
159int EVP_PKEY_missing_parameters(pkey) 149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
160EVP_PKEY *pkey;
161 { 150 {
162#ifndef NO_DSA 151#ifndef OPENSSL_NO_DSA
163 if (pkey->type == EVP_PKEY_DSA) 152 if (pkey->type == EVP_PKEY_DSA)
164 { 153 {
165 DSA *dsa; 154 DSA *dsa;
@@ -172,10 +161,9 @@ EVP_PKEY *pkey;
172 return(0); 161 return(0);
173 } 162 }
174 163
175int EVP_PKEY_cmp_parameters(a,b) 164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
176EVP_PKEY *a,*b;
177 { 165 {
178#ifndef NO_DSA 166#ifndef OPENSSL_NO_DSA
179 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) 167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
180 { 168 {
181 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) || 169 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
@@ -189,11 +177,11 @@ EVP_PKEY *a,*b;
189 return(-1); 177 return(-1);
190 } 178 }
191 179
192EVP_PKEY *EVP_PKEY_new() 180EVP_PKEY *EVP_PKEY_new(void)
193 { 181 {
194 EVP_PKEY *ret; 182 EVP_PKEY *ret;
195 183
196 ret=(EVP_PKEY *)Malloc(sizeof(EVP_PKEY)); 184 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));
197 if (ret == NULL) 185 if (ret == NULL)
198 { 186 {
199 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE); 187 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
@@ -207,10 +195,7 @@ EVP_PKEY *EVP_PKEY_new()
207 return(ret); 195 return(ret);
208 } 196 }
209 197
210int EVP_PKEY_assign(pkey,type,key) 198int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
211EVP_PKEY *pkey;
212int type;
213char *key;
214 { 199 {
215 if (pkey == NULL) return(0); 200 if (pkey == NULL) return(0);
216 if (pkey->pkey.ptr != NULL) 201 if (pkey->pkey.ptr != NULL)
@@ -218,11 +203,71 @@ char *key;
218 pkey->type=EVP_PKEY_type(type); 203 pkey->type=EVP_PKEY_type(type);
219 pkey->save_type=type; 204 pkey->save_type=type;
220 pkey->pkey.ptr=key; 205 pkey->pkey.ptr=key;
221 return(1); 206 return(key != NULL);
207 }
208
209#ifndef OPENSSL_NO_RSA
210int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
211{
212 int ret = EVP_PKEY_assign_RSA(pkey, key);
213 if(ret)
214 RSA_up_ref(key);
215 return ret;
216}
217
218RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
219 {
220 if(pkey->type != EVP_PKEY_RSA) {
221 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
222 return NULL;
222 } 223 }
224 RSA_up_ref(pkey->pkey.rsa);
225 return pkey->pkey.rsa;
226}
227#endif
228
229#ifndef OPENSSL_NO_DSA
230int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
231{
232 int ret = EVP_PKEY_assign_DSA(pkey, key);
233 if(ret)
234 DSA_up_ref(key);
235 return ret;
236}
237
238DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
239 {
240 if(pkey->type != EVP_PKEY_DSA) {
241 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
242 return NULL;
243 }
244 DSA_up_ref(pkey->pkey.dsa);
245 return pkey->pkey.dsa;
246}
247#endif
248
249#ifndef OPENSSL_NO_DH
250
251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
252{
253 int ret = EVP_PKEY_assign_DH(pkey, key);
254 if(ret)
255 DH_up_ref(key);
256 return ret;
257}
258
259DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
260 {
261 if(pkey->type != EVP_PKEY_DH) {
262 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
263 return NULL;
264 }
265 DH_up_ref(pkey->pkey.dh);
266 return pkey->pkey.dh;
267}
268#endif
223 269
224int EVP_PKEY_type(type) 270int EVP_PKEY_type(int type)
225int type;
226 { 271 {
227 switch (type) 272 switch (type)
228 { 273 {
@@ -242,8 +287,7 @@ int type;
242 } 287 }
243 } 288 }
244 289
245void EVP_PKEY_free(x) 290void EVP_PKEY_free(EVP_PKEY *x)
246EVP_PKEY *x;
247 { 291 {
248 int i; 292 int i;
249 293
@@ -262,21 +306,20 @@ EVP_PKEY *x;
262 } 306 }
263#endif 307#endif
264 EVP_PKEY_free_it(x); 308 EVP_PKEY_free_it(x);
265 Free((char *)x); 309 OPENSSL_free(x);
266 } 310 }
267 311
268static void EVP_PKEY_free_it(x) 312static void EVP_PKEY_free_it(EVP_PKEY *x)
269EVP_PKEY *x;
270 { 313 {
271 switch (x->type) 314 switch (x->type)
272 { 315 {
273#ifndef NO_RSA 316#ifndef OPENSSL_NO_RSA
274 case EVP_PKEY_RSA: 317 case EVP_PKEY_RSA:
275 case EVP_PKEY_RSA2: 318 case EVP_PKEY_RSA2:
276 RSA_free(x->pkey.rsa); 319 RSA_free(x->pkey.rsa);
277 break; 320 break;
278#endif 321#endif
279#ifndef NO_DSA 322#ifndef OPENSSL_NO_DSA
280 case EVP_PKEY_DSA: 323 case EVP_PKEY_DSA:
281 case EVP_PKEY_DSA2: 324 case EVP_PKEY_DSA2:
282 case EVP_PKEY_DSA3: 325 case EVP_PKEY_DSA3:
@@ -284,7 +327,7 @@ EVP_PKEY *x;
284 DSA_free(x->pkey.dsa); 327 DSA_free(x->pkey.dsa);
285 break; 328 break;
286#endif 329#endif
287#ifndef NO_DH 330#ifndef OPENSSL_NO_DH
288 case EVP_PKEY_DH: 331 case EVP_PKEY_DH:
289 DH_free(x->pkey.dh); 332 DH_free(x->pkey.dh);
290 break; 333 break;