Пример #1
0
    def test_lookup_by_params(self):
        """Test errors in EC curve lookup by params"""

        G, n = get_ec_curve_params(b'nistp256')

        with self.subTest('Bad curve'):
            with self.assertRaises(ValueError):
                lookup_ec_curve_by_params(G.curve.p+1, G.curve.a, G.curve.b,
                                          G.encode(), n)

        with self.subTest('Unknown curve'):
            with self.assertRaises(ValueError):
                lookup_ec_curve_by_params(263, 2, 3,
                                          encode_ec_point(2, 200, 39), 270)
Пример #2
0
    def test_encode(self):
        """Unit test native Python EC point encoding"""

        G, _ = get_ec_curve_params(b'nistp256')

        with self.subTest('Encode infinity'):
            self.assertEqual(encode_ec_point(None, None, None), b'\x00')

        with self.subTest('Decode infinity'):
            point = PrimePoint.decode(G.curve, b'\x00')
            self.assertEqual((point.curve, point.x, point.y),
                             (None, None, None))

        with self.subTest('Encode and decode'):
            self.assertEqual(PrimePoint.decode(G.curve, G.encode()), G)

        with self.subTest('Bad point type'):
            with self.assertRaises(ValueError):
                decode_ec_point(0, b'\x05')

        with self.subTest('Bad point length'):
            with self.assertRaises(ValueError):
                decode_ec_point(G.curve.keylen, G.encode()[:-1])