[openssl] master update

2021-10-06 Thread tomas
The branch master has been updated
   via  e8655e16cab9cd14ebfe9f2214c2f2aa39c67a26 (commit)
  from  64da15c40d15aac58e211fd25d00e9ae84d0379b (commit)


- Log -
commit e8655e16cab9cd14ebfe9f2214c2f2aa39c67a26
Author: Tomas Mraz 
Date:   Mon Oct 4 11:19:33 2021 +0200

s_socket.c: Avoid possible NULL pointer dereference

Reviewed-by: Dmitry Belyavskiy 
Reviewed-by: Bernd Edlinger 
(Merged from https://github.com/openssl/openssl/pull/16736)

---

Summary of changes:
 apps/lib/s_socket.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c
index 4e262e681d..805a1f0f3d 100644
--- a/apps/lib/s_socket.c
+++ b/apps/lib/s_socket.c
@@ -82,7 +82,6 @@ int init_client(int *sock, const char *host, const char *port,
 BIO_ADDRINFO *bindaddr = NULL;
 const BIO_ADDRINFO *ai = NULL;
 const BIO_ADDRINFO *bi = NULL;
-char *hostname = NULL;
 int found = 0;
 int ret;
 
@@ -173,10 +172,6 @@ int init_client(int *sock, const char *host, const char 
*port,
 break;
 }
 
-hostname = BIO_ADDR_hostname_string(BIO_ADDRINFO_address(ai), 1);
-BIO_printf(bio_out, "Connecting to %s\n", hostname);
-OPENSSL_free(hostname);
-
 if (*sock == INVALID_SOCKET) {
 if (bindaddr != NULL && !found) {
 BIO_printf(bio_err, "Can't bind %saddress for %s%s%s\n",
@@ -193,6 +188,13 @@ int init_client(int *sock, const char *host, const char 
*port,
 }
 ERR_print_errors(bio_err);
 } else {
+char *hostname = NULL;
+
+hostname = BIO_ADDR_hostname_string(BIO_ADDRINFO_address(ai), 1);
+if (hostname != NULL) {
+BIO_printf(bio_out, "Connecting to %s\n", hostname);
+OPENSSL_free(hostname);
+}
 /* Remove any stale errors from previous connection attempts */
 ERR_clear_error();
 ret = 1;


[openssl] master update

2021-10-06 Thread bernd . edlinger
The branch master has been updated
   via  64da15c40d15aac58e211fd25d00e9ae84d0379b (commit)
   via  39ed07454d8df794a36e2b6788043842a22b0909 (commit)
  from  6f6a5e0c7c41b6b3639e51f435cd98bb3ae061bc (commit)


- Log -
commit 64da15c40d15aac58e211fd25d00e9ae84d0379b
Author: Bernd Edlinger 
Date:   Sun May 24 16:14:02 2020 +0200

Replace the AES-128-CBC-HMAC-SHA1 cipher in e_ossltest.c

This replaces the AES-128-CBC-HMAC-SHA1 cipher with a
non-encrypting version for use the test suite.

[extended tests]

Reviewed-by: Tomas Mraz 
(Merged from https://github.com/openssl/openssl/pull/16693)

commit 39ed07454d8df794a36e2b6788043842a22b0909
Author: Bernd Edlinger 
Date:   Sun May 24 11:11:27 2020 +0200

Remove OPENSSL_ia32cap overrides in various test scripts

The removed override was: OPENSSL_ia32cap=~0x202
which disables AESNI codepaths and PCLMULQDQ (useful for ghash).
It is unclear why this was done, but it probably just hides bugs.

[extended tests]

Reviewed-by: Tomas Mraz 
(Merged from https://github.com/openssl/openssl/pull/16693)

---

Summary of changes:
 engines/e_ossltest.c  | 216 +++---
 ssl/record/ssl3_record.c  |  23 +---
 ssl/record/tls_pad.c  |   2 -
 ssl/tls_depr.c|  10 +-
 test/recipes/70-test_comp.t   |   2 -
 test/recipes/70-test_key_share.t  |   2 -
 test/recipes/70-test_renegotiation.t  |   1 -
 test/recipes/70-test_sslcbcpadding.t  |   1 -
 test/recipes/70-test_sslcertstatus.t  |   1 -
 test/recipes/70-test_sslextension.t   |   1 -
 test/recipes/70-test_sslmessages.t|   2 -
 test/recipes/70-test_sslrecords.t |   1 -
 test/recipes/70-test_sslsessiontick.t |   2 -
 test/recipes/70-test_sslsigalgs.t |   1 -
 test/recipes/70-test_sslsignature.t   |   1 -
 test/recipes/70-test_sslskewith0p.t   |   1 -
 test/recipes/70-test_sslversions.t|   2 -
 test/recipes/70-test_sslvertol.t  |   1 -
 test/recipes/70-test_tls13alerts.t|   2 -
 test/recipes/70-test_tls13cookie.t|   2 -
 test/recipes/70-test_tls13downgrade.t |   2 -
 test/recipes/70-test_tls13hrr.t   |   2 -
 test/recipes/70-test_tls13kexmodes.t  |   3 -
 test/recipes/70-test_tls13messages.t  |   2 -
 test/recipes/70-test_tls13psk.t   |   2 -
 test/recipes/70-test_tlsextms.t   |   2 -
 26 files changed, 210 insertions(+), 77 deletions(-)

diff --git a/engines/e_ossltest.c b/engines/e_ossltest.c
index 8479414f01..0506faa628 100644
--- a/engines/e_ossltest.c
+++ b/engines/e_ossltest.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "e_ossltest_err.c"
 
@@ -247,21 +248,39 @@ static int ossltest_ciphers(ENGINE *, const EVP_CIPHER **,
 const int **, int);
 
 static int ossltest_cipher_nids[] = {
-NID_aes_128_cbc, NID_aes_128_gcm, 0
+NID_aes_128_cbc, NID_aes_128_gcm,
+NID_aes_128_cbc_hmac_sha1, 0
 };
 
 /* AES128 */
 
-int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-   const unsigned char *in, size_t inl);
-int ossltest_aes128_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
-   const unsigned char *in, size_t inl);
+static int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx,
+const unsigned char *key,
+const unsigned char *iv, int enc);
+static int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
+  const unsigned char *in, size_t inl);
+static int ossltest_aes128_gcm_init_key(EVP_CIPHER_CTX *ctx,
+const unsigned char *key,
+const unsigned char *iv, int enc);
+static int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
+  const unsigned char *in, size_t inl);
 static int ossltest_aes128_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
 void *ptr);
+static int ossltest_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
+  const unsigned char *key,
+  const unsigned char *iv,
+  int enc);
+static int ossltest_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
+unsigned 

