@@ -344,6 +344,13 @@ static extern ERROR blst_core_verify_pk_in_g2([In] long[] pk, [In] long[] sig,
344
344
[ In ] byte [ ] dst , size_t dst_len ,
345
345
[ In ] byte [ ] aug , size_t aug_len ) ;
346
346
347
+ [ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
348
+ static extern ERROR blst_p1_deserialize_eip2537 ( [ Out ] long [ ] ret ,
349
+ [ In ] byte [ ] inp ) ;
350
+ [ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
351
+ static extern void blst_p1_affine_serialize_eip2537 ( [ Out ] byte [ ] ret ,
352
+ [ In ] long [ ] inp ) ;
353
+
347
354
public struct P1_Affine {
348
355
internal readonly long [ ] point ;
349
356
@@ -355,10 +362,12 @@ public struct P1_Affine {
355
362
356
363
public P1_Affine ( byte [ ] inp ) : this ( true )
357
364
{ int len = inp . Length ;
358
- if ( len == 0 || len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P1_COMPRESSED_SZ
359
- : 2 * P1_COMPRESSED_SZ ) )
365
+ if ( len == 0 || ( len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P1_COMPRESSED_SZ
366
+ : 2 * P1_COMPRESSED_SZ ) &&
367
+ len != 128 * 1 ) )
360
368
throw new Exception ( ERROR . BAD_ENCODING ) ;
361
- ERROR err = blst_p1_deserialize ( point , inp ) ;
369
+ ERROR err = len == 128 * 1 ? blst_p1_deserialize_eip2537 ( point , inp )
370
+ : blst_p1_deserialize ( point , inp ) ;
362
371
if ( err != ERROR . SUCCESS )
363
372
throw new Exception ( err ) ;
364
373
}
@@ -367,6 +376,11 @@ public P1_Affine(P1 jacobian) : this(true)
367
376
368
377
public P1_Affine dup ( ) { return new P1_Affine ( this ) ; }
369
378
public P1 to_jacobian ( ) { return new P1 ( this ) ; }
379
+ public byte [ ] serialize_eip2537 ( )
380
+ { byte [ ] ret = new byte [ 128 * 1 ] ;
381
+ blst_p1_affine_serialize_eip2537 ( ret , point ) ;
382
+ return ret ;
383
+ }
370
384
public byte [ ] serialize ( )
371
385
{ byte [ ] ret = new byte [ 2 * P1_COMPRESSED_SZ ] ;
372
386
blst_p1_affine_serialize ( ret , point ) ;
@@ -451,6 +465,9 @@ void blst_p1_add_or_double_affine([Out] long[] ret, [In] long[] a,
451
465
[ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
452
466
static extern void blst_p1_double ( [ Out ] long [ ] ret , [ In ] long [ ] a ) ;
453
467
468
+ [ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
469
+ static extern void blst_p1_serialize_eip2537 ( [ Out ] byte [ ] ret , [ In ] long [ ] inp ) ;
470
+
454
471
public struct P1 {
455
472
internal long [ ] point ;
456
473
@@ -466,10 +483,12 @@ public P1(SecretKey sk) : this(true)
466
483
{ blst_sk_to_pk_in_g1 ( point , sk . key ) ; }
467
484
public P1 ( byte [ ] inp ) : this ( true )
468
485
{ int len = inp . Length ;
469
- if ( len == 0 || len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P1_COMPRESSED_SZ
470
- : 2 * P1_COMPRESSED_SZ ) )
486
+ if ( len == 0 || ( len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P1_COMPRESSED_SZ
487
+ : 2 * P1_COMPRESSED_SZ ) &&
488
+ len != 128 * 1 ) )
471
489
throw new Exception ( ERROR . BAD_ENCODING ) ;
472
- ERROR err = blst_p1_deserialize ( point , inp ) ;
490
+ ERROR err = len == 128 * 1 ? blst_p1_deserialize_eip2537 ( point , inp )
491
+ : blst_p1_deserialize ( point , inp ) ;
473
492
if ( err != ERROR . SUCCESS )
474
493
throw new Exception ( err ) ;
475
494
blst_p1_from_affine ( point , point ) ;
@@ -479,6 +498,11 @@ public P1(P1_Affine affine) : this(true)
479
498
480
499
public P1 dup ( ) { return new P1 ( this ) ; }
481
500
public P1_Affine to_affine ( ) { return new P1_Affine ( this ) ; }
501
+ public byte [ ] serialize_eip2537 ( )
502
+ { byte [ ] ret = new byte [ 128 * 1 ] ;
503
+ blst_p1_serialize_eip2537 ( ret , point ) ;
504
+ return ret ;
505
+ }
482
506
public byte [ ] serialize ( )
483
507
{ byte [ ] ret = new byte [ 2 * P1_COMPRESSED_SZ ] ;
484
508
blst_p1_serialize ( ret , point ) ;
@@ -607,6 +631,13 @@ static extern ERROR blst_core_verify_pk_in_g1([In] long[] pk, [In] long[] sig,
607
631
[ In ] byte [ ] dst , size_t dst_len ,
608
632
[ In ] byte [ ] aug , size_t aug_len ) ;
609
633
634
+ [ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
635
+ static extern ERROR blst_p2_deserialize_eip2537 ( [ Out ] long [ ] ret ,
636
+ [ In ] byte [ ] inp ) ;
637
+ [ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
638
+ static extern void blst_p2_affine_serialize_eip2537 ( [ Out ] byte [ ] ret ,
639
+ [ In ] long [ ] inp ) ;
640
+
610
641
public struct P2_Affine {
611
642
internal readonly long [ ] point ;
612
643
@@ -618,10 +649,12 @@ public struct P2_Affine {
618
649
619
650
public P2_Affine ( byte [ ] inp ) : this ( true )
620
651
{ int len = inp . Length ;
621
- if ( len == 0 || len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P2_COMPRESSED_SZ
622
- : 2 * P2_COMPRESSED_SZ ) )
652
+ if ( len == 0 || ( len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P2_COMPRESSED_SZ
653
+ : 2 * P2_COMPRESSED_SZ ) &&
654
+ len != 128 * 2 ) )
623
655
throw new Exception ( ERROR . BAD_ENCODING ) ;
624
- ERROR err = blst_p2_deserialize ( point , inp ) ;
656
+ ERROR err = len == 128 * 2 ? blst_p2_deserialize_eip2537 ( point , inp )
657
+ : blst_p2_deserialize ( point , inp ) ;
625
658
if ( err != ERROR . SUCCESS )
626
659
throw new Exception ( err ) ;
627
660
}
@@ -630,6 +663,11 @@ public P2_Affine(P2 jacobian) : this(true)
630
663
631
664
public P2_Affine dup ( ) { return new P2_Affine ( this ) ; }
632
665
public P2 to_jacobian ( ) { return new P2 ( this ) ; }
666
+ public byte [ ] serialize_eip2537 ( )
667
+ { byte [ ] ret = new byte [ 128 * 2 ] ;
668
+ blst_p2_affine_serialize_eip2537 ( ret , point ) ;
669
+ return ret ;
670
+ }
633
671
public byte [ ] serialize ( )
634
672
{ byte [ ] ret = new byte [ 2 * P2_COMPRESSED_SZ ] ;
635
673
blst_p2_affine_serialize ( ret , point ) ;
@@ -714,6 +752,9 @@ void blst_p2_add_or_double_affine([Out] long[] ret, [In] long[] a,
714
752
[ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
715
753
static extern void blst_p2_double ( [ Out ] long [ ] ret , [ In ] long [ ] a ) ;
716
754
755
+ [ DllImport ( "blst.dll" , CallingConvention = CallingConvention . Cdecl ) ]
756
+ static extern void blst_p2_serialize_eip2537 ( [ Out ] byte [ ] ret , [ In ] long [ ] inp ) ;
757
+
717
758
public struct P2 {
718
759
internal long [ ] point ;
719
760
@@ -729,10 +770,12 @@ public P2(SecretKey sk) : this(true)
729
770
{ blst_sk_to_pk_in_g2 ( point , sk . key ) ; }
730
771
public P2 ( byte [ ] inp ) : this ( true )
731
772
{ int len = inp . Length ;
732
- if ( len == 0 || len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P2_COMPRESSED_SZ
733
- : 2 * P2_COMPRESSED_SZ ) )
773
+ if ( len == 0 || ( len != ( ( inp [ 0 ] & 0x80 ) == 0x80 ? P2_COMPRESSED_SZ
774
+ : 2 * P2_COMPRESSED_SZ ) &&
775
+ len != 128 * 2 ) )
734
776
throw new Exception ( ERROR . BAD_ENCODING ) ;
735
- ERROR err = blst_p2_deserialize ( point , inp ) ;
777
+ ERROR err = len == 128 * 2 ? blst_p2_deserialize_eip2537 ( point , inp )
778
+ : blst_p2_deserialize ( point , inp ) ;
736
779
if ( err != ERROR . SUCCESS )
737
780
throw new Exception ( err ) ;
738
781
blst_p2_from_affine ( point , point ) ;
@@ -742,6 +785,11 @@ public P2(P2_Affine affine) : this(true)
742
785
743
786
public P2 dup ( ) { return new P2 ( this ) ; }
744
787
public P2_Affine to_affine ( ) { return new P2_Affine ( this ) ; }
788
+ public byte [ ] serialize_eip2537 ( )
789
+ { byte [ ] ret = new byte [ 128 * 2 ] ;
790
+ blst_p2_serialize_eip2537 ( ret , point ) ;
791
+ return ret ;
792
+ }
745
793
public byte [ ] serialize ( )
746
794
{ byte [ ] ret = new byte [ 2 * P2_COMPRESSED_SZ ] ;
747
795
blst_p2_serialize ( ret , point ) ;
0 commit comments