test of window method is ok

dev
MITSUNARI Shigeo 10 years ago
parent 477950e58e
commit 448f142382
  1. 8
      include/mcl/elgamal.hpp
  2. 19
      include/mcl/window_method.hpp
  3. 8
      test/window_method_test.cpp

@ -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);

@ -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]);
}

@ -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);
Loading…
Cancel
Save