def test_carryless_multiplication(self): for x in [0, 1, 2, 3, 4, 5, 123, 267, 498327849327]: self.assertEqual(NumberTheory.cl_mul(0, x), 0) self.assertEqual(NumberTheory.cl_mul(x, 0), 0) self.assertEqual(NumberTheory.cl_mul(1, x), x) self.assertEqual(NumberTheory.cl_mul(x, 1), x) self.assertEqual(NumberTheory.cl_mul(2, x), 2 * x) self.assertEqual(NumberTheory.cl_mul(x, 2), 2 * x) self.assertEqual(NumberTheory.cl_mul(x, 1024), 1024 * x) self.assertEqual(NumberTheory.cl_mul(1024, x), 1024 * x) self.assertEqual(NumberTheory.cl_mul(x, 1 | 2 | 8 | 256), (1 * x) ^ (2 * x) ^ (8 * x) ^ (256 * x)) self.assertEqual(NumberTheory.cl_mul(1 | 2 | 8 | 256, x), (1 * x) ^ (2 * x) ^ (8 * x) ^ (256 * x))
def on_curve(self, point): lhs = NumberTheory.binpoly_reduce( NumberTheory.cl_mul(point.y, point.y) ^ NumberTheory.cl_mul(point.x, point.y), self.intpoly) rhs = NumberTheory.binpoly_reduce( NumberTheory.cl_mul(NumberTheory.cl_mul(point.x, point.x), point.x) ^ NumberTheory.cl_mul(NumberTheory.cl_mul(self.a, point.x), point.x) ^ self.b, self.intpoly) return lhs == rhs