From ba8e271ca9d294371ac4d62053e20f8abe9cb680 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 20 Apr 2017 03:59:45 +0200 Subject: [PATCH] Expose const time exponentiation for fields --- include/mcl/operator.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/mcl/operator.hpp b/include/mcl/operator.hpp index c1996c3..7d6cdac 100644 --- a/include/mcl/operator.hpp +++ b/include/mcl/operator.hpp @@ -41,23 +41,23 @@ struct Operator : E { friend MCL_FORCE_INLINE T operator/(const T& a, const T& b) { T c; T::inv(c, b); c *= a; return c; } MCL_FORCE_INLINE T operator-() const { T c; T::neg(c, static_cast(*this)); return c; } template class FpT> - static void pow(T& z, const T& x, const FpT& y) + static void pow(T& z, const T& x, const FpT& y, bool constTime = false) { fp::Block b; y.getBlock(b); - powArray(z, x, b.p, b.n, false); + powArray(z, x, b.p, b.n, false, constTime); } - static void pow(T& z, const T& x, int y) + static void pow(T& z, const T& x, int y, bool constTime = false) { const Unit u = abs(y); - powArray(z, x, &u, 1, y < 0); + powArray(z, x, &u, 1, y < 0, constTime); } - static void pow(T& z, const T& x, const mpz_class& y) + static void pow(T& z, const T& x, const mpz_class& y, bool constTime = false) { - powArray(z, x, gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size), y < 0); + powArray(z, x, gmp::getUnit(y), abs(y.get_mpz_t()->_mp_size), y < 0, constTime); } private: - static void powArray(T& z, const T& x, const Unit *y, size_t yn, bool isNegative) + static void powArray(T& z, const T& x, const Unit *y, size_t yn, bool isNegative, bool constTime) { T tmp; const T *px = &x; @@ -66,7 +66,7 @@ private: px = &tmp; } z = 1; - fp::powGeneric(z, *px, y, yn, T::mul, T::sqr, (void (*)(T&, const T&))0); + fp::powGeneric(z, *px, y, yn, T::mul, T::sqr, (void (*)(T&, const T&))0, constTime); if (isNegative) { T::inv(z, z); }