liboqs/tests/test_kat.py
Norman Ashley 971173ad82
Add Stateful Signature (XMSS and LMS) (#1650)
Add support for LMS and XMSS. Key generation and signing are disabled behind a feature flag labelled "hazardous experimental."

---------

Signed-off-by: Duc Tri Nguyen <dnguye69@gmu.edu>
Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca>
Signed-off-by: Norman Ashley <nashley@cisco.com>
Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
Co-authored-by: Duc Tri Nguyen <dnguye69@gmu.edu>
Co-authored-by: Douglas Stebila <dstebila@uwaterloo.ca>
Co-authored-by: Duc Nguyen <106774416+ducnguyen-sb@users.noreply.github.com>
Co-authored-by: Douglas Stebila <dstebila@users.noreply.github.com>
Co-authored-by: Duc Nguyen <ductri.nguyen@sandboxquantum.com>
Co-authored-by: Spencer Wilson <spencer.wilson@uwaterloo.ca>
Co-authored-by: Jason Goertzen <133878263+jgoertzen-sb@users.noreply.github.com>
2024-06-05 15:59:40 -04:00

57 lines
1.8 KiB
Python

# SPDX-License-Identifier: MIT
import helpers
import os
import os.path
import pytest
import platform
from hashlib import sha256
@helpers.filtered_test
@pytest.mark.parametrize('kem_name', helpers.available_kems_by_name())
def test_kem(kem_name):
kats = helpers.get_kats("kem")
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")
h256 = sha256()
h256.update(output.encode())
assert(kats[kem_name]['single'] == h256.hexdigest())
@helpers.filtered_test
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
def test_sig(sig_name):
kats = helpers.get_kats("sig")
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")
h256 = sha256()
h256.update(output.encode())
assert(kats[sig_name]['single'] == h256.hexdigest())
@helpers.filtered_test
@pytest.mark.parametrize('sig_stfl_name', helpers.available_sig_stfls_by_name())
def test_sig_stfl(sig_stfl_name):
kats = helpers.get_kats("sig_stfl")
if not(helpers.is_sig_stfl_enabled_by_name(sig_stfl_name)): pytest.skip('Not enabled')
katfile = helpers.get_katfile("sig_stfl", sig_stfl_name)
if not katfile: pytest.skip("KATs file is missing")
output = helpers.run_subprocess(
[helpers.path_to_executable('kat_sig_stfl'), sig_stfl_name, katfile],
)
output = output.replace("\r\n", "\n")
h256 = sha256()
h256.update(output.encode())
assert(kats[sig_stfl_name] == h256.hexdigest())
if __name__ == "__main__":
import sys
pytest.main(sys.argv)