summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-04-11 20:27:46 +0200
committerWerner Koch <wk@gnupg.org>2013-04-11 20:27:46 +0200
commit1f3cfad66456dd6f2e48f20b8eb0c51343449a1c (patch)
tree46076f365f00ae81e800a7a30bdcf3d5ab69192d /src
parenta4e1f6ae7ea7f140e36c331a362bc299dce08416 (diff)
downloadlibgcrypt-1f3cfad66456dd6f2e48f20b8eb0c51343449a1c.tar.gz
Add gcry_pubkey_get_sexp.
* src/gcrypt.h.in (GCRY_PK_GET_PUBKEY): New. (GCRY_PK_GET_SECKEY): New. (gcry_pubkey_get_sexp): New. * src/visibility.c (gcry_pubkey_get_sexp): New. * src/visibility.h (gcry_pubkey_get_sexp): Mark visible. * src/libgcrypt.def, src/libgcrypt.vers: Add new function. * cipher/pubkey-internal.h: New. * cipher/Makefile.am (libcipher_la_SOURCES): Add new file. * cipher/ecc.c: Include pubkey-internal.h (_gcry_pk_ecc_get_sexp): New. * cipher/pubkey.c: Include pubkey-internal.h and context.h. (_gcry_pubkey_get_sexp): New. * src/context.c (_gcry_ctx_find_pointer): New. * src/cipher-proto.h: Add _gcry_pubkey_get_sexp. * tests/t-mpi-point.c (print_sexp): New. (context_param, basic_ec_math_simplified): Add tests for the new function. * configure.ac (NEED_GPG_ERROR_VERSION): Set to 1.11. (AH_BOTTOM) Add error codes from gpg-error 1.12 * src/g10lib.h (fips_not_operational): Use GPG_ERR_NOT_OPERATIONAL. * mpi/ec.c (_gcry_mpi_ec_get_mpi): Fix computation of Q. (_gcry_mpi_ec_get_point): Ditto. -- While checking the new code I figured that the auto-computation of Q must have led to a segv. It seems we had no test case for that. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src')
-rw-r--r--src/cipher-proto.h6
-rw-r--r--src/context.c19
-rw-r--r--src/context.h1
-rw-r--r--src/g10lib.h2
-rw-r--r--src/gcrypt.h.in7
-rw-r--r--src/libgcrypt.def2
-rw-r--r--src/libgcrypt.vers2
-rw-r--r--src/visibility.c11
-rw-r--r--src/visibility.h1
9 files changed, 50 insertions, 1 deletions
diff --git a/src/cipher-proto.h b/src/cipher-proto.h
index 347681ff..e2f913df 100644
--- a/src/cipher-proto.h
+++ b/src/cipher-proto.h
@@ -121,4 +121,10 @@ gcry_error_t _gcry_hmac_selftest (int algo, int extended,
gcry_error_t _gcry_random_selftest (selftest_report_func_t report);
+
+/*-- pubkey.c --*/
+gcry_err_code_t _gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp,
+ int reserved, gcry_ctx_t ctx);
+
+
#endif /*G10_CIPHER_PROTO_H*/
diff --git a/src/context.c b/src/context.c
index 2c02c9c4..1b8090de 100644
--- a/src/context.c
+++ b/src/context.c
@@ -94,6 +94,25 @@ _gcry_ctx_get_pointer (gcry_ctx_t ctx, int type)
return &ctx->u;
}
+/* Return a pointer to the private part of the context CTX. TYPE is
+ the requested context type. Using an explicit type allows to cross
+ check the type and eventually allows to store several private
+ contexts in one context object. In contrast to
+ _gcry_ctx_get_pointer, this function returns NULL if no context for
+ the given type was found. If CTX is NULL the function does not
+ abort but returns NULL. */
+void *
+_gcry_ctx_find_pointer (gcry_ctx_t ctx, int type)
+{
+ if (!ctx)
+ return NULL;
+ if (memcmp (ctx->magic, CTX_MAGIC, CTX_MAGIC_LEN))
+ log_fatal ("bad pointer %p passed to _gcry_ctx_get_pointer\n", ctx);
+ if (ctx->type != type)
+ return NULL;
+ return &ctx->u;
+}
+
/* Release the generic context CTX. */
void
diff --git a/src/context.h b/src/context.h
index 72f14d48..875de243 100644
--- a/src/context.h
+++ b/src/context.h
@@ -26,6 +26,7 @@
gcry_ctx_t _gcry_ctx_alloc (int type, size_t length, void (*deinit)(void*));
void *_gcry_ctx_get_pointer (gcry_ctx_t ctx, int type);
+void *_gcry_ctx_find_pointer (gcry_ctx_t ctx, int type);
#endif /*GCRY_CONTEXT_H*/
diff --git a/src/g10lib.h b/src/g10lib.h
index d1bcfa9a..23ea0960 100644
--- a/src/g10lib.h
+++ b/src/g10lib.h
@@ -394,7 +394,7 @@ void _gcry_fips_signal_error (const char *srcfile,
int _gcry_fips_is_operational (void);
#define fips_is_operational() (_gcry_global_is_operational ())
-#define fips_not_operational() (GCRY_GPG_ERR_NOT_OPERATIONAL)
+#define fips_not_operational() (GPG_ERR_NOT_OPERATIONAL)
int _gcry_fips_test_operational (void);
int _gcry_fips_test_error_or_operational (void);
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index 72fb6d33..85213ea4 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -944,6 +944,10 @@ enum gcry_pk_algos
#define GCRY_PK_USAGE_AUTH 8 /* Good for authentication. */
#define GCRY_PK_USAGE_UNKN 128 /* Unknown usage flag. */
+/* Modes used with gcry_pubkey_get_sexp. */
+#define GCRY_PK_GET_PUBKEY 1
+#define GCRY_PK_GET_SECKEY 2
+
/* Encrypt the DATA using the public key PKEY and store the result as
a newly created S-expression at RESULT. */
gcry_error_t gcry_pk_encrypt (gcry_sexp_t *result,
@@ -1007,6 +1011,9 @@ gcry_sexp_t gcry_pk_get_param (int algo, const char *name);
#define gcry_pk_test_algo(a) \
gcry_pk_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
+/* Return an S-expression representing the context CTX. */
+gcry_error_t gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp,
+ int mode, gcry_ctx_t ctx);
diff --git a/src/libgcrypt.def b/src/libgcrypt.def
index 061c7e36..4da46232 100644
--- a/src/libgcrypt.def
+++ b/src/libgcrypt.def
@@ -232,3 +232,5 @@ EXPORTS
gcry_mpi_ec_dup @209
gcry_mpi_ec_add @210
gcry_mpi_ec_mul @211
+
+ gcry_pubkey_get_sexp @212
diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers
index 65959d36..29e46dbe 100644
--- a/src/libgcrypt.vers
+++ b/src/libgcrypt.vers
@@ -58,6 +58,8 @@ GCRYPT_1.6 {
gcry_pk_testkey; gcry_pk_verify;
gcry_pk_get_curve; gcry_pk_get_param;
+ gcry_pubkey_get_sexp;
+
gcry_kdf_derive;
gcry_prime_check; gcry_prime_generate;
diff --git a/src/visibility.c b/src/visibility.c
index ed68b860..b503be66 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -862,6 +862,17 @@ gcry_pk_get_param (int algo, const char *name)
}
gcry_error_t
+gcry_pubkey_get_sexp (gcry_sexp_t *r_sexp, int mode, gcry_ctx_t ctx)
+{
+ if (!fips_is_operational ())
+ {
+ *r_sexp = NULL;
+ return gpg_error (fips_not_operational ());
+ }
+ return gpg_error (_gcry_pubkey_get_sexp (r_sexp, mode, ctx));
+}
+
+gcry_error_t
gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags)
{
if (!fips_is_operational ())
diff --git a/src/visibility.h b/src/visibility.h
index 031537a1..1564e865 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -494,6 +494,7 @@ MARK_VISIBLE (gcry_pk_map_name)
MARK_VISIBLE (gcry_pk_sign)
MARK_VISIBLE (gcry_pk_testkey)
MARK_VISIBLE (gcry_pk_verify)
+MARK_VISIBLEX(gcry_pubkey_get_sexp)
MARK_VISIBLE (gcry_kdf_derive)