Skip to content

Commit 1f35994

Browse files
committed
Specialize compute_rsa_hash_digest into compute_rsa_hash_digest_sha256
1 parent 2a54d46 commit 1f35994

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
@@ -56,9 +56,9 @@ def _load_all_params(path, file_names, param_loader):
5656
return all_params
5757

5858

59-
def compute_rsa_hash_digest(backend, hash_alg, msg):
60-
oid = _hash_alg_oids[hash_alg.name]
61-
h = hashes.Hash(hash_alg, backend=backend)
59+
def compute_rsa_hash_digest_sha256(backend, msg):
60+
oid = binascii.unhexlify(b"3031300d060960864801650304020105000420")
61+
h = hashes.Hash(hashes.SHA256(), backend=backend)
6262
h.update(binascii.unhexlify(msg))
6363
return binascii.hexlify(oid) + binascii.hexlify(h.finalize())
6464

@@ -523,8 +523,8 @@ def test_rsa_verification(self, backend, subtests):
523523
]
524524
for params in all_params:
525525
with subtests.test():
526-
params["msg"] = compute_rsa_hash_digest(
527-
backend, hash_alg, params["msg"]
526+
params["msg"] = compute_rsa_hash_digest_sha256(
527+
backend, params["msg"]
528528
)
529529
rsa_verification_test(
530530
backend, params, asym_utils.NoDigestInfo(), pad_factory

0 commit comments

Comments
 (0)