Skip to content

Move the inclusion of crypto_sizes.h and crypto_struct.h in crypto.h #260

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

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

ronald-cron-arm
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm commented Apr 17, 2025

Description

Move the inclusion of crypto_sizes.h and crypto_struct.h in crypto.h
That way when API are declared, the types they used are defined.
This should resolve the issues related to psa_xyz_init functions returning a structure described in Mbed-TLS/mbedtls#7087.

PR checklist

  • changelog provided | not required because:
  • framework PR provided Mbed-TLS/mbedtls-framework# | not required
  • mbedtls development PR provided Mbed-TLS/mbedtls# | not required because:
  • mbedtls 3.6 PR provided Mbed-TLS/mbedtls# | not required because:
  • tests provided | not required because:

@ronald-cron-arm ronald-cron-arm added the needs-ci Needs to pass CI tests label Apr 17, 2025
@@ -39,6 +39,18 @@ extern "C" {
* algorithms, key types, policies, etc. */
#include "crypto_types.h"

/* The file "crypto_sizes.h" contains definitions for size calculation
* macros whose definitions are implementation-specific. */
#include "crypto_sizes.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

crypto_sizes.h uses macros from crypto_values.h, so it would make more sense to include crypto_values.h first. I don't think it actually matters for the sake of the C language, because crypto_sizes.h itself only defines macros, it doesn't expand them. But then crypto_struct.h does expand macros from crypto_sizes.h, and that can result in expanding macros from crypto_values.h. It works because crypto_struct.h (indirectly) includes crypto_driver_common.h which includes crypto_values.h. But it would make more sense to include crypto_values.h at the logical place in crypto.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I missed that, thanks. I've changed it and while at it I've tried to fix the similar issues in crypto_extra.h pointed to by #7087.

That way when API are declared, the types they used are defined.

This should resolve the issues related to psa_xyz_init functions
returning a structure described in #7087.

Signed-off-by: Ronald Cron <[email protected]>
Move the definitions of psa_pake_cipher_suite_s and
psa_pake_operation_s before the declarations
of respectively psa_pake_cipher_suite_init and
psa_pake_operation init. This is to avoid the
following pattern that some C++ compilers fail
to compile:

typedef struct foo_s foo_t;

foo_t get_a_foo(int search);

struct foo_s {
    int foo_int;
};

Signed-off-by: Ronald Cron <[email protected]>
Define the structure then the associated type.

Signed-off-by: Ronald Cron <[email protected]>
@ronald-cron-arm ronald-cron-arm force-pushed the move-crypto-struct-inclusion branch from 037a7ac to be9d9f0 Compare April 17, 2025 14:51
@gilles-peskine-arm gilles-peskine-arm added priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most) needs-work labels Apr 17, 2025
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM for the code change. I don't know if it actually fixes Mbed-TLS/mbedtls#7087, but at worst it's harmless.

If this does fix Mbed-TLS/mbedtls#7087 then we need a changelog entry, and preferably a non-regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci Needs to pass CI tests needs-work priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most)
Projects
Status: In Development
Development

Successfully merging this pull request may close these issues.

2 participants