IsOnCurve returns true if the given (x,y) lies on the BitCurve.
(x, y *big.Int)
| 100 | |
| 101 | // IsOnCurve returns true if the given (x,y) lies on the BitCurve. |
| 102 | func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool { |
| 103 | // y² = x³ + b |
| 104 | y2 := new(big.Int).Mul(y, y) //y² |
| 105 | y2.Mod(y2, BitCurve.P) //y²%P |
| 106 | |
| 107 | x3 := new(big.Int).Mul(x, x) //x² |
| 108 | x3.Mul(x3, x) //x³ |
| 109 | |
| 110 | x3.Add(x3, BitCurve.B) //x³+B |
| 111 | x3.Mod(x3, BitCurve.P) //(x³+B)%P |
| 112 | |
| 113 | return x3.Cmp(y2) == 0 |
| 114 | } |
| 115 | |
| 116 | //TODO: double check if the function is okay |
| 117 | // affineFromJacobian reverses the Jacobian transform. See the comment at the |