|
|
|
@ -238,57 +238,6 @@ struct GLV1 { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
twisted Frobenius for G2 |
|
|
|
|
*/ |
|
|
|
|
template<class G2> |
|
|
|
|
struct HaveFrobenius : public G2 { |
|
|
|
|
typedef typename G2::Fp Fp2; |
|
|
|
|
static Fp2 g2; |
|
|
|
|
static Fp2 g3; |
|
|
|
|
/*
|
|
|
|
|
BN254 is Dtype |
|
|
|
|
BLS12-381 is Mtype |
|
|
|
|
*/ |
|
|
|
|
static void init(bool isMtype) |
|
|
|
|
{ |
|
|
|
|
g2 = Fp2::get_gTbl()[0]; |
|
|
|
|
g3 = Fp2::get_gTbl()[3]; |
|
|
|
|
if (isMtype) { |
|
|
|
|
Fp2::inv(g2, g2); |
|
|
|
|
Fp2::inv(g3, g3); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
FrobeniusOnTwist for Dtype |
|
|
|
|
p mod 6 = 1, w^6 = xi |
|
|
|
|
Frob(x', y') = phi Frob phi^-1(x', y') |
|
|
|
|
= phi Frob (x' w^2, y' w^3) |
|
|
|
|
= phi (x'^p w^2p, y'^p w^3p) |
|
|
|
|
= (F(x') w^2(p - 1), F(y') w^3(p - 1)) |
|
|
|
|
= (F(x') g^2, F(y') g^3) |
|
|
|
|
|
|
|
|
|
FrobeniusOnTwist for Dtype |
|
|
|
|
use (1/g) instead of g |
|
|
|
|
*/ |
|
|
|
|
static void Frobenius(G2& D, const G2& S) |
|
|
|
|
{ |
|
|
|
|
Fp2::Frobenius(D.x, S.x); |
|
|
|
|
Fp2::Frobenius(D.y, S.y); |
|
|
|
|
Fp2::Frobenius(D.z, S.z); |
|
|
|
|
D.x *= g2; |
|
|
|
|
D.y *= g3; |
|
|
|
|
} |
|
|
|
|
static void Frobenius(HaveFrobenius& y, const HaveFrobenius& x) |
|
|
|
|
{ |
|
|
|
|
Frobenius(static_cast<G2&>(y), static_cast<const G2&>(x)); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
template<class G2> |
|
|
|
|
typename G2::Fp HaveFrobenius<G2>::g2; |
|
|
|
|
template<class G2> |
|
|
|
|
typename G2::Fp HaveFrobenius<G2>::g3; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
GLV method for G2 and GT |
|
|
|
|
*/ |
|
|
|
@ -459,7 +408,7 @@ struct GLV2 { |
|
|
|
|
} |
|
|
|
|
void mul(G2& Q, const G2& P, mpz_class x, bool constTime = false) const |
|
|
|
|
{ |
|
|
|
|
typedef HaveFrobenius<G2> G2withF; |
|
|
|
|
typedef util::HaveFrobenius<G2> G2withF; |
|
|
|
|
G2withF& QQ(static_cast<G2withF&>(Q)); |
|
|
|
|
const G2withF& PP(static_cast<const G2withF&>(P)); |
|
|
|
|
mul(QQ, PP, x, constTime); |
|
|
|
@ -499,7 +448,7 @@ struct BNT { |
|
|
|
|
typedef mcl::Fp12T<Fp> Fp12; |
|
|
|
|
typedef mcl::EcT<Fp> G1; |
|
|
|
|
typedef mcl::EcT<Fp2> G2; |
|
|
|
|
typedef HaveFrobenius<G2> G2withF; |
|
|
|
|
typedef util::HaveFrobenius<G2> G2withF; |
|
|
|
|
typedef mcl::FpDblT<Fp> FpDbl; |
|
|
|
|
typedef mcl::Fp2DblT<Fp> Fp2Dbl; |
|
|
|
|
typedef ParamT<Fp> Param; |
|
|
|
|