tlsfuzzer / python-ecdsa

pure-python ECDSA signature/verification and ECDH key agreement
Other
906 stars 311 forks source link

Tests keep running into hypothesis falsifying examples #307

Closed bnavigator closed 1 year ago

bnavigator commented 1 year ago

python-excdsa 0.18.0 hypothesis 6.56.2

[   35s] _____________________________ test_p192_mult_tests _____________________________
[   35s] 
[   35s]     @settings(**HYP_SLOW_SETTINGS)
[   35s] >   @given(st.integers(min_value=1, max_value=r + 1))
[   35s] 
[   35s] src/ecdsa/test_ellipticcurve.py:47: 
[   35s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   35s] src/ecdsa/test_ellipticcurve.py:49: in test_p192_mult_tests
[   35s]     inv_m = inverse_mod(multiple, r)
[   35s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   35s] 
[   35s] a = 627710173538668076...7194773182842284081
[   35s] m = 627710173538668076...7194773182842284081
[   35s] 
[   35s]     def inverse_mod(a, m):
[   35s]         """Inverse of a mod m."""
[   35s]         if a == 0:  # pragma: no branch
[   35s]             return 0
[   35s] >       return pow(a, -1, m)
[   35s] E       ValueError: base is not invertible for the given modulus
[   35s] E       Falsifying example: test_p192_mult_tests(
[   35s] E           multiple=6277101735386680763835789423176059013767194773182842284081,
[   35s] E       )
[   35s] 
[   35s] src/ecdsa/numbertheory.py:266: ValueError
[   29s] __________________ TestJacobi.test_add_different_scale_points __________________
[   29s] 
[   29s] self = <ecdsa.test_jacobi.TestJacobi testMethod=test_add_different_scale_points>
[   29s] 
[   29s]     @settings(max_examples=14)
[   29s] >   @given(
[   29s]         st.integers(
[   29s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   29s]         ),
[   29s]         st.integers(
[   29s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   29s]         ),
[   29s]         st.lists(
[   29s]             st.integers(
[   29s]                 min_value=1, max_value=int(curve_brainpoolp160r1.p() - 1)
[   29s]             ),
[   29s]             min_size=2,
[   29s]             max_size=2,
[   29s]             unique=True,
[   29s]         ),
[   29s]     )
[   29s] 
[   29s] src/ecdsa/test_jacobi.py:352: 
[   29s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   29s] 
[   29s] self = <ecdsa.test_jacobi.TestJacobi testMethod=test_add_different_scale_points>
[   29s] a_mul = 1, b_mul = 133229759844004487...0181364212942568457, new_z = [2, 1]
[   29s] 
[   29s]     @settings(max_examples=14)
[   29s]     @given(
[   29s]         st.integers(
[   29s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   29s]         ),
[   29s]         st.integers(
[   29s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   29s]         ),
[   29s]         st.lists(
[   29s]             st.integers(
[   29s]                 min_value=1, max_value=int(curve_brainpoolp160r1.p() - 1)
[   29s]             ),
[   29s]             min_size=2,
[   29s]             max_size=2,
[   29s]             unique=True,
[   29s]         ),
[   29s]     )
[   29s]     @example(2, 2, [2, 1])
[   29s]     @example(2, 2, [2, 3])
[   29s]     @example(2, int(generator_brainpoolp160r1.order() - 2), [2, 3])
[   29s]     @example(2, int(generator_brainpoolp160r1.order() - 2), [2, 1])
[   29s]     def test_add_different_scale_points(self, a_mul, b_mul, new_z):
[   29s]         j_g = PointJacobi.from_affine(generator_brainpoolp160r1)
[   29s]         a = PointJacobi.from_affine(j_g * a_mul)
[   29s]         b = PointJacobi.from_affine(j_g * b_mul)
[   29s]     
[   29s]         p = curve_brainpoolp160r1.p()
[   29s]     
[   29s]         assume(inverse_mod(new_z[0], p))
[   29s]         assume(inverse_mod(new_z[1], p))
[   29s]     
[   29s]         new_zz0 = new_z[0] * new_z[0] % p
[   29s]         new_zz1 = new_z[1] * new_z[1] % p
[   29s]     
[   29s]         a = PointJacobi(
[   29s]             curve_brainpoolp160r1,
[   29s]             a.x() * new_zz0 % p,
[   29s]             a.y() * new_zz0 * new_z[0] % p,
[   29s]             new_z[0],
[   29s]         )
[   29s]         b = PointJacobi(
[   29s]             curve_brainpoolp160r1,
[   29s] >           b.x() * new_zz1 % p,
[   29s]             b.y() * new_zz1 * new_z[1] % p,
[   29s]             new_z[1],
[   29s]         )
[   29s] E       TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
[   29s] E       Falsifying example: test_add_different_scale_points(
[   29s] E           new_z=[2, 1],
[   29s] E           b_mul=1332297598440044874827085038830181364212942568457,
[   29s] E           a_mul=1,
[   29s] E           self=<ecdsa.test_jacobi.TestJacobi testMethod=test_add_different_scale_points>,
[   29s] E       )
[   29s] 
[   29s] src/ecdsa/test_jacobi.py:393: TypeError
[   32s] ____________________ TestJacobi.test_add_same_scale_points _____________________
[   32s] 
[   32s] self = <ecdsa.test_jacobi.TestJacobi testMethod=test_add_same_scale_points>
[   32s] 
[   32s]     @settings(max_examples=10)
[   32s] >   @given(
[   32s]         st.integers(
[   32s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   32s]         ),
[   32s]         st.integers(
[   32s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   32s]         ),
[   32s]         st.integers(min_value=1, max_value=int(curve_brainpoolp160r1.p() - 1)),
[   32s]     )
[   32s] 
[   32s] src/ecdsa/test_jacobi.py:287: 
[   32s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   32s] 
[   32s] self = <ecdsa.test_jacobi.TestJacobi testMethod=test_add_same_scale_points>
[   32s] a_mul = 133229759844004487...0181364212942568457, b_mul = 1, new_z = 1
[   32s] 
[   32s]     @settings(max_examples=10)
[   32s]     @given(
[   32s]         st.integers(
[   32s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   32s]         ),
[   32s]         st.integers(
[   32s]             min_value=1, max_value=int(generator_brainpoolp160r1.order())
[   32s]         ),
[   32s]         st.integers(min_value=1, max_value=int(curve_brainpoolp160r1.p() - 1)),
[   32s]     )
[   32s]     @example(1, 1, 1)
[   32s]     @example(3, 3, 3)
[   32s]     @example(2, int(generator_brainpoolp160r1.order() - 2), 1)
[   32s]     @example(2, int(generator_brainpoolp160r1.order() - 2), 3)
[   32s]     def test_add_same_scale_points(self, a_mul, b_mul, new_z):
[   32s]         j_g = PointJacobi.from_affine(generator_brainpoolp160r1)
[   32s]         a = PointJacobi.from_affine(j_g * a_mul)
[   32s]         b = PointJacobi.from_affine(j_g * b_mul)
[   32s]     
[   32s]         p = curve_brainpoolp160r1.p()
[   32s]     
[   32s]         assume(inverse_mod(new_z, p))
[   32s]     
[   32s]         new_zz = new_z * new_z % p
[   32s]     
[   32s]         a = PointJacobi(
[   32s]             curve_brainpoolp160r1,
[   32s] >           a.x() * new_zz % p,
[   32s]             a.y() * new_zz * new_z % p,
[   32s]             new_z,
[   32s]         )
[   32s] E       TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
[   32s] E       Falsifying example: test_add_same_scale_points(
[   32s] E           new_z=1,
[   32s] E           b_mul=1,
[   32s] E           a_mul=1332297598440044874827085038830181364212942568457,
[   32s] E           self=<ecdsa.test_jacobi.TestJacobi testMethod=test_add_same_scale_points>,
[   32s] E       )
[   32s] 
[   32s] src/ecdsa/test_jacobi.py:313: TypeError
bnavigator commented 1 year ago
[  146s] _______________________________ test_sig_verify ________________________________
[  146s] 
[  146s]     @settings(**SIG_VER_SETTINGS)
[  146s] >   @example((generator_224, 4, 1, 1))
[  146s] 
[  146s] src/ecdsa/test_ecdsa.py:641: 
[  146s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  146s] src/ecdsa/test_ecdsa.py:650: in test_sig_verify
[  146s]     pubkey = Public_key(generator, generator * sec_mult)
[  146s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  146s] 
[  146s] self = <ecdsa.ecdsa.Public_key object at 0x7fb780c7c280>
[  146s] generator = <ecdsa.ellipticcurve.PointJacobi object at 0x7fb7819f53c0>
[  146s] point = <ecdsa.ellipticcurve.Point object at 0x7fb7819f5690>, verify = True
[  146s] 
[  146s]     def __init__(self, generator, point, verify=True):
[  146s]         """Low level ECDSA public key object.
[  146s]     
[  146s]         :param generator: the Point that generates the group (the base point)
[  146s]         :param point: the Point that defines the public key
[  146s]         :param bool verify: if True check if point is valid point on curve
[  146s]     
[  146s]         :raises InvalidPointError: if the point parameters are invalid or
[  146s]             point does not lay on the curve
[  146s]         """
[  146s]     
[  146s]         self.curve = generator.curve()
[  146s]         self.generator = generator
[  146s]         self.point = point
[  146s]         n = generator.order()
[  146s]         p = self.curve.p()
[  146s] >       if not (0 <= point.x() < p) or not (0 <= point.y() < p):
[  146s] E       TypeError: '<=' not supported between instances of 'int' and 'NoneType'
[  146s] E       Generator used: generator_192
[  146s] E       Falsifying example: test_sig_verify(
[  146s] E           args=(<ecdsa.ellipticcurve.PointJacobi at 0x7fb7819f53c0>,
[  146s] E            6277101735386680763835789423176059013767194773182842284081,
[  146s] E            1,
[  146s] E            1),
[  146s] E       )
[  146s] 
[  146s] src/ecdsa/ecdsa.py:149: TypeError