From a951c061523e1c13f1358c9760fc3a9d787ab2d4 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 11 Oct 2013 22:37:41 +0200 Subject: pubkey: Move sexp parsing of remaining fucntions to the modules. * cipher/pubkey.c (release_mpi_array): Remove. (pubkey_check_secret_key): Remove. (sexp_elements_extract): Remove. (sexp_elements_extract_ecc): Remove. (sexp_to_key): Remove. (get_hash_algo): Remove. (gcry_pk_testkey): Revamp. (gcry_pk_get_curve): Revamp. * cipher/rsa.c (rsa_check_secret_key): Revamp. * cipher/elgamal.c (elg_check_secret_key): Revamp. * cipher/dsa.c (dsa_check_secret_key): Revamp. * cipher/ecc.c (ecc_check_secret_key): Revamp. * cipher/ecc-curves.c: Include cipher.h and pubkey-internal.h (_gcry_ecc_get_curve): Revamp. * cipher/pubkey-util.c (_gcry_pk_util_extract_mpis): Set passed and used parameters on error to NULL. -- That is the final part of the changes modulo introduced regressions. pubkey.c is now actually maintainable code. Signed-off-by: Werner Koch --- cipher/ecc-curves.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'cipher/ecc-curves.c') diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 971dd322..53433a2c 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -26,8 +26,10 @@ #include "g10lib.h" #include "mpi.h" +#include "cipher.h" #include "context.h" #include "ec-context.h" +#include "pubkey-internal.h" #include "ecc-common.h" @@ -405,18 +407,20 @@ _gcry_ecc_fill_in_curve (unsigned int nbits, const char *name, /* Return the name matching the parameters in PKEY. This works only with curves described by the Weierstrass equation. */ const char * -_gcry_ecc_get_curve (gcry_mpi_t *pkey, int iterator, unsigned int *r_nbits) +_gcry_ecc_get_curve (gcry_sexp_t keyparms, int iterator, unsigned int *r_nbits) { - gpg_err_code_t err; + const char *result = NULL; elliptic_curve_t E; + gcry_mpi_t mpi_g = NULL; + gcry_mpi_t tmp = NULL; int idx; - gcry_mpi_t tmp; - const char *result = NULL; + + memset (&E, 0, sizeof E); if (r_nbits) *r_nbits = 0; - if (!pkey) + if (!keyparms) { idx = iterator; if (idx >= 0 && idx < DIM (domain_parms)) @@ -428,23 +432,20 @@ _gcry_ecc_get_curve (gcry_mpi_t *pkey, int iterator, unsigned int *r_nbits) return result; } - if (!pkey[0] || !pkey[1] || !pkey[2] || !pkey[3] || !pkey[4]) - return NULL; - E.model = MPI_EC_WEIERSTRASS; - E.dialect = ECC_DIALECT_STANDARD; - E.name = NULL; - E.p = pkey[0]; - E.a = pkey[1]; - E.b = pkey[2]; - _gcry_mpi_point_init (&E.G); - err = _gcry_ecc_os2ec (&E.G, pkey[3]); - if (err) + /* + * Extract the curve parameters.. + */ + if (_gcry_pk_util_extract_mpis (keyparms, "-pabgn", + &E.p, &E.a, &E.b, &mpi_g, &E.n, + NULL)) + goto leave; + if (mpi_g) { - _gcry_mpi_point_free_parts (&E.G); - return NULL; + _gcry_mpi_point_init (&E.G); + if (_gcry_ecc_os2ec (&E.G, mpi_g)) + goto leave; } - E.n = pkey[4]; for (idx = 0; domain_parms[idx].desc; idx++) { @@ -471,22 +472,26 @@ _gcry_ecc_get_curve (gcry_mpi_t *pkey, int iterator, unsigned int *r_nbits) tmp = scanval (domain_parms[idx].g_y); if (!mpi_cmp (tmp, E.G.y)) { - mpi_free (tmp); result = domain_parms[idx].desc; if (r_nbits) *r_nbits = domain_parms[idx].nbits; - break; + goto leave; } } } } } } - mpi_free (tmp); } + leave: + gcry_mpi_release (tmp); + gcry_mpi_release (E.p); + gcry_mpi_release (E.a); + gcry_mpi_release (E.b); + gcry_mpi_release (mpi_g); _gcry_mpi_point_free_parts (&E.G); - + gcry_mpi_release (E.n); return result; } -- cgit v1.2.1