[openssl] OpenSSL_1_1_1-stable update

2021-10-06 Thread bernd . edlinger
The branch OpenSSL_1_1_1-stable has been updated
   via  2fd9c433712a08474af071cef538ffcd94dc4b57 (commit)
  from  1be120ac5bf613a7277250b6e73f3c60adad4517 (commit)


- Log -
commit 2fd9c433712a08474af071cef538ffcd94dc4b57
Author: Bernd Edlinger 
Date:   Mon Oct 4 19:45:19 2021 +0200

Fix a memory leak in the afalg engine

Fixes: #16743

Reviewed-by: Tomas Mraz 
(Merged from https://github.com/openssl/openssl/pull/16744)

(cherry picked from commit 6f6a5e0c7c41b6b3639e51f435cd98bb3ae061bc)

---

Summary of changes:
 engines/e_afalg.c |  7 ++-
 test/afalgtest.c  | 42 +++---
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/engines/e_afalg.c b/engines/e_afalg.c
index 4b17228461..ccf838a9ea 100644
--- a/engines/e_afalg.c
+++ b/engines/e_afalg.c
@@ -624,11 +624,8 @@ static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx)
 }
 
 actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx);
-if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) {
-ALG_WARN("%s afalg ctx passed\n",
- ctx == NULL ? "NULL" : "Uninitialised");
-return 0;
-}
+if (actx == NULL || actx->init_done != MAGIC_INIT_NUM)
+return 1;
 
 close(actx->sfd);
 close(actx->bfd);
diff --git a/test/afalgtest.c b/test/afalgtest.c
index adb2977f30..0bd5653dba 100644
--- a/test/afalgtest.c
+++ b/test/afalgtest.c
@@ -21,26 +21,7 @@
 
 #ifndef OPENSSL_NO_ENGINE
 static ENGINE *e;
-#endif
-
 
