aboutsummaryrefslogtreecommitdiff
path: root/src/pki_crypto.c
diff options
context:
space:
mode:
authorPetar Koretic <petar.koretic@sartura.hr>2014-03-16 10:20:44 +0000
committerAndreas Schneider <asn@cryptomilk.org>2014-03-27 10:11:24 +0100
commit0b8d24f800bae5f4f86c0eaca41c609f40d7baef (patch)
tree19d0041426ae3bca398dda5ca5da960501a0d320 /src/pki_crypto.c
parent48354f56ec86bcd23b0947e2eb4ce85b9cdebd0f (diff)
downloadlibssh-0b8d24f800bae5f4f86c0eaca41c609f40d7baef.tar.gz
libssh-0b8d24f800bae5f4f86c0eaca41c609f40d7baef.tar.xz
libssh-0b8d24f800bae5f4f86c0eaca41c609f40d7baef.zip
pki_crypto: Replace deprecated RSA_generate_key() with RSA_generate_key_ex()
On Mar 16, 09:41, Aris Adamantiadis wrote: > Hi Petar, > I agree with the principle, but I don't think this code can work... > RSA_generate_key takes an RSA* as parameter and in our code we probably > have key->rsa==NULL. (if we don't then the old code had a memory leak). > > Does the test case work ? > > Aris > Yes, you are right. This works, tested with tests/unittests/torture_pki Signed-off-by: Petar Koretic <petar.koretic@sartura.hr>
Diffstat (limited to 'src/pki_crypto.c')
-rw-r--r--src/pki_crypto.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index 89bb5385..ccf05f43 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -383,10 +383,20 @@ fail:
}
int pki_key_generate_rsa(ssh_key key, int parameter){
- key->rsa = RSA_generate_key(parameter, 65537, NULL, NULL);
- if(key->rsa == NULL)
- return SSH_ERROR;
- return SSH_OK;
+ BIGNUM *e;
+ int rc;
+
+ e = BN_new();
+ key->rsa = RSA_new();
+
+ BN_set_word(e, 65537);
+ rc = RSA_generate_key_ex(key->rsa, parameter, e, NULL);
+
+ BN_free(e);
+
+ if (rc == -1 || key->rsa == NULL)
+ return SSH_ERROR;
+ return SSH_OK;
}
int pki_key_generate_dss(ssh_key key, int parameter){