From 041388af2a73c411703e3ee8d6b28d42b2799734 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Sat, 19 Mar 2022 18:06:52 +0100 Subject: [PATCH] Short-tag AEAD with the nominal length are encoded as nominal AEAD `PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, len) == aead_alg` when `len == PSA_AEAD_TAG_LENGTH(aead_alg)`. So skip this case when testing the printing of constants. This fixes one test case due to the way arguments of `PSA_ALG_AEAD_WITH_SHORTENED_TAG` are enumerated (all algorithms are tested for a value of `len` which isn't problematic, and all values of `len` are tested for one algorithm). Signed-off-by: Gilles Peskine --- tests/scripts/test_psa_constant_names.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/scripts/test_psa_constant_names.py b/tests/scripts/test_psa_constant_names.py index 07c8ab2e97..e43a0baef2 100755 --- a/tests/scripts/test_psa_constant_names.py +++ b/tests/scripts/test_psa_constant_names.py @@ -77,6 +77,22 @@ def normalize(expr: str) -> str: """ return re.sub(NORMALIZE_STRIP_RE, '', expr) +ALG_TRUNCATED_TO_SELF_RE = \ + re.compile(r'PSA_ALG_AEAD_WITH_SHORTENED_TAG\(' + r'PSA_ALG_(?:CCM|CHACHA20_POLY1305|GCM)' + r', *16\)\Z') + +def is_simplifiable(expr: str) -> bool: + """Determine whether an expression is simplifiable. + + Simplifiable expressions can't be output in their input form, since + the output will be the simple form. Therefore they must be excluded + from testing. + """ + if ALG_TRUNCATED_TO_SELF_RE.match(expr): + return True + return False + def collect_values(inputs: InputsForTest, type_word: str, include_path: Optional[str] = None, @@ -87,7 +103,9 @@ def collect_values(inputs: InputsForTest, value is a string representation of its integer value. """ names = inputs.get_names(type_word) - expressions = sorted(inputs.generate_expressions(names)) + expressions = sorted(expr + for expr in inputs.generate_expressions(names) + if not is_simplifiable(expr)) values = run_c(type_word, expressions, include_path=include_path, keep_c=keep_c) return expressions, values