summaryrefslogtreecommitdiff
path: root/cipher/ecc-curves.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2019-10-22 10:00:01 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2019-10-22 10:03:46 +0900
commit488704be6e044e23770d95344511c5a347b533c5 (patch)
treea44becdbcb1a8e0a8fec0d738b0e4f740fdfe1fb /cipher/ecc-curves.c
parent5415bc578080018e1cd36aa44cf5c0a9995cbafc (diff)
downloadlibgcrypt-488704be6e044e23770d95344511c5a347b533c5.tar.gz
ecc: Add key generation support to mpi_ec_get_elliptic_curve.
* cipher/ecc-curves.c (mpi_ec_get_elliptic_curve): Handle params for key generation. (_gcry_mpi_ec_internal_new): Remove duplication for handling of flags. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'cipher/ecc-curves.c')
-rw-r--r--cipher/ecc-curves.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c
index 98aed9a6..bd685c0e 100644
--- a/cipher/ecc-curves.c
+++ b/cipher/ecc-curves.c
@@ -925,9 +925,14 @@ static gpg_err_code_t
mpi_ec_get_elliptic_curve (elliptic_curve_t *E, int *r_flags,
gcry_sexp_t keyparam, const char *curvename)
{
- gpg_err_code_t errc = 0;
+ gpg_err_code_t errc;
+ unsigned int nbits;
gcry_sexp_t l1;
+ errc = _gcry_pk_util_get_nbits (keyparam, &nbits);
+ if (errc)
+ return errc;
+
E->model = MPI_EC_WEIERSTRASS;
E->dialect = ECC_DIALECT_STANDARD;
E->h = 1;
@@ -938,11 +943,23 @@ mpi_ec_get_elliptic_curve (elliptic_curve_t *E, int *r_flags,
l1 = sexp_find_token (keyparam, "flags", 0);
if (l1)
{
- errc = _gcry_pk_util_parse_flaglist (l1, r_flags, NULL);
+ int flags = 0;
+
+ errc = _gcry_pk_util_parse_flaglist (l1, &flags, NULL);
sexp_release (l1);
l1 = NULL;
if (errc)
goto leave;
+
+ *r_flags |= flags;
+ }
+
+ /* Parse the deprecated optional transient-key flag. */
+ l1 = sexp_find_token (keyparam, "transient-key", 0);
+ if (l1)
+ {
+ *r_flags |= PUBKEY_FLAG_TRANSIENT_KEY;
+ sexp_release (l1);
}
/* Check whether a curve name was given. */
@@ -1010,7 +1027,7 @@ mpi_ec_get_elliptic_curve (elliptic_curve_t *E, int *r_flags,
else
name = NULL;
- errc = _gcry_ecc_fill_in_curve (0, name? name : curvename, E, NULL);
+ errc = _gcry_ecc_fill_in_curve (nbits, name? name : curvename, E, NULL);
xfree (name);
if (errc)
goto leave;
@@ -1060,23 +1077,6 @@ _gcry_mpi_ec_internal_new (mpi_ec_t *r_ec, int *r_flags, const char *name_op,
*r_ec = NULL;
- /* Look for flags. */
- {
- gcry_sexp_t l1;
- int flags = 0;
-
- l1 = sexp_find_token (keyparam, "flags", 0);
- if (l1)
- {
- errc = _gcry_pk_util_parse_flaglist (l1, &flags, NULL);
- if (errc)
- return errc;
- }
- sexp_release (l1);
-
- *r_flags |= flags;
- }
-
memset (&E, 0, sizeof E);
errc = mpi_ec_get_elliptic_curve (&E, r_flags, keyparam, curvename);
if (errc)
@@ -1161,8 +1161,8 @@ _gcry_mpi_ec_new (gcry_ctx_t *r_ctx,
gcry_sexp_t keyparam, const char *curvename)
{
gpg_err_code_t errc;
- gcry_ctx_t ctx = NULL;
elliptic_curve_t E;
+ gcry_ctx_t ctx = NULL;
int flags = 0;
mpi_ec_t ec;