Skip to content

Conversation

@gilles-peskine-arm
Copy link
Collaborator

If the type/size attributes are specified during key creation but not required because they can be inferred from the actual data, check them against the actual data.

This PR adds tests for the type and size, but not for domain parameters which are currently mostly not implemented.

Internal ref: https://github.com/ARMmbed/psa-crypto/issues/140#issuecomment-489107823 — Validating unused attributes in key creation

In psa_import_key and psa_copy_key, some information comes from the
key data (input buffer or source key) rather than from the attributes:
key size for import, key size and type and domain parameters for copy.
If an unused attribute is nonzero in the attribute structure, check
that it matches the correct value. This protects against application
errors.
Add tests where psa_import_key is called with attributes specifying an
incorrect size.
Split the test function copy_key into two: one for success and one for
failure.

Add failure tests where the attributes specify an incorrect type or size.
@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. api-spec Issue or PR about the PSA specifications labels May 3, 2019
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.

For real implementation, should expand testing to include properly handling of all optional parameters (type, domain_parameters, bits) for RSA and AES as applicable.

{
mbedtls_mpi actual, required;
int ret;
mbedtls_mpi_init( &actual );
Copy link
Contributor

Choose a reason for hiding this comment

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

In a real implementation, we might want to comment that this is comparing the public exponent (the only RSA domain parameter).

goto exit;
}
PSA_ASSERT( psa_copy_key( source_handle,
&target_attributes, &target_handle ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

For real implementation, would recommend asserting target_handle is non-zero upon return

@Patater Patater removed the needs: review The pull request is ready for review. This generally means that it has no known issues. label May 13, 2019
@Patater Patater merged commit 1fe90fa into ARMmbed:psa-api-1.0-beta May 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-spec Issue or PR about the PSA specifications enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants