1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-28 00:21:48 +03:00

Add negative zero as an input to automatically generated tests

Although negative zero is officially unsupported, we've had bugs related to
it in the past. So do test functions with a negative zero input.

There will likely be cases where we don't want to accept negative zero as if
it was valid, because it's too hard to handle. We'll add exceptions on a
case by case basis.

For the functions that are currently tested by the generated tests, the new
test cases pass.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2022-11-15 20:43:33 +01:00
parent ca6e8aac58
commit 35af02171d
2 changed files with 32 additions and 4 deletions

View File

@ -38,7 +38,13 @@ def invmod(a: int, n: int) -> int:
raise ValueError("Not invertible")
def hex_to_int(val: str) -> int:
return int(val, 16) if val else 0
"""Implement the syntax accepted by mbedtls_test_read_mpi().
This is a superset of what is accepted by mbedtls_test_read_mpi_core().
"""
if val == '' or val == '-':
return 0
return int(val, 16)
def quote_str(val) -> str:
return "\"{}\"".format(val)