I'm using the FIPS-140 version of Crypto++ under VC++ 6.0, and when I
compile and link a program I am getting the following type of error:
HEAP[Crypto.exe]: Invalid Address specified to RtlFreeHeap( 00320000,
003443F0 )
As I understand, this could be due to either
- not compiling using 'Multithreaded DLL' (which I am), or
- having memory allocation conflicts between the DLL and the EXE - i.e. both
using a separate heap but trying to deallocate memory from the other heap.
Here's a snippet of code that I wrote to try and create RSA keys that has
this problem. Note: I started using StringSink in the HexEncoder
constructor, but backed off to passing NULL in the encoder and using Get to
get the keys so that the string was not created under one heap and extended
in the other. I'm still getting the same heap error, and am running out of
ideas to try and resolve this issue.
void Generate_RSA_Key()
{
const int keyLength = 1024;
AutoSeededX917RNG<AES> rng;
RSAES_OAEP_SHA_Decryptor decryptor(rng, keyLength);
HexEncoder privateEncoder(NULL);
decryptor.DEREncode(privateEncoder);
privateEncoder.MessageEnd();
unsigned int privateKeySize = privateEncoder.MaxRetrievable();
char* privateKeyP = new char[privateKeySize + 1];
privateEncoder.Get((byte*)privateKeyP, privateKeySize);
privateKeyP[privateKeySize] = 0;
RSAES_OAEP_SHA_Encryptor encryptor(decryptor);
HexEncoder publicEncoder(NULL);
encryptor.DEREncode(publicEncoder);
publicEncoder.MessageEnd();
unsigned int publicKeySize = publicEncoder.MaxRetrievable();
char* publicKeyP = new char[publicKeySize + 1];
publicEncoder.Get((byte*)publicKeyP, publicKeySize);
publicKeyP[publicKeySize] = 0;
cout << " RSA Key Generation" << endl;
cout << " Private Key (" << privateKeySize << ") " <<
privateKeyP << endl;
cout << " Public Key (" << publicKeySize << ") " << publicKeyP
<< endl;
}