Hi Kevin,
Kevin> Thanks for your answer. Generating a 256 bit key takes 12 seconds on an
Kevin> Athlon 3000 in debug. It takes 5 seconds in release. I believe this is too
Kevin> slow, especially for a game.
In that case it sounds like Crypto++ is much faster than the code
you're using.
Here's a C++ function I use for generating RSA keys:
/*
* CryptoPP include files
*/
#include "base64.h"
#include "filters.h"
#include "randpool.h"
#include "osrng.h"
#include "hex.h"
#include "rsa.h"
#include "oaep.h"
#include "sha.h"
#include "files.h"
#include "md5.h"
typedef CryptoPP::StringSinkTemplate<STLString> STLStringSink;
using namespace CryptoPP;
using namespace std;
void GenerateRSAKey(unsigned int ui_key_length,STLString& s_priv_key,
STLString& s_pub_key)
{
AutoSeededRandomPool rand_pool;
RSAES_OAEP_SHA_Decryptor priv(rand_pool,ui_key_length);
HexEncoder he_priv(new STLStringSink(s_priv_key));
priv.DEREncode(he_priv);
he_priv.MessageEnd();
RSAES_OAEP_SHA_Encryptor pub(priv);
HexEncoder he_pub(new STLStringSink(s_pub_key));
pub.DEREncode(he_pub);
he_pub.MessageEnd();
}
If you link to the Crypto++ library, you should only get the code you
need loaded in. It's going to be a bit of an overhead in space, but
that's the price of using any code.
As you can see it's a snap to use (once you know how).
The STLString class I'm using looks like this (you don't have to use
it - just replace "STLString" with "string" in the above code):
#include <string>
using namespace std;
class STLString : public string
{
public:
inline STLString(const STLString& ss) : string(static_cast<const string&>(ss))
{
};
inline STLString(const string& ss) : string(ss)
{
};
inline STLString(const char* p_str) : string(p_str)
{
};
inline STLString(const char* p_str,int n_chars) : string(p_str,n_chars)
{
};
inline STLString()
{
};
virtual ~STLString()
{
};
inline STLString(char ch,int n_rep = 1) : string(n_rep,ch)
{
};
};
I'd recommend that you generate the key once at program startup.
Don't try to keep generating new ones.
Anyway, that's a design issue for you. I hope the above helps.
--
Russell Robinson (mailto:[EMAIL PROTECTED])
Author of Tectite (CRM and Licensing for Software Developers)
Download your free CRM from: http://www.tectite.com/