enable Fp::sqr for bls12

dev
MITSUNARI Shigeo 6 years ago
parent a81be306be
commit ac0e9d9813
  1. 13
      src/fp.cpp
  2. 26
      src/fp_generator.hpp

@ -499,18 +499,17 @@ bool Op::init(const mpz_class& _p, size_t maxBitSize, Mode mode, size_t mclMaxBi
fpDbl_mod = &mcl::vint::mcl_fpDbl_mod_SECP256K1;
}
#endif
if (!fp::initForMont(*this, p, mode)) return false;
{
bool b;
sq.set(&b, mp);
if (!b) return false;
}
if (N * UnitBitSize <= 256) {
hash = sha256;
} else {
hash = sha512;
}
return true;
{
bool b;
sq.set(&b, mp);
if (!b) return false;
}
return fp::initForMont(*this, p, mode);
}
void copyUnitToByteAsLE(uint8_t *dst, const Unit *src, size_t byteSize)

@ -836,13 +836,19 @@ private:
gen_montMul4();
return func;
}
if (pn_ == 6 && useMulx_ && useAdx_) {
if (pn_ == 6 && !isFullBit_ && useMulx_ && useAdx_) {
// gen_montMul6(p_, rp_);
StackFrame sf(this, 3, 10 | UseRDX, (1 + 12) * 8);
mov(ptr[rsp + 12 * 8], gp0);
if (mulPreL.getAddress() == 0 || fpDbl_modL.getAddress() == 0) return 0;
StackFrame sf(this, 3, 10 | UseRDX, 12 * 8);
/*
use xm3
rsp
[0, ..12 * 8) ; mul(x, y)
*/
movq(xm3, gp0);
mov(gp0, rsp);
call(mulPreL); // gp0, x, y
mov(gp0, ptr[rsp + 12 * 8]);
movq(gp0, xm3);
mov(gp1, rsp);
call(fpDbl_modL);
return func;
@ -1154,7 +1160,7 @@ private:
ret();
return func;
}
if (pn_ == 6 && !isFullBit_ && useAdx_) {
if (pn_ == 6 && !isFullBit_ && useMulx_ && useAdx_) {
StackFrame sf(this, 3, 10 | UseRDX, 0, false);
call(fpDbl_modL);
sf.close();
@ -1203,20 +1209,22 @@ private:
#endif
return func;
}
if (pn_ == 6 && useMulx_ && useAdx_) {
StackFrame sf(this, 3, 10 | UseRDX, (1 + 12 + 6) * 8);
if (pn_ == 6 && !isFullBit_ && useMulx_ && useAdx_) {
if (fpDbl_modL.getAddress() == 0) return 0;
StackFrame sf(this, 3, 10 | UseRDX, (12 + 6) * 8);
/*
use xm3
rsp
[(12 + 6 * 8] ; gp0
[6 * 8, (12 + 6) * 8) ; sqrPre(x, x)
[0..6 * 8) ; stack for sqrPre6
*/
mov(ptr[rsp + (12 + 6) * 8], gp0);
movq(xm3, gp0);
Pack t = sf.t;
t.append(sf.p[2]);
// sqrPre6 uses 6 * 8 bytes stack
sqrPre6(rsp + 6 * 8, sf.p[1], t);
mov(gp0, ptr[rsp + (12 + 6) * 8]);
movq(gp0, xm3);
lea(gp1, ptr[rsp + 6 * 8]);
call(fpDbl_modL);
return func;

Loading…
Cancel
Save