mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
'g10/gpg2 --encrypt --debug 15 -r ecdsa -a -o _e.asc _' and 'g10/gpg2 --debug 15 _e.asc', as well as decoding of an old message posted on https://sites.google.com/site/brainhub/pgpecckeys work.
This is the milestone 2 that brings in ECDH support from http://code.google.com/p/gnupg-ecc/source/detail?r=15 . This corresponds to the commit 899386826c85f1e757e75bcc5d5b2159d05676a0 in libgcrypt
This commit is contained in:
parent
b0c55d08a8
commit
5761a9ba74
6 changed files with 73 additions and 131 deletions
74
g10/pkglue.c
74
g10/pkglue.c
|
@ -257,80 +257,6 @@ pk_encrypt (int algo, gcry_mpi_t * resarr, gcry_mpi_t data, const byte pk_fp[MAX
|
|||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************
|
||||
* Emulate our old PK interface here - sometime in the future we might
|
||||
* change the internal design to directly fit to libgcrypt.
|
||||
*/
|
||||
int
|
||||
pk_decrypt (int algo, gcry_mpi_t * result, const byte sk_fp[MAX_FINGERPRINT_LEN], gcry_mpi_t * data,
|
||||
gcry_mpi_t * skey)
|
||||
{
|
||||
gcry_sexp_t s_skey, s_data, s_plain;
|
||||
int rc;
|
||||
|
||||
*result = NULL;
|
||||
/* make a sexp from skey */
|
||||
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 || algo == GCRY_PK_RSA_E)
|
||||
{
|
||||
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 if( algo == PUBKEY_ALGO_ECDH ) {
|
||||
return pk_ecdh_decrypt( result, sk_fp, data, skey );
|
||||
}
|
||||
else
|
||||
return GPG_ERR_PUBKEY_ALGO;
|
||||
|
||||
if (rc)
|
||||
BUG ();
|
||||
|
||||
/* put data into a S-Exp s_data */
|
||||
if (algo == GCRY_PK_ELG || algo == GCRY_PK_ELG_E)
|
||||
{
|
||||
if (!data[0] || !data[1])
|
||||
rc = gpg_error (GPG_ERR_BAD_MPI);
|
||||
else
|
||||
rc = gcry_sexp_build (&s_data, NULL,
|
||||
"(enc-val(elg(a%m)(b%m)))", data[0], data[1]);
|
||||
}
|
||||
else if (algo == GCRY_PK_RSA || algo == GCRY_PK_RSA_E)
|
||||
{
|
||||
if (!data[0])
|
||||
rc = gpg_error (GPG_ERR_BAD_MPI);
|
||||
else
|
||||
rc = gcry_sexp_build (&s_data, NULL, "(enc-val(rsa(a%m)))", data[0]);
|
||||
}
|
||||
else
|
||||
BUG ();
|
||||
|
||||
if (rc)
|
||||
BUG ();
|
||||
|
||||
rc = gcry_pk_decrypt (&s_plain, s_data, s_skey);
|
||||
gcry_sexp_release (s_skey);
|
||||
gcry_sexp_release (s_data);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
*result = gcry_sexp_nth_mpi (s_plain, 0, 0);
|
||||
gcry_sexp_release (s_plain);
|
||||
if (!*result)
|
||||
return -1; /* oops */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Check whether SKEY is a suitable secret key. */
|
||||
int
|
||||
pk_check_secret_key (int algo, gcry_mpi_t *skey)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue