Skip to content

Commit

Permalink
fix python binding for from_message() on G1Element and G2Element
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed May 8, 2023
1 parent 1feb218 commit da50246
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions python-bindings/pythonbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ PYBIND11_MODULE(blspy, m)
return G1Element::FromBytesUnchecked({data_ptr, G1Element::SIZE});
})
.def("generator", &G1Element::Generator)
.def("from_message", py::overload_cast<const std::vector<uint8_t>&, const uint8_t*, int>(&G1Element::FromMessage), py::call_guard<py::gil_scoped_release>())
.def("from_message", [](std::string const msg, std::string const dst) {
py::gil_scoped_release release;
return G1Element::FromMessage(
std::vector<uint8_t>(msg.data(), msg.data() + msg.size()),
(uint8_t const*)dst.data(), dst.size());
})
.def("pair", &G1Element::Pair, py::call_guard<py::gil_scoped_release>())
.def("negate", &G1Element::Negate, py::call_guard<py::gil_scoped_release>())
.def("get_fingerprint", &G1Element::GetFingerprint, py::call_guard<py::gil_scoped_release>())
Expand Down Expand Up @@ -560,7 +565,12 @@ PYBIND11_MODULE(blspy, m)
return G2Element::FromBytesUnchecked({data_ptr, G2Element::SIZE});
})
.def("generator", &G2Element::Generator)
.def("from_message", py::overload_cast<const std::vector<uint8_t>&, const uint8_t*, int>(&G2Element::FromMessage), py::call_guard<py::gil_scoped_release>())
.def("from_message", [](std::string const msg, std::string const dst) {
py::gil_scoped_release release;
return G2Element::FromMessage(
std::vector<uint8_t>(msg.data(), msg.data() + msg.size()),
(uint8_t const*)dst.data(), dst.size());
})
.def("pair", &G2Element::Pair, py::call_guard<py::gil_scoped_release>())
.def("negate", &G2Element::Negate, py::call_guard<py::gil_scoped_release>())
.def(
Expand Down
6 changes: 6 additions & 0 deletions python-bindings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def test_schemes():
sk2 = BasicSchemeMPL.key_gen(seed)
pk2 = sk2.get_g1()

g1 = G1Element.from_message(b"abcd", b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_")
assert bytes(g1) == bytes.fromhex("a5f756594a96c55f302360378568378dc19ea5eae3d5a88d77b8a30bb25c25ce24a85c6d7c851bcb1e34064fc0c79383")

g2 = G2Element.from_message(b"abcd", b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_")
assert g2 == AugSchemeMPL.g2_from_message(b"abcd")

for Scheme in (BasicSchemeMPL, AugSchemeMPL, PopSchemeMPL):
# Aggregate same message
agg_pk = pk1 + pk2
Expand Down

0 comments on commit da50246

Please sign in to comment.