Double a Jacobian tuple p1 See https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates - Point Doubling
(self, p1)
| 110 | return (x, self.p - y if y & 1 else y, 1) |
| 111 | |
| 112 | def double(self, p1): |
| 113 | """Double a Jacobian tuple p1 |
| 114 | |
| 115 | See https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates - Point Doubling""" |
| 116 | x1, y1, z1 = p1 |
| 117 | if z1 == 0: |
| 118 | return (0, 1, 0) |
| 119 | y1_2 = (y1**2) % self.p |
| 120 | y1_4 = (y1_2**2) % self.p |
| 121 | x1_2 = (x1**2) % self.p |
| 122 | s = (4*x1*y1_2) % self.p |
| 123 | m = 3*x1_2 |
| 124 | if self.a: |
| 125 | m += self.a * pow(z1, 4, self.p) |
| 126 | m = m % self.p |
| 127 | x2 = (m**2 - 2*s) % self.p |
| 128 | y2 = (m*(s - x2) - 8*y1_4) % self.p |
| 129 | z2 = (2*y1*z1) % self.p |
| 130 | return (x2, y2, z2) |
| 131 | |
| 132 | def add_mixed(self, p1, p2): |
| 133 | """Add a Jacobian tuple p1 and an affine tuple p2 |