Original HUSH source code based on ZEC 1.0.8 . For historical purposes only!
https://hush.is
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
/** @file
|
|
*****************************************************************************
|
|
|
|
Implementation of interfaces for (square-and-multiply) exponentiation.
|
|
|
|
See exponentiation.hpp .
|
|
|
|
*****************************************************************************
|
|
* @author This file is part of libsnark, developed by SCIPR Lab
|
|
* and contributors (see AUTHORS).
|
|
* @copyright MIT license (see LICENSE file)
|
|
*****************************************************************************/
|
|
|
|
#ifndef EXPONENTIATION_TCC_
|
|
#define EXPONENTIATION_TCC_
|
|
|
|
#include "common/utils.hpp"
|
|
|
|
namespace libsnark {
|
|
|
|
template<typename FieldT, mp_size_t m>
|
|
FieldT power(const FieldT &base, const bigint<m> &exponent)
|
|
{
|
|
FieldT result = FieldT::one();
|
|
|
|
bool found_one = false;
|
|
|
|
for (long i = exponent.max_bits() - 1; i >= 0; --i)
|
|
{
|
|
if (found_one)
|
|
{
|
|
result = result * result;
|
|
}
|
|
|
|
if (exponent.test_bit(i))
|
|
{
|
|
found_one = true;
|
|
result = result * base;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
template<typename FieldT>
|
|
FieldT power(const FieldT &base, const unsigned long exponent)
|
|
{
|
|
return power<FieldT>(base, bigint<1>(exponent));
|
|
}
|
|
|
|
} // libsnark
|
|
|
|
#endif // EXPONENTIATION_TCC_
|
|
|