@@ -543,13 +543,21 @@ public PointJacobian DoubleVar(out UInt256_10x26 rzr)
543
543
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
544
544
public static PointJacobian CMov ( in PointJacobian r , in PointJacobian a , uint flag )
545
545
{
546
+ #if DEBUG
547
+ r . Verify ( ) ;
548
+ a . Verify ( ) ;
549
+ #endif
546
550
UInt256_10x26 rx = UInt256_10x26 . CMov ( r . x , a . x , flag ) ;
547
551
UInt256_10x26 ry = UInt256_10x26 . CMov ( r . y , a . y , flag ) ;
548
552
UInt256_10x26 rz = UInt256_10x26 . CMov ( r . z , a . z , flag ) ;
549
553
// TODO: can the following be simplified?
550
554
bool inf = r . isInfinity ^ ( r . isInfinity ^ a . isInfinity ) & ( flag == 1 ) ;
551
555
552
- return new PointJacobian ( rx , ry , rz , inf ) ;
556
+ PointJacobian result = new PointJacobian ( rx , ry , rz , inf ) ;
557
+ #if DEBUG
558
+ result . Verify ( ) ;
559
+ #endif
560
+ return result ;
553
561
}
554
562
555
563
/// <summary>
@@ -560,6 +568,7 @@ public static PointJacobian CMov(in PointJacobian r, in PointJacobian a, uint fl
560
568
public PointJacobian Rescale ( in UInt256_10x26 s )
561
569
{
562
570
#if DEBUG
571
+ Verify ( ) ;
563
572
s . Verify ( ) ;
564
573
Debug . Assert ( ! s . IsZeroNormalizedVar ( ) ) ;
565
574
#endif
@@ -570,7 +579,11 @@ public PointJacobian Rescale(in UInt256_10x26 s)
570
579
ry = y . Multiply ( s ) ; // r->y *= s^3
571
580
UInt256_10x26 rz = z . Multiply ( s ) ; // r->z *= s
572
581
573
- return new PointJacobian ( rx , ry , rz , isInfinity ) ;
582
+ PointJacobian result = new PointJacobian ( rx , ry , rz , isInfinity ) ;
583
+ #if DEBUG
584
+ result . Verify ( ) ;
585
+ #endif
586
+ return result ;
574
587
}
575
588
576
589
@@ -580,9 +593,16 @@ public PointJacobian Rescale(in UInt256_10x26 s)
580
593
/// <returns>-P</returns>
581
594
public PointJacobian Negate ( )
582
595
{
596
+ #if DEBUG
597
+ Verify ( ) ;
598
+ #endif
583
599
UInt256_10x26 yNorm = y . NormalizeWeak ( ) ;
584
600
UInt256_10x26 yNeg = yNorm . Negate ( 1 ) ;
585
- return new PointJacobian ( x , yNeg , z , isInfinity ) ;
601
+ PointJacobian result = new PointJacobian ( x , yNeg , z , isInfinity ) ;
602
+ #if DEBUG
603
+ result . Verify ( ) ;
604
+ #endif
605
+ return result ;
586
606
}
587
607
588
608
@@ -595,12 +615,19 @@ public PointJacobian Negate()
595
615
/// <returns>Result</returns>
596
616
public Point ToPoint ( )
597
617
{
618
+ #if DEBUG
619
+ Verify ( ) ;
620
+ #endif
598
621
UInt256_10x26 rz = z . Inverse ( ) ;
599
622
UInt256_10x26 z2 = rz . Sqr ( ) ;
600
623
UInt256_10x26 z3 = rz * z2 ;
601
624
UInt256_10x26 rx = x * z2 ;
602
625
UInt256_10x26 ry = y * z3 ;
603
- return new Point ( rx , ry , isInfinity ) ;
626
+ Point result = new Point ( rx , ry , isInfinity ) ;
627
+ #if DEBUG
628
+ result . Verify ( ) ;
629
+ #endif
630
+ return result ;
604
631
}
605
632
606
633
/// <summary>
@@ -612,6 +639,9 @@ public Point ToPoint()
612
639
/// <returns>Result</returns>
613
640
public Point ToPointVar ( )
614
641
{
642
+ #if DEBUG
643
+ Verify ( ) ;
644
+ #endif
615
645
if ( isInfinity )
616
646
{
617
647
return Point . Infinity ;
@@ -622,21 +652,30 @@ public Point ToPointVar()
622
652
UInt256_10x26 z3 = rz * z2 ;
623
653
UInt256_10x26 rx = x * z2 ;
624
654
UInt256_10x26 ry = y * z3 ;
625
- return new Point ( rx , ry , isInfinity ) ;
655
+ Point result = new Point ( rx , ry , isInfinity ) ;
656
+ #if DEBUG
657
+ result . Verify ( ) ;
658
+ #endif
659
+ return result ;
626
660
}
627
661
628
662
629
663
internal Point ToPointZInv ( in UInt256_10x26 zi )
630
664
{
631
665
#if DEBUG
666
+ Verify ( ) ;
632
667
zi . Verify ( ) ;
633
668
Debug . Assert ( ! isInfinity ) ;
634
669
#endif
635
670
UInt256_10x26 zi2 = zi . Sqr ( ) ;
636
671
UInt256_10x26 zi3 = zi2 * zi ;
637
672
UInt256_10x26 rx = x * zi2 ;
638
673
UInt256_10x26 ry = y * zi3 ;
639
- return new Point ( rx , ry , isInfinity ) ;
674
+ Point result = new Point ( rx , ry , isInfinity ) ;
675
+ #if DEBUG
676
+ result . Verify ( ) ;
677
+ #endif
678
+ return result ;
640
679
}
641
680
642
681
@@ -647,6 +686,10 @@ internal Point ToPointZInv(in UInt256_10x26 zi)
647
686
/// <returns>True if the two points are equal; otherwise false.</returns>
648
687
public bool EqualsVar ( in PointJacobian other )
649
688
{
689
+ #if DEBUG
690
+ Verify ( ) ;
691
+ other . Verify ( ) ;
692
+ #endif
650
693
PointJacobian tmp = Negate ( ) ;
651
694
tmp = tmp . AddVar ( other , out _ ) ;
652
695
return tmp . isInfinity ;
@@ -659,6 +702,10 @@ public bool EqualsVar(in PointJacobian other)
659
702
/// <returns>True if the two points are equal; otherwise false.</returns>
660
703
public bool EqualsVar ( in Point other )
661
704
{
705
+ #if DEBUG
706
+ Verify ( ) ;
707
+ other . Verify ( ) ;
708
+ #endif
662
709
PointJacobian tmp = Negate ( ) ;
663
710
tmp = tmp . AddVar ( other , out _ ) ;
664
711
return tmp . isInfinity ;
@@ -675,6 +722,7 @@ public bool EqualsVar(in Point other)
675
722
public bool EqualsVar ( in UInt256_10x26 x )
676
723
{
677
724
#if DEBUG
725
+ Verify ( ) ;
678
726
x . Verify ( ) ;
679
727
Debug . Assert ( ! isInfinity ) ;
680
728
#endif
0 commit comments