diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | doc/gcrypt.texi | 7 | ||||
-rw-r--r-- | mpi/ec.c | 14 | ||||
-rw-r--r-- | src/gcrypt-int.h | 3 | ||||
-rw-r--r-- | src/gcrypt.h.in | 4 | ||||
-rw-r--r-- | src/libgcrypt.def | 2 | ||||
-rw-r--r-- | src/libgcrypt.vers | 1 | ||||
-rw-r--r-- | src/visibility.c | 6 | ||||
-rw-r--r-- | src/visibility.h | 2 | ||||
-rw-r--r-- | tests/t-mpi-point.c | 17 |
10 files changed, 56 insertions, 1 deletions
@@ -72,6 +72,7 @@ Noteworthy changes in version 1.8.0 (unreleased) [C21/A1/R_] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRYCTL_REINIT_SYSCALL_CLAMP NEW macro. gcry_get_config NEW function. + gcry_mpi_point_copy NEW function. gcry_md_info DEPRECATED. diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index cab1318d..649332b4 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -4876,6 +4876,13 @@ Release @var{point} and free all associated resources. Passing @code{NULL} is allowed and ignored. @end deftypefun +@deftypefun gcry_mpi_point_t gcry_mpi_point_copy (@w{gcry_mpi_point_t @var{point}}) + +Allocate and return a new point object and initialize it with +@var{point}. If @var{point} is NULL the function is identical to +@code{gcry_mpi_point_new(0)}. +@end deftypefun + @deftypefun void gcry_mpi_point_get (@w{gcry_mpi_t @var{x}}, @ @w{gcry_mpi_t @var{y}}, @w{gcry_mpi_t @var{z}}, @ @w{gcry_mpi_point_t @var{point}}) @@ -139,6 +139,20 @@ point_set (mpi_point_t d, mpi_point_t s) } +/* Return a copy of POINT. */ +gcry_mpi_point_t +_gcry_mpi_point_copy (gcry_mpi_point_t point) +{ + mpi_point_t newpoint; + + newpoint = _gcry_mpi_point_new (0); + if (point) + point_set (newpoint, point); + + return newpoint; +} + + static void point_resize (mpi_point_t p, mpi_ec_t ctx) { diff --git a/src/gcrypt-int.h b/src/gcrypt-int.h index ef5337bb..ddcafa54 100644 --- a/src/gcrypt-int.h +++ b/src/gcrypt-int.h @@ -400,6 +400,7 @@ int _gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b); int _gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m); gcry_mpi_point_t _gcry_mpi_point_new (unsigned int nbits); void _gcry_mpi_point_release (gcry_mpi_point_t point); +gcry_mpi_point_t _gcry_mpi_point_copy (gcry_mpi_point_t point); void _gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point); void _gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, @@ -498,6 +499,8 @@ int _gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); } \ while (0) +#define mpi_point_copy(p) _gcry_mpi_point_copy((p)) + #define mpi_point_get(x,y,z,p) _gcry_mpi_point_get((x),(y),(z),(p)) #define mpi_point_snatch_get(x,y,z,p) _gcry_mpi_point_snatch_get((x),(y), \ (z),(p)) diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index 9a9acc4b..68c1f9e4 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -698,6 +698,9 @@ gcry_mpi_point_t gcry_mpi_point_new (unsigned int nbits); /* Release the object POINT. POINT may be NULL. */ void gcry_mpi_point_release (gcry_mpi_point_t point); +/* Return a copy of POINT. */ +gcry_mpi_point_t gcry_mpi_point_copy (gcry_mpi_point_t point); + /* Store the projective coordinates from POINT into X, Y, and Z. */ void gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point); @@ -868,6 +871,7 @@ gcry_mpi_t _gcry_mpi_get_const (int no); (p) = NULL; \ } \ while (0) +#define mpi_point_copy(p) gcry_mpi_point_copy((p)) #define mpi_point_get(x,y,z,p) gcry_mpi_point_get((x),(y),(z),(p)) #define mpi_point_snatch_get(x,y,z,p) gcry_mpi_point_snatch_get((x),(y),(z),(p)) #define mpi_point_set(p,x,y,z) gcry_mpi_point_set((p),(x),(y),(z)) diff --git a/src/libgcrypt.def b/src/libgcrypt.def index c4a9eacc..a76b3775 100644 --- a/src/libgcrypt.def +++ b/src/libgcrypt.def @@ -284,4 +284,6 @@ EXPORTS gcry_get_config @247 + gcry_mpi_point_copy @248 + ;; end of file with public symbols for Windows. diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers index 1d2d150a..1aa830f9 100644 --- a/src/libgcrypt.vers +++ b/src/libgcrypt.vers @@ -107,6 +107,7 @@ GCRYPT_1.6 { gcry_mpi_ec_get_affine; gcry_mpi_ec_dup; gcry_mpi_ec_add; gcry_mpi_ec_sub; gcry_mpi_ec_mul; gcry_mpi_ec_curve_point; gcry_mpi_ec_decode_point; + gcry_mpi_point_copy; gcry_log_debug; gcry_log_debughex; gcry_log_debugmpi; gcry_log_debugpnt; gcry_log_debugsxp; diff --git a/src/visibility.c b/src/visibility.c index fe46c82a..104c70d5 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -484,6 +484,12 @@ gcry_mpi_point_release (gcry_mpi_point_t point) _gcry_mpi_point_release (point); } +gcry_mpi_point_t +gcry_mpi_point_copy (gcry_mpi_point_t point) +{ + return _gcry_mpi_point_copy (point); +} + void gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, gcry_mpi_point_t point) diff --git a/src/visibility.h b/src/visibility.h index d28993a8..df2caf6f 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -246,6 +246,7 @@ MARK_VISIBLEX (gcry_mpi_new) MARK_VISIBLEX (gcry_mpi_point_get) MARK_VISIBLEX (gcry_mpi_point_new) MARK_VISIBLEX (gcry_mpi_point_release) +MARK_VISIBLEX (gcry_mpi_point_copy) MARK_VISIBLEX (gcry_mpi_point_set) MARK_VISIBLEX (gcry_mpi_point_snatch_get) MARK_VISIBLEX (gcry_mpi_point_snatch_set) @@ -466,6 +467,7 @@ MARK_VISIBLEX (_gcry_mpi_get_const) #define gcry_mpi_point_get _gcry_USE_THE_UNDERSCORED_FUNCTION #define gcry_mpi_point_new _gcry_USE_THE_UNDERSCORED_FUNCTION #define gcry_mpi_point_release _gcry_USE_THE_UNDERSCORED_FUNCTION +#define gcry_mpi_point_copy _gcry_USE_THE_UNDERSCORED_FUNCTION #define gcry_mpi_point_set _gcry_USE_THE_UNDERSCORED_FUNCTION #define gcry_mpi_point_snatch_get _gcry_USE_THE_UNDERSCORED_FUNCTION #define gcry_mpi_point_snatch_set _gcry_USE_THE_UNDERSCORED_FUNCTION diff --git a/tests/t-mpi-point.c b/tests/t-mpi-point.c index 9919932c..1eaa08a5 100644 --- a/tests/t-mpi-point.c +++ b/tests/t-mpi-point.c @@ -306,7 +306,7 @@ ec_p_new (gcry_ctx_t *r_ctx, gcry_mpi_t p, gcry_mpi_t a) static void set_get_point (void) { - gcry_mpi_point_t point; + gcry_mpi_point_t point, point2; gcry_mpi_t x, y, z; wherestr = "set_get_point"; @@ -350,7 +350,22 @@ set_get_point (void) || gcry_mpi_cmp_ui (y, 42) || gcry_mpi_cmp_ui (z, 11371)) fail ("point_snatch_set/point_get failed\n"); + point2 = gcry_mpi_point_copy (point); + + gcry_mpi_point_get (x, y, z, point2); + if (gcry_mpi_cmp_ui (x, 17) + || gcry_mpi_cmp_ui (y, 42) || gcry_mpi_cmp_ui (z, 11371)) + fail ("point_copy failed (1)\n"); + gcry_mpi_point_release (point); + + gcry_mpi_point_get (x, y, z, point2); + if (gcry_mpi_cmp_ui (x, 17) + || gcry_mpi_cmp_ui (y, 42) || gcry_mpi_cmp_ui (z, 11371)) + fail ("point_copy failed (2)\n"); + + gcry_mpi_point_release (point2); + gcry_mpi_release (x); gcry_mpi_release (y); gcry_mpi_release (z); |