Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test against all 100 KAT values #1560

Merged
merged 39 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2f4c86f
Add option to test against all 100 KAT values
SWilson4 Sep 21, 2023
2991fbe
Add Python script
SWilson4 Sep 22, 2023
4aacfb1
Satisfy astyle
SWilson4 Sep 22, 2023
ab8ca93
More KATs
SWilson4 Sep 25, 2023
452157f
Adjust number of KATs for McEliece
SWilson4 Sep 27, 2023
54eb476
Add weekly CircleCI workflow for NIST KATs
SWilson4 Oct 2, 2023
b80c00f
Try running scheduled tests on sw-full-kat branch
SWilson4 Oct 2, 2023
9fa9cf0
Skip test_kat_all in non-scheduled workflows
SWilson4 Oct 2, 2023
713ee5c
Satisfy XCode
SWilson4 Oct 2, 2023
3a4aa44
fixup! Skip test_kat_all in non-scheduled workflows
SWilson4 Oct 3, 2023
e4b9504
fixup! Add weekly CircleCI workflow for NIST KATs
SWilson4 Oct 3, 2023
3e013d6
Fix shell expansion in CircleCI config
SWilson4 Oct 3, 2023
17e0afd
fixup! Satisfy XCode
SWilson4 Oct 3, 2023
09dbdcb
fixup! Satisfy XCode
SWilson4 Oct 3, 2023
fa203dc
Address feedback
SWilson4 Oct 3, 2023
0853dda
Fix pytest argument parsing
SWilson4 Oct 10, 2023
816fb76
Run full KATs on this branch for testing purposes
SWilson4 Oct 10, 2023
6372a43
Only run neon job for testing purposes
SWilson4 Oct 11, 2023
8b6a9b7
See what macros are defined on the CircleCI ARM machine
SWilson4 Oct 11, 2023
c4d8cf7
Run on GitHub actions
SWilson4 Nov 3, 2023
7d2d5ef
Modify copy_from_upstream to work with the new KAT file format
SWilson4 Nov 3, 2023
d523acf
Pull new HQC implementation from upstream (#1585)
SWilson4 Nov 6, 2023
dccac01
Add save and restore state for HQC PRNG
SWilson4 Nov 7, 2023
0803636
Update HQC KATs
SWilson4 Nov 7, 2023
a26caec
Satisfy astyle
SWilson4 Dec 15, 2023
328e16a
Fix code duplication (rebase gone wrong)
SWilson4 Dec 15, 2023
579aa1d
Remove newlines to satisfy copy_from_upstream idempotence
SWilson4 Dec 15, 2023
669a862
Clean up bugs in kat_kem
SWilson4 Dec 15, 2023
e046b17
Don't run all KATs on ninja run_tests
SWilson4 Dec 15, 2023
c94798a
Update documentation for save/restore state
SWilson4 Dec 18, 2023
77538a1
All KATs passing with new PRNG abstraction
SWilson4 Dec 20, 2023
6d56d90
Reorganize to use get/set paradigm
SWilson4 Dec 21, 2023
f90bfb6
Clean up after rebase
SWilson4 Jan 22, 2024
7f13214
Satisfy astyle
SWilson4 Jan 22, 2024
86ef67f
Add const to cast
SWilson4 Jan 22, 2024
f3fece4
Remove OQS_API from NIST KAT init function
SWilson4 Jan 22, 2024
9320fae
fixup! Add const to cast
SWilson4 Jan 22, 2024
231611c
Unused parameter workaround
SWilson4 Jan 22, 2024
6ab46f9
Fix int / size_t comparison
SWilson4 Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ jobs:
-e PYTEST_ARGS="<< parameters.PYTEST_ARGS >>" \
-v `pwd`:/root/project \
openquantumsafe/ci-ubuntu-focal-arm64:latest bash \
-c "cd /root/project && \
-c 'cd /root/project && \
uname -a && \
mkdir build && cd build && source ~/.bashrc && \
cmake -GNinja -DOQS_STRICT_WARNINGS=ON $CMAKE_ARGS .. && cmake -LA .. && ninja && \
cd .. && mkdir -p tmp && \
python3 -m pytest --verbose \
--ignore=tests/test_code_conventions.py \
--junitxml=build/test-results/pytest/test-results.xml $PYTEST_ARGS"
--junitxml=build/test-results/pytest/test-results.xml $PYTEST_ARGS'
- store_test_results: # Note that this command will fail when running CircleCI locally, that is expected behaviour
path: build/test-results
- store_artifacts:
Expand Down Expand Up @@ -353,43 +353,47 @@ workflows:
context: openquantumsafe
CONTAINER: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DCMAKE_C_COMPILER=gcc-8 -DOQS_USE_OPENSSL=OFF
PYTEST_ARGS: --ignore=tests/test_leaks.py
PYTEST_ARGS: --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py
- linux_oqs:
<<: *require_buildcheck
name: ubuntu-focal-shared-noopenssl
context: openquantumsafe
CONTAINER: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DCMAKE_C_COMPILER=gcc-7 -DOQS_DIST_BUILD=OFF -DOQS_USE_OPENSSL=OFF -DBUILD_SHARED_LIBS=ON
PYTEST_ARGS: --ignore=tests/test_namespace.py --ignore=tests/test_leaks.py --numprocesses=auto
PYTEST_ARGS: --ignore=tests/test_namespace.py --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py --numprocesses=auto
- linux_oqs:
<<: *require_buildcheck
name: ubuntu-focal-clang15
context: openquantumsafe
CONTAINER: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DCMAKE_C_COMPILER=clang-15 -DOQS_OPT_TARGET=skylake
PYTEST_ARGS: --ignore=tests/test_kat_all.py
- linux_oqs:
<<: *require_buildcheck
name: ubuntu-bionic-i386
context: openquantumsafe
CONTAINER: openquantumsafe/ci-ubuntu-bionic-i386:latest
CMAKE_ARGS: -DCMAKE_TOOLCHAIN_FILE=../.CMake/toolchain_x86.cmake
PYTEST_ARGS: --ignore=tests/test_leaks.py
PYTEST_ARGS: --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py
- arm_machine:
<<: *require_buildcheck
name: arm64
PYTEST_ARGS: --numprocesses=auto --maxprocesses=10
PYTEST_ARGS: --numprocesses=auto --maxprocesses=10 --ignore=tests/test_kat_all.py
- macOS:
<<: *require_buildcheck
name: macOS-gcc11
CMAKE_ARGS: -DCMAKE_C_COMPILER=gcc-11
PYTEST_ARGS: --ignore=tests/test_kat_all.py
- macOS:
<<: *require_buildcheck
name: macOS-noopenssl
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DOQS_USE_OPENSSL=OFF
PYTEST_ARGS: --ignore=tests/test_kat_all.py
- macOS:
<<: *require_buildcheck
name: macOS-shared
CMAKE_ARGS: -DBUILD_SHARED_LIBS=ON -DOQS_DIST_BUILD=OFF -DOQS_ENABLE_KEM_CLASSIC_MCELIECE=OFF
PYTEST_ARGS: --ignore=tests/test_kat_all.py

commit-to-main:
when:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ jobs:
- name: alpine
container: openquantumsafe/ci-alpine-amd64:latest
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DOQS_USE_OPENSSL=ON -DBUILD_SHARED_LIBS=ON
PYTEST_ARGS: --ignore=tests/test_alg_info.py
PYTEST_ARGS: --ignore=tests/test_alg_info.py --ignore=tests/test_kat_all.py
- name: alpine-openssl-all
container: openquantumsafe/ci-alpine-amd64:latest
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DOQS_USE_OPENSSL=ON -DBUILD_SHARED_LIBS=ON -DOQS_USE_AES_OPENSSL=ON -DOQS_USE_SHA2_OPENSSL=ON -DOQS_USE_SHA3_OPENSSL=ON
PYTEST_ARGS: --ignore=tests/test_alg_info.py
PYTEST_ARGS: --ignore=tests/test_alg_info.py --ignore=tests/test_kat_all.py
- name: alpine-noopenssl
container: openquantumsafe/ci-alpine-amd64:latest
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DOQS_USE_OPENSSL=OFF
PYTEST_ARGS: --ignore=tests/test_alg_info.py
PYTEST_ARGS: --ignore=tests/test_alg_info.py --ignore=tests/test_kat_all.py
- name: focal-nistr4-openssl
container: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DOQS_ALGS_ENABLED=NIST_R4
PYTEST_ARGS: --ignore=tests/test_leaks.py
PYTEST_ARGS: --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py
- name: jammy-std-openssl3
container: openquantumsafe/ci-ubuntu-jammy:latest
CMAKE_ARGS: -DOQS_STRICT_WARNINGS=ON -DOQS_ALGS_ENABLED=STD -DBUILD_SHARED_LIBS=ON
PYTEST_ARGS: --ignore=tests/test_leaks.py
PYTEST_ARGS: --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py
- name: address-sanitizer
container: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DCMAKE_C_COMPILER=clang-9 -DCMAKE_BUILD_TYPE=Debug -DUSE_SANITIZER=Address
PYTEST_ARGS: --ignore=tests/test_distbuild.py --ignore=tests/test_leaks.py --numprocesses=auto --maxprocesses=10
PYTEST_ARGS: --ignore=tests/test_distbuild.py --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py --numprocesses=auto --maxprocesses=10
container:
image: ${{ matrix.container }}
steps:
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
- name: armhf
ARCH: armhf
CMAKE_ARGS: -DOQS_ENABLE_SIG_SPHINCS=OFF -DOQS_USE_OPENSSL=OFF -DOQS_OPT_TARGET=generic
PYTEST_ARGS: --ignore=tests/test_alg_info.py
PYTEST_ARGS: --ignore=tests/test_alg_info.py --ignore=tests/test_kat_all.py
# no longer supporting armel
# - name: armel
# ARCH: armel
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,30 @@ jobs:
timeout-minutes: 360
run: mkdir -p tmp && SKIP_ALGS='${{ matrix.SKIP_ALGS }}' python3 -m pytest --verbose ${{ matrix.PYTEST_ARGS }}

nistkat-x64:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: generic
container: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DOQS_DIST_BUILD=OFF -DOQS_OPT_TARGET=generic
PYTEST_ARGS: --numprocesses=auto -k 'test_kat_all'
- name: extensions
container: openquantumsafe/ci-ubuntu-focal-x86_64:latest
CMAKE_ARGS: -DOQS_DIST_BUILD=OFF -DOQS_OPT_TARGET=haswell
PYTEST_ARGS: --numprocesses=auto -k 'test_kat_all'
container:
image: ${{ matrix.container }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure
run: mkdir build && cd build && cmake -GNinja ${{ matrix.CMAKE_ARGS }} .. && cmake -LA ..
- name: Build
run: ninja
working-directory: build
- name: Run tests
timeout-minutes: 360
run: mkdir -p tmp && SKIP_ALGS='${{ matrix.SKIP_ALGS }}' python3 -m pytest --verbose ${{ matrix.PYTEST_ARGS }}
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: pip.exe install pytest pytest-xdist pyyaml
- name: Run tests
run: |
python -m pytest --numprocesses=auto -vv --maxfail=10 --ignore=tests/test_code_conventions.py --junitxml=build\test-results\pytest\test-results.xml
python -m pytest --numprocesses=auto -vv --maxfail=10 --ignore=tests/test_code_conventions.py --ignore=tests/test_kat_all.py --junitxml=build\test-results\pytest\test-results.xml
baentsch marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions scripts/copy_from_upstream/copy_from_upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,20 +544,20 @@ def process_families(instructions, basedir, with_kat, with_generator):
if with_kat:
if family in instructions['kems']:
try:
if kats['kem'][scheme['pretty_name_full']] != scheme['metadata']['nistkat-sha256']:
if kats['kem'][scheme['pretty_name_full']]['single'] != scheme['metadata']['nistkat-sha256']:
print("Info: Updating KAT for %s" % (scheme['pretty_name_full']))
except KeyError: # new key
print("Adding new KAT for %s" % (scheme['pretty_name_full']))
pass
kats['kem'][scheme['pretty_name_full']] = scheme['metadata']['nistkat-sha256']
kats['kem'][scheme['pretty_name_full']]['single'] = scheme['metadata']['nistkat-sha256']
else:
try:
if kats['sig'][scheme['pretty_name_full']] != scheme['metadata']['nistkat-sha256']:
if kats['sig'][scheme['pretty_name_full']]['single'] != scheme['metadata']['nistkat-sha256']:
print("Info: Updating KAT for %s" % (scheme['pretty_name_full']))
except KeyError: # new key
print("Adding new KAT for %s" % (scheme['pretty_name_full']))
pass
kats['sig'][scheme['pretty_name_full']] = scheme['metadata']['nistkat-sha256']
kats['sig'][scheme['pretty_name_full']]['single'] = scheme['metadata']['nistkat-sha256']

if with_generator:
generator(
Expand Down
31 changes: 22 additions & 9 deletions src/common/rand/rand_nist.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF
You are solely responsible for determining the appropriateness of using and distributing the software and you assume all risks associated with its use, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of operation. This software is not intended to be used in any situation where a failure could cause risk of injury or damage to property. The software developed by NIST employees is not subject to copyright protection within the United States.
*/
// SPDX-License-Identifier: Unknown
// Modified for liboqs by Douglas Stebila
// Modified for liboqs by Douglas Stebila and Spencer Wilson
//

#include <assert.h>
#include <string.h>

#include <oqs/common.h>
#include <oqs/rand.h>
#include <oqs/rand_nist.h>

#ifdef OQS_USE_OPENSSL
#include <openssl/conf.h>
Expand All @@ -31,13 +32,7 @@ You are solely responsible for determining the appropriateness of using and dist

void OQS_randombytes_nist_kat(unsigned char *x, size_t xlen);

typedef struct {
unsigned char Key[32];
unsigned char V[16];
int reseed_counter;
} AES256_CTR_DRBG_struct;

static AES256_CTR_DRBG_struct DRBG_ctx;
static OQS_NIST_DRBG_struct DRBG_ctx;
static void AES256_CTR_DRBG_Update(unsigned char *provided_data, unsigned char *Key, unsigned char *V);

#ifdef OQS_USE_OPENSSL
Expand Down Expand Up @@ -85,7 +80,7 @@ static void AES256_ECB(unsigned char *key, unsigned char *ctr, unsigned char *bu
#endif
}

OQS_API void OQS_randombytes_nist_kat_init_256bit(const uint8_t *entropy_input, const uint8_t *personalization_string) {
void OQS_randombytes_nist_kat_init_256bit(const uint8_t *entropy_input, const uint8_t *personalization_string) {
unsigned char seed_material[48];

memcpy(seed_material, entropy_input, 48);
Expand Down Expand Up @@ -127,6 +122,24 @@ void OQS_randombytes_nist_kat(unsigned char *x, size_t xlen) {
DRBG_ctx.reseed_counter++;
}

void OQS_randombytes_nist_kat_get_state(void *out) {
OQS_NIST_DRBG_struct *out_state = (OQS_NIST_DRBG_struct *)out;
if (out_state != NULL) {
memcpy(out_state->Key, DRBG_ctx.Key, sizeof(DRBG_ctx.Key));
memcpy(out_state->V, DRBG_ctx.V, sizeof(DRBG_ctx.V));
out_state->reseed_counter = DRBG_ctx.reseed_counter;
}
}

void OQS_randombytes_nist_kat_set_state(const void *in) {
const OQS_NIST_DRBG_struct *in_state = (const OQS_NIST_DRBG_struct *)in;
if (in_state != NULL) {
memcpy(DRBG_ctx.Key, in_state->Key, sizeof(DRBG_ctx.Key));
memcpy(DRBG_ctx.V, in_state->V, sizeof(DRBG_ctx.V));
DRBG_ctx.reseed_counter = in_state->reseed_counter;
}
}

static void AES256_CTR_DRBG_Update(unsigned char *provided_data, unsigned char *Key, unsigned char *V) {
unsigned char temp[48];

Expand Down
16 changes: 16 additions & 0 deletions src/common/rand/rand_nist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <stddef.h>
#include <stdint.h>

typedef struct {
unsigned char Key[32];
unsigned char V[16];
int reseed_counter;
} OQS_NIST_DRBG_struct;

/**
* Initializes the NIST DRBG with a given seed and with 256-bit security.
*
Expand All @@ -28,4 +34,14 @@ void OQS_randombytes_nist_kat_init_256bit(const uint8_t *entropy_input, const ui
*/
void OQS_randombytes_nist_kat(uint8_t *random_array, size_t bytes_to_read);

/**
* Writes the current state of the NIST DRBG into the provided memory.
*/
void OQS_randombytes_nist_kat_get_state(void *out);

/**
* Overwrites the current state of the NIST DRBG from the provided memory.
*/
void OQS_randombytes_nist_kat_set_state(const void *in);

#endif // OQS_RAND_NIST_H
7 changes: 4 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ endif()
add_executable(example_kem example_kem.c)
target_link_libraries(example_kem PRIVATE ${TEST_DEPS})

add_executable(kat_kem kat_kem.c)
add_executable(kat_kem kat_kem.c test_helpers.c)
target_link_libraries(kat_kem PRIVATE ${TEST_DEPS})

add_executable(test_kem test_kem.c)
Expand All @@ -80,7 +80,7 @@ set(KEM_TESTS example_kem kat_kem test_kem test_kem_mem speed_kem)
add_executable(example_sig example_sig.c)
target_link_libraries(example_sig PRIVATE ${TEST_DEPS})

add_executable(kat_sig kat_sig.c)
add_executable(kat_sig kat_sig.c test_helpers.c)
target_link_libraries(kat_sig PRIVATE ${TEST_DEPS})

add_executable(test_sig test_sig.c)
Expand Down Expand Up @@ -124,7 +124,8 @@ endif()
# for DLL builds.
add_custom_target(
run_tests
COMMAND ${CMAKE_COMMAND} -E env OQS_BUILD_DIR=${CMAKE_BINARY_DIR} ${PYTHON3_EXEC} -m pytest --verbose --numprocesses=auto --ignore=scripts/copy_from_upstream/repos
# skip long KAT tests
COMMAND ${CMAKE_COMMAND} -E env OQS_BUILD_DIR=${CMAKE_BINARY_DIR} ${PYTHON3_EXEC} -m pytest --verbose --numprocesses=auto --ignore=scripts/copy_from_upstream/repos --ignore=tests/test_kat_all.py
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS oqs dump_alg_info ${KEM_TESTS} ${SIG_TESTS} ${UNIX_TESTS}
USES_TERMINAL)
Loading
Loading