summaryrefslogtreecommitdiffstats
path: root/ssl/s3_lib.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2017-09-23 02:40:30 +0100
committerDr. Stephen Henson <steve@openssl.org>2017-09-26 13:00:26 +0100
commit612f9d2227897a3dc76c9dc74a8c30aa1dc7b5a1 (patch)
tree9a45e7f3aee4e8360658617108950bb3ad5d5152 /ssl/s3_lib.c
parent43b95d736561e64dd7c1c97555f39a98c56d1ae3 (diff)
New function ssl_generate_param_group
Setup EVP_PKEY structure from a group ID in ssl_generate_param_group, replace duplicate code with this function. Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/=4412)
Diffstat (limited to 'ssl/s3_lib.c')
-rw-r--r--ssl/s3_lib.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c
index 46e76e33c8..a8f5637be5 100644
--- a/ssl/s3_lib.c
+++ b/ssl/s3_lib.c
@@ -4621,6 +4621,43 @@ EVP_PKEY *ssl_generate_pkey_group(uint16_t id)
EVP_PKEY_CTX_free(pctx);
return pkey;
}
+
+/*
+ * Generate parameters from a group ID
+ */
+EVP_PKEY *ssl_generate_param_group(uint16_t id)
+{
+ EVP_PKEY_CTX *pctx = NULL;
+ EVP_PKEY *pkey = NULL;
+ const TLS_GROUP_INFO *ginf = tls1_group_id_lookup(id);
+
+ if (ginf == NULL)
+ goto err;
+
+ if ((ginf->flags & TLS_CURVE_TYPE) == TLS_CURVE_CUSTOM) {
+ pkey = EVP_PKEY_new();
+ if (pkey != NULL && EVP_PKEY_set_type(pkey, ginf->nid))
+ return pkey;
+ EVP_PKEY_free(pkey);
+ return NULL;
+ }
+
+ pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
+ if (pctx == NULL)
+ goto err;
+ if (EVP_PKEY_paramgen_init(pctx) <= 0)
+ goto err;
+ if (EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, ginf->nid) <= 0)
+ goto err;
+ if (EVP_PKEY_paramgen(pctx, &pkey) <= 0) {
+ EVP_PKEY_free(pkey);
+ pkey = NULL;
+ }
+
+ err:
+ EVP_PKEY_CTX_free(pctx);
+ return pkey;
+}
#endif
/* Derive secrets for ECDH/DH */