Skip to content

Commit f9c1cec

Browse files
Clean up header inclusions in pk_wrap.c
To better reflect what the code relies on, limit the headers that are included when MBEDTLS_USE_PSA_CRYPTO is disabled. Also stop including "pkwrite.h" when it is no longer needed. Include "mbedlts/platform_util.h" unconditionally. It was only included for RSA ALT but was also used for MBEDTLS_USE_PSA_CRYPTO (the code worked because other headers include "mbedtls/platform_util.h"). Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
1 parent 8ab4bbf commit f9c1cec

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

library/pk_wrap.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,37 @@
1919

2020
#include "common.h"
2121

22+
#include "mbedtls/platform_util.h"
23+
2224
#if defined(MBEDTLS_PK_C)
2325
#include "pk_wrap.h"
2426
#include "mbedtls/error.h"
2527

2628
/* Even if RSA not activated, for the sake of RSA-alt */
2729
#include "mbedtls/rsa.h"
2830

29-
#include <string.h>
30-
3131
#if defined(MBEDTLS_ECP_C)
3232
#include "mbedtls/ecp.h"
3333
#endif
3434

35-
#if defined(MBEDTLS_RSA_C) || defined(MBEDTLS_ECP_C)
36-
#include "pkwrite.h"
37-
#endif
38-
3935
#if defined(MBEDTLS_ECDSA_C)
4036
#include "mbedtls/ecdsa.h"
4137
#endif
4238

43-
#if defined(MBEDTLS_USE_PSA_CRYPTO)
44-
#include "mbedtls/asn1write.h"
45-
#endif
46-
47-
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
48-
#include "mbedtls/platform_util.h"
39+
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PSA_CRYPTO_C)
40+
#include "pkwrite.h"
4941
#endif
5042

5143
#if defined(MBEDTLS_USE_PSA_CRYPTO)
5244
#include "psa/crypto.h"
5345
#include "mbedtls/psa_util.h"
54-
#include "mbedtls/asn1.h"
5546
#include "hash_info.h"
47+
48+
#if defined(MBEDTLS_ECDSA_C)
49+
#include "mbedtls/asn1write.h"
50+
#include "mbedtls/asn1.h"
5651
#endif
52+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
5753

5854
#if defined(MBEDTLS_PLATFORM_C)
5955
#include "mbedtls/platform.h"
@@ -65,6 +61,7 @@
6561

6662
#include <limits.h>
6763
#include <stdint.h>
64+
#include <string.h>
6865

6966
#if defined(MBEDTLS_PSA_CRYPTO_C)
7067
int mbedtls_pk_error_from_psa( psa_status_t status )

0 commit comments

Comments
 (0)