Skip to content

Commit

Permalink
bindings/blst.{hpp,swg}: add SWIG bindings for EIP-2537 serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Jun 13, 2024
1 parent 20bbcc4 commit 2c6bbec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
36 changes: 18 additions & 18 deletions bindings/blst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,19 @@ class P1_Affine {
}
#endif
P1_Affine(const byte *in, size_t len)
{ if (len == 0 || len != (in[0]&0x80 ? 48 : 96))
{ if (len == 0 || (len != (in[0]&0x80 ? 48 : 96) && len != 128))
throw BLST_BAD_ENCODING;
BLST_ERROR err = blst_p1_deserialize(&point, in);
BLST_ERROR err = len == 128 ? blst_p1_deserialize_eip2537(&point, in)
: blst_p1_deserialize(&point, in);
if (err != BLST_SUCCESS)
throw err;
}
P1_Affine(const P1& jacobian);

P1_Affine dup() const { return *this; }
P1 to_jacobian() const;
void serialize_eip2537(byte out[128]) const
{ blst_p1_affine_serialize_eip2537(out, &point); }
void serialize(byte out[96]) const
{ blst_p1_affine_serialize(out, &point); }
void compress(byte out[48]) const
Expand Down Expand Up @@ -264,18 +267,15 @@ class P1 {
}
#endif
P1(const byte *in, size_t len)
{ if (len == 0 || len != (in[0]&0x80 ? 48 : 96))
throw BLST_BAD_ENCODING;
blst_p1_affine a;
BLST_ERROR err = blst_p1_deserialize(&a, in);
if (err != BLST_SUCCESS)
throw err;
blst_p1_from_affine(&point, &a);
{ P1_Affine affine{in, len};
blst_p1_from_affine(&point, &affine.point);
}
P1(const P1_Affine& affine) { blst_p1_from_affine(&point, affine); }

P1 dup() const { return *this; }
P1_Affine to_affine() const { return P1_Affine(*this); }
void serialize_eip2537(byte out[128]) const
{ blst_p1_serialize_eip2537(out, &point); }
void serialize(byte out[96]) const { blst_p1_serialize(out, &point); }
void compress(byte out[48]) const { blst_p1_compress(out, &point); }
bool on_curve() const { return blst_p1_on_curve(&point); }
Expand Down Expand Up @@ -502,16 +502,19 @@ class P2_Affine {
}
#endif
P2_Affine(const byte *in, size_t len)
{ if (len == 0 || len != (in[0]&0x80 ? 96 : 192))
{ if (len == 0 || (len != (in[0]&0x80 ? 96 : 192) && len != 256))
throw BLST_BAD_ENCODING;
BLST_ERROR err = blst_p2_deserialize(&point, in);
BLST_ERROR err = len == 256 ? blst_p2_deserialize_eip2537(&point, in)
: blst_p2_deserialize(&point, in);
if (err != BLST_SUCCESS)
throw err;
}
P2_Affine(const P2& jacobian);

P2_Affine dup() const { return *this; }
P2 to_jacobian() const;
void serialize_eip2537(byte out[256]) const
{ blst_p2_affine_serialize_eip2537(out, &point); }
void serialize(byte out[192]) const
{ blst_p2_affine_serialize(out, &point); }
void compress(byte out[96]) const
Expand Down Expand Up @@ -562,18 +565,15 @@ class P2 {
}
#endif
P2(const byte *in, size_t len)
{ if (len == 0 || len != (in[0]&0x80 ? 96 : 192))
throw BLST_BAD_ENCODING;
blst_p2_affine a;
BLST_ERROR err = blst_p2_deserialize(&a, in);
if (err != BLST_SUCCESS)
throw err;
blst_p2_from_affine(&point, &a);
{ P2_Affine affine{in, len};
blst_p2_from_affine(&point, &affine.point);
}
P2(const P2_Affine& affine) { blst_p2_from_affine(&point, affine); }

P2 dup() const { return *this; }
P2_Affine to_affine() const { return P2_Affine(*this); }
void serialize_eip2537(byte out[256]) const
{ blst_p2_serialize(out, &point); }
void serialize(byte out[192]) const { blst_p2_serialize(out, &point); }
void compress(byte out[96]) const { blst_p2_compress(out, &point); }
bool on_curve() const { return blst_p2_on_curve(&point); }
Expand Down
4 changes: 4 additions & 0 deletions bindings/blst.swg
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ import java.nio.file.*;
void blst_p2_serialize, void blst_p2_affine_serialize,
void compress, void blst_p1_compress, void blst_p1_affine_compress,
void blst_p2_compress, void blst_p2_affine_compress,
void serialize_eip2537, void blst_p1_serialize_eip2537,
void blst_p2_serialize_eip2537,
void blst_p1_affine_serialize_eip2537,
void blst_p2_affine_serialize_eip2537,
void blst_sk_to_pk2_in_g1, void blst_sign_pk2_in_g1,
void blst_sk_to_pk2_in_g2, void blst_sign_pk2_in_g2
}
Expand Down

0 comments on commit 2c6bbec

Please sign in to comment.