diff options
author | Werner Koch <wk@gnupg.org> | 2013-03-19 15:12:07 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-03-19 15:12:07 +0100 |
commit | 931e409e877d1e444edd53dead327ec8e64daf9a (patch) | |
tree | 841c4f30324273512effe06d32af6f36d8da26c8 /cipher/ecc.c | |
parent | 229f3219f80c9369ed9624242c0436ae6d293201 (diff) | |
download | libgcrypt-931e409e877d1e444edd53dead327ec8e64daf9a.tar.gz |
Extend the new EC interface and fix two bugs.
* src/ec-context.h (mpi_ec_ctx_s): Add field NEED_SYNC.
* mpi/ec.c (ec_p_sync): New.
(ec_p_init): Only set NEED_SYNC.
(_gcry_mpi_ec_set_mpi): Set NEED_SYNC for 'p' and 'a'.
(_gcry_mpi_ec_dup_point, _gcry_mpi_ec_add_points)
(_gcry_mpi_ec_mul_point): Call ec_p_sync.
(_gcry_mpi_ec_get_point): Recompute 'q' is needed.
(_gcry_mpi_ec_get_mpi): Ditto. Also allow for names 'q', 'q.x',
'q.y', and 'g'.
* cipher/ecc.c (_gcry_mpi_ec_ec2os): New.
* cipher/ecc.c (_gcry_mpi_ec_new): Fix init from parameters 'Q'->'q',
'G'->'q'.
--
Note that the parameter names are all lowercase. This patch fixes an
inconsistency.
The other bug was that changing the parameters D or A may have
resulted in wrong computations because helper variables were not
updated. Now we delay the computation of those helper variables until
we need them.
Diffstat (limited to 'cipher/ecc.c')
-rw-r--r-- | cipher/ecc.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/cipher/ecc.c b/cipher/ecc.c index c95a57af..c23ba08b 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -930,6 +930,27 @@ ec2os (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p) } +/* Convert POINT into affine coordinates using the context CTX and + return a newly allocated MPI. If the conversion is not possible + NULL is returned. This function won't print an error message. */ +gcry_mpi_t +_gcry_mpi_ec_ec2os (gcry_mpi_point_t point, mpi_ec_t ectx) +{ + gcry_mpi_t g_x, g_y, result; + + g_x = mpi_new (0); + g_y = mpi_new (0); + if (_gcry_mpi_ec_get_affine (g_x, g_y, point, ectx)) + result = NULL; + else + result = ec2os (g_x, g_y, ectx->p); + mpi_free (g_x); + mpi_free (g_y); + + return result; +} + + /* RESULT must have been initialized and is set on success to the point given by VALUE. */ static gcry_error_t @@ -1838,13 +1859,13 @@ _gcry_mpi_ec_new (gcry_ctx_t *r_ctx, errc = mpi_from_keyparam (&b, keyparam, "b"); if (errc) goto leave; - errc = point_from_keyparam (&G, keyparam, "G"); + errc = point_from_keyparam (&G, keyparam, "g"); if (errc) goto leave; errc = mpi_from_keyparam (&n, keyparam, "n"); if (errc) goto leave; - errc = point_from_keyparam (&Q, keyparam, "Q"); + errc = point_from_keyparam (&Q, keyparam, "q"); if (errc) goto leave; errc = mpi_from_keyparam (&d, keyparam, "d"); |