File openssl1.1.patch of Package qca

diff -Naru qca-tls-1.0_orig/qca-tls.cpp qca-tls-1.0/qca-tls.cpp
--- qca-tls-1.0_orig/qca-tls.cpp	2018-04-19 03:14:13.217904556 +0000
+++ qca-tls-1.0/qca-tls.cpp	2018-04-19 07:34:28.318426673 +0000
@@ -57,23 +57,60 @@
 	QByteArray k, i;
 	unsigned char *kp = 0;
 	unsigned char *ip = 0;
-	EVP_CIPHER type = *_type;
-	if(keysize != -1)
-		type.key_len = keysize;
+	EVP_CIPHER *type = NULL;
+
+	if(keysize != -1) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		type =
+		    EVP_CIPHER_meth_new(EVP_CIPHER_nid(_type),
+		      EVP_CIPHER_block_size(_type), keysize);
+#else
+		type = (EVP_CIPHER *) malloc(sizeof(EVP_CIPHER));
+		memcpy((void *)type, (void *)_type, sizeof(EVP_CIPHER));
+		type->key_len = keysize;
+#endif
+	} else {
+		type = (EVP_CIPHER *) _type;
+	}
 	if(key) {
-		k.resize(type.key_len);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		k.resize(EVP_CIPHER_key_length(type));
+#else
+		k.resize(_type->key_len);
+#endif
 		kp = (unsigned char *)k.data();
 	}
 	if(iv) {
-		i.resize(type.iv_len);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		i.resize(EVP_CIPHER_iv_length(type));
+#else
+		i.resize(_type->iv_len);
+#endif
 		ip = (unsigned char *)i.data();
 	}
-	if(!EVP_BytesToKey(&type, EVP_sha1(), (unsigned char *)salt.data(), (unsigned char *)data.data(), data.size(), 1, kp, ip))
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+	if(!EVP_BytesToKey(type, EVP_sha1(), (unsigned char *)salt.data(), (unsigned char *)data.data(), data.size(), 1, kp, ip)) {
+		if (type != _type) {
+			EVP_CIPHER_meth_free(type);
+		}
+		return false;
+	}
+#else
+	if(!EVP_BytesToKey(_type, EVP_sha1(), (unsigned char *)salt.data(), (unsigned char *)data.data(), data.size(), 1, kp, ip))
 		return false;
+#endif
+
 	if(key)
 		*key = k;
 	if(iv)
 		*iv = i;
+	if (type != _type) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		EVP_CIPHER_meth_free(type);
+#else
+		free(type);
+#endif
+	}
 	return true;
 }
 
@@ -172,14 +209,24 @@
 	EVPCipherContext()
 	{
 		type = 0;
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		c = EVP_CIPHER_CTX_new();
+#else
+		c = (EVP_CIPHER_CTX *) malloc(sizeof(EVP_CIPHER_CTX));
+#endif
 	}
 
 	virtual ~EVPCipherContext()
 	{
 		if(type) {
-			EVP_CIPHER_CTX_cleanup(&c);
+			EVP_CIPHER_CTX_cleanup(c);
 			type = 0;
 		}
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		EVP_CIPHER_CTX_free(c);
+#else
+		free((void *) c);
+#endif
 	}
 
 	QCA_CipherContext *clone()
@@ -192,8 +239,13 @@
 	virtual EVPCipherContext *cloneSelf() const=0;
 	virtual const EVP_CIPHER *getType(int mode) const=0;
 
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+	int keySize() { return EVP_CIPHER_key_length(getType(QCA::CBC)); }
+	int blockSize() { return EVP_CIPHER_block_size(getType(QCA::CBC)); }
+#else
 	int keySize() { return getType(QCA::CBC)->key_len; }
 	int blockSize() { return getType(QCA::CBC)->block_size; }