-#ifndef OPENSSL_NO_AFALGENG
-# include 
-# define K_MAJ   4
-# define K_MIN1  1
-# define K_MIN2  0
-# if LINUX_VERSION_CODE < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2)
-/*
- * If we get here then it looks like there is a mismatch between the linux
- * headers and the actual kernel version, so we have tried to compile with
- * afalg support, but then skipped it in e_afalg.c. As far as this test is
- * concerned we behave as if we had been configured without support
- */
-#  define OPENSSL_NO_AFALGENG
-# endif
-#endif
-
-#ifndef OPENSSL_NO_AFALGENG
 static int test_afalg_aes_cbc(int keysize_idx)
 {
 EVP_CIPHER_CTX *ctx;
@@ -112,9 +93,25 @@ static int test_afalg_aes_cbc(int keysize_idx)
 EVP_CIPHER_CTX_free(ctx);
 return ret;
 }
-#endif
 
-#ifndef OPENSSL_NO_ENGINE
+static int test_pr16743(void)
+{
+int ret = 0;
+const EVP_CIPHER * cipher;
+EVP_CIPHER_CTX *ctx;
+
+if (!TEST_true(ENGINE_init(e)))
+return 0;
+cipher = ENGINE_get_cipher(e, NID_aes_128_cbc);
+ctx = EVP_CIPHER_CTX_new();
+if (cipher != NULL && ctx != NULL)
+ret = EVP_EncryptInit_ex(ctx, cipher, e, NULL, NULL);
+TEST_true(ret);
+EVP_CIPHER_CTX_free(ctx);
+ENGINE_finish(e);
+return ret;
+}
+
 int global_init(void)
 {
 ENGINE_load_builtin_engines();
@@ -132,9 +129,8 @@ int setup_tests(void)
 /* Probably a platform env issue, not a test failure. */
 TEST_info("Can't load AFALG engine");
 } else {
-# ifndef OPENSSL_NO_AFALGENG
 ADD_ALL_TESTS(test_afalg_aes_cbc, 3);
-# endif
+ADD_TEST(test_pr16743);
 }
 #endif
 


[openssl] openssl-3.0 update

2021-10-06 Thread bernd . edlinger
The branch openssl-3.0 has been updated
   via  d5f6b038fe75f12603a67d0a67492aca4be9ccec (commit)
  from  d62c5d6be13cca99fa94e780e55a1c63445ad9cd (commit)


- Log -
commit d5f6b038fe75f12603a67d0a67492aca4be9ccec
Author: Bernd Edlinger 
Date:   Mon Oct 4 19:45:19 2021 +0200

Fix a memory leak in the afalg engine

Fixes: #16743

Reviewed-by: Tomas Mraz 
(Merged from https://github.com/openssl/openssl/pull/16744)

(cherry picked from commit 6f6a5e0c7c41b6b3639e51f435cd98bb3ae061bc)

---

Summary of changes:
 engines/e_afalg.c |  7 ++-
 test/afalgtest.c  | 42 +++---
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/engines/e_afalg.c b/engines/e_afalg.c
index d8d3ef610c..2c08cbb28d 100644
--- a/engines/e_afalg.c
+++ b/engines/e_afalg.c
@@ -683,11 +683,8 @@ static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx)
 }
 
 actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx);
-if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) {
-ALG_WARN("%s afalg ctx passed\n",
- ctx == NULL ? "NULL" : "Uninitialised");
-return 0;
-}
+if (actx == NULL || actx->init_done != MAGIC_INIT_NUM)
+return 1;
 
 close(actx->sfd);
 close(actx->bfd);
diff --git a/test/afalgtest.c b/test/afalgtest.c
index f0bdb26271..02947c1ed3 100644
--- a/test/afalgtest.c
+++ b/test/afalgtest.c
@@ -24,26 +24,7 @@
 
 #ifndef OPENSSL_NO_ENGINE
 static ENGINE *e;
-#endif
-
 
-#ifndef OPENSSL_NO_AFALGENG
-# include 
-# define K_MAJ   4
-# define K_MIN1  1
-# define K_MIN2  0
-# if LINUX_VERSION_CODE < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2)
-/*
- * If we get here then it looks like there is a mismatch between the linux
- * headers and the actual kernel version, so we have tried to compile with
- * afalg support, but then skipped it in e_afalg.c. As far as this test is
- * concerned we behave as if we had been configured without support
- */
-#  define OPENSSL_NO_AFALGENG
-# endif
-#endif
-
-#ifndef OPENSSL_NO_AFALGENG
 static int test_afalg_aes_cbc(int keysize_idx)
 {
 EVP_CIPHER_CTX *ctx;
@@ -127,9 +108,25 @@ static int test_afalg_aes_cbc(int keysize_idx)
 EVP_CIPHER_CTX_free(ctx);
 return ret;
 }
-#endif
 
