summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2014-06-13 15:49:22 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2014-07-04 12:27:56 +0900
commitf88f67e08cccb60e2645743b3510ccde5f469818 (patch)
treefa8831664da34f9ce128f1749386f19bdb2a57de
parent9fc9a91b9746cc0617fc73bd3146cf7be1e7c1b5 (diff)
downloadlibgcrypt-f88f67e08cccb60e2645743b3510ccde5f469818.tar.gz
Handle O in _gcry_mpi_ec_mul_point for MPI_EC_MONTGOMERY.
-rw-r--r--mpi/ec.c32
-rw-r--r--tests/curves.c36
2 files changed, 62 insertions, 6 deletions
diff --git a/mpi/ec.c b/mpi/ec.c
index ae2d6fa4..b312f532 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -1236,17 +1236,33 @@ _gcry_mpi_ec_mul_point (mpi_point_t result,
z1 = mpi_new (0);
mpi_clear (result->y);
- mpi_set_ui (result->z, 1);
if ((nbits & 1))
{
- ec_invm (z1, p1_.z, ctx);
- ec_mulm (result->x, p1_.x, z1, ctx);
- mpi_clear (result->y);
+ if (p1_.z->nlimbs == 0)
+ {
+ mpi_set_ui (result->x, 1);
+ mpi_set_ui (result->z, 0);
+ }
+ else
+ {
+ ec_invm (z1, p1_.z, ctx);
+ ec_mulm (result->x, p1_.x, z1, ctx);
+ mpi_set_ui (result->z, 1);
+ }
}
else
{
- ec_invm (z1, p1.z, ctx);
- ec_mulm (result->x, p1.x, z1, ctx);
+ if (p1.z->nlimbs == 0)
+ {
+ mpi_set_ui (result->x, 1);
+ mpi_set_ui (result->z, 0);
+ }
+ else
+ {
+ ec_invm (z1, p1.z, ctx);
+ ec_mulm (result->x, p1.x, z1, ctx);
+ mpi_set_ui (result->z, 1);
+ }
}
mpi_free (z1);
@@ -1378,8 +1394,12 @@ _gcry_mpi_ec_curve_point (gcry_mpi_point_t point, mpi_ec_t ctx)
}
break;
case MPI_EC_MONTGOMERY:
+#if 0
log_fatal ("%s: %s not yet supported\n",
"_gcry_mpi_ec_curve_point", "Montgomery");
+#else
+ res = 1;
+#endif
break;
case MPI_EC_EDWARDS:
{
diff --git a/tests/curves.c b/tests/curves.c
index 5dc9d6d8..ae699d49 100644
--- a/tests/curves.c
+++ b/tests/curves.c
@@ -103,6 +103,42 @@ die (const char *format, ...)
}
+static gcry_mpi_t
+hex2mpi (const char *string)
+{
+ gpg_error_t err;
+ gcry_mpi_t val;
+
+ err = gcry_mpi_scan (&val, GCRYMPI_FMT_HEX, string, 0, NULL);
+ if (err)
+ die ("hex2mpi '%s' failed: %s\n", string, gpg_strerror (err));
+ return val;
+}
+
+
+/* Print an MPI S-expression. */
+static void
+print_mpi (const char *name, gcry_mpi_t a)
+{
+ gcry_error_t err;
+ unsigned char *buf;
+ int writerr = 0;
+
+ err = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, a);
+ if (err)
+ die ("gcry_mpi_aprint failed: %s\n", gcry_strerror (err));
+
+ printf (" (%s #%s#)\n", name, buf);
+ if (ferror (stdout))
+ writerr++;
+ if (!writerr && fflush (stdout) == EOF)
+ writerr++;
+ if (writerr)
+ die ("writing output failed\n");
+ gcry_free (buf);
+}
+
+
static void
list_curves (void)
{