@@ -311,7 +311,7 @@ def sign_hash(hash_value: bytes, priv_key: key.PrivateKey, hash_method: str) ->
311
311
padded = _pad_for_signing (cleartext , keylength )
312
312
313
313
payload = transform .bytes2int (padded )
314
- encrypted = priv_key .blinded_encrypt (payload )
314
+ encrypted = priv_key .blinded_decrypt (payload )
315
315
block = transform .int2bytes (encrypted , keylength )
316
316
317
317
return block
@@ -355,8 +355,11 @@ def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) -> str:
355
355
"""
356
356
357
357
keylength = common .byte_size (pub_key .n )
358
+ if len (signature ) != keylength :
359
+ raise VerificationError ("Verification failed" )
360
+
358
361
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 )
360
363
clearsig = transform .int2bytes (decrypted , keylength )
361
364
362
365
# Get the hash method
@@ -367,9 +370,6 @@ def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) -> str:
367
370
cleartext = HASH_ASN1 [method_name ] + message_hash
368
371
expected = _pad_for_signing (cleartext , keylength )
369
372
370
- if len (signature ) != keylength :
371
- raise VerificationError ("Verification failed" )
372
-
373
373
# Compare with the signed one
374
374
if expected != clearsig :
375
375
raise VerificationError ("Verification failed" )
0 commit comments