@@ -164,40 +164,21 @@ def test_random_der_ecdsa_sig_value(params):
164164 verifying_key .verify (sig , example_data , sigdecode = sigdecode_der )
165165
166166
167- ####
168- #
169- # For string encoded signatures, only the length of string is important
170- #
171- ####
172-
173- str_sigs = []
174-
175- #for curve in curves:
176- for curve in [NIST256p ]:
177- #for hash_alg in ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"]:
178- for hash_alg in ["sha256" ]:
179- key = SigningKey .generate (curve )
180- signature = key .sign (example_data , hashfunc = getattr (hashlib , hash_alg ),
181- sigencode = sigencode_string )
182- for trunc in range (len (signature )):
183- str_sigs .append (pytest .param (
184- key .verifying_key , hash_alg ,
185- signature , trunc ,
186- id = "{0}-{1}-trunc-{2}" .format (
187- curve .name , hash_alg , trunc )))
188-
189-
190- @pytest .mark .parametrize ("verifying_key,hash_alg,signature,trunc" , str_sigs )
191- def test_truncated_string_signatures (verifying_key , hash_alg , signature , trunc ):
192- # check if a malformed string encoded signature causes the same exception
193- # to be raised irrespective of the type of error
194- sig = bytearray (signature )
195- sig = sig [:trunc ]
196- sig = binary_type (sig )
197-
198- try :
199- verifying_key .verify (sig , example_data , getattr (hashlib , hash_alg ),
200- sigdecode_string )
201- assert False
202- except BadSignatureError :
203- assert True
167+ keys_and_string_sigs = [
168+ (name , verifying_key ,
169+ sigencode_string (* sigdecode_der (sig , verifying_key .curve .order ),
170+ order = verifying_key .curve .order ))
171+ for name , verifying_key , sig in keys_and_sigs ]
172+ """
173+ Name of the curve+hash combination, VerifyingKey and signature as a
174+ byte string.
175+ """
176+
177+
178+ @settings (** params )
179+ @given (st_fuzzed_sig (keys_and_string_sigs ))
180+ def test_fuzzed_string_signatures (params ):
181+ verifying_key , sig = params
182+
183+ with pytest .raises (BadSignatureError ):
184+ verifying_key .verify (sig , example_data , sigdecode = sigdecode_string )
0 commit comments