aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2020-10-09 13:53:23 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2020-10-09 13:57:35 +0900
commit228836f79f64559c9582ac2d475e50af57684bf8 (patch)
tree291bd42f4c0eb1fbb2c259ff5d96f5dd9e690ed2
parent33cb1655f1b7c597d1ebdcb38447648477e6ac9f (diff)
downloadgnupg-228836f79f64559c9582ac2d475e50af57684bf8.tar.gz
gpg,ecc: Fix SOS handling when receiving from agent.
* g10/export.c (transfer_format_to_openpgp): It's not simple opaque MPI, but SOS. -- Fixes-commit: f5bc94555458123f93d8b07816a68fb7485421e1 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--g10/export.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/g10/export.c b/g10/export.c
index 08b161835..a9eba1544 100644
--- a/g10/export.c
+++ b/g10/export.c
@@ -982,11 +982,26 @@ transfer_format_to_openpgp (gcry_sexp_t s_pgp, PKT_public_key *pk)
|| pk->pubkey_algo == PUBKEY_ALGO_EDDSA
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
{
- skey[skeyidx] = gcry_mpi_set_opaque_copy (NULL, value, valuelen*8);
+ unsigned int nbits = valuelen*8;
+ const unsigned char *p = value;
+
+ if (nbits >= 8 && !(*p & 0x80))
+ if (--nbits >= 7 && !(*p & 0x40))
+ if (--nbits >= 6 && !(*p & 0x20))
+ if (--nbits >= 5 && !(*p & 0x10))
+ if (--nbits >= 4 && !(*p & 0x08))
+ if (--nbits >= 3 && !(*p & 0x04))
+ if (--nbits >= 2 && !(*p & 0x02))
+ if (--nbits >= 1 && !(*p & 0x01))
+ --nbits;
+
+ skey[skeyidx] = gcry_mpi_set_opaque_copy (NULL, value, nbits);
if (!skey[skeyidx])
goto outofmem;
if (is_enc)
gcry_mpi_set_flag (skey[skeyidx], GCRYMPI_FLAG_USER1);
+ else
+ gcry_mpi_set_flag (skey[skeyidx], GCRYMPI_FLAG_USER2);
}
else
{