aboutsummaryrefslogtreecommitdiff
path: root/src/pki_gcrypt.c
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2016-03-29 13:07:02 +0200
committerAndreas Schneider <asn@cryptomilk.org>2016-05-02 11:55:38 +0200
commite518ec1cb7c50a4070eed5a63541e77ed902617b (patch)
tree5144267736204e60bf22dc13736b9d66df22b5e5 /src/pki_gcrypt.c
parented34425306926ff174b8ab0f2004b995be450f75 (diff)
downloadlibssh-e518ec1cb7c50a4070eed5a63541e77ed902617b.tar.gz
libssh-e518ec1cb7c50a4070eed5a63541e77ed902617b.tar.xz
libssh-e518ec1cb7c50a4070eed5a63541e77ed902617b.zip
pki_gcrypt: Rework 'pki_export_pubkey_rsa1'
* src/pki_gcrypt.c (pki_export_pubkey_rsa1): Rework to be more idiomatic. Fix leaking MPIs. Signed-off-by: Justus Winter <justus@g10code.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/pki_gcrypt.c')
-rw-r--r--src/pki_gcrypt.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index fcbe8517..4865ea35 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -1189,34 +1189,17 @@ int pki_export_pubkey_rsa1(const ssh_key key,
char *rsa1,
size_t rsa1_len)
{
- gcry_sexp_t sexp;
+ gpg_error_t err;
int rsa_size;
- bignum b;
+ bignum E, N;
char *e, *n;
- sexp = gcry_sexp_find_token(key->rsa, "e", 0);
- if (sexp == NULL) {
- return SSH_ERROR;
- }
- b = gcry_sexp_nth_mpi(sexp, 1, GCRYMPI_FMT_USG);
- gcry_sexp_release(sexp);
- if (b == NULL) {
- return SSH_ERROR;
- }
- e = bignum_bn2dec(b);
-
- sexp = gcry_sexp_find_token(key->rsa, "n", 0);
- if (sexp == NULL) {
- SAFE_FREE(e);
- return SSH_ERROR;
- }
- b = gcry_sexp_nth_mpi(sexp, 1, GCRYMPI_FMT_USG);
- gcry_sexp_release(sexp);
- if (b == NULL) {
- SAFE_FREE(e);
+ err = gcry_sexp_extract_param(key->rsa, NULL, "en", &E, &N, NULL);
+ if (err != 0) {
return SSH_ERROR;
}
- n = bignum_bn2dec(b);
+ e = bignum_bn2dec(E);
+ n = bignum_bn2dec(N);
rsa_size = (gcry_pk_get_nbits(key->rsa) + 7) / 8;
@@ -1225,6 +1208,8 @@ int pki_export_pubkey_rsa1(const ssh_key key,
host, rsa_size << 3, e, n);
SAFE_FREE(e);
SAFE_FREE(n);
+ bignum_free(E);
+ bignum_free(N);
return SSH_OK;
}