c2f9ab
From c80991c79f701dac42c630af4bd39593b0c7efb4 Mon Sep 17 00:00:00 2001
c2f9ab
From: Vladislav Vaintroub <wlad@mariadb.com>
c2f9ab
Date: Mon, 8 Nov 2021 18:48:19 +0100
c2f9ab
Subject: [PATCH] MDEV-25785 Add support for OpenSSL 3.0
c2f9ab
c2f9ab
Summary of changes
c2f9ab
c2f9ab
- MD_CTX_SIZE is increased
c2f9ab
c2f9ab
- EVP_CIPHER_CTX_buf_noconst(ctx) does not work anymore, points
c2f9ab
  to nobody knows where. The assumption made previously was that
c2f9ab
  (since the function does not seem to be documented)
c2f9ab
  was that it points to the last partial source block.
c2f9ab
  Add own partial block buffer for NOPAD encryption instead
c2f9ab
c2f9ab
- SECLEVEL in CipherString in openssl.cnf
c2f9ab
  had been downgraded to 0, from 1, to make TLSv1.0 and TLSv1.1 possible
c2f9ab
c2f9ab
- Workaround Ssl_cipher_list issue, it now returns TLSv1.3 ciphers,
c2f9ab
  in addition to what was set in --ssl-cipher
c2f9ab
c2f9ab
- ctx_buf buffer now must be aligned to 16 bytes with openssl(
c2f9ab
  previously with WolfSSL only), ot crashes will happen
c2f9ab
c2f9ab
- updated aes-t , to be better debuggable
c2f9ab
  using function, rather than a huge multiline macro
c2f9ab
  added test that does "nopad" encryption piece-wise, to test
c2f9ab
  replacement of EVP_CIPHER_CTX_buf_noconst
c2f9ab
---
c2f9ab
 cmake/ssl.cmake                   |  19 ++++-
c2f9ab
 include/ssl_compat.h              |   3 +-
c2f9ab
 mysql-test/lib/openssl.cnf        |   2 +-
c2f9ab
 mysql-test/main/ssl_cipher.result |   6 +-
c2f9ab
 mysql-test/main/ssl_cipher.test   |   2 +-
c2f9ab
 mysys_ssl/my_crypt.cc             |  46 +++++++-----
c2f9ab
 unittest/mysys/aes-t.c            | 121 ++++++++++++++++++++++--------
c2f9ab
 7 files changed, 141 insertions(+), 58 deletions(-)
c2f9ab
c2f9ab
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/cmake/ssl.cmake.patch16 mariadb-10.5.12-downstream_modified/cmake/ssl.cmake
c2f9ab
--- mariadb-10.5.12-downstream_modified/cmake/ssl.cmake.patch16	2021-08-03 10:29:07.000000000 +0200
c2f9ab
+++ mariadb-10.5.12-downstream_modified/cmake/ssl.cmake	2021-11-18 16:58:41.552440737 +0100
c2f9ab
@@ -139,9 +139,20 @@ MACRO (MYSQL_CHECK_SSL)
c2f9ab
       SET(SSL_INTERNAL_INCLUDE_DIRS "")
c2f9ab
       SET(SSL_DEFINES "-DHAVE_OPENSSL")
c2f9ab
 
c2f9ab
+      FOREACH(x INCLUDES LIBRARIES DEFINITIONS)
c2f9ab
+        SET(SAVE_CMAKE_REQUIRED_${x} ${CMAKE_REQUIRED_${x}})
c2f9ab
+      ENDFOREACH()
c2f9ab
+
c2f9ab
+      # Silence "deprecated in OpenSSL 3.0"
c2f9ab
+      IF((NOT OPENSSL_VERSION) # 3.0 not determined by older cmake
c2f9ab
+         OR NOT(OPENSSL_VERSION VERSION_LESS "3.0.0"))
c2f9ab
+        SET(SSL_DEFINES "${SSL_DEFINES} -DOPENSSL_API_COMPAT=0x10100000L")
c2f9ab
+        SET(CMAKE_REQUIRED_DEFINITIONS -DOPENSSL_API_COMPAT=0x10100000L)
c2f9ab
+      ENDIF()
c2f9ab
+
c2f9ab
       SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
