summaryrefslogtreecommitdiff
path: root/cipher/ecc-misc.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-12-02 16:18:25 +0100
committerWerner Koch <wk@gnupg.org>2013-12-02 16:21:45 +0100
commit14ae6224b1b17abbfc80c26ad0f4c60f1e8635e2 (patch)
treec783cf16f3a1e69943b7fa2d76e9487dbf4325b9 /cipher/ecc-misc.c
parent485f35124b1a74af0bad321ed70be3a79d8d11d7 (diff)
downloadlibgcrypt-14ae6224b1b17abbfc80c26ad0f4c60f1e8635e2.tar.gz
ecc: Make gcry_pk_testkey work for Ed25519.
* cipher/ecc-misc.c (_gcry_ecc_compute_public): Add optional args G and d. Change all callers. * cipher/ecc.c (gen_y_2): Remove. (check_secret_key): Use generic public key compute function. Adjust for use with Ed25519 and EdDSA. (nist_generate_key): Do not use the compliant key thingy for Ed25519. (ecc_check_secret_key): Make parameter parsing similar to the other functions. * cipher/ecc-curves.c (domain_parms): Zero prefix some parameters so that _gcry_ecc_update_curve_param works correctly. * tests/keygen.c (check_ecc_keys): Add "param" flag. Check all Ed25519 keys.
Diffstat (limited to 'cipher/ecc-misc.c')
-rw-r--r--cipher/ecc-misc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/cipher/ecc-misc.c b/cipher/ecc-misc.c
index 0eb3391c..1633d32d 100644
--- a/cipher/ecc-misc.c
+++ b/cipher/ecc-misc.c
@@ -253,13 +253,20 @@ reverse_buffer (unsigned char *buffer, unsigned int length)
/* Compute the public key from the the context EC. Obviously a
requirement is that the secret key is available in EC. On success
Q is returned; on error NULL. If Q is NULL a newly allocated point
- is returned. */
+ is returned. If G or D are given they override the values taken
+ from EC. */
mpi_point_t
-_gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec)
+_gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec,
+ mpi_point_t G, gcry_mpi_t d)
{
int rc;
- if (!ec->d || !ec->G || !ec->p || !ec->a)
+ if (!G)
+ G = ec->G;
+ if (!d)
+ d = ec->d;
+
+ if (!d || !G || !ec->p || !ec->a)
return NULL;
if (ec->model == MPI_EC_TWISTEDEDWARDS && !ec->b)
return NULL;
@@ -280,7 +287,7 @@ _gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec)
return NULL;
memset (hvec, 0, sizeof hvec);
- rawmpi = _gcry_mpi_get_buffer (ec->d, 0, &rawmpilen, NULL);
+ rawmpi = _gcry_mpi_get_buffer (d, 0, &rawmpilen, NULL);
if (!rawmpi)
return NULL;
memset (digest, 0, b);
@@ -311,7 +318,7 @@ _gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec)
if (!Q)
Q = gcry_mpi_point_new (0);
if (Q)
- _gcry_mpi_ec_mul_point (Q, a, ec->G, ec);
+ _gcry_mpi_ec_mul_point (Q, a, G, ec);
mpi_free (a);
}
else
@@ -319,7 +326,7 @@ _gcry_ecc_compute_public (mpi_point_t Q, mpi_ec_t ec)
if (!Q)
Q = gcry_mpi_point_new (0);
if (Q)
- _gcry_mpi_ec_mul_point (Q, ec->d, ec->G, ec);
+ _gcry_mpi_ec_mul_point (Q, d, G, ec);
}
return Q;