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

Add swig bindings for field element mapping to G1 and G2 #220

Closed
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
4 changes: 2 additions & 2 deletions bindings/blst.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ void blst_p2s_tile_pippenger(blst_p2 *ret, const blst_p2_affine *const points[],
/*
* Hash-to-curve operations.
*/
#ifndef SWIG

void blst_map_to_g1(blst_p1 *out, const blst_fp *u, const blst_fp *v DEFNULL);

void blst_map_to_g2(blst_p2 *out, const blst_fp2 *u, const blst_fp2 *v DEFNULL);
#endif

void blst_encode_to_g1(blst_p1 *out,
const byte *msg, size_t msg_len,
Expand Down
17 changes: 17 additions & 0 deletions bindings/blst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ class P1 {
aug, aug_len);
return this;
}
P1* map_to(const byte *u)
{
blst_fp ret;
blst_fp_from_bendian(&ret, u);
blst_map_to_g1(&point, &ret, nullptr);
return this;
}

#if __cplusplus >= 201703L
P1* hash_to(const app__string_view msg, const std::string& DST = "",
const app__string_view aug = None)
Expand Down Expand Up @@ -605,6 +613,15 @@ class P2 {
aug, aug_len);
return this;
}
P2* map_to(const byte *u)
{
blst_fp2 fp2;
blst_fp_from_bendian(&fp2.fp[0], u);
blst_fp_from_bendian(&fp2.fp[1], u+48);
blst_map_to_g2(&point, &fp2, nullptr);
return this;
}

#if __cplusplus >= 201703L
P2* hash_to(const app__string_view msg, const std::string& DST = "",
const app__string_view aug = None)
Expand Down
1 change: 1 addition & 0 deletions bindings/blst.swg
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ import java.nio.file.*;
blst::P1* sign_with, blst::P2* sign_with,
blst::P1* hash_to, blst::P2* hash_to,
blst::P1* encode_to, blst::P2* encode_to,
blst::P1* map_to, blst::P2* map_to,
blst::P1* mult, blst::P2* mult,
blst::P1* cneg, blst::P2* cneg,
blst::P1* neg, blst::P2* neg,
Expand Down