75 while (group->
poly[i] != 0)
86 #ifndef OPENSSL_NO_EC2M
93 || !((group->
poly[0] != 0) && (group->
poly[1] != 0) && (group->
poly[2] == 0)))
105 unsigned int *k2,
unsigned int *k3)
111 || !((group->
poly[0] != 0) && (group->
poly[1] != 0) && (group->
poly[2] != 0) && (group->
poly[3] != 0) && (group->
poly[4] == 0)))
118 *k1 = group->
poly[3];
120 *k2 = group->
poly[2];
122 *k3 = group->
poly[1];
209 ASN1_ADB(X9_62_CHARACTERISTIC_TWO) = {
213 }
ASN1_ADB_END(X9_62_CHARACTERISTIC_TWO, 0,
type, 0, &char_two_def_tt, NULL);
229 }
ASN1_ADB_END(X9_62_FIELDID, 0, fieldType, 0, &fieldID_def_tt, NULL);
267 ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0),
278 static
int ec_asn1_group2fieldid(const
EC_GROUP *, X9_62_FIELDID *);
280 static
int ec_asn1_group2curve(const EC_GROUP *,
X9_62_CURVE *);
283 static EC_GROUP *ec_asn1_parameters2group(const
ECPARAMETERS *);
286 static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *,ECPARAMETERS *);
289 static EC_GROUP *ec_asn1_pkparameters2group(const
ECPKPARAMETERS *);
292 static ECPKPARAMETERS *ec_asn1_group2pkparameters(const EC_GROUP *,
298 static
int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
303 if (group == NULL || field == NULL)
307 if (field->fieldType != NULL)
309 if (field->p.other != NULL)
310 ASN1_TYPE_free(field->p.other);
322 if ((tmp =
BN_new()) == NULL)
335 if (field->p.prime == NULL)
342 #ifdef OPENSSL_NO_EC2M
350 X9_62_CHARACTERISTIC_TWO *char_two;
352 field->p.char_two = X9_62_CHARACTERISTIC_TWO_new();
353 char_two = field->
p.char_two;
355 if (char_two == NULL)
384 char_two->
p.
tpBasis = ASN1_INTEGER_new();
399 unsigned int k1, k2, k3;
404 char_two->
p.
ppBasis = X9_62_PENTANOMIAL_new();
419 char_two->
p.
onBasis = ASN1_NULL_new();
436 static int ec_asn1_group2curve(
const EC_GROUP *group, X9_62_CURVE *curve)
439 BIGNUM *tmp_1=NULL, *tmp_2=NULL;
440 unsigned char *buffer_1=NULL, *buffer_2=NULL,
441 *a_buf=NULL, *b_buf=NULL;
443 unsigned char char_zero = 0;
445 if (!group || !curve || !curve->
a || !curve->
b)
448 if ((tmp_1 =
BN_new()) == NULL || (tmp_2 =
BN_new()) == NULL)
465 #ifndef OPENSSL_NO_EC2M
492 if ( (len_1 =
BN_bn2bin(tmp_1, buffer_1)) == 0)
514 if ( (len_2 =
BN_bn2bin(tmp_2, buffer_2)) == 0)
534 if ((curve->
seed = ASN1_BIT_STRING_new()) == NULL)
552 ASN1_BIT_STRING_free(curve->
seed);
570 static ECPARAMETERS *ec_asn1_group2parameters(
const EC_GROUP *group,
575 ECPARAMETERS *ret=NULL;
577 unsigned char *buffer=NULL;
581 if ((tmp =
BN_new()) == NULL)
589 if ((ret = ECPARAMETERS_new()) == NULL)
603 if (!ec_asn1_group2fieldid(group, ret->
fieldID))
610 if (!ec_asn1_group2curve(group, ret->
curve))
641 if (ret->
base == NULL && (ret->
base = ASN1_OCTET_STRING_new()) == NULL)
659 if (ret->
order == NULL)
681 ECPARAMETERS_free(ret);
691 ECPKPARAMETERS *ec_asn1_group2pkparameters(
const EC_GROUP *group,
692 ECPKPARAMETERS *params)
695 ECPKPARAMETERS *ret = params;
699 if ((ret = ECPKPARAMETERS_new()) == NULL)
735 group, NULL)) == NULL)
741 ECPKPARAMETERS_free(ret);
747 static EC_GROUP *ec_asn1_parameters2group(
const ECPARAMETERS *params)
750 EC_GROUP *ret = NULL;
786 #ifdef OPENSSL_NO_EC2M
793 X9_62_CHARACTERISTIC_TWO *char_two;
797 field_bits = char_two->
m;
804 if ((p =
BN_new()) == NULL)
825 if (!(char_two->
m > tmp_long && tmp_long > 0))
850 if (!(char_two->
m > penta->
k3 && penta->
k3 > penta->
k2 && penta->
k2 > penta->
k1 && penta->
k1 > 0))
925 if (ret->
seed != NULL)
1017 EC_GROUP *ec_asn1_pkparameters2group(
const ECPKPARAMETERS *params)
1029 if (params->
type == 0)
1040 else if (params->
type == 1)
1051 else if (params->
type == 2)
1068 EC_GROUP *group = NULL;
1069 ECPKPARAMETERS *params = NULL;
1071 if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL)
1074 ECPKPARAMETERS_free(params);
1078 if ((group = ec_asn1_pkparameters2group(params)) == NULL)
1081 ECPKPARAMETERS_free(params);
1091 ECPKPARAMETERS_free(params);
1098 ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL);
1104 if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0)
1107 ECPKPARAMETERS_free(tmp);
1110 ECPKPARAMETERS_free(tmp);
1120 EC_PRIVATEKEY *priv_key=NULL;
1122 if ((priv_key = EC_PRIVATEKEY_new()) == NULL)
1128 if ((priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len)) == NULL)
1131 EC_PRIVATEKEY_free(priv_key);
1135 if (a == NULL || *a == NULL)
1156 if (ret->
group == NULL)
1186 const unsigned char *pub_oct;
1202 pub_oct, pub_oct_len, NULL))
1219 EC_PRIVATEKEY_free(priv_key);
1227 unsigned char *buffer=NULL;
1228 size_t buf_len=0, tmp_len;
1229 EC_PRIVATEKEY *priv_key=NULL;
1238 if ((priv_key = EC_PRIVATEKEY_new()) == NULL)
1270 if ((priv_key->
parameters = ec_asn1_group2pkparameters(
1291 if (tmp_len > buf_len)
1299 buffer = tmp_buffer;
1320 if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0)
1330 EC_PRIVATEKEY_free(priv_key);
1348 if (in == NULL || *in == NULL)
1354 if (a == NULL || *a == NULL)
1380 if (a == NULL || (*a) == NULL || (*a)->
group == NULL)
1419 if (out == NULL || buf_len == 0)
1433 *out, buf_len, NULL))