Hello all, I started using this library a couple of days ago and I'm really
having a hard time trying to get this BN_mod_exp function to work.
So, basically, no matter what base, exponet and modulus I use, the
calculation always returns 1 as result.
Here's a snippet of the code:
/extern EReturnCode PowerMod(const unsigned char* base,
const unsigned char* exponent,
const unsigned char* modulus,
const unsigned char* result)
{
BIGNUM* bnResult = BN_new();
BIGNUM* bnBase = BN_new();
BIGNUM* bnExponent = BN_new();
BIGNUM* bnModulus = BN_new();
ConvertBufferToBIGNUM(base, 128 /*1024 bits*/, bnBase); // just calling
BN_bin2bn
ConvertBufferToBIGNUM(exponent, 128 /*1024 bits*/, bnExponent); // just
calling BN_bin2bn
ConvertBufferToBIGNUM(modulus, 128 /*1024 bits*/, bnModulus); // just
calling BN_bin2bn
BN_CTX* dummy = BN_CTX_new();
if (dummy == NULL)
{
return eOPENSSLERROR;
}
int retcode = BN_mod_exp(bnResult, bnBase, bnExponent, bnModulus,
dummy);
unsigned char* tempbuff = malloc(BN_num_bytes(bnResult)); //
BN_num_bytes always returns 1
BN_bn2bin(bnResult, tempbuff);
printf("Dumping result:\n");
DumpNumberBuffer(tempbuff, BN_num_bytes(bnResult)); // I only get 0x01
as the dump.
if(retcode <= 0) {
CheckError(retcode);
return eOPENSSLERROR;
}
BN_CTX_free(dummy);
BN_free(bnResult);
BN_free(bnBase);
BN_free(bnExponent);
BN_free(bnModulus);
free(tempbuff);
return eSUCCESS;
}/
What am I doing wrong? What am I missing?
Thank you so much.
--
View this message in context:
http://openssl.6102.n7.nabble.com/Noob-warning-Can-t-get-the-correct-result-BN-mod-exp-tp45872.html
Sent from the OpenSSL - User mailing list archive at Nabble.com.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]