--- /dev/null
+diff --git a/src/Mayaqua/Encrypt.c b/src/Mayaqua/Encrypt.c
+index f3b3908..06b7fea 100644
+--- a/src/Mayaqua/Encrypt.c
++++ b/src/Mayaqua/Encrypt.c
+@@ -129,6 +129,7 @@
+ #include <openssl/rand.h>\r
+ #include <openssl/engine.h>\r
+ #include <openssl/bio.h>\r
++#include <openssl/bn.h>\r
+ #include <openssl/x509.h>\r
+ #include <openssl/pkcs7.h>\r
+ #include <openssl/pkcs12.h>\r
+@@ -137,6 +138,7 @@
+ #include <openssl/md4.h>\r
+ #include <openssl/hmac.h>\r
+ #include <openssl/sha.h>\r
++#include <openssl/rsa.h>\r
+ #include <openssl/des.h>\r
+ #include <openssl/aes.h>\r
+ #include <openssl/dh.h>\r
+@@ -634,7 +636,7 @@ UINT CipherProcess(CIPHER *c, void *iv, void *dest, void *src, UINT size)
+ return 0;\r
+ }\r
+ \r
+- if (EVP_CipherFinal(c->Ctx, ((UCHAR *)dest) + (UINT)r, &r2) == 0)\r
++ if (EVP_CipherFinal_ex(c->Ctx, ((UCHAR *)dest) + (UINT)r, &r2) == 0)\r
+ {\r
+ return 0;\r
+ }\r
+@@ -933,6 +935,7 @@ BUF *BigNumToBuf(const BIGNUM *bn)
+ // Initialization of the lock of OpenSSL\r
+ void OpenSSL_InitLock()\r
+ {\r
++#if OPENSSL_VERSION_NUMBER < 0x10100000L\r
+ UINT i;\r
+ \r
+ // Initialization of the lock object\r
+@@ -946,11 +949,13 @@ void OpenSSL_InitLock()
+ // Setting the lock function\r
+ CRYPTO_set_locking_callback(OpenSSL_Lock);\r
+ CRYPTO_set_id_callback(OpenSSL_Id);\r
++#endif\r
+ }\r
+ \r
+ // Release of the lock of OpenSSL\r
+ void OpenSSL_FreeLock()\r
+ {\r
++#if OPENSSL_VERSION_NUMBER < 0x10100000L\r
+ UINT i;\r
+ \r
+ for (i = 0;i < ssl_lock_num;i++)\r
+@@ -962,11 +967,13 @@ void OpenSSL_FreeLock()
+ \r
+ CRYPTO_set_locking_callback(NULL);\r
+ CRYPTO_set_id_callback(NULL);\r
++#endif\r
+ }\r
+ \r
+ // Lock function for OpenSSL\r
+ void OpenSSL_Lock(int mode, int n, const char *file, int line)\r
+ {\r
++#if OPENSSL_VERSION_NUMBER < 0x10100000L\r
+ LOCK *lock = ssl_lock_obj[n];\r
+ \r
+ if (mode & CRYPTO_LOCK)\r
+@@ -979,12 +986,15 @@ void OpenSSL_Lock(int mode, int n, const char *file, int line)
+ // Unlock\r
+ Unlock(lock);\r
+ }\r
++#endif\r
+ }\r
+ \r
+ // Return the thread ID\r
+ unsigned long OpenSSL_Id(void)\r
+ {\r
++#if OPENSSL_VERSION_NUMBER < 0x10100000L\r
+ return (unsigned long)ThreadId();\r
++#endif\r
+ }\r
+ \r
+ // Get the display name of the certificate\r
+@@ -1908,8 +1918,8 @@ X509 *NewX509(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial)
+ X509_set_version(x509, 2L);\r
+ \r
+ // Set the Expiration\r
+- t1 = X509_get_notBefore(x509);\r
+- t2 = X509_get_notAfter(x509);\r
++ t1 = X509_getm_notBefore(x509);\r
++ t2 = X509_getm_notAfter(x509);\r
+ if (!UINT64ToAsn1Time(t1, notBefore))\r
+ {\r
+ FreeX509(x509);\r
+@@ -2050,8 +2060,8 @@ X509 *NewRootX509(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial)
+ X509_set_version(x509, 2L);\r
+ \r
+ // Set the Expiration\r
+- t1 = X509_get_notBefore(x509);\r
+- t2 = X509_get_notAfter(x509);\r
++ t1 = X509_getm_notBefore(x509);\r
++ t2 = X509_getm_notAfter(x509);\r
+ if (!UINT64ToAsn1Time(t1, notBefore))\r
+ {\r
+ FreeX509(x509);\r
+@@ -2677,6 +2687,43 @@ bool RsaCheckEx()
+ \r
+ return false;\r
+ }\r
++\r
++// RSA key generation\r
++static RSA *RsaGenKey(UINT bit, BN_ULONG e)\r
++{\r
++ RSA *rsa = NULL;\r
++ char errbuf[MAX_SIZE];\r
++ BIGNUM *bne = NULL;\r
++\r
++ if ((bne = BN_new()) == NULL)\r
++ {\r
++ Debug("BN_new: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
++ return NULL;\r
++ }\r
++ if (BN_set_word(bne, e) == 0)\r
++ {\r
++ Debug("BN_set_word: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
++ goto fail;\r
++ }\r
++ if ((rsa = RSA_new()) == NULL)\r
++ {\r
++ Debug("RSA_new: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
++ goto fail;\r
++ }\r
++ if (RSA_generate_key_ex(rsa, bit, bne, NULL) == 0)\r
++ {\r
++ Debug("RSA_generate_key_ex: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
++ goto fail;\r
++ }\r
++ BN_free(bne);\r
++ return rsa;\r
++\r
++fail:\r
++ RSA_free(rsa);\r
++ BN_free(bne);\r
++ return NULL;\r
++}\r
++\r
+ bool RsaCheck()\r
+ {\r
+ RSA *rsa;\r
+@@ -2690,12 +2737,11 @@ bool RsaCheck()
+ // Key generation\r
+ Lock(openssl_lock);\r
+ {\r
+- rsa = RSA_generate_key(bit, RSA_F4, NULL, NULL);\r
++ rsa = RsaGenKey(bit, RSA_F4);\r
+ }\r
+ Unlock(openssl_lock);\r
+ if (rsa == NULL)\r
+ {\r
+- Debug("RSA_generate_key: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
+ return false;\r
+ }\r
+ \r
+@@ -2760,12 +2806,11 @@ bool RsaGen(K **priv, K **pub, UINT bit)
+ // Key generation\r
+ Lock(openssl_lock);\r
+ {\r
+- rsa = RSA_generate_key(bit, RSA_F4, NULL, NULL);\r
++ rsa = RsaGenKey(bit, RSA_F4);\r
+ }\r
+ Unlock(openssl_lock);\r
+ if (rsa == NULL)\r
+ {\r
+- Debug("RSA_generate_key: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
+ return false;\r
+ }\r
+ \r
+@@ -3875,7 +3920,7 @@ X *X509ToX(X509 *x509)
+ {\r
+ if (OBJ_obj2nid(ad->method) == NID_ad_ca_issuers && ad->location->type == GEN_URI)\r
+ {\r
+- char *uri = (char *)ASN1_STRING_data(ad->location->d.uniformResourceIdentifier);\r
++ char *uri = (char *)ASN1_STRING_get0_data(ad->location->d.uniformResourceIdentifier);\r
+ \r
+ if (IsEmptyStr(uri) == false)\r
+ {\r
+@@ -4088,7 +4133,9 @@ void Rand(void *buf, UINT size)
+ // Delete a thread-specific information that OpenSSL has holded\r
+ void FreeOpenSSLThreadState()\r
+ {\r
++#if OPENSSL_VERSION_NUMBER < 0x10100000L\r
+ ERR_remove_state(0);\r
++#endif\r
+ }\r
+ \r
+ // Release the Crypt library\r
+@@ -4110,13 +4157,16 @@ void InitCryptLibrary()
+ CheckIfIntelAesNiSupportedInit();\r
+ // RAND_Init_For_SoftEther()\r
+ openssl_lock = NewLock();\r
++#if OPENSSL_VERSION_NUMBER < 0x10100000L\r
+ SSL_library_init();\r
+ //OpenSSL_add_all_algorithms();\r
+ OpenSSL_add_all_ciphers();\r
+ OpenSSL_add_all_digests();\r
+ ERR_load_crypto_strings();\r
+ SSL_load_error_strings();\r
+-\r
++#else\r
++ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);\r
++#endif\r
+ #ifdef OS_UNIX\r
+ {\r
+ char *name1 = "/dev/random";\r