[botan-devel] Possible to rsa encrypt a zero ?

Stuart Maclean stuart at apl.washington.edu
Thu May 1 13:56:20 EDT 2014


I am playing with a session key exchange using RSA, I am using Botan 
1.8.10 in Linux.

In testing, I initially set my session key of 32 bytes to all zeros.  
This failed to encrypt, I get a Botan error

terminate called after throwing an instance of 'Botan::Invalid_Argument'
   what():  Botan: Power_Mod::set_base: arg must be > 0
Aborted (core dumped)

I am wondering if this is a bug or whether you simply cannot set the 
message 'm' to zero and expect m^e mod n to work??  Here's the code used 
to produce the error above:

using namespace Botan;

LibraryInitializer init;

int main( int argc, char* argv[] ) {

   // deliberate random/undefined
   char n[512];

   const BigInt mod = BigInt::decode( (byte*)n, 512 );
   RSA_PublicKey* kPub = new RSA_PublicKey( mod, 65537 );

   char sessionKey[32];
   if( 1 )
     memset( sessionKey, 0, 32 );

   AutoSeeded_RNG rng;
   SecureVector<byte> c = kPub->encrypt( (byte*)sessionKey, 32, rng );
}


NOT memsetting the sessionkey buffer to zero, which will result in 
undefined data in sessionkey (from the stack) somehow 'fixes' the issue.

Anyone care to comment on this?

Thanks

Stuart



More information about the botan-devel mailing list