-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca593a9
commit 45b10e2
Showing
1 changed file
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,36 +543,37 @@ def test_deterministic_nonce(self, backend, subtests): | |
load_rfc6979_vectors, | ||
) | ||
|
||
for vector in vectors: | ||
input = bytes(vector["input"], "utf-8") | ||
output = bytes.fromhex(vector["output"]) | ||
key = bytes("\n".join(vector["key"]), "utf-8") | ||
if "digest_sign" in vector: | ||
algorithm = vector["digest_sign"] | ||
hash_algorithm = supported_hash_algorithms[algorithm] | ||
algorithm = ec.ECDSA( | ||
hash_algorithm, | ||
deterministic_signing=vector["deterministic_nonce"], | ||
) | ||
private_key = serialization.load_pem_private_key( | ||
key, password=None | ||
) | ||
assert isinstance(private_key, EllipticCurvePrivateKey) | ||
signature = private_key.sign(input, algorithm) | ||
assert signature == output | ||
else: | ||
assert "digest_verify" in vector | ||
algorithm = vector["digest_verify"] | ||
assert algorithm in supported_hash_algorithms | ||
hash_algorithm = supported_hash_algorithms[algorithm] | ||
algorithm = ec.ECDSA(hash_algorithm) | ||
public_key = serialization.load_pem_public_key(key) | ||
assert isinstance(public_key, EllipticCurvePublicKey) | ||
if vector["verify_error"]: | ||
with pytest.raises(exceptions.InvalidSignature): | ||
public_key.verify(output, input, algorithm) | ||
with subtests.test(): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
facutuesca
Author
Contributor
|
||
for vector in vectors: | ||
input = bytes(vector["input"], "utf-8") | ||
output = bytes.fromhex(vector["output"]) | ||
key = bytes("\n".join(vector["key"]), "utf-8") | ||
if "digest_sign" in vector: | ||
algorithm = vector["digest_sign"] | ||
hash_algorithm = supported_hash_algorithms[algorithm] | ||
algorithm = ec.ECDSA( | ||
hash_algorithm, | ||
deterministic_signing=vector["deterministic_nonce"], | ||
) | ||
private_key = serialization.load_pem_private_key( | ||
key, password=None | ||
) | ||
assert isinstance(private_key, EllipticCurvePrivateKey) | ||
signature = private_key.sign(input, algorithm) | ||
assert signature == output | ||
else: | ||
public_key.verify(output, input, algorithm) | ||
assert "digest_verify" in vector | ||
algorithm = vector["digest_verify"] | ||
assert algorithm in supported_hash_algorithms | ||
hash_algorithm = supported_hash_algorithms[algorithm] | ||
algorithm = ec.ECDSA(hash_algorithm) | ||
public_key = serialization.load_pem_public_key(key) | ||
assert isinstance(public_key, EllipticCurvePublicKey) | ||
if vector["verify_error"]: | ||
with pytest.raises(exceptions.InvalidSignature): | ||
public_key.verify(output, input, algorithm) | ||
else: | ||
public_key.verify(output, input, algorithm) | ||
|
||
def test_sign(self, backend): | ||
_skip_curve_unsupported(backend, ec.SECP256R1()) | ||
|
Invert the order, you want the
with subtests.test()
inside teh loop, not outisde