def pop_verify(pk: JacobianPoint, proof: JacobianPoint) -> bool: try: proof.check_valid() pk.check_valid() q = g2_map(bytes(pk), pop_scheme_pop_dst) one = Fq12.one(default_ec.q) pairing_result = ate_pairing_multi([pk, G1Generator().negate()], [q, proof]) return pairing_result == one except AssertionError: return False
def core_verify_mpl(pk: JacobianPoint, message: bytes, signature: JacobianPoint, dst: bytes) -> bool: try: signature.check_valid() pk.check_valid() except AssertionError: return False q = g2_map(message, dst) one = Fq12.one(default_ec.q) pairing_result = ate_pairing_multi([pk, G1Generator().negate()], [q, signature]) return pairing_result == one
def core_aggregate_verify(pks: List[JacobianPoint], ms: List[bytes], signature: JacobianPoint, dst: bytes) -> bool: if len(pks) != len(ms) or len(pks) < 1: return False try: signature.check_valid() qs = [signature] ps = [G1Generator().negate()] for i in range(len(pks)): pks[i].check_valid() qs.append(g2_map(ms[i], dst)) ps.append(pks[i]) return Fq12.one(default_ec.q) == ate_pairing_multi(ps, qs) except AssertionError: return False
def test_swu(): dst_1 = b"QUUX-V01-CS02-with-BLS12381G2_XMD:SHA-256_SSWU_RO_" msg_1 = b"abcdef0123456789" res = g2_map(msg_1, dst_1).to_affine() assert ( res.x[0].value == 0x121982811D2491FDE9BA7ED31EF9CA474F0E1501297F68C298E9F4C0028ADD35AEA8BB83D53C08CFC007C1E005723CD0 ) assert ( res.x[1].value == 0x190D119345B94FBD15497BCBA94ECF7DB2CBFD1E1FE7DA034D26CBBA169FB3968288B3FAFB265F9EBD380512A71C3F2C ) assert ( res.y[0].value == 0x05571A0F8D3C08D094576981F4A3B8EDA0A8E771FCDCC8ECCEAF1356A6ACF17574518ACB506E435B639353C2E14827C8 ) assert ( res.y[1].value == 0x0BB5E7572275C567462D91807DE765611490205A941A5A6AF3B1691BFE596C31225D3AABDF15FAFF860CB4EF17C7C3BE )
def pop_prove(sk: PrivateKey) -> JacobianPoint: pk: JacobianPoint = sk.get_g1() return sk.value * g2_map(bytes(pk), pop_scheme_pop_dst)
def core_sign_mpl(sk: PrivateKey, message: bytes, dst: bytes) -> JacobianPoint: return sk.value * g2_map(message, dst)