From 6713f80f6f32fce4803eaed49233f89b9ab13e05 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 30 May 2024 15:40:53 -0700 Subject: [PATCH 1/2] add to swig bindings field element mapping for G1 and G2 Signed-off-by: garyschulte --- bindings/blst.h | 4 ++-- bindings/blst.hpp | 17 +++++++++++++++++ bindings/blst.swg | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bindings/blst.h b/bindings/blst.h index 8e0a488c..e92ed793 100644 --- a/bindings/blst.h +++ b/bindings/blst.h @@ -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, diff --git a/bindings/blst.hpp b/bindings/blst.hpp index 127755be..9204005c 100644 --- a/bindings/blst.hpp +++ b/bindings/blst.hpp @@ -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) @@ -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) diff --git a/bindings/blst.swg b/bindings/blst.swg index 4cb9c30d..07d62df5 100644 --- a/bindings/blst.swg +++ b/bindings/blst.swg @@ -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_g1, blst::P2* map_to_g2, blst::P1* mult, blst::P2* mult, blst::P1* cneg, blst::P2* cneg, blst::P1* neg, blst::P2* neg, From 0462f2efb758c7560063547e1778cc5503cbfaa7 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 30 May 2024 15:57:20 -0700 Subject: [PATCH 2/2] remove _g1 and _g2 suffixes from swg Signed-off-by: garyschulte --- bindings/blst.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/blst.swg b/bindings/blst.swg index 07d62df5..12417b1e 100644 --- a/bindings/blst.swg +++ b/bindings/blst.swg @@ -723,7 +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_g1, blst::P2* map_to_g2, + 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,