@@ -135,6 +135,18 @@ def test_ed25519_pem(self):
135135 def test_ed25519_raw (self ):
136136 self ._gen_sign_verify ("ed25519" , "edkey" , "ed-signed.sig" , "raw" )
137137
138+ def test_ed25519_signature_size (self ):
139+ """ED25519 signatures must be exactly 64 bytes."""
140+ priv , pub = self ._genkey ("ed25519" , "edkey-sztest" , "der" ,
141+ use_output_flag = True )
142+ sig_file = "ed-sz-test.sig"
143+ self ._sign ("ed25519" , priv , "der" , sig_file )
144+
145+ sig_size = os .path .getsize (sig_file )
146+ self .assertEqual (sig_size , 64 ,
147+ "ED25519 signature size is {}, expected 64" .format (
148+ sig_size ))
149+
138150
139151class EccTest (_GenkeySignVerifyBase ):
140152
@@ -160,6 +172,55 @@ def test_ecc_der(self):
160172 def test_ecc_pem (self ):
161173 self ._gen_sign_verify ("ecc" , "ecckey" , "ecc-signed.sig" , "pem" )
162174
175+ def test_ecc_der_key_size_and_roundtrip (self ):
176+ """Regression: ECC DER private key must be reasonably sized, and the
177+ full sign/verify round-trip must succeed on the generated keypair."""
178+ priv , pub = self ._genkey ("ecc" , "ecc-rt-test" , "der" ,
179+ use_output_flag = True )
180+
181+ key_size = os .path .getsize (priv )
182+ self .assertLessEqual (key_size , 256 ,
183+ "ECC DER private key too large ({} bytes), "
184+ "may contain trailing garbage" .format (key_size ))
185+
186+ data_file = "ecc-rt-data.txt"
187+ sig_file = "ecc-rt-test.sig"
188+ self ._track (data_file , sig_file )
189+ with open (data_file , "w" ) as f :
190+ f .write ("ECC round trip test data\n " )
191+
192+ r = run_wolfssl ("-ecc" , "-sign" , "-inkey" , priv , "-inform" , "der" ,
193+ "-in" , data_file , "-out" , sig_file )
194+ self .assertEqual (r .returncode , 0 ,
195+ "ECC sign round-trip failed: {}" .format (r .stderr ))
196+
197+ r = run_wolfssl ("-ecc" , "-verify" , "-inkey" , pub , "-pubin" ,
198+ "-inform" , "der" , "-sigfile" , sig_file ,
199+ "-in" , data_file )
200+ self .assertEqual (r .returncode , 0 ,
201+ "ECC verify round-trip failed: {}" .format (r .stderr ))
202+
203+ def test_ecc_sign_invalid_key_fails (self ):
204+ """Signing with an empty key file must fail gracefully."""
205+ bad_key = "bad-ecc-key.der"
206+ bad_sig = "bad-ecc-sign.sig"
207+ self ._track (bad_key , bad_sig )
208+ open (bad_key , "wb" ).close ()
209+
210+ r = run_wolfssl ("-ecc" , "-sign" , "-inkey" , bad_key , "-inform" , "der" ,
211+ "-in" , self .SIGN_FILE , "-out" , bad_sig )
212+ self .assertNotEqual (r .returncode , 0 ,
213+ "ECC signing with empty key should have failed" )
214+
215+ def test_ecc_sign_missing_inkey_value (self ):
216+ """-inkey with no value must fail gracefully (no segfault)."""
217+ r = run_wolfssl ("-ecc" , "-sign" , "-inkey" )
218+ self .assertNotEqual (r .returncode , 0 ,
219+ "expected failure for missing -inkey value" )
220+ self .assertGreaterEqual (r .returncode , 0 ,
221+ "-inkey without value crashed with signal "
222+ "{}" .format (r .returncode ))
223+
163224
164225class RsaTest (_GenkeySignVerifyBase ):
165226
@@ -197,6 +258,18 @@ def test_rsa_exponent_flag(self):
197258 self .assertEqual (r .returncode , 0 ,
198259 f"rsa genkey with -exponent failed: { r .stderr } " )
199260
261+ def test_rsa_sign_invalid_key_fails (self ):
262+ """RSA signing with an empty key file must fail gracefully."""
263+ bad_key = "bad-rsa-key.der"
264+ bad_sig = "bad-rsa-sign.sig"
265+ self ._track (bad_key , bad_sig )
266+ open (bad_key , "wb" ).close ()
267+
268+ r = run_wolfssl ("-rsa" , "-sign" , "-inkey" , bad_key , "-inform" , "der" ,
269+ "-in" , self .SIGN_FILE , "-out" , bad_sig )
270+ self .assertNotEqual (r .returncode , 0 ,
271+ "RSA signing with empty key should have failed" )
272+
200273
201274@unittest .skipUnless (_has_algorithm ("dilithium" ),
202275 "dilithium not available" )
@@ -252,6 +325,18 @@ def test_sign_bad_path(self):
252325 self .assertNotEqual (r .returncode , 0 ,
253326 "sign to invalid path should have failed" )
254327
328+ def test_sign_nonexistent_key_fails (self ):
329+ """Dilithium sign with nonexistent key file must fail gracefully."""
330+ bad_sig = "bad-dil.sig"
331+ self ._track (bad_sig )
332+ r = run_wolfssl ("-dilithium" , "-sign" ,
333+ "-inkey" , os .path .join ("nonexistent_dir" , "key.priv" ),
334+ "-inform" , "der" , "-in" , self .SIGN_FILE ,
335+ "-out" , bad_sig )
336+ self .assertNotEqual (r .returncode , 0 ,
337+ "Dilithium sign with nonexistent key should have "
338+ "failed" )
339+
255340
256341@unittest .skipUnless (_has_algorithm ("xmss" ), "xmss not available" )
257342class XmssTest (_GenkeySignVerifyBase ):
@@ -264,6 +349,17 @@ def test_xmss_raw(self):
264349 extra_genkey_args = ["-height" , "10" ],
265350 skip_priv_verify = True , use_output_flag = True )
266351
352+ def test_xmss_missing_height_value (self ):
353+ """-height with no value must fail gracefully (no crash)."""
354+ self ._track ("xmss-bad.priv" , "xmss-bad.pub" )
355+ r = run_wolfssl ("-genkey" , "xmss" , "-out" , "xmss-bad" ,
356+ "-outform" , "raw" , "-output" , "KEYPAIR" , "-height" )
357+ self .assertNotEqual (r .returncode , 0 ,
358+ "expected failure for missing -height value" )
359+ self .assertGreaterEqual (r .returncode , 0 ,
360+ "-height without value crashed with signal "
361+ "{}" .format (r .returncode ))
362+
267363
268364if __name__ == "__main__" :
269365 test_main ()
0 commit comments