From d72fa47d308ca99dcd83d507d54fc6ebbf69099a Mon Sep 17 00:00:00 2001 From: dahmed Date: Sat, 21 Oct 2023 00:38:29 +0000 Subject: [PATCH 1/3] Added division operator for GTElement --- src/elements.cpp | 10 ++++++++++ src/elements.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/src/elements.cpp b/src/elements.cpp index bdb3bc6ec..6a6989953 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -474,6 +474,16 @@ GTElement operator*(GTElement& a, GTElement& b) return ans; } +GTElement operator/(GTElement& a, GTElement& b) +{ + GTElement ans; + GTElement b_inv; + blst_fp12_inverse(&(b_inv.r), &(b.r)); + blst_fp12_mul(&(ans.r), &(a.r), &(b_inv.r)); + + return ans; +} + void GTElement::Serialize(uint8_t* buffer) const { memcpy(buffer, &r, GTElement::SIZE); diff --git a/src/elements.hpp b/src/elements.hpp index af7dd6e25..8e6ebf07e 100644 --- a/src/elements.hpp +++ b/src/elements.hpp @@ -130,6 +130,7 @@ class GTElement { friend bool operator!=(GTElement const &a, GTElement const &b); friend std::ostream &operator<<(std::ostream &os, const GTElement &s); friend GTElement operator*(GTElement &a, GTElement &b); + friend GTElement operator/(GTElement &a, GTElement &b); private: blst_fp12 r; From ee44e35bc7fdcc79193519365de9024fb50f0a36 Mon Sep 17 00:00:00 2001 From: dahmed Date: Wed, 25 Oct 2023 18:16:52 +0000 Subject: [PATCH 2/3] Added test for GT division operator --- src/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test.cpp b/src/test.cpp index 1c7a95640..754bc0093 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1525,6 +1525,11 @@ TEST_CASE("GTElement") auto agg_sig_pair = G1Element::Generator().Pair(aggsig); REQUIRE(pair == agg_sig_pair); + + // test division operator + GTElement gt1 = G1Element::Generator().Pair(G2Element::Generator()); + GTElement gt2 = G1Element::Generator().Pair(G2Element::Generator()); + REQUIRE(gt1 / gt2 == gt2 / gt1 ); } } From 28ec4cf392ef9f9dfd64ca9b9a0ecb955c3dad2a Mon Sep 17 00:00:00 2001 From: "David L. Adei" Date: Wed, 25 Oct 2023 18:16:52 +0000 Subject: [PATCH 3/3] Added test for GT division operator --- src/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test.cpp b/src/test.cpp index 1c7a95640..754bc0093 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1525,6 +1525,11 @@ TEST_CASE("GTElement") auto agg_sig_pair = G1Element::Generator().Pair(aggsig); REQUIRE(pair == agg_sig_pair); + + // test division operator + GTElement gt1 = G1Element::Generator().Pair(G2Element::Generator()); + GTElement gt2 = G1Element::Generator().Pair(G2Element::Generator()); + REQUIRE(gt1 / gt2 == gt2 / gt1 ); } }