@@ -311,7 +311,7 @@ def sign_hash(hash_value: bytes, priv_key: key.PrivateKey, hash_method: str) ->
311311 padded = _pad_for_signing (cleartext , keylength )
312312
313313 payload = transform .bytes2int (padded )
314- encrypted = priv_key .blinded_encrypt (payload )
314+ encrypted = priv_key .blinded_decrypt (payload )
315315 block = transform .int2bytes (encrypted , keylength )
316316
317317 return block
@@ -355,8 +355,11 @@ def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) -> str:
355355 """
356356
357357 keylength = common .byte_size (pub_key .n )
358+ if len (signature ) != keylength :
359+ raise VerificationError ("Verification failed" )
360+
358361 encrypted = transform .bytes2int (signature )
359- decrypted = core .decrypt_int (encrypted , pub_key .e , pub_key .n )
362+ decrypted = core .encrypt_int (encrypted , pub_key .e , pub_key .n )
360363 clearsig = transform .int2bytes (decrypted , keylength )
361364
362365 # Get the hash method
@@ -367,9 +370,6 @@ def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) -> str:
367370 cleartext = HASH_ASN1 [method_name ] + message_hash
368371 expected = _pad_for_signing (cleartext , keylength )
369372
370- if len (signature ) != keylength :
371- raise VerificationError ("Verification failed" )
372-
373373 # Compare with the signed one
374374 if expected != clearsig :
375375 raise VerificationError ("Verification failed" )
0 commit comments