summaryrefslogtreecommitdiff
path: root/lib/libcrypto/ec/ec_asn1.c
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2014-04-17 13:37:51 +0000
committerBob Beck <beck@cvs.openbsd.org>2014-04-17 13:37:51 +0000
commit798a6f0972ce4f8ea25aa987dc43e626dc6d4087 (patch)
tree557371c7b1514332c466ec6233d3e6af96c88520 /lib/libcrypto/ec/ec_asn1.c
parenteea79ffdb77e3dd4cdbd3f98ed1b44d9522496fa (diff)
Change library to use intrinsic memory allocation functions instead of
OPENSSL_foo wrappers. This changes: OPENSSL_malloc->malloc OPENSSL_free->free OPENSSL_relloc->realloc OPENSSL_freeFunc->free
Diffstat (limited to 'lib/libcrypto/ec/ec_asn1.c')
-rw-r--r--lib/libcrypto/ec/ec_asn1.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/lib/libcrypto/ec/ec_asn1.c b/lib/libcrypto/ec/ec_asn1.c
index ae555398594..2bde9a6a3c5 100644
--- a/lib/libcrypto/ec/ec_asn1.c
+++ b/lib/libcrypto/ec/ec_asn1.c
@@ -83,13 +83,14 @@ int EC_GROUP_get_basis_type(const EC_GROUP *group)
/* everything else is currently not supported */
return 0;
}
-
+#ifndef OPENSSL_NO_EC2M
int EC_GROUP_get_trinomial_basis(const EC_GROUP *group, unsigned int *k)
{
if (group == NULL)
return 0;
- if (EC_GROUP_method_of(group)->group_set_curve != ec_GF2m_simple_group_set_curve
+ if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
+ NID_X9_62_characteristic_two_field
|| !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] == 0)))
{
ECerr(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
@@ -101,14 +102,14 @@ int EC_GROUP_get_trinomial_basis(const EC_GROUP *group, unsigned int *k)
return 1;
}
-
int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1,
unsigned int *k2, unsigned int *k3)
{
if (group == NULL)
return 0;
- if (EC_GROUP_method_of(group)->group_set_curve != ec_GF2m_simple_group_set_curve
+ if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
+ NID_X9_62_characteristic_two_field
|| !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] != 0) && (group->poly[3] != 0) && (group->poly[4] == 0)))
{
ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
@@ -124,7 +125,7 @@ int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1,
return 1;
}
-
+#endif
/* some structures needed for the asn1 encoding */
@@ -340,6 +341,12 @@ static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
}
}
else /* nid == NID_X9_62_characteristic_two_field */
+#ifdef OPENSSL_NO_EC2M
+ {
+ ECerr(EC_F_EC_ASN1_GROUP2FIELDID, EC_R_GF2M_NOT_SUPPORTED);
+ goto err;
+ }
+#else
{
int field_type;
X9_62_CHARACTERISTIC_TWO *char_two;
@@ -419,6 +426,7 @@ static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
}
}
}
+#endif
ok = 1;
@@ -456,6 +464,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
goto err;
}
}
+#ifndef OPENSSL_NO_EC2M
else /* nid == NID_X9_62_characteristic_two_field */
{
if (!EC_GROUP_get_curve_GF2m(group, NULL, tmp_1, tmp_2, NULL))
@@ -464,7 +473,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
goto err;
}
}
-
+#endif
len_1 = (size_t)BN_num_bytes(tmp_1);
len_2 = (size_t)BN_num_bytes(tmp_2);
@@ -476,7 +485,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
}
else
{
- if ((buffer_1 = OPENSSL_malloc(len_1)) == NULL)
+ if ((buffer_1 = malloc(len_1)) == NULL)
{
ECerr(EC_F_EC_ASN1_GROUP2CURVE,
ERR_R_MALLOC_FAILURE);
@@ -498,7 +507,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
}
else
{
- if ((buffer_2 = OPENSSL_malloc(len_2)) == NULL)
+ if ((buffer_2 = malloc(len_2)) == NULL)
{
ECerr(EC_F_EC_ASN1_GROUP2CURVE,
ERR_R_MALLOC_FAILURE);
@@ -550,9 +559,9 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
ok = 1;
err: if (buffer_1)
- OPENSSL_free(buffer_1);
+ free(buffer_1);
if (buffer_2)
- OPENSSL_free(buffer_2);
+ free(buffer_2);
if (tmp_1)
BN_free(tmp_1);
if (tmp_2)
@@ -621,7 +630,7 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB);
goto err;
}
- if ((buffer = OPENSSL_malloc(len)) == NULL)
+ if ((buffer = malloc(len)) == NULL)
{
ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE);
goto err;
@@ -677,7 +686,7 @@ err : if(!ok)
if (tmp)
BN_free(tmp);
if (buffer)
- OPENSSL_free(buffer);
+ free(buffer);
return(ret);
}
@@ -775,8 +784,13 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
/* get the field parameters */
tmp = OBJ_obj2nid(params->fieldID->fieldType);
-
if (tmp == NID_X9_62_characteristic_two_field)
+#ifdef OPENSSL_NO_EC2M
+ {
+ ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_GF2M_NOT_SUPPORTED);
+ goto err;
+ }
+#else
{
X9_62_CHARACTERISTIC_TWO *char_two;
@@ -862,6 +876,7 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
/* create the EC_GROUP structure */
ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL);
}
+#endif
else if (tmp == NID_X9_62_prime_field)
{
/* we have a curve over a prime field */
@@ -910,8 +925,8 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
if (params->curve->seed != NULL)
{
if (ret->seed != NULL)
- OPENSSL_free(ret->seed);
- if (!(ret->seed = OPENSSL_malloc(params->curve->seed->length)))
+ free(ret->seed);
+ if (!(ret->seed = malloc(params->curve->seed->length)))
{
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,
ERR_R_MALLOC_FAILURE);
@@ -1065,6 +1080,7 @@ EC_GROUP *d2i_ECPKParameters(EC_GROUP **a, const unsigned char **in, long len)
if ((group = ec_asn1_pkparameters2group(params)) == NULL)
{
ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_PKPARAMETERS2GROUP_FAILURE);
+ ECPKPARAMETERS_free(params);
return NULL;
}
@@ -1231,7 +1247,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
priv_key->version = a->version;
buf_len = (size_t)BN_num_bytes(a->priv_key);
- buffer = OPENSSL_malloc(buf_len);
+ buffer = malloc(buf_len);
if (buffer == NULL)
{
ECerr(EC_F_I2D_ECPRIVATEKEY,
@@ -1276,7 +1292,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
if (tmp_len > buf_len)
{
- unsigned char *tmp_buffer = OPENSSL_realloc(buffer, tmp_len);
+ unsigned char *tmp_buffer = realloc(buffer, tmp_len);
if (!tmp_buffer)
{
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
@@ -1311,7 +1327,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
ok=1;
err:
if (buffer)
- OPENSSL_free(buffer);
+ free(buffer);
if (priv_key)
EC_PRIVATEKEY_free(priv_key);
return(ok?ret:0);
@@ -1408,7 +1424,7 @@ int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
if (*out == NULL)
{
- if ((*out = OPENSSL_malloc(buf_len)) == NULL)
+ if ((*out = malloc(buf_len)) == NULL)
{
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
return 0;
@@ -1419,7 +1435,7 @@ int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
*out, buf_len, NULL))
{
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB);
- OPENSSL_free(*out);
+ free(*out);
*out = NULL;
return 0;
}