forked from pyca/cryptography
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs pyca#3331 -- added initial wycheproof integration, starting with…
… x25519 tests
- Loading branch information
Showing
7 changed files
with
87 additions
and
6 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
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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--wycheproof-root", default=None) | ||
|
||
|
||
@pytest.fixture | ||
def whycheproof(request): | ||
wycheproof = request.config.getoption("--wycheproof-root") | ||
if wycheproof is None: | ||
pytest.skip("--wycheproof-root not provided") | ||
return wycheproof | ||
|
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import binascii | ||
|
||
from cryptography.hazmat.primitives.asymmetric.x25519 import ( | ||
X25519PrivateKey, X25519PublicKey | ||
) | ||
|
||
from .utils import load_tests | ||
|
||
def test_x25519(backend, wycheproof): | ||
for group, test in load_tests(wycheproof, "x25519_test.json"): | ||
assert not group | ||
private_key = X25519PrivateKey._from_private_bytes( | ||
binascii.unhexlify(test["private"]) | ||
) | ||
public_key = X25519PublicKey.from_public_bytes( | ||
binascii.unhexlify(test{"public"]) | ||
) | ||
|
||
assert test["result"] in ["valid", "acceptable"] | ||
assert ( | ||
private_key.exchange(public_key) == | ||
binascii.unhexlify(test["shared"] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import json | ||
|
||
|
||
def load_tests(wycheproof, test_file): | ||
path = os.path.join(wycheproof, "testvectors", test_file) | ||
with open(path) as f: | ||
data = json.load(f) | ||
for group in data["testGroups"]: | ||
cases = group.pop("tests") | ||
for c in cases: | ||
yield group, c |