-#ifndef OPENSSL_NO_ENGINE
+static int test_pr16743(void)
+{
+int ret = 0;
+const EVP_CIPHER * cipher;
+EVP_CIPHER_CTX *ctx;
+
+if (!TEST_true(ENGINE_init(e)))
+return 0;
+cipher = ENGINE_get_cipher(e, NID_aes_128_cbc);
+ctx = EVP_CIPHER_CTX_new();
+if (cipher != NULL && ctx != NULL)
+ret = EVP_EncryptInit_ex(ctx, cipher, e, NULL, NULL);
+TEST_true(ret);
+EVP_CIPHER_CTX_free(ctx);
+ENGINE_finish(e);
+return ret;
+}
+
 int global_init(void)
 {
 ENGINE_load_builtin_engines();
@@ -147,9 +144,8 @@ int setup_tests(void)
 /* Probably a platform env issue, not a test failure. */
 TEST_info("Can't load AFALG engine");
 } else {
-# ifndef OPENSSL_NO_AFALGENG
 ADD_ALL_TESTS(test_afalg_aes_cbc, 3);
-# endif
+ADD_TEST(test_pr16743);
 }
 #endif
 


[openssl] master update

2021-10-06 Thread bernd . edlinger
The branch master has been updated
   via  6f6a5e0c7c41b6b3639e51f435cd98bb3ae061bc (commit)
  from  59cd0bc1364b5ea817af7f6d36df89c93610cdb5 (commit)


- Log -
commit 6f6a5e0c7c41b6b3639e51f435cd98bb3ae061bc
Author: Bernd Edlinger 
Date:   Mon Oct 4 19:45:19 2021 +0200

Fix a memory leak in the afalg engine

Fixes: #16743

Reviewed-by: Tomas Mraz 
(Merged from https://github.com/openssl/openssl/pull/16744)

---

Summary of changes:
 engines/e_afalg.c |  7 ++-
 test/afalgtest.c  | 42 +++---
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/engines/e_afalg.c b/engines/e_afalg.c
index d8d3ef610c..2c08cbb28d 100644
--- a/engines/e_afalg.c
+++ b/engines/e_afalg.c
@@ -683,11 +683,8 @@ static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx)
 }
 
 actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx);
-if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) {
-ALG_WARN("%s afalg ctx passed\n",
- ctx == NULL ? "NULL" : "Uninitialised");
-return 0;
-}
+if (actx == NULL || actx->init_done != MAGIC_INIT_NUM)
+return 1;
 
 close(actx->sfd);
 close(actx->bfd);
diff --git a/test/afalgtest.c b/test/afalgtest.c
index f0bdb26271..02947c1ed3 100644
--- a/test/afalgtest.c
+++ b/test/afalgtest.c
@@ -24,26 +24,7 @@
 
 #ifndef OPENSSL_NO_ENGINE
 static ENGINE *e;
-#endif
-
 
-#ifndef OPENSSL_NO_AFALGENG
-# include 
-# define K_MAJ   4
-# define K_MIN1  1
-# define K_MIN2  0
-# if LINUX_VERSION_CODE < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2)
-/*
- * If we get here then it looks like there is a mismatch between the linux
- * headers and the actual kernel version, so we have tried to compile with
- * afalg support, but then skipped it in e_afalg.c. As far as this test is
- * concerned we behave as if we had been configured without support
- */
-#  define OPENSSL_NO_AFALGENG
-# endif
-#endif
-
-#ifndef OPENSSL_NO_AFALGENG
 static int test_afalg_aes_cbc(int keysize_idx)
 {
 EVP_CIPHER_CTX *ctx;
@@ -127,9 +108,25 @@ static int test_afalg_aes_cbc(int keysize_idx)
 EVP_CIPHER_CTX_free(ctx);
 return ret;
 }
-#endif
 
-#ifndef OPENSSL_NO_ENGINE
+static int test_pr16743(void)
+{
+int ret = 0;
+const EVP_CIPHER * cipher;
+EVP_CIPHER_CTX *ctx;
+
+if (!TEST_true(ENGINE_init(e)))
+return 0;
+cipher = ENGINE_get_cipher(e, NID_aes_128_cbc);
+ctx = EVP_CIPHER_CTX_new();
+if (cipher != NULL && ctx != NULL)
+ret = EVP_EncryptInit_ex(ctx, cipher, e, NULL, NULL);
+TEST_true(ret);
+EVP_CIPHER_CTX_free(ctx);
+ENGINE_finish(e);
+return ret;
+}
+
 int global_init(void)
 {
 ENGINE_load_builtin_engines();
@@ -147,9 +144,8 @@ int setup_tests(void)
 /* Probably a platform env issue, not a test failure. */
 TEST_info("Can't load AFALG engine");
 } else {
-# ifndef OPENSSL_NO_AFALGENG
 ADD_ALL_TESTS(test_afalg_aes_cbc, 3);
-# endif
+ADD_TEST(test_pr16743);
 }
 #endif
 


