def solve(x): # Solve for y, given x # There are two possible points that satisfy the curve, # an even and an odd. We choose the odd one. y = sqrt(x**3 + 7) if y.n % 2 == 0: y = -y if not curve.testPoint(x, y): raise ValueError return Point(curve, x, y)
def fast__mul__(self, n): if n < 0: return -self * -n if n == 0: return Ideal(self.curve) p = secp256k1_openssl.SPoint(self.x.n, self.y.n) x, y = p.mult(n)._coords() #slow = self._slow_mul(n) #assert slow.x == x #assert slow.y == y return Point(self.curve, Fq(x), Fq(y))
# Then the curve, always of the form y^2 = x^3 + {a6} # The curve E: y2 = x3+ax+b over Fp is defined by: # a = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 # b = 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000007 curve = GeneralizedEllipticCurve(a6=Fq(7)) # Ex: y2 = x3+7 # base point, a generator of the group # The base point G in compressed form is: # G = 02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798 Gx = Fq(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798) Gy = Fq(0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8) G = Point(curve, Gx, Gy) # Finally the order n of G and the cofactor are: # n = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141 # h = 01 # This is the order (# of elements in) the curve p = order = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 Fp = FiniteField(p, 1) ## # Convenience functions ## def random_oracle_string_to_Zp(s): return sha2_to_long(s) % p