Пример #1
0
    def test_equals(self):
        pt = Point(self.coords,
                   X=Mod(0x4, self.secp128r1.curve.prime),
                   Y=Mod(0x6, self.secp128r1.curve.prime),
                   Z=Mod(2, self.secp128r1.curve.prime))
        other = Point(self.coords,
                      X=Mod(0x2, self.secp128r1.curve.prime),
                      Y=Mod(0x3, self.secp128r1.curve.prime),
                      Z=Mod(1, self.secp128r1.curve.prime))
        self.assertTrue(pt.equals(other))
        self.assertNotEqual(pt, other)
        self.assertFalse(pt.equals(2))
        self.assertNotEqual(pt, 2)

        infty_one = InfinityPoint(self.coords)
        infty_other = InfinityPoint(self.coords)
        self.assertTrue(infty_one.equals(infty_other))
        self.assertEqual(infty_one, infty_other)

        mont = MontgomeryModel()
        different = Point(mont.coordinates["xz"],
                          X=Mod(0x64daccd2656420216545e5f65221eb,
                                0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),
                          Z=Mod(1, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa))
        self.assertFalse(pt.equals(different))
        self.assertNotEqual(pt, different)
Пример #2
0
    def test_equals(self):
        pt = Point(
            self.coords,
            X=Mod(0x4, self.secp128r1.curve.prime),
            Y=Mod(0x6, self.secp128r1.curve.prime),
            Z=Mod(2, self.secp128r1.curve.prime),
        )
        other = Point(
            self.coords,
            X=Mod(0x2, self.secp128r1.curve.prime),
            Y=Mod(0x3, self.secp128r1.curve.prime),
            Z=Mod(1, self.secp128r1.curve.prime),
        )
        third = Point(
            self.coords,
            X=Mod(0x5, self.secp128r1.curve.prime),
            Y=Mod(0x3, self.secp128r1.curve.prime),
            Z=Mod(1, self.secp128r1.curve.prime),
        )
        self.assertTrue(pt.equals(other))
        self.assertNotEqual(pt, other)
        self.assertFalse(pt.equals(2))
        self.assertNotEqual(pt, 2)
        self.assertFalse(pt.equals(third))
        self.assertNotEqual(pt, third)
        self.assertTrue(pt.equals_scaled(other))
        self.assertTrue(pt.equals_affine(other))
        self.assertFalse(pt.equals_scaled(third))

        infty_one = InfinityPoint(self.coords)
        infty_other = InfinityPoint(self.coords)
        self.assertTrue(infty_one.equals(infty_other))
        self.assertTrue(infty_one.equals_affine(infty_other))
        self.assertTrue(infty_one.equals_scaled(infty_other))
        self.assertEqual(infty_one, infty_other)
        self.assertFalse(pt.equals(infty_one))
        self.assertFalse(pt.equals_affine(infty_one))
        self.assertFalse(pt.equals_scaled(infty_one))

        mont = MontgomeryModel()
        different = Point(
            mont.coordinates["xz"],
            X=Mod(
                0x64DACCD2656420216545E5F65221EB,
                0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
            ),
            Z=Mod(1, 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA),
        )
        self.assertFalse(pt.equals(different))
        self.assertNotEqual(pt, different)