def test_listPointGenerator(self): r = SystemRandom() for i in range(10): p = getRandPrime(5) while p <= 10: p = getRandPrime(5) e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p) for point in e.listPointGenerator(): self.assertTrue(e.isInCurve(point))
def test_basePoint(self): r = SystemRandom() for i in range(10): p = getRandPrime(5) while p <= 10: p = getRandPrime(5) e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p) G = e.G self.assertTrue(e.isInCurve(G))
def test_sqrtmod(self): r = random.SystemRandom() for i in range(10): p = prime.getRandPrime(20) while p < 10: p = prime.getRandPrime(10) for j in range(100): a = r.randint(1, p - 1) x = prime.sqrtmod(a, p) if x: self.assertTrue(x * x % p == a)
def test_add(self): r = SystemRandom() for i in range(10): p = getRandPrime(5) while p <= 10: p = getRandPrime(5) e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p) all_points = list(e.listPointGenerator()) for j in range(100): point1 = r.choice(all_points) point2 = r.choice(all_points) point = e.add(point1, point2) self.assertEqual(e.isInCurve(point), True)
def test_inv(self): r = random.SystemRandom() for p in [prime.getRandPrime(10 + i) for i in range(10)]: self.assertEqual(prime.inv(1, p) % p, 1) self.assertEqual(prime.inv(p - 1, p) * (p - 1) % p, 1) for i in range(10): a = r.randint(1, p-1) self.assertEqual(prime.inv(a, p) * a % p, 1)
def test_inv(self): r = random.SystemRandom() for p in [prime.getRandPrime(10 + i) for i in range(10)]: self.assertEqual(prime.inv(1, p) % p, 1) self.assertEqual(prime.inv(p - 1, p) * (p - 1) % p, 1) for i in range(10): a = r.randint(1, p - 1) self.assertEqual(prime.inv(a, p) * a % p, 1)
def test_getRandPrime(self): for i in range(100): n = prime.getRandPrime(10 + i) self.assertTrue(prime.isPrime(n))