liboqs/tests/test_hash.py
Douglas Stebila a6f426044b
Sync with PQClean and update hashing API (#616)
* Sync with PQClean commit 6de728361e33ad3a5a6997e0896ff9fe8e44a999

* Revise SHA-2 API to match PQClean

* Revise SHA-3 API to match PQClean

* Fix compiler warning

* Fix typo

[skip ci]

* Fix typo

[skip ci]
2020-02-16 15:47:49 -05:00

69 lines
2.4 KiB
Python

import hashlib
import helpers
import pytest
import sys
@helpers.filtered_test
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_aes():
helpers.run_subprocess(
[helpers.path_to_executable('test_aes')],
)
@helpers.filtered_test
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_sha3():
helpers.run_subprocess(
[helpers.path_to_executable('test_sha3')],
)
@helpers.filtered_test
@pytest.mark.parametrize('msg', ['', 'a', 'abc', '1234567890123456789012345678901678901567890'])
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_sha256(msg):
output = helpers.run_subprocess(
[helpers.path_to_executable('test_hash'), 'sha256'],
input = msg.encode(),
)
assert(output.rstrip() == hashlib.sha256(msg.encode()).hexdigest())
output = helpers.run_subprocess(
[helpers.path_to_executable('test_hash'), 'sha256inc'],
input = msg.encode(),
)
assert(output.rstrip() == hashlib.sha256(msg.encode()).hexdigest())
@helpers.filtered_test
@pytest.mark.parametrize('msg', ['', 'a', 'abc', '1234567890123456789012345678901678901567890'])
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_sha384(msg):
output = helpers.run_subprocess(
[helpers.path_to_executable('test_hash'), 'sha384'],
input = msg.encode(),
)
assert(output.rstrip() == hashlib.sha384(msg.encode()).hexdigest())
output = helpers.run_subprocess(
[helpers.path_to_executable('test_hash'), 'sha384inc'],
input = msg.encode(),
)
assert(output.rstrip() == hashlib.sha384(msg.encode()).hexdigest())
@helpers.filtered_test
@pytest.mark.parametrize('msg', ['', 'a', 'abc', '1234567890123456789012345678901678901567890'])
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_sha512(msg):
output = helpers.run_subprocess(
[helpers.path_to_executable('test_hash'), 'sha512'],
input = msg.encode(),
)
assert(output.rstrip() == hashlib.sha512(msg.encode()).hexdigest())
output = helpers.run_subprocess(
[helpers.path_to_executable('test_hash'), 'sha512inc'],
input = msg.encode(),
)
assert(output.rstrip() == hashlib.sha512(msg.encode()).hexdigest())
if __name__ == "__main__":
import sys
pytest.main(sys.argv)