diff --git a/bindings/c#/run.me b/bindings/c#/run.me index a7a1f42b..124710c2 100755 --- a/bindings/c#/run.me +++ b/bindings/c#/run.me @@ -348,6 +348,13 @@ static extern ERROR blst_core_verify_pk_in_g2([In] long[] pk, [In] long[] sig, [In] byte[] dst, size_t dst_len, [In] byte[] aug, size_t aug_len); +[DllImport("blst.dll", CallingConvention = CallingConvention.Cdecl)] +static extern ERROR blst_p1_deserialize_eip2537([Out] long[] ret, + [In] byte[] inp); +[DllImport("blst.dll", CallingConvention = CallingConvention.Cdecl)] +static extern void blst_p1_affine_serialize_eip2537([Out] byte[] ret, + [In] long[] inp); + public struct P1_Affine { internal readonly long[] point; @@ -359,10 +366,12 @@ public struct P1_Affine { public P1_Affine(byte[] inp) : this(true) { int len = inp.Length; - if (len == 0 || len != ((inp[0]&0x80) == 0x80 ? P1_COMPRESSED_SZ - : 2*P1_COMPRESSED_SZ)) + if (len == 0 || (len != ((inp[0]&0x80) == 0x80 ? P1_COMPRESSED_SZ + : 2*P1_COMPRESSED_SZ) && + len != 128*1)) throw new Exception(ERROR.BAD_ENCODING); - ERROR err = blst_p1_deserialize(point, inp); + ERROR err = len == 128*1 ? blst_p1_deserialize_eip2537(point, inp) + : blst_p1_deserialize(point, inp); if (err != ERROR.SUCCESS) throw new Exception(err); } @@ -371,6 +380,11 @@ public struct P1_Affine { public P1_Affine dup() { return new P1_Affine(this); } public P1 to_jacobian() { return new P1(this); } + public byte[] serialize_eip2537() + { byte[] ret = new byte[128*1]; + blst_p1_affine_serialize_eip2537(ret, point); + return ret; + } public byte[] serialize() { byte[] ret = new byte[2*P1_COMPRESSED_SZ]; blst_p1_affine_serialize(ret, point); @@ -455,6 +469,9 @@ void blst_p1_add_or_double_affine([Out] long[] ret, [In] long[] a, [DllImport("blst.dll", CallingConvention = CallingConvention.Cdecl)] static extern void blst_p1_double([Out] long[] ret, [In] long[] a); +[DllImport("blst.dll", CallingConvention = CallingConvention.Cdecl)] +static extern void blst_p1_serialize_eip2537([Out] byte[] ret, [In] long[] inp); + public struct P1 { internal long[] point; @@ -470,10 +487,12 @@ public struct P1 { { blst_sk_to_pk_in_g1(point, sk.key); } public P1(byte[] inp) : this(true) { int len = inp.Length; - if (len == 0 || len != ((inp[0]&0x80) == 0x80 ? P1_COMPRESSED_SZ - : 2*P1_COMPRESSED_SZ)) + if (len == 0 || (len != ((inp[0]&0x80) == 0x80 ? P1_COMPRESSED_SZ + : 2*P1_COMPRESSED_SZ) && + len != 128*1)) throw new Exception(ERROR.BAD_ENCODING); - ERROR err = blst_p1_deserialize(point, inp); + ERROR err = len == 128*1 ? blst_p1_deserialize_eip2537(point, inp) + : blst_p1_deserialize(point, inp); if (err != ERROR.SUCCESS) throw new Exception(err); blst_p1_from_affine(point, point); @@ -483,6 +502,11 @@ public struct P1 { public P1 dup() { return new P1(this); } public P1_Affine to_affine() { return new P1_Affine(this); } + public byte[] serialize_eip2537() + { byte[] ret = new byte[128*1]; + blst_p1_serialize_eip2537(ret, point); + return ret; + } public byte[] serialize() { byte[] ret = new byte[2*P1_COMPRESSED_SZ]; blst_p1_serialize(ret, point); @@ -789,7 +813,7 @@ if newer([here[-1], fname]): print("\n\n", file=fd) print(top, file=fd) print(middle, file=fd) - print(re.sub(r'((?