[openssl] master update

2021-10-06 Thread beldmit
The branch master has been updated
   via  59cd0bc1364b5ea817af7f6d36df89c93610cdb5 (commit)
  from  a596d38a8cddca4af3416b2664e120028d96e6a9 (commit)


- Log -
commit 59cd0bc1364b5ea817af7f6d36df89c93610cdb5
Author: Dmitry Belyavskiy 
Date:   Sun Oct 3 20:20:23 2021 +0200

Fix for the dasync engine

Fixes: #16724
Fixes: #16735

Reviewed-by: Matt Caswell 
(Merged from https://github.com/openssl/openssl/pull/16734)

---

Summary of changes:
 engines/e_dasync.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/engines/e_dasync.c b/engines/e_dasync.c
index e2e587d839..b775d59a2c 100644
--- a/engines/e_dasync.c
+++ b/engines/e_dasync.c
@@ -211,7 +211,8 @@ static int bind_dasync(ENGINE *e)
 /* Setup RSA */
 ;
 if ((dasync_rsa_orig = EVP_PKEY_meth_find(EVP_PKEY_RSA)) == NULL
-|| (dasync_rsa = EVP_PKEY_meth_new(EVP_PKEY_RSA, 0)) == NULL)
+|| (dasync_rsa = EVP_PKEY_meth_new(EVP_PKEY_RSA,
+   EVP_PKEY_FLAG_AUTOARGLEN)) == NULL)
 return 0;
 EVP_PKEY_meth_set_init(dasync_rsa, dasync_rsa_init);
 EVP_PKEY_meth_set_cleanup(dasync_rsa, dasync_rsa_cleanup);
@@ -312,7 +313,10 @@ static int bind_dasync(ENGINE *e)
 
 static void destroy_pkey(void)
 {
-EVP_PKEY_meth_free(dasync_rsa);
+/*
+ * We don't actually need to free the dasync_rsa method since this is
+ * automatically freed for us by libcrypto.
+ */
 dasync_rsa_orig = NULL;
 dasync_rsa = NULL;
 }
@@ -829,7 +833,7 @@ static int dasync_rsa_paramgen_init(EVP_PKEY_CTX *ctx)
 
 if (pparamgen_init == NULL)
 EVP_PKEY_meth_get_paramgen(dasync_rsa_orig, _init, NULL);
-return pparamgen_init(ctx);
+return pparamgen_init != NULL ? pparamgen_init(ctx) : 1;
 }
 
 static int dasync_rsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
@@ -838,7 +842,7 @@ static int dasync_rsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY 
*pkey)
 
 if (pparamgen == NULL)
 EVP_PKEY_meth_get_paramgen(dasync_rsa_orig, NULL, );
-return pparamgen(ctx, pkey);
+return pparamgen != NULL ? pparamgen(ctx, pkey) : 1;
 }
 
 static int dasync_rsa_keygen_init(EVP_PKEY_CTX *ctx)
@@ -847,7 +851,7 @@ static int dasync_rsa_keygen_init(EVP_PKEY_CTX *ctx)
 
 if (pkeygen_init == NULL)
 EVP_PKEY_meth_get_keygen(dasync_rsa_orig, _init, NULL);
-return pkeygen_init(ctx);
+return pkeygen_init != NULL ? pkeygen_init(ctx) : 1;
 }
 
 static int dasync_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
@@ -865,7 +869,7 @@ static int dasync_rsa_encrypt_init(EVP_PKEY_CTX *ctx)
 
 if (pencrypt_init == NULL)
 EVP_PKEY_meth_get_encrypt(dasync_rsa_orig, _init, NULL);
-return pencrypt_init(ctx);
+return pencrypt_init != NULL ? pencrypt_init(ctx) : 1;
 }
 
 static int dasync_rsa_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
@@ -887,7 +891,7 @@ static int dasync_rsa_decrypt_init(EVP_PKEY_CTX *ctx)
 
 if (pdecrypt_init == NULL)
 EVP_PKEY_meth_get_decrypt(dasync_rsa_orig, _init, NULL);
