Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Division operator for GTElement (e1/e2) #438

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down