c2f9ab
       SET(CMAKE_REQUIRED_LIBRARIES ${SSL_LIBRARIES})
c2f9ab
-      SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
c2f9ab
+
c2f9ab
       CHECK_SYMBOL_EXISTS(ERR_remove_thread_state "openssl/err.h"
c2f9ab
                           HAVE_ERR_remove_thread_state)
c2f9ab
       CHECK_SYMBOL_EXISTS(EVP_aes_128_ctr "openssl/evp.h"
c2f9ab
@@ -150,8 +161,10 @@ MACRO (MYSQL_CHECK_SSL)
c2f9ab
                           HAVE_EncryptAes128Gcm)
c2f9ab
       CHECK_SYMBOL_EXISTS(X509_check_host "openssl/x509v3.h"
c2f9ab
                           HAVE_X509_check_host)
c2f9ab
-      SET(CMAKE_REQUIRED_INCLUDES)
c2f9ab
-      SET(CMAKE_REQUIRED_LIBRARIES)
c2f9ab
+
c2f9ab
+      FOREACH(x INCLUDES LIBRARIES DEFINITIONS)
c2f9ab
+        SET(CMAKE_REQUIRED_${x} ${SAVE_CMAKE_REQUIRED_${x}})
c2f9ab
+      ENDFOREACH()
c2f9ab
     ELSE()
c2f9ab
       IF(WITH_SSL STREQUAL "system")
c2f9ab
         MESSAGE(FATAL_ERROR "Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to enable SSL support")
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/include/ssl_compat.h.patch16 mariadb-10.5.12-downstream_modified/include/ssl_compat.h
c2f9ab
--- mariadb-10.5.12-downstream_modified/include/ssl_compat.h.patch16	2021-08-03 10:29:07.000000000 +0200
c2f9ab
+++ mariadb-10.5.12-downstream_modified/include/ssl_compat.h	2021-11-18 16:58:41.552440737 +0100
c2f9ab
@@ -24,7 +24,7 @@
c2f9ab
 #define SSL_LIBRARY OpenSSL_version(OPENSSL_VERSION)
c2f9ab
 #define ERR_remove_state(X) ERR_clear_error()
c2f9ab
 #define EVP_CIPHER_CTX_SIZE 176
c2f9ab
-#define EVP_MD_CTX_SIZE 48
c2f9ab
+#define EVP_MD_CTX_SIZE 72
c2f9ab
 #undef EVP_MD_CTX_init
c2f9ab
 #define EVP_MD_CTX_init(X) do { memset((X), 0, EVP_MD_CTX_SIZE); EVP_MD_CTX_reset(X); } while(0)
c2f9ab
 #undef EVP_CIPHER_CTX_init
c2f9ab
@@ -74,7 +74,6 @@
c6991b
 #define DH_set0_pqg(D,P,Q,G)            ((D)->p= (P), (D)->g= (G))
c2f9ab
 #endif
c2f9ab
 
c2f9ab
-#define EVP_CIPHER_CTX_buf_noconst(ctx) ((ctx)->buf)
c2f9ab
 #define EVP_CIPHER_CTX_encrypting(ctx)  ((ctx)->encrypt)
c2f9ab
 #define EVP_CIPHER_CTX_SIZE             sizeof(EVP_CIPHER_CTX)
c2f9ab
 
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/mysql-test/lib/openssl.cnf.patch16 mariadb-10.5.12-downstream_modified/mysql-test/lib/openssl.cnf
c2f9ab
--- mariadb-10.5.12-downstream_modified/mysql-test/lib/openssl.cnf.patch16	2021-08-03 10:29:07.000000000 +0200
c2f9ab
+++ mariadb-10.5.12-downstream_modified/mysql-test/lib/openssl.cnf	2021-11-18 16:58:41.552440737 +0100
c2f9ab
@@ -9,4 +9,4 @@ ssl_conf = ssl_section
c2f9ab
 system_default = system_default_section
