Skip to content

Commit

Permalink
[modify] Ec::mul accepts only Ec::Fr, not general Fp
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Apr 9, 2024
1 parent 6a24a96 commit eccb0c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
8 changes: 3 additions & 5 deletions include/mcl/ec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,12 +1461,10 @@ class EcT : public fp::Serializable<EcT<_Fp, _Fr> > {
Fp::neg(R.y, P.y);
R.z = P.z;
}
template<class tag, size_t maxBitSize, template<class _tag, size_t _maxBitSize>class FpT>
static inline void mul(EcT& z, const EcT& x, const FpT<tag, maxBitSize>& y, bool constTime = false)
static inline void mul(EcT& z, const EcT& x, const EcT::Fr& y, bool constTime = false)
{
typedef FpT<tag, maxBitSize> F;
fp::getMpzAtType getMpzAt = fp::getMpzAtT<F>;
fp::getUnitAtType getUnitAt = fp::getUnitAtT<F>;
fp::getMpzAtType getMpzAt = fp::getMpzAtT<Fr>;
fp::getUnitAtType getUnitAt = fp::getUnitAtT<Fr>;
if (mulVecGLV) {
mulVecGLV(z, &x, &y, 1, getMpzAt, getUnitAt, constTime);
return;
Expand Down
2 changes: 1 addition & 1 deletion include/mcl/fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class FpT : public fp::Serializable<FpT<tag, maxBitSize>,
*pb = false;
return;
}
setArray(pb, gmp::getUnit(x), gmp::getUnitSize(x));
setArrayMod(pb, gmp::getUnit(x), gmp::getUnitSize(x));
}
static void add(FpT& z, const FpT& x, const FpT& y)
{
Expand Down
2 changes: 1 addition & 1 deletion test/glv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testGLV(const G& P, const char *name)
G::mulGeneric(P1, P, s.getMpz());
G::mul(P2, P, s);
CYBOZU_TEST_EQUAL(P1, P2);
Fp ss;
Fr ss;
ss.setRand(rg);
G::mulGeneric(P1, P, ss.getMpz());
G::mul(P2, P, ss);
Expand Down
11 changes: 7 additions & 4 deletions test/window_method_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CYBOZU_TEST_AUTO(int)
typedef mcl::EcT<Fp, Fr> Ec;
const struct mcl::EcParam& para = mcl::ecparam::secp192k1;
Fp::init(para.p);
Fr::init(para.n);
Ec::init(para.a, para.b);
const Fp x(para.gx);
const Fp y(para.gy);
Expand All @@ -33,6 +34,8 @@ CYBOZU_TEST_AUTO(int)
Ec::mul(R, P, -12345);
CYBOZU_TEST_EQUAL(Q, R);
mpz_class t(para.gx);
Fr r;
r.setMpz(t);
pw.mul(Q, t);
Ec::mul(R, P, t);
CYBOZU_TEST_EQUAL(Q, R);
Expand All @@ -41,11 +44,11 @@ CYBOZU_TEST_AUTO(int)
Ec::mul(R, P, t);
CYBOZU_TEST_EQUAL(Q, R);

pw.mul(Q, x);
Ec::mul(R, P, x);
pw.mul(Q, r);
Ec::mul(R, P, r);
CYBOZU_TEST_EQUAL(Q, R);

pw.mul(Q, y);
Ec::mul(R, P, y);
pw.mul(Q, r);
Ec::mul(R, P, r);
CYBOZU_TEST_EQUAL(Q, R);
}

0 comments on commit eccb0c2

Please sign in to comment.