Hi Jeff,

Ok I think those RSA errors with memory are due to this pipelining, because 
the b64decode(..) b64encode(..) is called every where, and if I understand 
correctly, the string inside will be destroyed and I have to use the 
redirector. Can you confirm if you agree with this code change and my 
understanding of the problem ?

*Previous Code:*
std::string b64encode(std::string str)
{
std::string encoded;
CryptoPP::StringSource(str, true,
new CryptoPP::Base64Encoder(
new CryptoPP::StringSink(encoded),
false 
)
);
return encoded; //encoded will be destroyed once StringSource(..) goes out 
of scope
}


*New Code:*

std::string b64encode(std::string str)
{
std::string encoded;
CryptoPP::Base64Encoder df(new CryptoPP::StringSink(encoded),false);
CryptoPP::StringSource(str, true, new Redirector(df) );
return encoded; //encoded won't be destroyed
}


based on this:

CCM< AES, TAG_SIZE >::Decryption d; 
d.SetKeyWithIV( key, key.size(), iv, sizeof(iv) ); 
AuthenticatedDecryptionFilter df( d, new StringSink( recovered ) ); // 
AuthenticatedDecryptionFilter // Cipher text includes the MAC tag 
StringSource ss( cipher, true, new Redirector( df ) ); // StringSource // 
If the object does not throw, here's the only // opportunity to check the 
data's integrity 
bool b = df.GetLastResult(); 
if( true == b ) { cout << recovered << endl; }




On Thursday, April 27, 2023 at 1:35:43 PM UTC-4 Jeffrey Walton wrote:

On Thu, Apr 27, 2023 at 1:31 PM Dwight Kulkarni <dwi...@realtime-7.com> 
wrote: 
> 
> I note an example code sample for b64encode(..). I note that there are 
"new" calls inside the constructor(..). 
> 
> The result is returned in the encoded string. 
> 
> Do I need to do anything to delete the memory from the new calls ? 
> 
> What happens to the memory in the variable "encoded", if the variable is 
passed up to another function and the StringSink is destroyed. 
> 
> Should I make a copy of encoded and send it on to be safe ? 

https://www.cryptopp.com/wiki/Pipelining#Ownership 

Jeff 

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/3cb2a4e9-3319-49ee-a7f3-4ab8e7596043n%40googlegroups.com.

Reply via email to