summaryrefslogtreecommitdiff
path: root/mpi/ec.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-09-06 20:07:07 +0200
committerWerner Koch <wk@gnupg.org>2013-09-07 10:16:45 +0200
commitddfefe429660cc5d798f3517208936449247ae5c (patch)
treef048cf22d4cc2de5994b44560877b25e0fb825f5 /mpi/ec.c
parent1bd2c67aa55b40589654d3fa5dea05cf1ed7dc5f (diff)
downloadlibgcrypt-ddfefe429660cc5d798f3517208936449247ae5c.tar.gz
mpi: Add gcry_mpi_ec_curve_point.
* mpi/ec.c (_gcry_mpi_ec_curve_point): New. (ec_powm): Return the absolute value. * src/visibility.c, src/visibility.c: Add wrappers. * src/libgcrypt.def, src/libgcrypt.vers: Export them.
Diffstat (limited to 'mpi/ec.c')
-rw-r--r--mpi/ec.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/mpi/ec.c b/mpi/ec.c
index 478416fa..7da2e3b7 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -328,6 +328,7 @@ ec_powm (gcry_mpi_t w, const gcry_mpi_t b, const gcry_mpi_t e,
mpi_ec_t ctx)
{
mpi_powm (w, b, e, ctx->p);
+ _gcry_mpi_abs (w);
}
static void
@@ -1104,3 +1105,52 @@ _gcry_mpi_ec_mul_point (mpi_point_t result,
mpi_free (k);
#endif
}
+
+
+/* Return true if POINT is on the curve described by CTX. */
+int
+_gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx)
+{
+ int res = 0;
+ gcry_mpi_t x, y, w;
+
+ x = mpi_new (0);
+ y = mpi_new (0);
+ w = mpi_new (0);
+
+ if (_gcry_mpi_ec_get_affine (x, y, point, ctx))
+ return 0;
+
+ switch (ctx->model)
+ {
+ case MPI_EC_WEIERSTRASS:
+ log_fatal ("%s: %s not yet supported\n",
+ "_gcry_mpi_ec_curve_point", "Weierstrass");
+ break;
+ case MPI_EC_MONTGOMERY:
+ log_fatal ("%s: %s not yet supported\n",
+ "_gcry_mpi_ec_curve_point", "Montgomery");
+ break;
+ case MPI_EC_TWISTEDEDWARDS:
+ {
+ /* a · x^2 + y^2 - 1 - b · x^2 · y^2 == 0 */
+ ec_powm (x, x, mpi_const (MPI_C_TWO), ctx);
+ ec_powm (y, y, mpi_const (MPI_C_TWO), ctx);
+ ec_mulm (w, ctx->a, x, ctx);
+ ec_addm (w, w, y, ctx);
+ ec_subm (w, w, mpi_const (MPI_C_ONE), ctx);
+ ec_mulm (x, x, y, ctx);
+ ec_mulm (x, x, ctx->b, ctx);
+ ec_subm (w, w, x, ctx);
+ if (!mpi_cmp_ui (w, 0))
+ res = 1;
+ }
+ break;
+ }
+
+ gcry_mpi_release (w);
+ gcry_mpi_release (x);
+ gcry_mpi_release (y);
+
+ return res;
+}