liboqs/tests/test_kat.py
Douglas Stebila 6e0b0d79a9
Add SPDX-License-Identifier headers (#749)
* Add SPDX-License-Identifier in src/common

* Add SPDX-License-Identifier in FrodoKEM

* Add SPDX-License-Identifier in SIKE

* Add SPDX-License-Identifier in BIKE

* Add SPDX-License-Identifier in OQS headers

* Add SPDX-License-Identifier in files generated during copy-from-pqclean

* Add SPDX-License-Identifier in Picnic

* Add SPDX-License-Identifier in qTesla

* Add SPDX-License-Identifier in CMake files

* Update license info in README

* Add SPDX-License-Identifier in scripts

* Add SPDX-License-Info to CMakeLists

* Add SPDX-License-Info in tests

* Add SPDX-License-Info to various files

* Prettyprint

* Add test for SPDX-License-Identifier headers

* Updated license identifiers for CPU extension detection code.

* Use conjunction for SPDX in file with two licenses

Co-authored-by: xvzcf <xvzcf@users.noreply.github.com>
2020-05-12 11:45:37 -04:00

56 lines
2.3 KiB
Python

# SPDX-License-Identifier: MIT
import helpers
import os
import os.path
import pytest
import platform
@helpers.filtered_test
@pytest.mark.parametrize('kem_name', helpers.available_kems_by_name())
def test_kem(kem_name):
if kem_name.startswith('SIDH'): pytest.skip('KATs not available for SIDH')
if not(helpers.is_kem_enabled_by_name(kem_name)): pytest.skip('Not enabled')
output = helpers.run_subprocess(
[helpers.path_to_executable('kat_kem'), kem_name],
)
output = output.replace("\r\n", "\n")
kats = []
for filename in os.listdir(os.path.join('tests', 'KATs', 'kem')):
if filename.startswith(kem_name + '.') and filename.endswith('.kat'):
with open(os.path.join('tests', 'KATs', 'kem', filename), 'r') as myfile:
kats.append(myfile.read())
assert(output in kats)
@helpers.filtered_test
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
def test_sig(sig_name):
if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled')
output = helpers.run_subprocess(
[helpers.path_to_executable('kat_sig'), sig_name],
)
output = output.replace("\r\n", "\n")
kats = []
avx2_aes_enabled_on_linux = helpers.is_use_option_enabled_by_name('AVX2_INSTRUCTIONS') and helpers.is_use_option_enabled_by_name('AES_INSTRUCTIONS') and platform.system() == 'Linux'
for filename in os.listdir(os.path.join('tests', 'KATs', 'sig')):
if filename.startswith(sig_name + '.') and filename.endswith('.kat'):
# qtesla's avx2 implementation uses an optimized sampling method that results in different KAT values; we use the correct one (if avx2/aes instructions are available)
append_kat = False
if sig_name.startswith('qTesla'):
if 'avx2' in filename:
if avx2_aes_enabled_on_linux and not helpers.is_build_portable():
append_kat = True
else:
append_kat = True
else:
append_kat = True
if append_kat:
with open(os.path.join('tests', 'KATs', 'sig', filename), 'r') as myfile:
kats.append(myfile.read())
assert(output in kats)
if __name__ == "__main__":
import sys
pytest.main(sys.argv)