package sm9

import (
	"math/big"
)

// dup duplicates a byte slice b.
func dup(b []byte) []byte {
	ret := make([]byte, len(b))
	copy(ret, b)
	return ret
}

// pairingThenMul computes e = e(p,q)^k
func pairingThenMul(p *G1, q *G2, k *big.Int) *GT {
	e := Pairing(p, q)
	return e.ScalarMult(e, k)
}

// mulG1ThenPairing computes e = e(p,q)^k = e(kp,q)
func mulG1ThenPairing(p *G1, q *G2, k *big.Int) *GT {
	p1 := (&G1{}).ScalarMult(p, k)
	return Pairing(p1, q)
}

// mulG2ThenPairing computes e = e(p,q)^k = e(p,kq)
func mulG2ThenPairing(p *G1, q *G2, k *big.Int) *GT {
	q2 := (&G2{}).ScalarMult(q, k)
	return Pairing(p, q2)
}

// mulG1BaseThenPairing computes e = e(p,q)^k = e(kp,q)
func mulG1BaseThenPairing(e *GT, q *G2, k *big.Int) {
	p1 := (&G1{}).ScalarBaseMult(k)
	pairing(e, p1, q)
}

// mulG2BaseThenPairing computes e = e(p,q)^k = e(kp,q)
func mulG2BaseThenPairing(p *G1, k *big.Int) *GT {
	q2 := (&G2{}).ScalarBaseMult(k)
	return Pairing(p, q2)
}
