2023-04-27 15:52:26 +00:00
|
|
|
diff -up openssh-9.3p1/ssh-rsa.c.evpgenrsa openssh-9.3p1/ssh-rsa.c
|
|
|
|
--- openssh-9.3p1/ssh-rsa.c.evpgenrsa 2022-06-30 15:14:58.200518353 +0200
|
|
|
|
+++ openssh-9.3p1/ssh-rsa.c 2022-06-30 15:24:31.499641196 +0200
|
2022-08-10 13:08:21 +00:00
|
|
|
@@ -1657,7 +1657,8 @@ sshkey_cert_type(const struct sshkey *k)
|
|
|
|
static int
|
2023-04-27 15:52:26 +00:00
|
|
|
ssh_rsa_generate(struct sshkey *k, int bits)
|
2022-08-10 13:08:21 +00:00
|
|
|
{
|
|
|
|
- RSA *private = NULL;
|
|
|
|
+ EVP_PKEY_CTX *ctx = NULL;
|
|
|
|
+ EVP_PKEY *res = NULL;
|
|
|
|
BIGNUM *f4 = NULL;
|
|
|
|
int ret = SSH_ERR_INTERNAL_ERROR;
|
|
|
|
|
2023-04-27 15:52:26 +00:00
|
|
|
@@ -1667,20 +1668,42 @@ ssh_rsa_generate(u_int bits, RSA
|
|
|
|
if (bits < SSH_RSA_MINIMUM_MODULUS_SIZE ||
|
2022-08-10 13:08:21 +00:00
|
|
|
bits > SSHBUF_MAX_BIGNUM * 8)
|
|
|
|
return SSH_ERR_KEY_LENGTH;
|
|
|
|
- if ((private = RSA_new()) == NULL || (f4 = BN_new()) == NULL) {
|
|
|
|
+
|
|
|
|
+ if ((ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL)) == NULL
|
|
|
|
+ || (f4 = BN_new()) == NULL || !BN_set_word(f4, RSA_F4)) {
|
|
|
|
ret = SSH_ERR_ALLOC_FAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
- if (!BN_set_word(f4, RSA_F4) ||
|
|
|
|
- !RSA_generate_key_ex(private, bits, f4, NULL)) {
|
|
|
|
+
|
|
|
|
+ if (EVP_PKEY_keygen_init(ctx) <= 0) {
|
|
|
|
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) <= 0) {
|
|
|
|
+ ret = SSH_ERR_KEY_LENGTH;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (EVP_PKEY_CTX_set1_rsa_keygen_pubexp(ctx, f4) <= 0)
|
|
|
|
+ goto out;
|
|
|
|
+
|
|
|
|
+ if (EVP_PKEY_keygen(ctx, &res) <= 0) {
|
|
|
|
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* This function is deprecated in OpenSSL 3.0 but OpenSSH doesn't worry about it*/
|
2023-04-27 15:52:26 +00:00
|
|
|
+ k->rsa = EVP_PKEY_get1_RSA(res);
|
|
|
|
+ if (k->rsa) {
|
2022-08-10 13:08:21 +00:00
|
|
|
+ ret = 0;
|
|
|
|
+ } else {
|
|
|
|
ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2023-04-27 15:52:26 +00:00
|
|
|
- k->rsa = private;
|
2022-08-10 13:08:21 +00:00
|
|
|
- private = NULL;
|
|
|
|
- ret = 0;
|
|
|
|
out:
|
|
|
|
- RSA_free(private);
|
|
|
|
+ EVP_PKEY_CTX_free(ctx);
|
|
|
|
+ EVP_PKEY_free(res);
|
|
|
|
BN_free(f4);
|
|
|
|
return ret;
|
|
|
|
}
|
2023-04-27 15:52:26 +00:00
|
|
|
diff -up openssh-9.3p1/ssh-ecdsa.c.evpgenrsa openssh-9.3p1/ssh-ecdsa.c
|
|
|
|
--- openssh-9.3p1/ssh-ecdsa.c.evpgenrsa 2022-06-30 15:14:58.200518353 +0200
|
|
|
|
+++ openssh-9.3p1/ssh-ecdsa.c 2022-06-30 15:24:31.499641196 +0200
|
2022-08-10 13:08:21 +00:00
|
|
|
@@ -1820,7 +1820,8 @@ sshkey_ecdsa_key_to_nid(EC_KEY *k)
|
|
|
|
static int
|
2023-04-27 15:52:26 +00:00
|
|
|
ssh_ecdsa_generate(struct sshkey *k, int bits)
|
2022-08-10 13:08:21 +00:00
|
|
|
{
|
|
|
|
- EC_KEY *private;
|
|
|
|
+ EVP_PKEY_CTX *ctx = NULL;
|
|
|
|
+ EVP_PKEY *res = NULL;
|
|
|
|
|
2023-04-27 15:52:26 +00:00
|
|
|
if ((k->ecdsa_nid = sshkey_ecdsa_bits_to_nid(bits)) == -1)
|
|
|
|
return SSH_ERR_KEY_LENGTH;
|
|
|
|
@@ -1828,15 +1829,24 @@ ssh_ecdsa_generate(u_int bits, i
|
|
|
|
|
|
|
|
if ((k->ecdsa_nid = sshkey_ecdsa_bits_to_nid(bits)) == -1)
|
2022-08-10 13:08:21 +00:00
|
|
|
return SSH_ERR_KEY_LENGTH;
|
2023-04-27 15:52:26 +00:00
|
|
|
- if ((private = EC_KEY_new_by_curve_name(k->ecdsa_nid)) == NULL)
|
2022-08-10 13:08:21 +00:00
|
|
|
+
|
2023-04-27 15:52:26 +00:00
|
|
|
+ if ((ctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL)) == NULL)
|
|
|
|
return SSH_ERR_ALLOC_FAIL;
|
2022-08-10 13:08:21 +00:00
|
|
|
- if (EC_KEY_generate_key(private) != 1) {
|
2023-04-27 15:52:26 +00:00
|
|
|
- EC_KEY_free(private);
|
|
|
|
- return SSH_ERR_LIBCRYPTO_ERROR;
|
|
|
|
- }
|
2022-08-10 13:08:21 +00:00
|
|
|
+
|
2023-04-27 15:52:26 +00:00
|
|
|
+ if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_CTX_set_group_name(ctx, OBJ_nid2sn(k->ecdsa_nid)) <= 0
|
2022-08-10 13:08:21 +00:00
|
|
|
+ || EVP_PKEY_keygen(ctx, &res) <= 0) {
|
2023-04-27 15:52:26 +00:00
|
|
|
+ EVP_PKEY_CTX_free(ctx);
|
|
|
|
+ EVP_PKEY_free(res);
|
|
|
|
+ return SSH_ERR_LIBCRYPTO_ERROR;
|
2022-08-10 13:08:21 +00:00
|
|
|
+ }
|
|
|
|
+ /* This function is deprecated in OpenSSL 3.0 but OpenSSH doesn't worry about it*/
|
2023-04-27 15:52:26 +00:00
|
|
|
+ k->ecdsa = EVP_PKEY_get1_EC_KEY(res);
|
|
|
|
+ if (k->ecdsa)
|
|
|
|
+ EC_KEY_set_asn1_flag(k->ecdsa, OPENSSL_EC_NAMED_CURVE);
|
|
|
|
+
|
2022-08-10 13:08:21 +00:00
|
|
|
- EC_KEY_set_asn1_flag(private, OPENSSL_EC_NAMED_CURVE);
|
2023-04-27 15:52:26 +00:00
|
|
|
- k->ecdsa = private;
|
|
|
|
- return 0;
|
2022-08-10 13:08:21 +00:00
|
|
|
+ EVP_PKEY_CTX_free(ctx);
|
|
|
|
+ EVP_PKEY_free(res);
|
2023-04-27 15:52:26 +00:00
|
|
|
+ return (k->ecdsa) ? 0 : SSH_ERR_LIBCRYPTO_ERROR;
|
2022-08-10 13:08:21 +00:00
|
|
|
}
|
2023-04-27 15:52:26 +00:00
|
|
|
|
|
|
|
static int
|