Fix MBEDTLS_PRIVATE wrapping in the library's headers.

Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
Mateusz Starzyk 2021-05-19 17:32:44 +02:00
parent 88fa17d1e9
commit 363eb29d4b
9 changed files with 55 additions and 53 deletions

View file

@ -84,13 +84,13 @@ typedef enum
*/ */
typedef struct mbedtls_ecdh_context_mbed typedef struct mbedtls_ecdh_context_mbed
{ {
mbedtls_ecp_group grp; /*!< The elliptic curve used. */ mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /*!< The elliptic curve used. */
mbedtls_mpi d; /*!< The private key. */ mbedtls_mpi MBEDTLS_PRIVATE(d); /*!< The private key. */
mbedtls_ecp_point Q; /*!< The public key. */ mbedtls_ecp_point MBEDTLS_PRIVATE(Q); /*!< The public key. */
mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */ mbedtls_ecp_point MBEDTLS_PRIVATE(Qp); /*!< The value of the public key of the peer. */
mbedtls_mpi z; /*!< The shared secret. */ mbedtls_mpi MBEDTLS_PRIVATE(z); /*!< The shared secret. */
#if defined(MBEDTLS_ECP_RESTARTABLE) #if defined(MBEDTLS_ECP_RESTARTABLE)
mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */ mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(rs); /*!< The restart context for EC computations. */
#endif #endif
} mbedtls_ecdh_context_mbed; } mbedtls_ecdh_context_mbed;
#endif #endif
@ -119,21 +119,21 @@ typedef struct mbedtls_ecdh_context
mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */ mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */
#endif /* MBEDTLS_ECP_RESTARTABLE */ #endif /* MBEDTLS_ECP_RESTARTABLE */
#else #else
uint8_t point_format; /*!< The format of point export in TLS messages uint8_t MBEDTLS_PRIVATE(point_format); /*!< The format of point export in TLS messages
as defined in RFC 4492. */ as defined in RFC 4492. */
mbedtls_ecp_group_id grp_id;/*!< The elliptic curve used. */ mbedtls_ecp_group_id MBEDTLS_PRIVATE(grp_id);/*!< The elliptic curve used. */
mbedtls_ecdh_variant var; /*!< The ECDH implementation/structure used. */ mbedtls_ecdh_variant MBEDTLS_PRIVATE(var); /*!< The ECDH implementation/structure used. */
union union
{ {
mbedtls_ecdh_context_mbed mbed_ecdh; mbedtls_ecdh_context_mbed MBEDTLS_PRIVATE(mbed_ecdh);
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
mbedtls_ecdh_context_everest everest_ecdh; mbedtls_ecdh_context_everest MBEDTLS_PRIVATE(everest_ecdh);
#endif #endif
} ctx; /*!< Implementation-specific context. The } MBEDTLS_PRIVATE(ctx); /*!< Implementation-specific context. The
context in use is specified by the \c var context in use is specified by the \c var
field. */ field. */
#if defined(MBEDTLS_ECP_RESTARTABLE) #if defined(MBEDTLS_ECP_RESTARTABLE)
uint8_t restart_enabled; /*!< The flag for restartable mode. Functions of uint8_t MBEDTLS_PRIVATE(restart_enabled); /*!< The flag for restartable mode. Functions of
an alternative implementation not supporting an alternative implementation not supporting
restartable mode must return restartable mode must return
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error

View file

@ -107,12 +107,12 @@ typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
*/ */
typedef struct typedef struct
{ {
mbedtls_ecp_restart_ctx ecp; /*!< base context for ECP restart and mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(ecp); /*!< base context for ECP restart and
shared administrative info */ shared administrative info */
mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */ mbedtls_ecdsa_restart_ver_ctx *MBEDTLS_PRIVATE(ver); /*!< ecdsa_verify() sub-context */
mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */ mbedtls_ecdsa_restart_sig_ctx *MBEDTLS_PRIVATE(sig); /*!< ecdsa_sign() sub-context */
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */ mbedtls_ecdsa_restart_det_ctx *MBEDTLS_PRIVATE(det); /*!< ecdsa_sign_det() sub-context */
#endif #endif
} mbedtls_ecdsa_restart_ctx; } mbedtls_ecdsa_restart_ctx;

View file

@ -317,10 +317,10 @@ typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
*/ */
typedef struct typedef struct
{ {
unsigned ops_done; /*!< current ops count */ unsigned MBEDTLS_PRIVATE(ops_done); /*!< current ops count */
unsigned depth; /*!< call depth (0 = top-level) */ unsigned MBEDTLS_PRIVATE(depth); /*!< call depth (0 = top-level) */
mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */ mbedtls_ecp_restart_mul_ctx *MBEDTLS_PRIVATE(rsm); /*!< ecp_mul_comb() sub-context */
mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */ mbedtls_ecp_restart_muladd_ctx *MBEDTLS_PRIVATE(ma); /*!< ecp_muladd() sub-context */
} mbedtls_ecp_restart_ctx; } mbedtls_ecp_restart_ctx;
/* /*

View file

@ -192,8 +192,8 @@ typedef struct mbedtls_pk_context
*/ */
typedef struct typedef struct
{ {
const mbedtls_pk_info_t * pk_info; /**< Public key information */ const mbedtls_pk_info_t * MBEDTLS_PRIVATE(pk_info); /**< Public key information */
void * rs_ctx; /**< Underlying restart context */ void * MBEDTLS_PRIVATE(rs_ctx); /**< Underlying restart context */
} mbedtls_pk_restart_ctx; } mbedtls_pk_restart_ctx;
#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
/* Now we can declare functions that take a pointer to that */ /* Now we can declare functions that take a pointer to that */
@ -209,7 +209,7 @@ typedef void mbedtls_pk_restart_ctx;
*/ */
static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk ) static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
{ {
return( (mbedtls_rsa_context *) (pk).pk_ctx ); return( (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx) );
} }
#endif /* MBEDTLS_RSA_C */ #endif /* MBEDTLS_RSA_C */
@ -222,7 +222,7 @@ static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
*/ */
static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk ) static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk )
{ {
return( (mbedtls_ecp_keypair *) (pk).pk_ctx ); return( (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx) );
} }
#endif /* MBEDTLS_ECP_C */ #endif /* MBEDTLS_ECP_C */