-return pdecrypt_init(ctx);
+return pdecrypt_init != NULL ? pdecrypt_init(ctx) : 1;
 }
 
 static int dasync_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out,


[openssl] openssl-3.0 update

2021-10-06 Thread beldmit
The branch openssl-3.0 has been updated
   via  d62c5d6be13cca99fa94e780e55a1c63445ad9cd (commit)
  from  7b4fccc8a53b6befc9dc1aa4204a87cf5050747c (commit)


- Log -
commit d62c5d6be13cca99fa94e780e55a1c63445ad9cd
Author: Dmitry Belyavskiy 
Date:   Sun Oct 3 20:20:23 2021 +0200

Fix for the dasync engine

Fixes: #16724
Fixes: #16735

Reviewed-by: Matt Caswell 
(Merged from https://github.com/openssl/openssl/pull/16734)

(cherry picked from commit 59cd0bc1364b5ea817af7f6d36df89c93610cdb5)

---

Summary of changes:
 engines/e_dasync.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/engines/e_dasync.c b/engines/e_dasync.c
index e2e587d839..b775d59a2c 100644
--- a/engines/e_dasync.c
+++ b/engines/e_dasync.c
@@ -211,7 +211,8 @@ static int bind_dasync(ENGINE *e)
 /* Setup RSA */
 ;
 if ((dasync_rsa_orig = EVP_PKEY_meth_find(EVP_PKEY_RSA)) == NULL
-|| (dasync_rsa = EVP_PKEY_meth_new(EVP_PKEY_RSA, 0)) == NULL)
+|| (dasync_rsa = EVP_PKEY_meth_new(EVP_PKEY_RSA,
+   EVP_PKEY_FLAG_AUTOARGLEN)) == NULL)
 return 0;
 EVP_PKEY_meth_set_init(dasync_rsa, dasync_rsa_init);
 EVP_PKEY_meth_set_cleanup(dasync_rsa, dasync_rsa_cleanup);
@@ -312,7 +313,10 @@ static int bind_dasync(ENGINE *e)
 
 static void destroy_pkey(void)
 {
-EVP_PKEY_meth_free(dasync_rsa);
+/*
+ * We don't actually need to free the dasync_rsa method since this is
+ * automatically freed for us by libcrypto.
+ */
 dasync_rsa_orig = NULL;
 dasync_rsa = NULL;
 }
@@ -829,7 +833,7 @@ static int dasync_rsa_paramgen_init(EVP_PKEY_CTX *ctx)
 
 if (pparamgen_init == NULL)
 EVP_PKEY_meth_get_paramgen(dasync_rsa_orig, _init, NULL);
-return pparamgen_init(ctx);
+return pparamgen_init != NULL ? pparamgen_init(ctx) : 1;
 }
 
 static int dasync_rsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
@@ -838,7 +842,7 @@ static int dasync_rsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY 
*pkey)
 
 if (pparamgen == NULL)
 EVP_PKEY_meth_get_paramgen(dasync_rsa_orig, NULL, );
-return pparamgen(ctx, pkey);
+return pparamgen != NULL ? pparamgen(ctx, pkey) : 1;
 }
 
 static int dasync_rsa_keygen_init(EVP_PKEY_CTX *ctx)
@@ -847,7 +851,7 @@ static int dasync_rsa_keygen_init(EVP_PKEY_CTX *ctx)
 
 if (pkeygen_init == NULL)
 EVP_PKEY_meth_get_keygen(dasync_rsa_orig, _init, NULL);
-return pkeygen_init(ctx);
+return pkeygen_init != NULL ? pkeygen_init(ctx) : 1;
 }
 
 static int dasync_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
@@ -865,7 +869,7 @@ static int dasync_rsa_encrypt_init(EVP_PKEY_CTX *ctx)
 
 if (pencrypt_init == NULL)
 EVP_PKEY_meth_get_encrypt(dasync_rsa_orig, _init, NULL);
-return pencrypt_init(ctx);
+return pencrypt_init != NULL ? pencrypt_init(ctx) : 1;
 }
 
 static int dasync_rsa_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out,
@@ -887,7 +891,7 @@ static int dasync_rsa_decrypt_init(EVP_PKEY_CTX *ctx)
 
 if (pdecrypt_init == NULL)
 EVP_PKEY_meth_get_decrypt(dasync_rsa_orig, _init, NULL);
-return pdecrypt_init(ctx);
+return pdecrypt_init != NULL ? pdecrypt_init(ctx) : 1;
 }
 
 static int dasync_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out,