def test_add(self): i1 = ecc.ECPoint(0, 0, 1) i2 = ecc.ECPoint(1, 2, 1) assert (self.ec.add(i1, i2) == i1) assert (self.ec.add(i1, i2) == i2) p1 = ecc.ECPoint(4, 1) p2 = ecc.ECPoint(6, 6) p3 = ecc.ECPoint(5, 0) assert (self.ec.add(p1, p1) == p2) assert (self.ec.add(p1, p2) == p3) assert (self.ec.add(p2, p1) == p3)
class TestBasic: """ Create the curve Y^2 = X^3 + X + 3. """ g = ecc.ECPoint(4, 1) # generator ec = ecc.EllipticCurve(7, g, 1, 3) def test_generator(self): s = set() p = self.g for i in range(12): s.add(p) p = self.ec.add(p, self.g) assert (len(s) == 6) def test_add(self): i1 = ecc.ECPoint(0, 0, 1) i2 = ecc.ECPoint(1, 2, 1) assert (self.ec.add(i1, i2) == i1) assert (self.ec.add(i1, i2) == i2) p1 = ecc.ECPoint(4, 1) p2 = ecc.ECPoint(6, 6) p3 = ecc.ECPoint(5, 0) assert (self.ec.add(p1, p1) == p2) assert (self.ec.add(p1, p2) == p3) assert (self.ec.add(p2, p1) == p3) def test_mul(self): p1 = ecc.ECPoint(4, 1) assert (self.ec.mul(p1, 2) == self.ec.add(p1, p1)) # the order of P1 is 6 assert (self.ec.mul(p1, 7) == p1)
class TestSecp256k1: """ Create the secp256k1 curve Y^2 = X^3 + 7. """ p = int('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16) a = 0 b = 7 g = ecc.ECPoint( int('79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798', 16), int('483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8', 16)) ec = ecc.EllipticCurve(p, g, a, b) # order of group n = int('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 16) def test_generator(self): # the order is such that nP = 0 assert self.ec.mul(self.g, self.n) == ecc.ECPoint(0, 0, 1) def test_arithmetic(self): p1 = self.ec.random_point() assert self.ec.add(p1, self.ec.neg(p1)) == self.ec.identity() p2 = self.ec.random_point() p3 = self.ec.add(p1, p2) assert self.ec.is_valid(p3) == True
def test_mul(self): p1 = ecc.ECPoint(4, 1) assert (self.ec.mul(p1, 2) == self.ec.add(p1, p1)) # the order of P1 is 6 assert (self.ec.mul(p1, 7) == p1)
def test_generator(self): # the order is such that nP = 0 assert self.ec.mul(self.g, self.n) == ecc.ECPoint(0, 0, 1)