Use mpz_pown_sec where available

pull/220/merge
Nils Maier 2014-04-13 18:01:05 +02:00
parent ead6685b18
commit aa02545fba
2 changed files with 14 additions and 0 deletions

View File

@ -427,6 +427,10 @@ if test "x$have_openssl" != "xyes"; then
AC_SEARCH_LIBS([__gmpz_init], [gmp], [have_libgmp=yes], [have_libgmp=no])
if test "x$have_libgmp" = "xyes"; then
AC_DEFINE([HAVE_LIBGMP], [1], [Define to 1 if you have libgmp.])
AC_CHECK_FUNCS([__gmpz_powm_sec], [have_mpz_powm_sec=yes])
if test "x$have_mpz_powm_sec" = "xyes"; then
AC_DEFINE([HAVE_GMP_SEC], [1], [Define to 1 if you have a GMP with sec functions.])
fi
else
AC_MSG_WARN([libgmp not found])
if test "x$with_libgmp_requested" = "xyes"; then

View File

@ -86,7 +86,11 @@ void DHKeyExchange::init
void DHKeyExchange::generatePublicKey()
{
#if HAVE_GMP_SEC
mpz_powm_sec(publicKey_, generator_, privateKey_, prime_);
#else // HAVE_GMP_SEC
mpz_powm(publicKey_, generator_, privateKey_, prime_);
#endif // HAVE_GMP_SEC
}
size_t DHKeyExchange::getPublicKey(unsigned char* out, size_t outLength) const
@ -126,7 +130,13 @@ size_t DHKeyExchange::computeSecret
mpz_import(peerPublicKey, peerPublicKeyLength, 1, 1, 1, 0, peerPublicKeyData);
mpz_t secret;
mpz_init(secret);
#if HAVE_GMP_SEC
mpz_powm_sec(secret, peerPublicKey, privateKey_, prime_);
#else // HAVE_GMP_SEC
mpz_powm(secret, peerPublicKey, privateKey_, prime_);
#endif // HAVE_GMP_SEC
mpz_clear(peerPublicKey);
memset(out, 0, outLength);