aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2015-06-10 16:20:31 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2015-06-10 16:20:31 +0800
commit448f142382fe73eabda8ce87f5252827d40d824a (patch)
tree503c131c4ad260a41e51454c23d09b1c6de1e901
parent477950e58ee935a23128cd9033b13cf9a2805305 (diff)
downloaddexon-mcl-448f142382fe73eabda8ce87f5252827d40d824a.tar.gz
dexon-mcl-448f142382fe73eabda8ce87f5252827d40d824a.tar.zst
dexon-mcl-448f142382fe73eabda8ce87f5252827d40d824a.zip
test of window method is ok
-rw-r--r--include/mcl/elgamal.hpp8
-rw-r--r--include/mcl/window_method.hpp (renamed from include/mcl/power_window.hpp)19
-rw-r--r--test/window_method_test.cpp (renamed from test/power_window_test.cpp)8
3 files changed, 14 insertions, 21 deletions
diff --git a/include/mcl/elgamal.hpp b/include/mcl/elgamal.hpp
index 2146318..452b0e0 100644
--- a/include/mcl/elgamal.hpp
+++ b/include/mcl/elgamal.hpp
@@ -151,11 +151,11 @@ struct ElgamalT {
G g;
G h;
bool enablePowerWindow_;
- mcl::PowerWindow<G> powf;
- mcl::PowerWindow<G> powg;
- mcl::PowerWindow<G> powh;
+ mcl::WindowMethod<G> powf;
+ mcl::WindowMethod<G> powg;
+ mcl::WindowMethod<G> powh;
template<class N>
- void powerSub(G& z, const G& x, const N& n, const mcl::PowerWindow<G>& pw) const
+ void powerSub(G& z, const G& x, const N& n, const mcl::WindowMethod<G>& pw) const
{
if (enablePowerWindow_) {
pw.power(z, n);
diff --git a/include/mcl/power_window.hpp b/include/mcl/window_method.hpp
index 97f6fb1..bca92c3 100644
--- a/include/mcl/power_window.hpp
+++ b/include/mcl/window_method.hpp
@@ -1,12 +1,8 @@
#pragma once
/**
@file
- @brief power window method
+ @brief window method
@author MITSUNARI Shigeo(@herumi)
- @note
- Copyright (c) 2014, National Institute of Advanced Industrial
- Science and Technology All rights reserved.
- This source file is subject to BSD 3-Clause license.
*/
#include <vector>
#include <mcl/fp.hpp>
@@ -71,17 +67,17 @@ struct ArrayIterator {
};
template<class Ec>
-class PowerWindow {
+class WindowMethod {
public:
typedef std::vector<Ec> EcV;
size_t bitLen_;
size_t winSize_;
std::vector<EcV> tbl_;
- PowerWindow(const Ec& x, size_t bitLen, size_t winSize)
+ WindowMethod(const Ec& x, size_t bitLen, size_t winSize)
{
init(x, bitLen, winSize);
}
- PowerWindow()
+ WindowMethod()
: bitLen_(0)
, winSize_(0)
{
@@ -95,9 +91,8 @@ public:
{
bitLen_ = bitLen;
winSize_ = winSize;
- const size_t tblNum = (bitLen + winSize) / winSize;
+ const size_t tblNum = (bitLen + winSize - 1) / winSize;
const size_t r = size_t(1) << winSize;
- // alloc table
tbl_.resize(tblNum);
Ec t(x);
for (size_t i = 0; i < tblNum; i++) {
@@ -112,7 +107,7 @@ public:
}
}
/*
- @param z [out] x^y
+ @param z [out] x multiplied by y
@param y [in] exponent
*/
template<class tag2, size_t maxBitN2>
@@ -137,13 +132,13 @@ public:
}
void powerArray(Ec& z, const Unit* y, size_t bitLen, bool isNegative) const
{
+ if ((bitLen + winSize_ - 1) / winSize_ > tbl_.size()) throw cybozu::Exception("mcl:WindowMethod:powerArray:bad value") << bitLen << bitLen_ << winSize_;
z.clear();
if (bitLen == 0) return;
size_t i = 0;
ArrayIterator<Unit> ai(y, bitLen, winSize_);
do {
Unit v = ai.getNext();
- if (i >= tbl_.size()) throw cybozu::Exception("mcl:PowerWindow:power:bad value") << i << tbl_.size() << bitLen << winSize_;
if (v) {
Ec::add(z, z, tbl_[i][v]);
}
diff --git a/test/power_window_test.cpp b/test/window_method_test.cpp
index d2e4156..26d016a 100644
--- a/test/power_window_test.cpp
+++ b/test/window_method_test.cpp
@@ -1,10 +1,9 @@
#include <cybozu/test.hpp>
-#include <mcl/power_window.hpp>
+#include <mcl/window_method.hpp>
#include <mcl/ec.hpp>
#include <mcl/fp.hpp>
#include <mcl/ecparam.hpp>
-#if 0
CYBOZU_TEST_AUTO(ArrayIterator)
{
const uint32_t in[2] = { 0x12345678, 0xabcdef89 };
@@ -24,7 +23,6 @@ CYBOZU_TEST_AUTO(ArrayIterator)
CYBOZU_TEST_ASSERT(!ai.hasNext());
}
}
-#endif
CYBOZU_TEST_AUTO(int)
{
@@ -37,11 +35,11 @@ CYBOZU_TEST_AUTO(int)
const Fp y(para.gy);
const Ec P(x, y);
- typedef mcl::fp::PowerWindow<Ec> PW;
+ typedef mcl::fp::WindowMethod<Ec> PW;
const size_t bitLen = 16;
Ec Q, R;
- for (size_t winSize = 2; winSize <= 12; winSize += 3) {
+ for (size_t winSize = 2; winSize <= bitLen; winSize += 3) {
PW pw(P, bitLen, winSize);
for (int i = 0; i < (1 << bitLen); i++) {
pw.power(Q, i);