diff options
author | Werner Koch <wk@gnupg.org> | 2013-03-08 22:10:23 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-03-08 22:13:52 +0100 |
commit | 8ac9e756d3ca545a9b97e61ad3d42fc2e877d788 (patch) | |
tree | 9c371da68f09dca2379381529f9d7810957260b2 /src/visibility.c | |
parent | 7cce620acddac2df024ca421ed3abc32a88f3738 (diff) | |
download | libgcrypt-8ac9e756d3ca545a9b97e61ad3d42fc2e877d788.tar.gz |
mpi: Add an API for EC math.
* src/context.c, src/context.h: New.
* src/Makefile.am (libgcrypt_la_SOURCES): Add new files.
* src/gcrypt.h.in (struct gcry_context, gcry_ctx_t): New types.
(gcry_ctx_release): New prototype.
(gcry_mpi_ec_p_new, gcry_mpi_ec_get_affine, gcry_mpi_ec_dup)
(gcry_mpi_ec_add, gcry_mpi_ec_mul): New prototypes.
* mpi/ec.c: Include errno.h and context.h.
(_gcry_mpi_ec_init): Rename to ..
(ec_p_init): this, make static, remove allocation and add arg CTX.
(_gcry_mpi_ec_p_internal_new): New; to replace _gcry_mpi_ec_init.
Change all callers to use this func.
(_gcry_mpi_ec_free): Factor code out to ..
(ec_deinit): New func.
(gcry_mpi_ec_p_new): New.
* src/visibility.c: Include context.h and mpi.h.
(gcry_mpi_ec_p_new, gcry_mpi_ec_get_affine, gcry_mpi_ec_dup)
(gcry_mpi_ec_add, gcry_mpi_ec_mul)
(gcry_ctx_release): New wrapper functions.
* src/visibility.h: Mark new wrapper functions visible.
* src/libgcrypt.def, src/libgcrypt.vers: Add new symbols.
* tests/t-mpi-point.c (print_mpi, hex2mpi, cmp_mpihex): New.
(context_alloc): New.
(make_point, basic_ec_math): New.
--
This part finishes the basic API to do EC math. It provides a wrapper
around all internal functions. tests/t-mpi-point.c may be useful as
sample code. Eventually we will add function to retrieve curve
parameters etc.
Diffstat (limited to 'src/visibility.c')
-rw-r--r-- | src/visibility.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/visibility.c b/src/visibility.c index 1fb29f2b..5c3216d2 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -24,8 +24,8 @@ #define _GCRY_INCLUDED_BY_VISIBILITY_C #include "g10lib.h" #include "cipher-proto.h" - - +#include "context.h" +#include "mpi.h" const char * gcry_strerror (gcry_error_t err) @@ -461,6 +461,42 @@ gcry_mpi_point_snatch_set (gcry_mpi_point_t point, return _gcry_mpi_point_snatch_set (point, x, y, z); } +gcry_ctx_t +gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a) +{ + return _gcry_mpi_ec_p_new (p, a); +} + +int +gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point, + gcry_ctx_t ctx) +{ + return _gcry_mpi_ec_get_affine (x, y, point, + _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + +void +gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx) +{ + _gcry_mpi_ec_dup_point (w, u, _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + +void +gcry_mpi_ec_add (gcry_mpi_point_t w, + gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx) +{ + _gcry_mpi_ec_add_points (w, u, v, + _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + +void +gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u, + gcry_ctx_t ctx) +{ + _gcry_mpi_ec_mul_point (w, n, u, + _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + unsigned int gcry_mpi_get_nbits (gcry_mpi_t a) { @@ -1067,6 +1103,12 @@ gcry_prime_check (gcry_mpi_t x, unsigned int flags) } void +gcry_ctx_release (gcry_ctx_t ctx) +{ + _gcry_ctx_release (ctx); +} + +void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data) { _gcry_set_progress_handler (cb, cb_data); |