Skip to content

test_psa_constant_names: support key agreement, better code structure #324

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

Conversation

gilles-peskine-arm
Copy link
Collaborator

This pull request consists mostly of changes to test_psa_constant_names.py:

  • Many small refactorings of test_psa_constant_names.py. I initially did them in preparation for reusing major parts of the code in another script. This other script is not stable yet and I'm not sure if I need it after all. Since the refactorings are at worst harmless and at best useful to make the code easier to maintain, I'm submitting them.
  • Fix the collection of curves, which I discovered to be broken.
  • Error out if a test case uses a macro name which isn't defined in a header covered by this script.
  • Add support for key agreement, which was long overdue.
  • In test_suite_psa_crypto_metadata, add a few more test cases for KDF.

FOO(BAR) is an expression, not a name.
Pack expression generation into a method.
No behavior change.
No need to split lines, or remove whitespace after removing
whitespace. No behavior change.
No behavior change.
@gilles-peskine-arm gilles-peskine-arm added enhancement New feature or request needs: review The pull request is ready for review. This generally means that it has no known issues. labels Nov 22, 2019
@dgreen-arm dgreen-arm self-requested a review November 25, 2019 10:14
@Patater Patater self-requested a review November 25, 2019 10:59
Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on what looks like incorrect patch composition, but otherwise looks good.

c, e = do_test(options, inputs, type_word, names)
for type_word in ['status', 'algorithm', 'ecc_curve', 'dh_group',
'key_type', 'key_usage']:
c, e = do_test(options, inputs, type_word)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Move the type_word->name_set mapping into its own method", which says it has no change on behavior, we don't need to call get_names() anywhere? For example, while passing a names parameter to do_test()

values = run_c(options, type_word, expressions)
return expressions, values

def do_test(options, inputs, type_word):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Move value collection into its own function", which says it makes no change to behavior, don't we need to update all callers of do_test()? We are changing the parameters do_test() makes in a commit that doesn't change the callers, so I don't see how this wouldn't change behavior.

Copy link
Contributor

@dgreen-arm dgreen-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the function do_test, the updating of its parameters is split between 898c2d8 and 9348b12. Other than this, everything looks good to me.

This makes the structure of the code more apparent.

No behavior change.
No behavior change.
PSA_ECC_CURVE_xxx and PSA_DH_GROUP_xxx were not collected from
headers, only from test suites.
Insist that test cases must only use macro names that are declared in
a header. This may catch errors such as not parsing the intended
files.

Make this check easily overridden in a derived class.
Key agreement algorithms were excluded back when they were constructed
with a macro conveying the key agreement itself taking the KDF as an
argument, because that was hard to support. Now the encoding has
changed and key agreement algorithms are constructed with
PSA_ALG_KEY_AGREEMENT taking two arguments, one that identifies the
raw key agreement and one that identifies the KDF. This is easy to
process, so add support.
@gilles-peskine-arm gilles-peskine-arm force-pushed the psa-test_psa_constant_names-refactor_and_ka branch from cc72675 to d2cea9f Compare November 25, 2019 14:45
@gilles-peskine-arm
Copy link
Collaborator Author

I rewrote the history in two places:

  • I fixed the split between "Move the type_word->name_set mapping into its own method" and "Move value collection into its own function" to make each commit correct as pointed out in the review.
  • I modified the commit "add_test_case_line: data-driven dispatch" significantly to better separate data and code and to avoid reaching pylint's threshold for too many branches when the kdf/ka cases are added.

# Keep the expression as one to test as an algorithm.
function = 'other_algorithm'
if function in self.table_by_test_function:
sets.append(self.table_by_test_function[function])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to call accept_test_case_line() if function was not in self.table_by_test_function? I see accept_test_case_line() throws an exception instead of returning False for not accepted test cases.

Copy link
Collaborator Author

@gilles-peskine-arm gilles-peskine-arm Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. If we add a function to test_suite_psa_crypto_metadata, what do we want to happen here? I don't think the current behavior is correct: a new function whose name does not end in _algorithm would undergo the argument validity check without contributing to the data tested by this script. I'll change the code to insist on the function being partially known (i.e. either in the table or ending in _algorithm): better fail with an exception than silently not test something that we might reasonably believe is tested.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the code to insist on knowing the function name. This uncovered a lack of coverage for some expressions involving a wildcard.

When gathering test cases from test_suite_psa_crypto_metadata, look up
the test function explicitly. This way test_psa_constant_names will
error out if we add a new test function that needs coverage here.

This change highlights an omission in the previous version:
asymmetric_signature_wildcard was silently ignored as a source of
algorithm expressions to test. Fix that.
@gilles-peskine-arm gilles-peskine-arm removed the needs: review The pull request is ready for review. This generally means that it has no known issues. label Nov 26, 2019
@gilles-peskine-arm gilles-peskine-arm merged commit 4eca19b into ARMmbed:development Nov 26, 2019
gilles-peskine-arm added a commit to gilles-peskine-arm/mbed-crypto that referenced this pull request Feb 3, 2020
* ARMmbed#321: Replace config.pl by config.py
* ARMmbed#322: Update Mbed Crypto with latest Mbed TLS changes as of 2019-11-15
* ARMmbed#308: Small performance improvement of mbedtls_mpi_div_mpi()
* ARMmbed#324: test_psa_constant_names: support key agreement, better code structure
* ARMmbed#320: Link to the PSA crypto portal page from README.md
* ARMmbed#293: Always gather MBEDTLS_ENTROPY_BLOCK_SIZE bytes of entropy
* ARMmbed#310: Clarify test descriptions in test_suite_memory_buffer_alloc
* ARMmbed#307: Add ASN.1 ENUMERATED tag support
* ARMmbed#328: Remove dependency of crypto_values.h on crypto_extra.h
* ARMmbed#325: Rename psa_asymmetric_{sign_verify} to psa_{sign,verify}_hash

Missed listing in the previous submodule update:

* ARMmbed#304: Make sure Asan failures are detected in 'make test'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants