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