Skip to content

Commit 90f5e82

Browse files
committed
Specialize compute_rsa_hash_digest into compute_rsa_hash_digest_sha256
1 parent de5824f commit 90f5e82

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

tests/hazmat/primitives/test_rsa.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
)
5252
from .utils import (
5353
_check_rsa_private_numbers,
54-
compute_rsa_hash_digest,
54+
compute_rsa_hash_digest_sha256,
5555
generate_rsa_verification_test,
5656
generate_rsa_verification_without_digest_test,
5757
skip_fips_traditional_openssl,
@@ -488,9 +488,7 @@ def test_pkcs1v15_signing_without_digest(self, backend, subtests):
488488
).private_key(backend, unsafe_skip_rsa_key_validation=True)
489489
signature = private_key.sign(
490490
binascii.unhexlify(
491-
compute_rsa_hash_digest(
492-
backend, hashes.SHA256(), params["msg"]
493-
)
491+
compute_rsa_hash_digest_sha256(backend, params["msg"])
494492
),
495493
padding.PKCS1v15(),
496494
asym_utils.NoDigestInfo(),

tests/hazmat/primitives/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def _load_all_params(path, file_names, param_loader):
4848
return all_params
4949

5050

51-
def compute_rsa_hash_digest(backend, hash_alg, msg):
52-
oid = _hash_alg_oids[hash_alg.name]
53-
h = hashes.Hash(hash_alg, backend=backend)
51+
def compute_rsa_hash_digest_sha256(backend, msg):
52+
oid = binascii.unhexlify(b"3031300d060960864801650304020105000420")
53+
h = hashes.Hash(hashes.SHA256(), backend=backend)
5454
h.update(binascii.unhexlify(msg))
5555
return binascii.hexlify(oid) + binascii.hexlify(h.finalize())
5656

@@ -519,8 +519,8 @@ def test_rsa_verification(self, backend, subtests):
519519
]
520520
for params in all_params:
521521
with subtests.test():
522-
params["msg"] = compute_rsa_hash_digest(
523-
backend, hash_alg, params["msg"]
522+
params["msg"] = compute_rsa_hash_digest_sha256(
523+
backend, params["msg"]
524524
)
525525
rsa_verification_test(
526526
backend, params, asym_utils.NoDigestInfo(), pad_factory

0 commit comments

Comments
 (0)