c2f9ab
 
c2f9ab
 [system_default_section]
c2f9ab
-CipherString = ALL:@SECLEVEL=1
c2f9ab
+CipherString = ALL:@SECLEVEL=0
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.result.patch16 mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.result
c2f9ab
--- mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.result.patch16	2021-08-03 10:29:08.000000000 +0200
c2f9ab
+++ mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.result	2021-11-18 16:58:41.552440737 +0100
c2f9ab
@@ -61,8 +61,8 @@ connect  ssl_con,localhost,root,,,,,SSL;
c2f9ab
 SHOW STATUS LIKE 'Ssl_cipher';
ebd438
 Variable_name	Value
c2f9ab
 Ssl_cipher	AES128-SHA
c2f9ab
-SHOW STATUS LIKE 'Ssl_cipher_list';
c2f9ab
-Variable_name	Value
c2f9ab
-Ssl_cipher_list	AES128-SHA
c2f9ab
+SELECT VARIABLE_VALUE like '%AES128-SHA%' FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher_list';
c2f9ab
+VARIABLE_VALUE like '%AES128-SHA%'
c2f9ab
+1
c2f9ab
 disconnect ssl_con;
c2f9ab
 connection default;
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.test.patch16 mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.test
c2f9ab
--- mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.test.patch16	2021-11-18 16:58:41.552440737 +0100
c2f9ab
+++ mariadb-10.5.12-downstream_modified/mysql-test/main/ssl_cipher.test	2021-11-18 17:00:47.753839711 +0100
c2f9ab
@@ -100,6 +100,6 @@ connect (ssl_con,localhost,root,,,,,SSL)
c2f9ab
 --replace_regex /TLS_AES_.*/AES128-SHA/
c2f9ab
 SHOW STATUS LIKE 'Ssl_cipher';
c2f9ab
 --replace_regex /TLS_AES_.*/AES128-SHA/
c2f9ab
-SHOW STATUS LIKE 'Ssl_cipher_list';
c2f9ab
+SELECT VARIABLE_VALUE like '%AES128-SHA%' FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher_list';
c2f9ab
 disconnect ssl_con;
c2f9ab
 connection default;
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/mysys_ssl/my_crypt.cc.patch16 mariadb-10.5.12-downstream_modified/mysys_ssl/my_crypt.cc
c2f9ab
--- mariadb-10.5.12-downstream_modified/mysys_ssl/my_crypt.cc.patch16	2021-08-03 10:29:08.000000000 +0200
c2f9ab
+++ mariadb-10.5.12-downstream_modified/mysys_ssl/my_crypt.cc	2021-11-18 16:58:41.552440737 +0100
c2f9ab
@@ -29,11 +29,7 @@
c2f9ab
 #include <ssl_compat.h>
c2f9ab
 #include <cstdint>
c2f9ab
 
c2f9ab
-#ifdef HAVE_WOLFSSL
c2f9ab
 #define CTX_ALIGN 16
c2f9ab
-#else
c2f9ab
-#define CTX_ALIGN 0
c2f9ab
-#endif
c2f9ab
 
ebd438
 class MyCTX
