From 8ac9e756d3ca545a9b97e61ad3d42fc2e877d788 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 8 Mar 2013 22:10:23 +0100 Subject: 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. --- src/visibility.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/visibility.h') diff --git a/src/visibility.h b/src/visibility.h index f4507ceb..90c6ad14 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -154,6 +154,7 @@ #define gcry_mpi_copy _gcry_mpi_copy #define gcry_mpi_div _gcry_mpi_div #define gcry_mpi_dump _gcry_mpi_dump +#define gcry_mpi_ec_p_new _gcry_mpi_ec_p_new #define gcry_mpi_gcd _gcry_mpi_gcd #define gcry_mpi_get_flag _gcry_mpi_get_flag #define gcry_mpi_get_nbits _gcry_mpi_get_nbits @@ -192,6 +193,8 @@ #define gcry_mpi_swap _gcry_mpi_swap #define gcry_mpi_test_bit _gcry_mpi_test_bit +#define gcry_ctx_release _gcry_ctx_release + /* Include the main header here so that public symbols are mapped to the internal underscored ones. */ @@ -367,6 +370,7 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_copy #undef gcry_mpi_div #undef gcry_mpi_dump +#undef gcry_mpi_ec_p_new #undef gcry_mpi_gcd #undef gcry_mpi_get_flag #undef gcry_mpi_get_nbits @@ -405,6 +409,8 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_swap #undef gcry_mpi_test_bit +#undef gcry_ctx_release + /* Now mark all symbols. */ @@ -540,6 +546,11 @@ MARK_VISIBLE (gcry_mpi_cmp_ui) MARK_VISIBLE (gcry_mpi_copy) MARK_VISIBLE (gcry_mpi_div) MARK_VISIBLE (gcry_mpi_dump) +MARK_VISIBLEX(gcry_mpi_ec_add) +MARK_VISIBLEX(gcry_mpi_ec_dup) +MARK_VISIBLEX(gcry_mpi_ec_get_affine) +MARK_VISIBLEX(gcry_mpi_ec_mul) +MARK_VISIBLE (gcry_mpi_ec_p_new) MARK_VISIBLE (gcry_mpi_gcd) MARK_VISIBLE (gcry_mpi_get_flag) MARK_VISIBLE (gcry_mpi_get_nbits) @@ -578,6 +589,7 @@ MARK_VISIBLE (gcry_mpi_subm) MARK_VISIBLE (gcry_mpi_swap) MARK_VISIBLE (gcry_mpi_test_bit) +MARK_VISIBLE (gcry_ctx_release) #undef MARK_VISIBLE -- cgit v1.2.1