+#endif
 
 	bool generateKey(char *out, int keysize)
 	{
@@ -219,22 +271,30 @@
 		pad = _pad;
 		type = getType(mode);
 		r.resize(0);
-		EVP_CIPHER_CTX_init(&c);
+		EVP_CIPHER_CTX_init(c);
 
 		if(dir == QCA::Encrypt) {
-			if(!EVP_EncryptInit(&c, type, NULL, NULL))
+			if(!EVP_EncryptInit(c, type, NULL, NULL))
 				return false;
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+			if(keysize != EVP_CIPHER_key_length(type))
+#else
 			if(keysize != type->key_len)
-				EVP_CIPHER_CTX_set_key_length(&c, keysize);
-			if(!EVP_EncryptInit(&c, NULL, (unsigned char *)key, (unsigned char *)iv))
+#endif
+				EVP_CIPHER_CTX_set_key_length(c, keysize);
+			if(!EVP_EncryptInit(c, NULL, (unsigned char *)key, (unsigned char *)iv))
 				return false;
 		}
 		else {
-			if(!EVP_DecryptInit(&c, type, NULL, NULL))
+			if(!EVP_DecryptInit(c, type, NULL, NULL))
 				return false;
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+			if(keysize != EVP_CIPHER_key_length(type))
+#else
 			if(keysize != type->key_len)
-				EVP_CIPHER_CTX_set_key_length(&c, keysize);
-			if(!EVP_DecryptInit(&c, NULL, (unsigned char *)key, (unsigned char *)iv))
+#endif
+				EVP_CIPHER_CTX_set_key_length(c, keysize);
+			if(!EVP_DecryptInit(c, NULL, (unsigned char *)key, (unsigned char *)iv))
 				return false;
 		}
 		return true;
@@ -242,14 +302,18 @@
 
 	bool update(const char *in, unsigned int len)
 	{
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		QByteArray result(len + EVP_CIPHER_block_size(type));
+#else
 		QByteArray result(len + type->block_size);
+#endif
 		int olen;
 		if(dir == QCA::Encrypt || !pad) {
-			if(!EVP_EncryptUpdate(&c, (unsigned char *)result.data(), &olen, (unsigned char *)in, len))
+			if(!EVP_EncryptUpdate(c, (unsigned char *)result.data(), &olen, (unsigned char *)in, len))
 				return false;
 		}
 		else {
-			if(!EVP_DecryptUpdate(&c, (unsigned char *)result.data(), &olen, (unsigned char *)in, len))
+			if(!EVP_DecryptUpdate(c, (unsigned char *)result.data(), &olen, (unsigned char *)in, len))
 				return false;
 		}
 		result.resize(olen);
@@ -260,14 +324,18 @@
 	bool final(QByteArray *out)
 	{
 		if(pad) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+			QByteArray result(EVP_CIPHER_block_size(type));
+#else
 			QByteArray result(type->block_size);
+#endif
 			int olen;
 			if(dir == QCA::Encrypt) {
-				if(!EVP_EncryptFinal(&c, (unsigned char *)result.data(), &olen))
+				if(!EVP_EncryptFinal(c, (unsigned char *)result.data(), &olen))
 					return false;
 			}
 			else {
-				if(!EVP_DecryptFinal(&c, (unsigned char *)result.data(), &olen))
+				if(!EVP_DecryptFinal(c, (unsigned char *)result.data(), &olen))
 					return false;
 			}
 			result.resize(olen);
@@ -279,7 +347,7 @@
 		return true;
 	}
 
-	EVP_CIPHER_CTX c;
+	EVP_CIPHER_CTX *c;
 	const EVP_CIPHER *type;
 	QByteArray r;
 	int dir;
@@ -522,11 +590,19 @@
 		// deep copy
 		RSAKeyContext *c = new RSAKeyContext;
 		if(pub) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+			RSA_up_ref(pub);
+#else
 			++(pub->references);
+#endif
 			c->pub = pub; //RSAPublicKey_dup(pub);
 		}
 		if(sec) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+			RSA_up_ref(sec);
+#else
 			++(sec->references);
+#endif
 			c->sec = sec; //RSAPrivateKey_dup(sec);
 		}
 		return c;
@@ -769,7 +845,11 @@
 	{
 		CertContext *c = new CertContext(*this);
 		if(x) {
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+			X509_up_ref(x);
+#else
 			++(x->references);
+#endif
 			c->x = x;
 		}
 		return c;
@@ -841,7 +921,11 @@
 	void fromX509(X509 *t)
 	{
 		reset();
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+		X509_up_ref(t);
+#else
 		++(t->references);
+#endif
 		x = t;
 
 		// serial number