<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Openssl Speicherlöcher]]></title><description><![CDATA[<p>Hallo,<br />
ich habe in unserer Verschlüsselungsfunktion Speicherlöcher und komme nicht dahinter wie ich sie beseitigen kann.</p>
<pre><code class="language-cpp">unsigned char*	EncryptData(unsigned char*  pbPlainTextData,
							unsigned long   ulLengthOfPlainTextData,
							unsigned char** ppbEncryptedData,
							unsigned long*  pulLengthOfEncryptedData,
							void*			pVoid) {

	PKCS7 *pkcs7=0;
	const EVP_CIPHER *cipher=0;
	STACK_OF (X509) * certs=0;
	X509 *tmp=0;
	BIO*	bio=0, *in=0, *out=0;

	/* choose the AES 128 cipher block chaining cipher and read in all certificates as encryption targets */
	cipher = EVP_aes_128_cbc ();
	certs = sk_X509_new_null ();

//#### gibt es hierfür eine remove-Funktion ?
	OpenSSL_add_all_algorithms ();

	//Put the plaintext in a buffer which will be treated as a standard in

	//This is for the public key (which is in fact not public)
	bio = BIO_new(BIO_s_mem());
	//This is for the plaintext
	in = BIO_new(BIO_s_mem());
	BIO_write(in,pbPlainTextData,ulLengthOfPlainTextData);

	//This will hold the cipher
	out = BIO_new(BIO_s_mem());
	//Put the public key in the bio
	BIO_puts(bio, PUBLIC_KEY);
/*
	if (!(tmp=PEM_read_bio_X509(bio,NULL, 0, NULL))) {
		goto err;
	}
*/

	//Push the cert in the stack
	sk_X509_push (certs, tmp);
	//Encrypt the PlainTextData
/*
	if (!(pkcs7 = PKCS7_encrypt (certs, in, cipher, 0))) {
		goto err;
	}
*/
/*	if (PEM_write_bio_PKCS7(out, pkcs7)!= 1) {
		goto err;
	}
	//Let's alocate some memory and save the PKCS#7 in to it
	*pulLengthOfEncryptedData=(out-&gt;num_write);
	*ppbEncryptedData=(unsigned char*) malloc(out-&gt;num_write);
	BIO_read(out,*ppbEncryptedData,out-&gt;num_write);
	//Destroy all BIO's

	X509_free(tmp);
*/
//	PKCS7_free(pkcs7);
	BIO_free(out);
	BIO_free(in);
	BIO_free(bio);
	sk_X509_free(certs);
	return *ppbEncryptedData;

err:
	return NULL;

}
</code></pre>
<p>ich hab schon einiges auskommentiert,<br />
wenn <strong>OpenSSL_add_all_algorithms ();</strong> drin ist fängt es an mit den Speicherlöchern, die anderen auskommentierten Codestellen sollen<br />
hinterher auch wieder rein. (Natürlich so verändert das ich keine Speicherlöcher mehr habe)</p>
<p>Die Funktion nutzt folgende Header</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/err.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/rand.h&gt;

// hier liegen die Keys
#include &quot;public.h&quot; 
#include &quot;private.h&quot;
</code></pre>
<p>Leider konnte ich noch keine gute Doku für dies Openssl finden.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/153577/openssl-speicherlöcher</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 15:02:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/153577.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Jul 2006 15:41:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Openssl Speicherlöcher on Tue, 18 Jul 2006 15:41:46 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe in unserer Verschlüsselungsfunktion Speicherlöcher und komme nicht dahinter wie ich sie beseitigen kann.</p>
<pre><code class="language-cpp">unsigned char*	EncryptData(unsigned char*  pbPlainTextData,
							unsigned long   ulLengthOfPlainTextData,
							unsigned char** ppbEncryptedData,
							unsigned long*  pulLengthOfEncryptedData,
							void*			pVoid) {

	PKCS7 *pkcs7=0;
	const EVP_CIPHER *cipher=0;
	STACK_OF (X509) * certs=0;
	X509 *tmp=0;
	BIO*	bio=0, *in=0, *out=0;

	/* choose the AES 128 cipher block chaining cipher and read in all certificates as encryption targets */
	cipher = EVP_aes_128_cbc ();
	certs = sk_X509_new_null ();

//#### gibt es hierfür eine remove-Funktion ?
	OpenSSL_add_all_algorithms ();

	//Put the plaintext in a buffer which will be treated as a standard in

	//This is for the public key (which is in fact not public)
	bio = BIO_new(BIO_s_mem());
	//This is for the plaintext
	in = BIO_new(BIO_s_mem());
	BIO_write(in,pbPlainTextData,ulLengthOfPlainTextData);

	//This will hold the cipher
	out = BIO_new(BIO_s_mem());
	//Put the public key in the bio
	BIO_puts(bio, PUBLIC_KEY);
/*
	if (!(tmp=PEM_read_bio_X509(bio,NULL, 0, NULL))) {
		goto err;
	}
*/

	//Push the cert in the stack
	sk_X509_push (certs, tmp);
	//Encrypt the PlainTextData
/*
	if (!(pkcs7 = PKCS7_encrypt (certs, in, cipher, 0))) {
		goto err;
	}
*/
/*	if (PEM_write_bio_PKCS7(out, pkcs7)!= 1) {
		goto err;
	}
	//Let's alocate some memory and save the PKCS#7 in to it
	*pulLengthOfEncryptedData=(out-&gt;num_write);
	*ppbEncryptedData=(unsigned char*) malloc(out-&gt;num_write);
	BIO_read(out,*ppbEncryptedData,out-&gt;num_write);
	//Destroy all BIO's

	X509_free(tmp);
*/
//	PKCS7_free(pkcs7);
	BIO_free(out);
	BIO_free(in);
	BIO_free(bio);
	sk_X509_free(certs);
	return *ppbEncryptedData;

err:
	return NULL;

}
</code></pre>
<p>ich hab schon einiges auskommentiert,<br />
wenn <strong>OpenSSL_add_all_algorithms ();</strong> drin ist fängt es an mit den Speicherlöchern, die anderen auskommentierten Codestellen sollen<br />
hinterher auch wieder rein. (Natürlich so verändert das ich keine Speicherlöcher mehr habe)</p>
<p>Die Funktion nutzt folgende Header</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;openssl/crypto.h&gt;
#include &lt;openssl/err.h&gt;
#include &lt;openssl/pem.h&gt;
#include &lt;openssl/rand.h&gt;

// hier liegen die Keys
#include &quot;public.h&quot; 
#include &quot;private.h&quot;
</code></pre>
<p>Leider konnte ich noch keine gute Doku für dies Openssl finden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099892</guid><dc:creator><![CDATA[Rufus]]></dc:creator><pubDate>Tue, 18 Jul 2006 15:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to Openssl Speicherlöcher on Tue, 18 Jul 2006 16:28:35 GMT]]></title><description><![CDATA[<p>Also die einfachste Variante wäre, dass du immer vor dein goto err die Einträge zur Speicherfreigabe machst von den Dingen, die bis zu diesem Zeitpunkt mit deiner BIO_NEW-Funktion geholt wurde.</p>
<p>Besser wäre natürlich eine andere Struktur zu machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099916</guid><dc:creator><![CDATA[Pellaeon]]></dc:creator><pubDate>Tue, 18 Jul 2006 16:28:35 GMT</pubDate></item><item><title><![CDATA[Reply to Openssl Speicherlöcher on Thu, 20 Jul 2006 14:52:19 GMT]]></title><description><![CDATA[<p>hab etwas gefunden:</p>
<p>CRYPTO_cleanup_all_ex_data();</p>
<p>räumt den Speicher auf !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1101317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1101317</guid><dc:creator><![CDATA[Rufus]]></dc:creator><pubDate>Thu, 20 Jul 2006 14:52:19 GMT</pubDate></item></channel></rss>