summaryrefslogtreecommitdiff
path: root/mpi/ec.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-16 14:40:40 +0200
commit8ebc94d11a1eb93f2365c93f555e958700fdfbd4 (patch)
tree57d37dae72c2e1f8dc147660745e52adecac37fd /mpi/ec.c
parent58eaf0c4332ac2f645ede28c4d18337389dfa753 (diff)
downloadlibgcrypt-8ebc94d11a1eb93f2365c93f555e958700fdfbd4.tar.gz
mpi: Add debug function to print a point.
* mpi/ec.c (_gcry_mpi_point_log): New. * src/mpi.h (log_printpnt): new macro. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'mpi/ec.c')
-rw-r--r--mpi/ec.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/mpi/ec.c b/mpi/ec.c
index 049afa9e..46cc2705 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -34,6 +34,45 @@
#define point_free(a) _gcry_mpi_point_free_parts ((a))
+/* Print a point using the log fucntions. If CTX is not NULL affine
+ coordinates will be printed. */
+void
+_gcry_mpi_point_log (const char *name, mpi_point_t point, mpi_ec_t ctx)
+{
+ gcry_mpi_t x, y;
+ char buf[100];
+
+ snprintf (buf, sizeof buf - 1, "%s.X", name);
+
+ if (ctx)
+ {
+ x = gcry_mpi_new (0);
+ y = gcry_mpi_new (0);
+ }
+ if (!ctx || _gcry_mpi_ec_get_affine (x, y, point, ctx))
+ {
+ log_mpidump (buf, point->x);
+ buf[strlen(buf)-1] = 'Y';
+ log_mpidump (buf, point->y);
+ buf[strlen(buf)-1] = 'Z';
+ log_mpidump (buf, point->z);
+ }
+ else
+ {
+ buf[strlen(buf)-1] = 'x';
+ log_mpidump (buf, x);
+ buf[strlen(buf)-1] = 'y';
+ log_mpidump (buf, y);
+
+ }
+ if (ctx)
+ {
+ gcry_mpi_release (x);
+ gcry_mpi_release (y);
+ }
+}
+
+
/* Create a new point option. NBITS gives the size in bits of one
coordinate; it is only used to pre-allocate some resources and
might also be passed as 0 to use a default value. */