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