From 13e988b6ee852b0ed71b9336c4aeed55823cc167 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 9 Jan 2020 19:16:29 +0000 Subject: [PATCH] Factor out rsa_ssh1_private_blob_agent and expose in testcrypt. This will come in useful in an upcoming testcrypt-using Python script. --- pageant.c | 8 +------- ssh.h | 1 + sshrsa.c | 9 +++++++++ testcrypt.h | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pageant.c b/pageant.c index 70b21743..2391fa77 100644 --- a/pageant.c +++ b/pageant.c @@ -1247,13 +1247,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase, request = strbuf_new_for_agent_query(); put_byte(request, SSH1_AGENTC_ADD_RSA_IDENTITY); - put_uint32(request, mp_get_nbits(rkey->modulus)); - put_mp_ssh1(request, rkey->modulus); - put_mp_ssh1(request, rkey->exponent); - put_mp_ssh1(request, rkey->private_exponent); - put_mp_ssh1(request, rkey->iqmp); - put_mp_ssh1(request, rkey->q); - put_mp_ssh1(request, rkey->p); + rsa_ssh1_private_blob_agent(BinarySink_UPCAST(request), rkey); put_stringz(request, rkey->comment); agent_query_synchronous(request, &vresponse, &resplen); strbuf_free(request); diff --git a/ssh.h b/ssh.h index e3acf5be..e25313c0 100644 --- a/ssh.h +++ b/ssh.h @@ -551,6 +551,7 @@ char *rsa_ssh1_fingerprint(RSAKey *key); bool rsa_verify(RSAKey *key); void rsa_ssh1_public_blob(BinarySink *bs, RSAKey *key, RsaSsh1Order order); int rsa_ssh1_public_blob_len(ptrlen data); +void rsa_ssh1_private_blob_agent(BinarySink *bs, RSAKey *key); void freersapriv(RSAKey *key); void freersakey(RSAKey *key); diff --git a/sshrsa.c b/sshrsa.c index 2f68c663..b98388cd 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -374,6 +374,15 @@ void rsa_ssh1_public_blob(BinarySink *bs, RSAKey *key, } } +void rsa_ssh1_private_blob_agent(BinarySink *bs, RSAKey *key) +{ + rsa_ssh1_public_blob(bs, key, RSA_SSH1_MODULUS_FIRST); + put_mp_ssh1(bs, key->private_exponent); + put_mp_ssh1(bs, key->iqmp); + put_mp_ssh1(bs, key->q); + put_mp_ssh1(bs, key->p); +} + /* Given an SSH-1 public key blob, determine its length. */ int rsa_ssh1_public_blob_len(ptrlen data) { diff --git a/testcrypt.h b/testcrypt.h index ded05d48..a04672c3 100644 --- a/testcrypt.h +++ b/testcrypt.h @@ -214,6 +214,7 @@ FUNC1(val_string_asciz, rsastr_fmt, val_rsa) FUNC1(val_string_asciz, rsa_ssh1_fingerprint, val_rsa) FUNC3(void, rsa_ssh1_public_blob, out_val_string_binarysink, val_rsa, rsaorder) FUNC1(int, rsa_ssh1_public_blob_len, val_string_ptrlen) +FUNC2(void, rsa_ssh1_private_blob_agent, out_val_string_binarysink, val_rsa) /* * The PRNG type. Similarly to hashes and MACs, I've invented an extra