aboutsummaryrefslogtreecommitdiff
path: root/src/pki_gcrypt.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-09-05 11:02:23 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-09-05 11:28:19 +0200
commit808c7a9be4f110605e76ea5678bf0b1986cc9b38 (patch)
tree75823375575323a4b59aa6f9b381a0e3e0e2c183 /src/pki_gcrypt.c
parent6901e25085f8924f9d83e12107c05f935bd24287 (diff)
downloadlibssh-808c7a9be4f110605e76ea5678bf0b1986cc9b38.tar.gz
libssh-808c7a9be4f110605e76ea5678bf0b1986cc9b38.tar.xz
libssh-808c7a9be4f110605e76ea5678bf0b1986cc9b38.zip
pki: Add ssh_pki_export_pubkey_rsa1().
Diffstat (limited to 'src/pki_gcrypt.c')
-rw-r--r--src/pki_gcrypt.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index cf770611..6f3cd957 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -1145,6 +1145,51 @@ fail:
return NULL;
}
+int pki_export_pubkey_rsa1(const ssh_key key,
+ const char *host,
+ char *rsa1,
+ size_t rsa1_len)
+{
+ gcry_sexp_t sexp;
+ int rsa_size;
+ bignum b;
+ 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);
+ return SSH_ERROR;
+ }
+ n = bignum_bn2dec(b);
+
+ rsa_size = (gcry_pk_get_nbits(key->rsa) + 7) / 8;
+
+ snprintf(rsa1, rsa1_len,
+ "%s %d %s %s\n",
+ host, rsa_size << 3, e, n);
+ SAFE_FREE(e);
+ SAFE_FREE(n);
+
+ return SSH_OK;
+}
+
ssh_string pki_signature_to_blob(const ssh_signature sig)
{
char buffer[40] = {0};