CryptoPP Signing fails

Hello, after trying for long enough to work with openSSL, I have decided to not use it, Instead I'm going to use CryptoPP for what I need.

Unfortunately, it's causing some issues with the following code sample I have:

I've already checked the rsa object, all of the fields are in it as required.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const byte * xxz568::rsaSign(InvertibleRSAFunction rsa, string message) { 
   AutoSeededRandomPool rng;
   RSA::PrivateKey privateKey(rsa);

   // Signer object
   RSASSA_PKCS1v15_SHA_Signer signer(privateKey);

   // Create signature space
   size_t length = signer.MaxSignatureLength();
   SecByteBlock signature(length);

   // Sign message
   signer.SignMessage(rng, (const byte*) message.c_str(), message.length(), signature);
   return signature;
}


Once it hits the SignMessage line my program throws the following from int __cdecl fflush (:
1
2
First-chance exception at 0x7625f328 in cppauth.exe: Microsoft C++ exception: CryptoPP::Exception at memory location 0x003df7b0..
Unhandled exception at 0x7625f328 in cppauth.exe: Microsoft C++ exception: CryptoPP::Exception at memory location 0x003df7b0..


Any reasons why it is doing this?
You are returning a SecByteBlock from a function declared to return a const byte*. That seems odd to me.

Even if SecByteBlock had a const byte* conversion operator, that object is out of scope and destructed.

Edit: That's your problem exactly: http://cryptopp.com/docs/ref/class_sec_block.html You are returning a pointer to an internal buffer that has been deallocated.
Last edited on
I tried a few other examples, and none of them seem to work, same error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int xxz568::rsaSign(InvertibleRSAFunction rsa, string message, string &output) { 
   AutoSeededRandomPool rng;
   // Signer object
   RSASS< PKCS1v15, SHA >::Signer signer( rsa );

   // Create signature space
   byte* signature = new byte[ signer.MaxSignatureLength() ];
   if( NULL == signature ) { 
      return -1; 
   }

   // Sign message
   signer.SignMessage(rng, (const byte*) message.c_str(), message.length(), signature);
   return 1;
}


The crash comes when it hits: signer.SignMessage(rng, (const byte*) message.c_str(), message.length(), signature);

This time, I'm using a byte array above. I have no idea why this one is crashing at that spot, if the array was incorrect, that if would catch it. I'm not even storing the signature anywhere yet which brings up a red flag to me to this crash.

*EDIT*

Here is the other method I tried:

1
2
3
4
5
6
7
8
9
10
   AutoSeededRandomPool rng;
   // Signer object
   RSASS< PKCS1v15, SHA1 >::Signer signer(rsa);
   StringSource(message, true, 
	   new SignerFilter(rng,
	      RSASS< PKCS1v15, SHA1>::Signer(signer),
		  new HexEncoder(
		  new StringSink(output))
	   )
	);


Got this error, VS debugger has the size of the message returned to be over 100,000, which is obviously not correct.
1
2
First-chance exception at 0x75aff328 in cppauth.exe: Microsoft C++ exception: CryptoPP::Exception at memory location 0x0038f200..
Unhandled exception at 0x75aff328 in cppauth.exe: Microsoft C++ exception: CryptoPP::Exception at memory location 0x0038f200..


*END EDIT*

Do you have anything I can go off of to help me fix this?
Last edited on
Topic archived. No new replies allowed.