ebd438
 {
c2f9ab
@@ -100,8 +96,9 @@ class MyCTX_nopad : public MyCTX
c2f9ab
 {
ebd438
 public:
c2f9ab
   const uchar *key;
c2f9ab
-  uint klen, buf_len;
c2f9ab
+  uint klen, source_tail_len;
c2f9ab
   uchar oiv[MY_AES_BLOCK_SIZE];
c2f9ab
+  uchar source_tail[MY_AES_BLOCK_SIZE];
c2f9ab
 
c2f9ab
   MyCTX_nopad() : MyCTX() { }
c2f9ab
   ~MyCTX_nopad() { }
c2f9ab
@@ -112,7 +109,7 @@ public:
c2f9ab
     compile_time_assert(MY_AES_CTX_SIZE >= sizeof(MyCTX_nopad));
c2f9ab
     this->key= key;
c2f9ab
     this->klen= klen;
c2f9ab
-    this->buf_len= 0;
c2f9ab
+    this->source_tail_len= 0;
c2f9ab
     if (ivlen)
c2f9ab
       memcpy(oiv, iv, ivlen);
c2f9ab
     DBUG_ASSERT(ivlen == 0 || ivlen == sizeof(oiv));
c2f9ab
@@ -123,26 +120,41 @@ public:
c2f9ab
     return res;
ebd438
   }
c2f9ab
 
c2f9ab
+  /** Update last partial source block, stored in source_tail array. */
c2f9ab
+  void update_source_tail(const uchar* src, uint slen)
c2f9ab
+  {
c2f9ab
+    if (!slen)
c2f9ab
+      return;
c2f9ab
+    uint new_tail_len= (source_tail_len + slen) % MY_AES_BLOCK_SIZE;
c2f9ab
+    if (new_tail_len)
c2f9ab
+    {
c2f9ab
+      if (slen + source_tail_len < MY_AES_BLOCK_SIZE)
c2f9ab
+      {
c2f9ab
+        memcpy(source_tail + source_tail_len, src, slen);
c2f9ab
+      }
c2f9ab
+      else
c2f9ab
+      {
c2f9ab
+        DBUG_ASSERT(slen > new_tail_len);
c2f9ab
+        memcpy(source_tail, src + slen - new_tail_len, new_tail_len);
c2f9ab
+      }
c2f9ab
+    }
c2f9ab
+    source_tail_len= new_tail_len;
c2f9ab
+  }
c2f9ab
+
c2f9ab
   int update(const uchar *src, uint slen, uchar *dst, uint *dlen)
ebd438
   {
c2f9ab
-    buf_len+= slen;
c2f9ab
+    update_source_tail(src, slen);
c2f9ab
     return MyCTX::update(src, slen, dst, dlen);
ebd438
   }
ebd438
 
c2f9ab
   int finish(uchar *dst, uint *dlen)
c2f9ab
   {
c2f9ab
-    buf_len %= MY_AES_BLOCK_SIZE;
c2f9ab
-    if (buf_len)
c2f9ab
+    if (source_tail_len)
c2f9ab
     {
c2f9ab
-      uchar *buf= EVP_CIPHER_CTX_buf_noconst(ctx);
c2f9ab
       /*
c2f9ab
         Not much we can do, block ciphers cannot encrypt data that aren't
c2f9ab
         a multiple of the block length. At least not without padding.
c2f9ab
         Let's do something CTR-like for the last partial block.
c2f9ab
-
c2f9ab
-        NOTE this assumes that there are only buf_len bytes in the buf.
c2f9ab
-        If OpenSSL will change that, we'll need to change the implementation
c2f9ab
-        of this class too.
c2f9ab
       */
c2f9ab
       uchar mask[MY_AES_BLOCK_SIZE];
c2f9ab
       uint mlen;
c2f9ab
@@ -154,10 +166,10 @@ public:
c2f9ab
         return rc;
c2f9ab
       DBUG_ASSERT(mlen == sizeof(mask));
ebd438
 
c2f9ab
-      for (uint i=0; i < buf_len; i++)
c2f9ab
-        dst[i]= buf[i] ^ mask[i];
c2f9ab
+      for (uint i=0; i < source_tail_len; i++)
c2f9ab
+        dst[i]= source_tail[i] ^ mask[i];
c2f9ab
     }
c2f9ab
-    *dlen= buf_len;
c2f9ab
+    *dlen= source_tail_len;
c2f9ab
     return MY_AES_OK;
c2f9ab
   }
c2f9ab
 };
