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

Expose uncompress and hash_to functions for JVM bindings #232

Open
wants to merge 2 commits into
base: master
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
31 changes: 31 additions & 0 deletions bindings/blst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ class P1 {
{ blst_sign_pk_in_g2(&point, &point, &sk.key); return this; }
P1* sign_with(const Scalar& scalar)
{ blst_sign_pk_in_g2(&point, &point, scalar); return this; }
P1* hash_to(const byte* msg, size_t msg_len,
const byte* DST,
size_t DST_len,
const byte* aug = nullptr, size_t aug_len = 0)
{ blst_hash_to_g1(&point, msg, msg_len, DST, DST_len,
aug, aug_len);
return this;
}
P1* hash_to(const byte* msg, size_t msg_len,
const std::string& DST = "",
const byte* aug = nullptr, size_t aug_len = 0)
Expand Down Expand Up @@ -343,6 +351,14 @@ class P1 {
#endif
static P1 generator()
{ return P1(blst_p1_generator()); }
static P1_Affine uncompress(const byte in[48])
{
P1_Affine ret;
BLST_ERROR err = blst_p1_uncompress(ret, in);
if (err != BLST_SUCCESS)
throw err;
return ret;
}

private:
friend class P1_Affine;
Expand Down Expand Up @@ -591,6 +607,13 @@ class P2 {
{ blst_sign_pk_in_g1(&point, &point, &sk.key); return this; }
P2* sign_with(const Scalar& scalar)
{ blst_sign_pk_in_g1(&point, &point, scalar); return this; }
P2* hash_to(const byte* msg, size_t msg_len,
const byte* DST, size_t DST_len,
const byte* aug = nullptr, size_t aug_len = 0)
{ blst_hash_to_g2(&point, msg, msg_len, DST, DST_len,
aug, aug_len);
return this;
}
P2* hash_to(const byte* msg, size_t msg_len,
const std::string& DST = "",
const byte* aug = nullptr, size_t aug_len = 0)
Expand Down Expand Up @@ -641,6 +664,14 @@ class P2 {
#endif
static P2 generator()
{ return P2(blst_p2_generator()); }
static P2_Affine uncompress(const byte in[96])
{
P2_Affine ret;
BLST_ERROR err = blst_p2_uncompress(ret, in);
if (err != BLST_SUCCESS)
throw err;
return ret;
}

private:
friend class P2_Affine;
Expand Down
2 changes: 2 additions & 0 deletions bindings/blst.swg
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,12 @@ import java.nio.file.*;
%catches(BLST_ERROR) P1(const byte* in, size_t len);
%catches(BLST_ERROR) P1_Affine(const byte* in, size_t len);
%catches(BLST_ERROR) aggregate(const P1_Affine& in);
%catches(BLST_ERROR) uncompress(const byte in[48]);

%catches(BLST_ERROR) P2(const byte* in, size_t len);
%catches(BLST_ERROR) P2_Affine(const byte* in, size_t len);
%catches(BLST_ERROR) aggregate(const P2_Affine& in);
%catches(BLST_ERROR) uncompress(const byte in[96]);

%catches(BLST_ERROR) blst::Scalar::add;
%catches(BLST_ERROR) blst::Scalar::sub;
Expand Down