1*2139Sjp161948 /* crypto/ec/ec_key.c */
2*2139Sjp161948 /*
3*2139Sjp161948 * Written by Nils Larsch for the OpenSSL project.
4*2139Sjp161948 */
5*2139Sjp161948 /* ====================================================================
6*2139Sjp161948 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
7*2139Sjp161948 *
8*2139Sjp161948 * Redistribution and use in source and binary forms, with or without
9*2139Sjp161948 * modification, are permitted provided that the following conditions
10*2139Sjp161948 * are met:
11*2139Sjp161948 *
12*2139Sjp161948 * 1. Redistributions of source code must retain the above copyright
13*2139Sjp161948 * notice, this list of conditions and the following disclaimer.
14*2139Sjp161948 *
15*2139Sjp161948 * 2. Redistributions in binary form must reproduce the above copyright
16*2139Sjp161948 * notice, this list of conditions and the following disclaimer in
17*2139Sjp161948 * the documentation and/or other materials provided with the
18*2139Sjp161948 * distribution.
19*2139Sjp161948 *
20*2139Sjp161948 * 3. All advertising materials mentioning features or use of this
21*2139Sjp161948 * software must display the following acknowledgment:
22*2139Sjp161948 * "This product includes software developed by the OpenSSL Project
23*2139Sjp161948 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24*2139Sjp161948 *
25*2139Sjp161948 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26*2139Sjp161948 * endorse or promote products derived from this software without
27*2139Sjp161948 * prior written permission. For written permission, please contact
28*2139Sjp161948 * openssl-core@openssl.org.
29*2139Sjp161948 *
30*2139Sjp161948 * 5. Products derived from this software may not be called "OpenSSL"
31*2139Sjp161948 * nor may "OpenSSL" appear in their names without prior written
32*2139Sjp161948 * permission of the OpenSSL Project.
33*2139Sjp161948 *
34*2139Sjp161948 * 6. Redistributions of any form whatsoever must retain the following
35*2139Sjp161948 * acknowledgment:
36*2139Sjp161948 * "This product includes software developed by the OpenSSL Project
37*2139Sjp161948 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38*2139Sjp161948 *
39*2139Sjp161948 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40*2139Sjp161948 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41*2139Sjp161948 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42*2139Sjp161948 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43*2139Sjp161948 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44*2139Sjp161948 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45*2139Sjp161948 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46*2139Sjp161948 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47*2139Sjp161948 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48*2139Sjp161948 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49*2139Sjp161948 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50*2139Sjp161948 * OF THE POSSIBILITY OF SUCH DAMAGE.
51*2139Sjp161948 * ====================================================================
52*2139Sjp161948 *
53*2139Sjp161948 * This product includes cryptographic software written by Eric Young
54*2139Sjp161948 * (eay@cryptsoft.com). This product includes software written by Tim
55*2139Sjp161948 * Hudson (tjh@cryptsoft.com).
56*2139Sjp161948 *
57*2139Sjp161948 */
58*2139Sjp161948 /* ====================================================================
59*2139Sjp161948 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60*2139Sjp161948 * Portions originally developed by SUN MICROSYSTEMS, INC., and
61*2139Sjp161948 * contributed to the OpenSSL project.
62*2139Sjp161948 */
63*2139Sjp161948
64*2139Sjp161948 #include <string.h>
65*2139Sjp161948 #include "ec_lcl.h"
66*2139Sjp161948 #include <openssl/err.h>
67*2139Sjp161948 #include <string.h>
68*2139Sjp161948
EC_KEY_new(void)69*2139Sjp161948 EC_KEY *EC_KEY_new(void)
70*2139Sjp161948 {
71*2139Sjp161948 EC_KEY *ret;
72*2139Sjp161948
73*2139Sjp161948 ret=(EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY));
74*2139Sjp161948 if (ret == NULL)
75*2139Sjp161948 {
76*2139Sjp161948 ECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE);
77*2139Sjp161948 return(NULL);
78*2139Sjp161948 }
79*2139Sjp161948
80*2139Sjp161948 ret->version = 1;
81*2139Sjp161948 ret->group = NULL;
82*2139Sjp161948 ret->pub_key = NULL;
83*2139Sjp161948 ret->priv_key= NULL;
84*2139Sjp161948 ret->enc_flag= 0;
85*2139Sjp161948 ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
86*2139Sjp161948 ret->references= 1;
87*2139Sjp161948 ret->method_data = NULL;
88*2139Sjp161948 return(ret);
89*2139Sjp161948 }
90*2139Sjp161948
EC_KEY_new_by_curve_name(int nid)91*2139Sjp161948 EC_KEY *EC_KEY_new_by_curve_name(int nid)
92*2139Sjp161948 {
93*2139Sjp161948 EC_KEY *ret = EC_KEY_new();
94*2139Sjp161948 if (ret == NULL)
95*2139Sjp161948 return NULL;
96*2139Sjp161948 ret->group = EC_GROUP_new_by_curve_name(nid);
97*2139Sjp161948 if (ret->group == NULL)
98*2139Sjp161948 {
99*2139Sjp161948 EC_KEY_free(ret);
100*2139Sjp161948 return NULL;
101*2139Sjp161948 }
102*2139Sjp161948 return ret;
103*2139Sjp161948 }
104*2139Sjp161948
EC_KEY_free(EC_KEY * r)105*2139Sjp161948 void EC_KEY_free(EC_KEY *r)
106*2139Sjp161948 {
107*2139Sjp161948 int i;
108*2139Sjp161948
109*2139Sjp161948 if (r == NULL) return;
110*2139Sjp161948
111*2139Sjp161948 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_EC);
112*2139Sjp161948 #ifdef REF_PRINT
113*2139Sjp161948 REF_PRINT("EC_KEY",r);
114*2139Sjp161948 #endif
115*2139Sjp161948 if (i > 0) return;
116*2139Sjp161948 #ifdef REF_CHECK
117*2139Sjp161948 if (i < 0)
118*2139Sjp161948 {
119*2139Sjp161948 fprintf(stderr,"EC_KEY_free, bad reference count\n");
120*2139Sjp161948 abort();
121*2139Sjp161948 }
122*2139Sjp161948 #endif
123*2139Sjp161948
124*2139Sjp161948 if (r->group != NULL)
125*2139Sjp161948 EC_GROUP_free(r->group);
126*2139Sjp161948 if (r->pub_key != NULL)
127*2139Sjp161948 EC_POINT_free(r->pub_key);
128*2139Sjp161948 if (r->priv_key != NULL)
129*2139Sjp161948 BN_clear_free(r->priv_key);
130*2139Sjp161948
131*2139Sjp161948 EC_EX_DATA_free_all_data(&r->method_data);
132*2139Sjp161948
133*2139Sjp161948 OPENSSL_cleanse((void *)r, sizeof(EC_KEY));
134*2139Sjp161948
135*2139Sjp161948 OPENSSL_free(r);
136*2139Sjp161948 }
137*2139Sjp161948
EC_KEY_copy(EC_KEY * dest,const EC_KEY * src)138*2139Sjp161948 EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
139*2139Sjp161948 {
140*2139Sjp161948 EC_EXTRA_DATA *d;
141*2139Sjp161948
142*2139Sjp161948 if (dest == NULL || src == NULL)
143*2139Sjp161948 {
144*2139Sjp161948 ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER);
145*2139Sjp161948 return NULL;
146*2139Sjp161948 }
147*2139Sjp161948 /* copy the parameters */
148*2139Sjp161948 if (src->group)
149*2139Sjp161948 {
150*2139Sjp161948 const EC_METHOD *meth = EC_GROUP_method_of(src->group);
151*2139Sjp161948 /* clear the old group */
152*2139Sjp161948 if (dest->group)
153*2139Sjp161948 EC_GROUP_free(dest->group);
154*2139Sjp161948 dest->group = EC_GROUP_new(meth);
155*2139Sjp161948 if (dest->group == NULL)
156*2139Sjp161948 return NULL;
157*2139Sjp161948 if (!EC_GROUP_copy(dest->group, src->group))
158*2139Sjp161948 return NULL;
159*2139Sjp161948 }
160*2139Sjp161948 /* copy the public key */
161*2139Sjp161948 if (src->pub_key && src->group)
162*2139Sjp161948 {
163*2139Sjp161948 if (dest->pub_key)
164*2139Sjp161948 EC_POINT_free(dest->pub_key);
165*2139Sjp161948 dest->pub_key = EC_POINT_new(src->group);
166*2139Sjp161948 if (dest->pub_key == NULL)
167*2139Sjp161948 return NULL;
168*2139Sjp161948 if (!EC_POINT_copy(dest->pub_key, src->pub_key))
169*2139Sjp161948 return NULL;
170*2139Sjp161948 }
171*2139Sjp161948 /* copy the private key */
172*2139Sjp161948 if (src->priv_key)
173*2139Sjp161948 {
174*2139Sjp161948 if (dest->priv_key == NULL)
175*2139Sjp161948 {
176*2139Sjp161948 dest->priv_key = BN_new();
177*2139Sjp161948 if (dest->priv_key == NULL)
178*2139Sjp161948 return NULL;
179*2139Sjp161948 }
180*2139Sjp161948 if (!BN_copy(dest->priv_key, src->priv_key))
181*2139Sjp161948 return NULL;
182*2139Sjp161948 }
183*2139Sjp161948 /* copy method/extra data */
184*2139Sjp161948 EC_EX_DATA_free_all_data(&dest->method_data);
185*2139Sjp161948
186*2139Sjp161948 for (d = src->method_data; d != NULL; d = d->next)
187*2139Sjp161948 {
188*2139Sjp161948 void *t = d->dup_func(d->data);
189*2139Sjp161948
190*2139Sjp161948 if (t == NULL)
191*2139Sjp161948 return 0;
192*2139Sjp161948 if (!EC_EX_DATA_set_data(&dest->method_data, t, d->dup_func, d->free_func, d->clear_free_func))
193*2139Sjp161948 return 0;
194*2139Sjp161948 }
195*2139Sjp161948
196*2139Sjp161948 /* copy the rest */
197*2139Sjp161948 dest->enc_flag = src->enc_flag;
198*2139Sjp161948 dest->conv_form = src->conv_form;
199*2139Sjp161948 dest->version = src->version;
200*2139Sjp161948
201*2139Sjp161948 return dest;
202*2139Sjp161948 }
203*2139Sjp161948
EC_KEY_dup(const EC_KEY * ec_key)204*2139Sjp161948 EC_KEY *EC_KEY_dup(const EC_KEY *ec_key)
205*2139Sjp161948 {
206*2139Sjp161948 EC_KEY *ret = EC_KEY_new();
207*2139Sjp161948 if (ret == NULL)
208*2139Sjp161948 return NULL;
209*2139Sjp161948 if (EC_KEY_copy(ret, ec_key) == NULL)
210*2139Sjp161948 {
211*2139Sjp161948 EC_KEY_free(ret);
212*2139Sjp161948 return NULL;
213*2139Sjp161948 }
214*2139Sjp161948 return ret;
215*2139Sjp161948 }
216*2139Sjp161948
EC_KEY_up_ref(EC_KEY * r)217*2139Sjp161948 int EC_KEY_up_ref(EC_KEY *r)
218*2139Sjp161948 {
219*2139Sjp161948 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC);
220*2139Sjp161948 #ifdef REF_PRINT
221*2139Sjp161948 REF_PRINT("EC_KEY",r);
222*2139Sjp161948 #endif
223*2139Sjp161948 #ifdef REF_CHECK
224*2139Sjp161948 if (i < 2)
225*2139Sjp161948 {
226*2139Sjp161948 fprintf(stderr, "EC_KEY_up, bad reference count\n");
227*2139Sjp161948 abort();
228*2139Sjp161948 }
229*2139Sjp161948 #endif
230*2139Sjp161948 return ((i > 1) ? 1 : 0);
231*2139Sjp161948 }
232*2139Sjp161948
EC_KEY_generate_key(EC_KEY * eckey)233*2139Sjp161948 int EC_KEY_generate_key(EC_KEY *eckey)
234*2139Sjp161948 {
235*2139Sjp161948 int ok = 0;
236*2139Sjp161948 BN_CTX *ctx = NULL;
237*2139Sjp161948 BIGNUM *priv_key = NULL, *order = NULL;
238*2139Sjp161948 EC_POINT *pub_key = NULL;
239*2139Sjp161948
240*2139Sjp161948 if (!eckey || !eckey->group)
241*2139Sjp161948 {
242*2139Sjp161948 ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);
243*2139Sjp161948 return 0;
244*2139Sjp161948 }
245*2139Sjp161948
246*2139Sjp161948 if ((order = BN_new()) == NULL) goto err;
247*2139Sjp161948 if ((ctx = BN_CTX_new()) == NULL) goto err;
248*2139Sjp161948
249*2139Sjp161948 if (eckey->priv_key == NULL)
250*2139Sjp161948 {
251*2139Sjp161948 priv_key = BN_new();
252*2139Sjp161948 if (priv_key == NULL)
253*2139Sjp161948 goto err;
254*2139Sjp161948 }
255*2139Sjp161948 else
256*2139Sjp161948 priv_key = eckey->priv_key;
257*2139Sjp161948
258*2139Sjp161948 if (!EC_GROUP_get_order(eckey->group, order, ctx))
259*2139Sjp161948 goto err;
260*2139Sjp161948
261*2139Sjp161948 do
262*2139Sjp161948 if (!BN_rand_range(priv_key, order))
263*2139Sjp161948 goto err;
264*2139Sjp161948 while (BN_is_zero(priv_key));
265*2139Sjp161948
266*2139Sjp161948 if (eckey->pub_key == NULL)
267*2139Sjp161948 {
268*2139Sjp161948 pub_key = EC_POINT_new(eckey->group);
269*2139Sjp161948 if (pub_key == NULL)
270*2139Sjp161948 goto err;
271*2139Sjp161948 }
272*2139Sjp161948 else
273*2139Sjp161948 pub_key = eckey->pub_key;
274*2139Sjp161948
275*2139Sjp161948 if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))
276*2139Sjp161948 goto err;
277*2139Sjp161948
278*2139Sjp161948 eckey->priv_key = priv_key;
279*2139Sjp161948 eckey->pub_key = pub_key;
280*2139Sjp161948
281*2139Sjp161948 ok=1;
282*2139Sjp161948
283*2139Sjp161948 err:
284*2139Sjp161948 if (order)
285*2139Sjp161948 BN_free(order);
286*2139Sjp161948 if (pub_key != NULL && eckey->pub_key == NULL)
287*2139Sjp161948 EC_POINT_free(pub_key);
288*2139Sjp161948 if (priv_key != NULL && eckey->priv_key == NULL)
289*2139Sjp161948 BN_free(priv_key);
290*2139Sjp161948 if (ctx != NULL)
291*2139Sjp161948 BN_CTX_free(ctx);
292*2139Sjp161948 return(ok);
293*2139Sjp161948 }
294*2139Sjp161948
EC_KEY_check_key(const EC_KEY * eckey)295*2139Sjp161948 int EC_KEY_check_key(const EC_KEY *eckey)
296*2139Sjp161948 {
297*2139Sjp161948 int ok = 0;
298*2139Sjp161948 BN_CTX *ctx = NULL;
299*2139Sjp161948 BIGNUM *order = NULL;
300*2139Sjp161948 EC_POINT *point = NULL;
301*2139Sjp161948
302*2139Sjp161948 if (!eckey || !eckey->group || !eckey->pub_key)
303*2139Sjp161948 {
304*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);
305*2139Sjp161948 return 0;
306*2139Sjp161948 }
307*2139Sjp161948
308*2139Sjp161948 if ((ctx = BN_CTX_new()) == NULL)
309*2139Sjp161948 goto err;
310*2139Sjp161948 if ((order = BN_new()) == NULL)
311*2139Sjp161948 goto err;
312*2139Sjp161948 if ((point = EC_POINT_new(eckey->group)) == NULL)
313*2139Sjp161948 goto err;
314*2139Sjp161948
315*2139Sjp161948 /* testing whether the pub_key is on the elliptic curve */
316*2139Sjp161948 if (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx))
317*2139Sjp161948 {
318*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE);
319*2139Sjp161948 goto err;
320*2139Sjp161948 }
321*2139Sjp161948 /* testing whether pub_key * order is the point at infinity */
322*2139Sjp161948 if (!EC_GROUP_get_order(eckey->group, order, ctx))
323*2139Sjp161948 {
324*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);
325*2139Sjp161948 goto err;
326*2139Sjp161948 }
327*2139Sjp161948 if (!EC_POINT_copy(point, eckey->pub_key))
328*2139Sjp161948 {
329*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
330*2139Sjp161948 goto err;
331*2139Sjp161948 }
332*2139Sjp161948 if (!EC_POINT_mul(eckey->group, point, order, NULL, NULL, ctx))
333*2139Sjp161948 {
334*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
335*2139Sjp161948 goto err;
336*2139Sjp161948 }
337*2139Sjp161948 if (!EC_POINT_is_at_infinity(eckey->group, point))
338*2139Sjp161948 {
339*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
340*2139Sjp161948 goto err;
341*2139Sjp161948 }
342*2139Sjp161948 /* in case the priv_key is present :
343*2139Sjp161948 * check if generator * priv_key == pub_key
344*2139Sjp161948 */
345*2139Sjp161948 if (eckey->priv_key)
346*2139Sjp161948 {
347*2139Sjp161948 if (BN_cmp(eckey->priv_key, order) >= 0)
348*2139Sjp161948 {
349*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
350*2139Sjp161948 goto err;
351*2139Sjp161948 }
352*2139Sjp161948 if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
353*2139Sjp161948 NULL, NULL, ctx))
354*2139Sjp161948 {
355*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
356*2139Sjp161948 goto err;
357*2139Sjp161948 }
358*2139Sjp161948 if (EC_POINT_cmp(eckey->group, point, eckey->pub_key,
359*2139Sjp161948 ctx) != 0)
360*2139Sjp161948 {
361*2139Sjp161948 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY);
362*2139Sjp161948 goto err;
363*2139Sjp161948 }
364*2139Sjp161948 }
365*2139Sjp161948 ok = 1;
366*2139Sjp161948 err:
367*2139Sjp161948 if (ctx != NULL)
368*2139Sjp161948 BN_CTX_free(ctx);
369*2139Sjp161948 if (order != NULL)
370*2139Sjp161948 BN_free(order);
371*2139Sjp161948 if (point != NULL)
372*2139Sjp161948 EC_POINT_free(point);
373*2139Sjp161948 return(ok);
374*2139Sjp161948 }
375*2139Sjp161948
EC_KEY_get0_group(const EC_KEY * key)376*2139Sjp161948 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
377*2139Sjp161948 {
378*2139Sjp161948 return key->group;
379*2139Sjp161948 }
380*2139Sjp161948
EC_KEY_set_group(EC_KEY * key,const EC_GROUP * group)381*2139Sjp161948 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)
382*2139Sjp161948 {
383*2139Sjp161948 if (key->group != NULL)
384*2139Sjp161948 EC_GROUP_free(key->group);
385*2139Sjp161948 key->group = EC_GROUP_dup(group);
386*2139Sjp161948 return (key->group == NULL) ? 0 : 1;
387*2139Sjp161948 }
388*2139Sjp161948
EC_KEY_get0_private_key(const EC_KEY * key)389*2139Sjp161948 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
390*2139Sjp161948 {
391*2139Sjp161948 return key->priv_key;
392*2139Sjp161948 }
393*2139Sjp161948
EC_KEY_set_private_key(EC_KEY * key,const BIGNUM * priv_key)394*2139Sjp161948 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
395*2139Sjp161948 {
396*2139Sjp161948 if (key->priv_key)
397*2139Sjp161948 BN_clear_free(key->priv_key);
398*2139Sjp161948 key->priv_key = BN_dup(priv_key);
399*2139Sjp161948 return (key->priv_key == NULL) ? 0 : 1;
400*2139Sjp161948 }
401*2139Sjp161948
EC_KEY_get0_public_key(const EC_KEY * key)402*2139Sjp161948 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key)
403*2139Sjp161948 {
404*2139Sjp161948 return key->pub_key;
405*2139Sjp161948 }
406*2139Sjp161948
EC_KEY_set_public_key(EC_KEY * key,const EC_POINT * pub_key)407*2139Sjp161948 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key)
408*2139Sjp161948 {
409*2139Sjp161948 if (key->pub_key != NULL)
410*2139Sjp161948 EC_POINT_free(key->pub_key);
411*2139Sjp161948 key->pub_key = EC_POINT_dup(pub_key, key->group);
412*2139Sjp161948 return (key->pub_key == NULL) ? 0 : 1;
413*2139Sjp161948 }
414*2139Sjp161948
EC_KEY_get_enc_flags(const EC_KEY * key)415*2139Sjp161948 unsigned int EC_KEY_get_enc_flags(const EC_KEY *key)
416*2139Sjp161948 {
417*2139Sjp161948 return key->enc_flag;
418*2139Sjp161948 }
419*2139Sjp161948
EC_KEY_set_enc_flags(EC_KEY * key,unsigned int flags)420*2139Sjp161948 void EC_KEY_set_enc_flags(EC_KEY *key, unsigned int flags)
421*2139Sjp161948 {
422*2139Sjp161948 key->enc_flag = flags;
423*2139Sjp161948 }
424*2139Sjp161948
EC_KEY_get_conv_form(const EC_KEY * key)425*2139Sjp161948 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key)
426*2139Sjp161948 {
427*2139Sjp161948 return key->conv_form;
428*2139Sjp161948 }
429*2139Sjp161948
EC_KEY_set_conv_form(EC_KEY * key,point_conversion_form_t cform)430*2139Sjp161948 void EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform)
431*2139Sjp161948 {
432*2139Sjp161948 key->conv_form = cform;
433*2139Sjp161948 if (key->group != NULL)
434*2139Sjp161948 EC_GROUP_set_point_conversion_form(key->group, cform);
435*2139Sjp161948 }
436*2139Sjp161948
EC_KEY_get_key_method_data(EC_KEY * key,void * (* dup_func)(void *),void (* free_func)(void *),void (* clear_free_func)(void *))437*2139Sjp161948 void *EC_KEY_get_key_method_data(EC_KEY *key,
438*2139Sjp161948 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
439*2139Sjp161948 {
440*2139Sjp161948 return EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
441*2139Sjp161948 }
442*2139Sjp161948
EC_KEY_insert_key_method_data(EC_KEY * key,void * data,void * (* dup_func)(void *),void (* free_func)(void *),void (* clear_free_func)(void *))443*2139Sjp161948 void EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
444*2139Sjp161948 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
445*2139Sjp161948 {
446*2139Sjp161948 EC_EXTRA_DATA *ex_data;
447*2139Sjp161948 CRYPTO_w_lock(CRYPTO_LOCK_EC);
448*2139Sjp161948 ex_data = EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
449*2139Sjp161948 if (ex_data == NULL)
450*2139Sjp161948 EC_EX_DATA_set_data(&key->method_data, data, dup_func, free_func, clear_free_func);
451*2139Sjp161948 CRYPTO_w_unlock(CRYPTO_LOCK_EC);
452*2139Sjp161948 }
453*2139Sjp161948
EC_KEY_set_asn1_flag(EC_KEY * key,int flag)454*2139Sjp161948 void EC_KEY_set_asn1_flag(EC_KEY *key, int flag)
455*2139Sjp161948 {
456*2139Sjp161948 if (key->group != NULL)
457*2139Sjp161948 EC_GROUP_set_asn1_flag(key->group, flag);
458*2139Sjp161948 }
459*2139Sjp161948
EC_KEY_precompute_mult(EC_KEY * key,BN_CTX * ctx)460*2139Sjp161948 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx)
461*2139Sjp161948 {
462*2139Sjp161948 if (key->group == NULL)
463*2139Sjp161948 return 0;
464*2139Sjp161948 return EC_GROUP_precompute_mult(key->group, ctx);
465*2139Sjp161948 }
466