View file

@ -375,19 +375,19 @@ typedef struct mbedtls_ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t;
*/ */
struct mbedtls_ssl_ciphersuite_t struct mbedtls_ssl_ciphersuite_t
{ {
int id; int MBEDTLS_PRIVATE(id);
const char * name; const char * MBEDTLS_PRIVATE(name);
mbedtls_cipher_type_t cipher; mbedtls_cipher_type_t MBEDTLS_PRIVATE(cipher);
mbedtls_md_type_t mac; mbedtls_md_type_t MBEDTLS_PRIVATE(mac);
mbedtls_key_exchange_type_t key_exchange; mbedtls_key_exchange_type_t MBEDTLS_PRIVATE(key_exchange);
int min_major_ver; int MBEDTLS_PRIVATE(min_major_ver);
int min_minor_ver; int MBEDTLS_PRIVATE(min_minor_ver);
int max_major_ver; int MBEDTLS_PRIVATE(max_major_ver);
int max_minor_ver; int MBEDTLS_PRIVATE(max_minor_ver);
unsigned char flags; unsigned char MBEDTLS_PRIVATE(flags);
}; };
const int *mbedtls_ssl_list_ciphersuites( void ); const int *mbedtls_ssl_list_ciphersuites( void );

View file

@ -301,23 +301,23 @@ typedef struct
typedef struct typedef struct
{ {
/* for check_signature() */ /* for check_signature() */
mbedtls_pk_restart_ctx pk; mbedtls_pk_restart_ctx MBEDTLS_PRIVATE(pk);
/* for find_parent_in() */ /* for find_parent_in() */
mbedtls_x509_crt *parent; /* non-null iff parent_in in progress */ mbedtls_x509_crt *MBEDTLS_PRIVATE(parent); /* non-null iff parent_in in progress */
mbedtls_x509_crt *fallback_parent; mbedtls_x509_crt *MBEDTLS_PRIVATE(fallback_parent);
int fallback_signature_is_good; int MBEDTLS_PRIVATE(fallback_signature_is_good);
/* for find_parent() */ /* for find_parent() */
int parent_is_trusted; /* -1 if find_parent is not in progress */ int MBEDTLS_PRIVATE(parent_is_trusted); /* -1 if find_parent is not in progress */
/* for verify_chain() */ /* for verify_chain() */
enum { enum {
x509_crt_rs_none, x509_crt_rs_none,
x509_crt_rs_find_parent, x509_crt_rs_find_parent,
} in_progress; /* none if no operation is in progress */ } MBEDTLS_PRIVATE(in_progress); /* none if no operation is in progress */
int self_cnt; int MBEDTLS_PRIVATE(self_cnt);
mbedtls_x509_crt_verify_chain ver_chain; mbedtls_x509_crt_verify_chain MBEDTLS_PRIVATE(ver_chain);
} mbedtls_x509_crt_restart_ctx; } mbedtls_x509_crt_restart_ctx;

