summaryrefslogtreecommitdiff
path: root/cipher/ecc.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-09-07 10:06:46 +0200
committerWerner Koch <wk@gnupg.org>2013-09-07 10:16:45 +0200
commit4d8c8c7aa88cddb1624301957e6245405f46d027 (patch)
treec8b7e7550a0beccfaa547e241bcbfda3417f3c4b /cipher/ecc.c
parentddfefe429660cc5d798f3517208936449247ae5c (diff)
downloadlibgcrypt-4d8c8c7aa88cddb1624301957e6245405f46d027.tar.gz
mpi: Improve support for non-Weierstrass support.
* mpi/ec.c (ec_p_init): Add args MODEL and P. Change all callers. (_gcry_mpi_ec_p_internal_new): Ditto. (_gcry_mpi_ec_p_new): Ditto. * cipher/ecc-curves.c (_gcry_ecc_fill_in_curve): Return GPG_ERR_UNKNOWN_CURVE instead of invalid value. Init curve model. * cipher/ecc.c (ecc_verify, ecc_encrypt_raw): Ditto. * cipher/pubkey.c (sexp_data_to_mpi): Fix EDDSA flag error checking. -- (fixes commit c26be7a337d0bf98193bc58e043209e46d0769bb)
Diffstat (limited to 'cipher/ecc.c')
-rw-r--r--cipher/ecc.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/cipher/ecc.c b/cipher/ecc.c
index 0cb279f6..9d318cc6 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -174,10 +174,11 @@ generate_key (ECC_secret_key *sk, unsigned int nbits, const char *name,
/* Compute Q. */
point_init (&Q);
- ctx = _gcry_mpi_ec_p_internal_new (E.p, E.a);
+ ctx = _gcry_mpi_ec_p_internal_new (E.model, E.p, E.a, E.b);
_gcry_mpi_ec_mul_point (&Q, sk->d, &E.G, ctx);
/* Copy the stuff to the key structures. */
+ sk->E.model = E.model;
sk->E.p = mpi_copy (E.p);
sk->E.a = mpi_copy (E.a);
sk->E.b = mpi_copy (E.b);
@@ -343,7 +344,7 @@ check_secret_key (ECC_secret_key * sk)
goto leave;
}
- ctx = _gcry_mpi_ec_p_internal_new (sk->E.p, sk->E.a);
+ ctx = _gcry_mpi_ec_p_internal_new (sk->E.model, sk->E.p, sk->E.a, sk->E.b);
_gcry_mpi_ec_mul_point (&Q, sk->E.n, &sk->E.G, ctx);
if (mpi_cmp_ui (Q.z, 0))
@@ -457,7 +458,8 @@ sign_ecdsa (gcry_mpi_t input, ECC_secret_key *skey, gcry_mpi_t r, gcry_mpi_t s,
mpi_set_ui (s, 0);
mpi_set_ui (r, 0);
- ctx = _gcry_mpi_ec_p_internal_new (skey->E.p, skey->E.a);
+ ctx = _gcry_mpi_ec_p_internal_new (skey->E.model,
+ skey->E.p, skey->E.a, skey->E.b);
while (!mpi_cmp_ui (s, 0)) /* s == 0 */
{
@@ -556,7 +558,8 @@ verify_ecdsa (gcry_mpi_t input, ECC_public_key *pkey,
point_init (&Q1);
point_init (&Q2);
- ctx = _gcry_mpi_ec_p_internal_new (pkey->E.p, pkey->E.a);
+ ctx = _gcry_mpi_ec_p_internal_new (pkey->E.model,
+ pkey->E.p, pkey->E.a, pkey->E.b);
/* h = s^(-1) (mod n) */
mpi_invm (h, s, pkey->E.n);
@@ -786,6 +789,7 @@ ecc_check_secret_key (int algo, gcry_mpi_t *skey)
|| !skey[6])
return GPG_ERR_BAD_MPI;
+ sk.E.model = MPI_EC_WEIERSTRASS;
sk.E.p = skey[0];
sk.E.a = skey[1];
sk.E.b = skey[2];
@@ -833,6 +837,9 @@ ecc_sign (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey,
|| !skey[6] )
return GPG_ERR_BAD_MPI;
+ sk.E.model = ((flags & PUBKEY_FLAG_EDDSA)
+ ? MPI_EC_TWISTEDEDWARDS
+ : MPI_EC_WEIERSTRASS);
sk.E.p = skey[0];
sk.E.a = skey[1];
sk.E.b = skey[2];
@@ -880,6 +887,9 @@ ecc_verify (int algo, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
|| !pkey[3] || !pkey[4] || !pkey[5] )
return GPG_ERR_BAD_MPI;
+ pk.E.model = ((flags & PUBKEY_FLAG_EDDSA)
+ ? MPI_EC_TWISTEDEDWARDS
+ : MPI_EC_WEIERSTRASS);
pk.E.p = pkey[0];
pk.E.a = pkey[1];
pk.E.b = pkey[2];
@@ -976,6 +986,7 @@ ecc_encrypt_raw (int algo, gcry_mpi_t *resarr, gcry_mpi_t k,
|| !pkey[0] || !pkey[1] || !pkey[2] || !pkey[3] || !pkey[4] || !pkey[5])
return GPG_ERR_BAD_MPI;
+ pk.E.model = MPI_EC_WEIERSTRASS;
pk.E.p = pkey[0];
pk.E.a = pkey[1];
pk.E.b = pkey[2];
@@ -996,7 +1007,7 @@ ecc_encrypt_raw (int algo, gcry_mpi_t *resarr, gcry_mpi_t k,
return err;
}
- ctx = _gcry_mpi_ec_p_internal_new (pk.E.p, pk.E.a);
+ ctx = _gcry_mpi_ec_p_internal_new (pk.E.model, pk.E.p, pk.E.a, pk.E.b);
/* The following is false: assert( mpi_cmp_ui( R.x, 1 )==0 );, so */
{
@@ -1084,7 +1095,7 @@ ecc_decrypt_raw (int algo, gcry_mpi_t *result, gcry_mpi_t *data,
return err;
}
-
+ sk.E.model = MPI_EC_WEIERSTRASS;
sk.E.p = skey[0];
sk.E.a = skey[1];
sk.E.b = skey[2];
@@ -1108,7 +1119,7 @@ ecc_decrypt_raw (int algo, gcry_mpi_t *result, gcry_mpi_t *data,
}
sk.d = skey[6];
- ctx = _gcry_mpi_ec_p_internal_new (sk.E.p, sk.E.a);
+ ctx = _gcry_mpi_ec_p_internal_new (sk.E.model, sk.E.p, sk.E.a, sk.E.b);
/* R = dkG */
point_init (&R);