summaryrefslogtreecommitdiffstats
path: root/g10/pkglue.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2003-08-05 19:11:04 +0200
committerWerner Koch <wk@gnupg.org>2003-08-05 19:11:04 +0200
commit1bcf8ef9dea1a9b171c27ef48cadb79df6201e33 (patch)
tree2ad720429f4b04941ebf0fcbe005e63c89fe69c6 /g10/pkglue.c
parentThis commit was manufactured by cvs2svn to create branch (diff)
downloadgnupg2-1bcf8ef9dea1a9b171c27ef48cadb79df6201e33.tar.xz
gnupg2-1bcf8ef9dea1a9b171c27ef48cadb79df6201e33.zip
Cleanups, fixes and PC/SC support
Diffstat (limited to 'g10/pkglue.c')
-rw-r--r--g10/pkglue.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/g10/pkglue.c b/g10/pkglue.c
index 7920a5223..015aaf9ff 100644
--- a/g10/pkglue.c
+++ b/g10/pkglue.c
@@ -287,8 +287,39 @@ pk_decrypt (int algo, gcry_mpi_t * result, gcry_mpi_t * data,
}
+/* Check whether SKEY is a suitable secret key. */
+int
+pk_check_secret_key (int algo, gcry_mpi_t *skey)
+{
+ gcry_sexp_t s_skey;
+ int rc;
+ if (algo == GCRY_PK_DSA)
+ {
+ rc = gcry_sexp_build (&s_skey, NULL,
+ "(private-key(dsa(p%m)(q%m)(g%m)(y%m)(x%m)))",
+ skey[0], skey[1], skey[2], skey[3], skey[4]);
+ }
+ else if (algo == GCRY_PK_ELG || algo == GCRY_PK_ELG_E)
+ {
+ rc = gcry_sexp_build (&s_skey, NULL,
+ "(private-key(elg(p%m)(g%m)(y%m)(x%m)))",
+ skey[0], skey[1], skey[2], skey[3]);
+ }
+ else if (algo == GCRY_PK_RSA)
+ {
+ rc = gcry_sexp_build (&s_skey, NULL,
+ "(private-key(rsa(n%m)(e%m)(d%m)(p%m)(q%m)(u%m)))",
+ skey[0], skey[1], skey[2], skey[3], skey[4],
+ skey[5]);
+ }
+ else
+ return GPG_ERR_PUBKEY_ALGO;
-
-
-
+ if (!rc)
+ {
+ rc = gcry_pk_testkey (s_skey);
+ gcry_sexp_release (s_skey);
+ }
+ return rc;
+}