c2f9ab
diff -up mariadb-10.5.12-downstream_modified/unittest/mysys/aes-t.c.patch16 mariadb-10.5.12-downstream_modified/unittest/mysys/aes-t.c
c2f9ab
--- mariadb-10.5.12-downstream_modified/unittest/mysys/aes-t.c.patch16	2021-08-03 10:29:10.000000000 +0200
c2f9ab
+++ mariadb-10.5.12-downstream_modified/unittest/mysys/aes-t.c	2021-11-18 16:58:41.553440740 +0100
c2f9ab
@@ -21,27 +21,96 @@
c2f9ab
 #include <string.h>
c2f9ab
 #include <ctype.h>
c2f9ab
 
c2f9ab
-#define DO_TEST(mode, nopad, slen, fill, dlen, hash)                    \
c2f9ab
-  SKIP_BLOCK_IF(mode == 0xDEADBEAF, nopad ? 4 : 5, #mode " not supported")     \
c2f9ab
-  {                                                                     \
c2f9ab
-    memset(src, fill, src_len= slen);                                   \
c2f9ab
-    ok(my_aes_crypt(mode, nopad | ENCRYPTION_FLAG_ENCRYPT,              \
c2f9ab
-                    src, src_len, dst, &dst_len,                        \
c2f9ab
-                    key, sizeof(key), iv, sizeof(iv)) == MY_AES_OK,     \
c2f9ab
-      "encrypt " #mode " %u %s", src_len, nopad ? "nopad" : "pad");     \
c2f9ab
-    if (!nopad)                                                         \
c2f9ab
-      ok (dst_len == my_aes_get_size(mode, src_len), "my_aes_get_size");\
c2f9ab
-    my_md5(md5, (char*)dst, dst_len);                                   \
c2f9ab
-    ok(dst_len == dlen && memcmp(md5, hash, sizeof(md5)) == 0, "md5");  \
c2f9ab
-    ok(my_aes_crypt(mode, nopad | ENCRYPTION_FLAG_DECRYPT,              \
c2f9ab
-                    dst, dst_len, ddst, &ddst_len,                      \
c2f9ab
-                    key, sizeof(key), iv, sizeof(iv)) == MY_AES_OK,     \
c2f9ab
-       "decrypt " #mode " %u", dst_len);                                \
c2f9ab
-    ok(ddst_len == src_len && memcmp(src, ddst, src_len) == 0, "memcmp"); \
c2f9ab
+
c2f9ab
+/** Test streaming encryption, bytewise update.*/
c2f9ab
+static int aes_crypt_bytewise(enum my_aes_mode mode, int flags, const unsigned char *src,
c2f9ab
+                 unsigned int slen, unsigned char *dst, unsigned int *dlen,
c2f9ab
+                 const unsigned char *key, unsigned int klen,
c2f9ab
+                 const unsigned char *iv, unsigned int ivlen)
c2f9ab
+{
c2f9ab
+  /* Allocate context on odd address on stack, in order to
c2f9ab
+   catch misalignment errors.*/
c2f9ab
+  void *ctx= (char *)alloca(MY_AES_CTX_SIZE+1)+1;
c2f9ab
+
c2f9ab
+  int res1, res2;
c2f9ab
+  uint d1= 0, d2;
c2f9ab
+  uint i;
c2f9ab
+
c2f9ab
+  if ((res1= my_aes_crypt_init(ctx, mode, flags, key, klen, iv, ivlen)))
c2f9ab
+    return res1;
c2f9ab
+  for (i= 0; i < slen; i++)
c2f9ab
+  {
c2f9ab
+    uint tmp_d1=0;
c2f9ab
+    res1= my_aes_crypt_update(ctx, src+i,1, dst, &tmp_d1);
c2f9ab
+    if (res1)
c2f9ab
+      return res1;
c2f9ab
+    d1+= tmp_d1;
c2f9ab
+    dst+= tmp_d1;
c2f9ab
+  }
c2f9ab
+  res2= my_aes_crypt_finish(ctx, dst, &d2;;
c2f9ab
+  *dlen= d1 + d2;
c2f9ab
+  return res1 ? res1 : res2;
c2f9ab
+}
c2f9ab
+
c2f9ab
+
c2f9ab
+#ifndef HAVE_EncryptAes128Ctr
c2f9ab
+const uint MY_AES_CTR=0xDEADBEAF;
c2f9ab
+#endif
c2f9ab
+#ifndef HAVE_EncryptAes128Gcm
c2f9ab
+const uint MY_AES_GCM=0xDEADBEAF;
c2f9ab
+#endif
c2f9ab
+
c2f9ab
+#define MY_AES_UNSUPPORTED(x)  (x == 0xDEADBEAF)
ebd438
+
c2f9ab
+static void do_test(uint mode, const char *mode_str, int nopad, uint slen,
c2f9ab
+                    char fill, size_t dlen, const char *hash)
c2f9ab
+{
c2f9ab
+  uchar key[16]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6};
c2f9ab
+  uchar iv[16]= {2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7};
c2f9ab
+  uchar src[1000], dst[1100], dst2[1100], ddst[1000];
c2f9ab
+  uchar md5[MY_MD5_HASH_SIZE];
c2f9ab
+  uint src_len, dst_len, dst_len2, ddst_len;
c2f9ab
+  int result;
ebd438
+
c2f9ab
+  if (MY_AES_UNSUPPORTED(mode))
c2f9ab
+  {
c2f9ab
+    skip(nopad?7:6, "%s not supported", mode_str);
c2f9ab
+    return;
c2f9ab
+  }
c2f9ab
+  memset(src, fill, src_len= slen);
c2f9ab
+  result= my_aes_crypt(mode, nopad | ENCRYPTION_FLAG_ENCRYPT, src, src_len,
c2f9ab
+                       dst, &dst_len, key, sizeof(key), iv, sizeof(iv));
c2f9ab
+  ok(result == MY_AES_OK, "encrypt %s %u %s", mode_str, src_len,
c2f9ab
+     nopad ? "nopad" : "pad");
c2f9ab
+
c2f9ab
+  if (nopad)
c2f9ab
+  {
c2f9ab
+    result= aes_crypt_bytewise(mode, nopad | ENCRYPTION_FLAG_ENCRYPT, src,
c2f9ab
+                                src_len, dst2, &dst_len2, key, sizeof(key),
c2f9ab
+                                iv, sizeof(iv));
c2f9ab
+    ok(result == MY_AES_OK, "encrypt bytewise %s %u", mode_str, src_len);
c2f9ab
+    /* Compare with non-bytewise encryption result*/
c2f9ab
+    ok(dst_len == dst_len2 && memcmp(dst, dst2, dst_len) == 0,
c2f9ab
+       "memcmp bytewise  %s %u", mode_str, src_len);
c2f9ab
   }
c2f9ab
+  else
c2f9ab
+  {
c2f9ab
+    int dst_len_real= my_aes_get_size(mode, src_len);
c2f9ab
+    ok(dst_len_real= dst_len, "my_aes_get_size");
c2f9ab
+  }
c2f9ab
+  my_md5(md5, (char *) dst, dst_len);
c2f9ab
+  ok(dst_len == dlen, "md5 len");
c2f9ab
+  ok(memcmp(md5, hash, sizeof(md5)) == 0, "md5");
c2f9ab
+  result= my_aes_crypt(mode, nopad | ENCRYPTION_FLAG_DECRYPT,
c2f9ab
+                       dst, dst_len, ddst, &ddst_len, key, sizeof(key), iv,
c2f9ab
+                       sizeof(iv));
c2f9ab
+
c2f9ab
+  ok(result == MY_AES_OK, "decrypt %s %u", mode_str, dst_len);
c2f9ab
+  ok(ddst_len == src_len && memcmp(src, ddst, src_len) == 0, "memcmp");
c2f9ab
+}
ebd438
 
c2f9ab
-#define DO_TEST_P(M,S,F,D,H) DO_TEST(M,0,S,F,D,H)
c2f9ab
-#define DO_TEST_N(M,S,F,D,H) DO_TEST(M,ENCRYPTION_FLAG_NOPAD,S,F,D,H)
c2f9ab
+#define DO_TEST_P(M, S, F, D, H) do_test(M, #M, 0, S, F, D, H)
c2f9ab
+#define DO_TEST_N(M, S, F, D, H) do_test(M, #M, ENCRYPTION_FLAG_NOPAD, S, F, D, H)
ebd438
 
c2f9ab
 /* useful macro for debugging */
c2f9ab
 #define PRINT_MD5()                                     \
c2f9ab
@@ -53,25 +122,15 @@
c2f9ab
     printf("\"\n");                                     \
c2f9ab
   } while(0);
ebd438
 
c2f9ab
-#ifndef HAVE_EncryptAes128Ctr
c2f9ab
-const uint MY_AES_CTR=0xDEADBEAF;
c2f9ab
-#endif
c2f9ab
-#ifndef HAVE_EncryptAes128Gcm
c2f9ab
-const uint MY_AES_GCM=0xDEADBEAF;
c2f9ab
-#endif
ebd438
 
c2f9ab
 int
c2f9ab
 main(int argc __attribute__((unused)),char *argv[])
c2f9ab
 {
c2f9ab
-  uchar key[16]= {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6};
c2f9ab
-  uchar iv[16]=  {2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7};
c2f9ab
-  uchar src[1000], dst[1100], ddst[1000];
c2f9ab
-  uchar md5[MY_MD5_HASH_SIZE];
c2f9ab
-  uint src_len, dst_len, ddst_len;
ebd438
 
c2f9ab
   MY_INIT(argv[0]);
c2f9ab
 
c2f9ab
-  plan(87);
c2f9ab
+  plan(122);
c2f9ab
+
c2f9ab
   DO_TEST_P(MY_AES_ECB, 200, '.', 208, "\xd8\x73\x8e\x3a\xbc\x66\x99\x13\x7f\x90\x23\x52\xee\x97\x6f\x9a");
c2f9ab
   DO_TEST_P(MY_AES_ECB, 128, '?', 144, "\x19\x58\x33\x85\x4c\xaa\x7f\x06\xd1\xb2\xec\xd7\xb7\x6a\xa9\x5b");
c2f9ab
   DO_TEST_P(MY_AES_CBC, 159, '%', 160, "\x4b\x03\x18\x3d\xf1\xa7\xcd\xa1\x46\xb3\xc6\x8a\x92\xc0\x0f\xc9");
c6991b
c6991b
c6991b
c6991b
MariaDB before 10.8 series does not contain the OpenSSL 3 patch on the upstream.
c6991b
MariaDB upstream later added the following condition:
c6991b
https://github.com/MariaDB/server/commit/c9beef4315
c6991b
limiting the OpenSSL that can be used to < 3. and reverted this commit for 10.8 and later:
c6991b
https://github.com/MariaDB/server/commit/64e358821e
c6991b
c6991b
Since we apply the OpenSSL 3 patch from MariaDB 10.8 series to earlier series, we need to revert this commit
c6991b
on those earlier series too.
c6991b
c6991b
--- mariadb-10.5.15-downstream_modified/cmake/ssl.cmake	2022-02-22 05:13:17.259097302 +0100
c6991b
+++ mariadb-10.5.15-downstream_modified/cmake/ssl.cmake_patched	2022-02-23 07:22:20.290082378 +0100
c6991b
@@ -118,7 +118,7 @@ MACRO (MYSQL_CHECK_SSL)
c6991b
     ENDIF()
c6991b
     FIND_PACKAGE(OpenSSL)
c6991b
     SET_PACKAGE_PROPERTIES(OpenSSL PROPERTIES TYPE RECOMMENDED)
c6991b
-    IF(OPENSSL_FOUND AND OPENSSL_VERSION AND OPENSSL_VERSION VERSION_LESS "3.0.0")
c6991b
+    IF(OPENSSL_FOUND)
c6991b
       SET(OPENSSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
c6991b
       INCLUDE(CheckSymbolExists)
c6991b
       SET(SSL_SOURCES "")