mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-10-04 00:02:01 -04:00
* [#1823] replace malloc/calloc/strdup/free with openssl allocator Signed-off-by: Songling Han <shan@paloaltonetworks.com> * [#1823] update memory allocator for copy_from_upstream Signed-off-by: Songling Han <shan@paloaltonetworks.com> * [#1823] Use OpenSSL Memory Allocator for BIKE, FrodoKEM, and NTRUPrime Signed-off-by: Songling Han <shan@paloaltonetworks.com> * [#1823] Add Comments for Doxygen Signed-off-by: Songling Han <shan@paloaltonetworks.com> * include openssl/crypto.h and resolve conflict varible for ntru Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Add openssl version check to fix build error Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Fix build for OQS_DLOPEN_OPENSSL Signed-off-by: Songling Han <shan@paloaltonetworks.com> * remove OQS_MEM_free Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Add allocator check in tests/test_code_conventions.py Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Add IGNORE memory-check Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Delect checked allocation functions Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Revert back p_param to p for sntrup Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Add allocator check for '.c', '.h', '.fragment' Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Add NULL for previous checked allocation Signed-off-by: Songling Han <shan@paloaltonetworks.com> * Add fprintf error for abort cases Signed-off-by: Songling Han <shan@paloaltonetworks.com> * use OQS_EXIT_IF_NULLPTR for checked malloc cases Signed-off-by: Songling Han <shan@paloaltonetworks.com> --------- Signed-off-by: Songling Han <shan@paloaltonetworks.com>
94 lines
3.3 KiB
Python
94 lines
3.3 KiB
Python
# SPDX-License-Identifier: MIT
|
|
|
|
import helpers
|
|
import os
|
|
import pytest
|
|
import re
|
|
import sys
|
|
|
|
# Ensure every key-exchange algorithm in the code
|
|
# is mentioned in the documentation.
|
|
@helpers.filtered_test
|
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
|
|
@pytest.mark.parametrize('kem_name', helpers.available_kems_by_name())
|
|
def test_datasheet_kem(kem_name):
|
|
helpers.run_subprocess(
|
|
['grep', '-r', kem_name, 'docs/algorithms']
|
|
)
|
|
|
|
# Ensure every signature algorithm in the code
|
|
# is mentioned in the documentation.
|
|
@helpers.filtered_test
|
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
|
|
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
|
|
def test_datasheet_sig(sig_name):
|
|
helpers.run_subprocess(
|
|
['grep', '-r', sig_name, 'docs/algorithms']
|
|
)
|
|
|
|
# Ensure astyle agrees with the formatting.
|
|
@helpers.filtered_test
|
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
|
|
def test_style():
|
|
|
|
result = helpers.run_subprocess(
|
|
['tests/run_astyle.sh']
|
|
)
|
|
assert 'Formatted' not in result
|
|
|
|
@helpers.filtered_test
|
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
|
|
def test_spdx():
|
|
|
|
result = helpers.run_subprocess(
|
|
['tests/test_spdx.sh']
|
|
)
|
|
if len(result) != 0:
|
|
print("The following files do not have proper SPDX-License-Identifier headers:")
|
|
print(result)
|
|
assert False
|
|
|
|
def test_memory_functions():
|
|
c_h_files = []
|
|
for path, _, files in os.walk('src'):
|
|
c_h_files += [os.path.join(path, f) for f in files if f.endswith(('.c', '.h', '.fragment'))]
|
|
|
|
memory_functions = ['free', 'malloc', 'calloc', 'realloc', 'strdup']
|
|
okay = True
|
|
|
|
for fn in c_h_files:
|
|
with open(fn) as f:
|
|
content = f.read()
|
|
lines = content.splitlines()
|
|
in_multiline_comment = False
|
|
for no, line in enumerate(lines, 1):
|
|
# Skip single-line comments
|
|
if line.strip().startswith('//'):
|
|
continue
|
|
# Check for start of multi-line comment
|
|
if '/*' in line and not in_multiline_comment:
|
|
in_multiline_comment = True
|
|
# Check for end of multi-line comment
|
|
if '*/' in line and in_multiline_comment:
|
|
in_multiline_comment = False
|
|
continue
|
|
# Skip lines inside multi-line comments
|
|
if in_multiline_comment:
|
|
continue
|
|
for func in memory_functions:
|
|
if re.search(r'\b{}\('.format(func), line) and not re.search(r'\b_{}\('.format(func), line):
|
|
if 'IGNORE memory-check' in line:
|
|
continue
|
|
okay = False
|
|
print(f"Suspicious `{func}` in {fn}:{no}:{line.strip()}")
|
|
|
|
assert okay, ("Standard memory functions are used in some files. "
|
|
"These should be changed to OQS_MEM_* equivalents as appropriate. "
|
|
"If you are sure you want to use these functions in a particular spot, "
|
|
"add the comment '// IGNORE memory-check' on the line where the function occurs.")
|
|
|
|
if __name__ == "__main__":
|
|
test_memory_functions()
|
|
import sys
|
|
pytest.main(sys.argv)
|