aboutsummaryrefslogtreecommitdiff
path: root/crypto/ec/ec_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/ec/ec_lib.c')
-rw-r--r--crypto/ec/ec_lib.c78
1 files changed, 58 insertions, 20 deletions
diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c
index a082876fb479..b55677fb1f4f 100644
--- a/crypto/ec/ec_lib.c
+++ b/crypto/ec/ec_lib.c
@@ -19,6 +19,7 @@
#include <openssl/core_names.h>
#include <openssl/err.h>
#include <openssl/opensslv.h>
+#include <openssl/param_build.h>
#include "crypto/ec.h"
#include "crypto/bn.h"
#include "internal/nelem.h"
@@ -41,18 +42,14 @@ EC_GROUP *ossl_ec_group_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
}
ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
ret->libctx = libctx;
if (propq != NULL) {
ret->propq = OPENSSL_strdup(propq);
- if (ret->propq == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ if (ret->propq == NULL)
goto err;
- }
}
ret->meth = meth;
if ((ret->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {
@@ -103,12 +100,16 @@ void EC_pre_comp_free(EC_GROUP *group)
case PCT_nistp256:
EC_nistp256_pre_comp_free(group->pre_comp.nistp256);
break;
+ case PCT_nistp384:
+ ossl_ec_nistp384_pre_comp_free(group->pre_comp.nistp384);
+ break;
case PCT_nistp521:
EC_nistp521_pre_comp_free(group->pre_comp.nistp521);
break;
#else
case PCT_nistp224:
case PCT_nistp256:
+ case PCT_nistp384:
case PCT_nistp521:
break;
#endif
@@ -192,12 +193,16 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
case PCT_nistp256:
dest->pre_comp.nistp256 = EC_nistp256_pre_comp_dup(src->pre_comp.nistp256);
break;
+ case PCT_nistp384:
+ dest->pre_comp.nistp384 = ossl_ec_nistp384_pre_comp_dup(src->pre_comp.nistp384);
+ break;
case PCT_nistp521:
dest->pre_comp.nistp521 = EC_nistp521_pre_comp_dup(src->pre_comp.nistp521);
break;
#else
case PCT_nistp224:
case PCT_nistp256:
+ case PCT_nistp384:
case PCT_nistp521:
break;
#endif
@@ -247,10 +252,8 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
if (src->seed) {
OPENSSL_free(dest->seed);
- if ((dest->seed = OPENSSL_malloc(src->seed_len)) == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ if ((dest->seed = OPENSSL_malloc(src->seed_len)) == NULL)
return 0;
- }
if (!memcpy(dest->seed, src->seed, src->seed_len))
return 0;
dest->seed_len = src->seed_len;
@@ -533,10 +536,8 @@ size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
if (!len || !p)
return 1;
- if ((group->seed = OPENSSL_malloc(len)) == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ if ((group->seed = OPENSSL_malloc(len)) == NULL)
return 0;
- }
memcpy(group->seed, p, len);
group->seed_len = len;
@@ -727,10 +728,8 @@ EC_POINT *EC_POINT_new(const EC_GROUP *group)
}
ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
ret->meth = group->meth;
ret->curve_name = group->curve_name;
@@ -748,9 +747,13 @@ void EC_POINT_free(EC_POINT *point)
if (point == NULL)
return;
+#ifdef OPENSSL_PEDANTIC_ZEROIZATION
+ EC_POINT_clear_free(point);
+#else
if (point->meth->point_finish != 0)
point->meth->point_finish(point);
OPENSSL_free(point);
+#endif
}
void EC_POINT_clear_free(EC_POINT *point)
@@ -1508,7 +1511,7 @@ int ossl_ec_group_set_params(EC_GROUP *group, const OSSL_PARAM params[])
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT);
if (p != NULL) {
if (!ossl_ec_pt_format_param2id(p, &format)) {
- ECerr(0, EC_R_INVALID_FORM);
+ ERR_raise(ERR_LIB_EC, EC_R_INVALID_FORM);
return 0;
}
EC_GROUP_set_point_conversion_form(group, format);
@@ -1517,7 +1520,7 @@ int ossl_ec_group_set_params(EC_GROUP *group, const OSSL_PARAM params[])
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_EC_ENCODING);
if (p != NULL) {
if (!ossl_ec_encoding_param2id(p, &encoding_flag)) {
- ECerr(0, EC_R_INVALID_FORM);
+ ERR_raise(ERR_LIB_EC, EC_R_INVALID_FORM);
return 0;
}
EC_GROUP_set_asn1_flag(group, encoding_flag);
@@ -1528,7 +1531,7 @@ int ossl_ec_group_set_params(EC_GROUP *group, const OSSL_PARAM params[])
/* The seed is allowed to be NULL */
if (p->data_type != OSSL_PARAM_OCTET_STRING
|| !EC_GROUP_set_seed(group, p->data, p->data_size)) {
- ECerr(0, EC_R_INVALID_SEED);
+ ERR_raise(ERR_LIB_EC, EC_R_INVALID_SEED);
return 0;
}
}
@@ -1583,7 +1586,7 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
/* If it gets here then we are trying explicit parameters */
bnctx = BN_CTX_new_ex(libctx);
if (bnctx == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
return 0;
}
BN_CTX_start(bnctx);
@@ -1593,7 +1596,7 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
b = BN_CTX_get(bnctx);
order = BN_CTX_get(bnctx);
if (order == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
goto err;
}
@@ -1759,3 +1762,38 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
return group;
#endif /* FIPS_MODULE */
}
+
+OSSL_PARAM *EC_GROUP_to_params(const EC_GROUP *group, OSSL_LIB_CTX *libctx,
+ const char *propq, BN_CTX *bnctx)
+{
+ OSSL_PARAM_BLD *tmpl = NULL;
+ BN_CTX *new_bnctx = NULL;
+ unsigned char *gen_buf = NULL;
+ OSSL_PARAM *params = NULL;
+
+ if (group == NULL)
+ goto err;
+
+ tmpl = OSSL_PARAM_BLD_new();
+ if (tmpl == NULL)
+ goto err;
+
+ if (bnctx == NULL)
+ bnctx = new_bnctx = BN_CTX_new_ex(libctx);
+ if (bnctx == NULL)
+ goto err;
+ BN_CTX_start(bnctx);
+
+ if (!ossl_ec_group_todata(
+ group, tmpl, NULL, libctx, propq, bnctx, &gen_buf))
+ goto err;
+
+ params = OSSL_PARAM_BLD_to_param(tmpl);
+
+ err:
+ OSSL_PARAM_BLD_free(tmpl);
+ OPENSSL_free(gen_buf);
+ BN_CTX_end(bnctx);
+ BN_CTX_free(new_bnctx);
+ return params;
+}