View file

@ -345,7 +345,7 @@ static inline struct psa_key_attributes_s psa_key_attributes_init( void )
static inline void psa_set_key_id( psa_key_attributes_t *attributes, static inline void psa_set_key_id( psa_key_attributes_t *attributes,
mbedtls_svc_key_id_t key ) mbedtls_svc_key_id_t key )
{ {
psa_key_lifetime_t MBEDTLS_PRIVATE(lifetime) = attributes->MBEDTLS_PRIVATE(core).lifetime; psa_key_lifetime_t lifetime = attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(lifetime);
attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id) = key; attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id) = key;
@ -368,7 +368,7 @@ static inline mbedtls_svc_key_id_t psa_get_key_id(
static inline void mbedtls_set_key_owner_id( psa_key_attributes_t *attributes, static inline void mbedtls_set_key_owner_id( psa_key_attributes_t *attributes,
mbedtls_key_owner_id_t owner ) mbedtls_key_owner_id_t owner )
{ {
attributes->core.id.owner = owner; attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(owner) = owner;
} }
#endif #endif
@ -379,7 +379,7 @@ static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes,
if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
{ {
#ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id).key_id = 0; attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(key_id) = 0;
#else #else
attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id) = 0; attributes->MBEDTLS_PRIVATE(core).MBEDTLS_PRIVATE(id) = 0;
#endif #endif

View file

@ -32,6 +32,7 @@
#ifndef PSA_CRYPTO_TYPES_H #ifndef PSA_CRYPTO_TYPES_H
#define PSA_CRYPTO_TYPES_H #define PSA_CRYPTO_TYPES_H
#include "mbedtls/private_access.h"
#include "crypto_platform.h" #include "crypto_platform.h"
@ -234,8 +235,8 @@ typedef psa_key_id_t mbedtls_svc_key_id_t;
*/ */
typedef struct typedef struct
{ {
psa_key_id_t key_id; psa_key_id_t MBEDTLS_PRIVATE(key_id);
mbedtls_key_owner_id_t owner; mbedtls_key_owner_id_t MBEDTLS_PRIVATE(owner);
} mbedtls_svc_key_id_t; } mbedtls_svc_key_id_t;
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ #endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */

View file

@ -33,6 +33,7 @@
#ifndef PSA_CRYPTO_VALUES_H #ifndef PSA_CRYPTO_VALUES_H
#define PSA_CRYPTO_VALUES_H #define PSA_CRYPTO_VALUES_H
#include "mbedtls/private_access.h"
/** \defgroup error Error codes /** \defgroup error Error codes
* @{ * @{
@ -2124,8 +2125,8 @@ static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make( static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make(
mbedtls_key_owner_id_t owner_id, psa_key_id_t key_id ) mbedtls_key_owner_id_t owner_id, psa_key_id_t key_id )
{ {
return( (mbedtls_svc_key_id_t){ .key_id = key_id, return( (mbedtls_svc_key_id_t){ .MBEDTLS_PRIVATE(key_id) = key_id,
.owner = owner_id } ); .MBEDTLS_PRIVATE(owner) = owner_id } );
} }
/** Compare two key identifiers. /** Compare two key identifiers.
@ -2138,8 +2139,8 @@ static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make(
static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1, static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1,
mbedtls_svc_key_id_t id2 ) mbedtls_svc_key_id_t id2 )
{ {
return( ( id1.key_id == id2.key_id ) && return( ( id1.MBEDTLS_PRIVATE(key_id) == id2.MBEDTLS_PRIVATE(key_id) ) &&
mbedtls_key_owner_id_equal( id1.owner, id2.owner ) ); mbedtls_key_owner_id_equal( id1.MBEDTLS_PRIVATE(owner), id2.MBEDTLS_PRIVATE(owner) ) );
} }
/** Check whether a key identifier is null. /** Check whether a key identifier is null.
@ -2150,7 +2151,7 @@ static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1,
*/ */
static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key ) static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
{ {
return( ( key.key_id == 0 ) && ( key.owner == 0 ) ); return( ( key.MBEDTLS_PRIVATE(key_id) == 0 ) && ( key.MBEDTLS_PRIVATE(owner) == 0 ) );
} }
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ #endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */