Skip to content

Commit 127985b

Browse files
Andrzej Kureknordicjm
authored andcommitted
[nrf fromtree] Make KEY_ID_ENCODES_OWNER compatible with USE_PSA_CRYPTO
Fix library references, tests and programs. Testing is performed in the already present all.sh test. ref: NCSDK-17464 Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com> Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no> (cherry picked from commit 03e0146)
1 parent d540e87 commit 127985b

14 files changed

Lines changed: 51 additions & 56 deletions

File tree

include/mbedtls/check_config.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,6 @@
561561
#error "MBEDTLS_PSA_ITS_FILE_C defined, but not all prerequisites"
562562
#endif
563563

564-
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) && \
565-
defined(MBEDTLS_USE_PSA_CRYPTO)
566-
#error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER defined, but it cannot coexist with MBEDTLS_USE_PSA_CRYPTO."
567-
#endif
568-
569564
#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
570565
!defined(MBEDTLS_OID_C) )
571566
#error "MBEDTLS_RSA_C defined, but not all prerequisites"

include/mbedtls/pk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
351351
* \return #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
352352
*/
353353
int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx,
354-
const psa_key_id_t key );
354+
const mbedtls_svc_key_id_t key );
355355
#endif /* MBEDTLS_USE_PSA_CRYPTO */
356356

357357
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
@@ -898,7 +898,7 @@ int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
898898
* \return An Mbed TLS error code otherwise.
899899
*/
900900
int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk,
901-
psa_key_id_t *key,
901+
mbedtls_svc_key_id_t *key,
902902
psa_algorithm_t hash_alg );
903903
#endif /* MBEDTLS_USE_PSA_CRYPTO */
904904

include/mbedtls/ssl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ struct mbedtls_ssl_config
13781378
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
13791379

13801380
#if defined(MBEDTLS_USE_PSA_CRYPTO)
1381-
psa_key_id_t MBEDTLS_PRIVATE(psk_opaque); /*!< PSA key slot holding opaque PSK. This field
1381+
mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psk_opaque); /*!< PSA key slot holding opaque PSK. This field
13821382
* should only be set via
13831383
* mbedtls_ssl_conf_psk_opaque().
13841384
* If either no PSK or a raw PSK have been
@@ -3040,7 +3040,7 @@ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
30403040
* \return Another negative error code on other kinds of failure.
30413041
*/
30423042
int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf,
3043-
psa_key_id_t psk,
3043+
mbedtls_svc_key_id_t psk,
30443044
const unsigned char *psk_identity,
30453045
size_t psk_identity_len );
30463046
#endif /* MBEDTLS_USE_PSA_CRYPTO */
@@ -3086,7 +3086,7 @@ int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
30863086
* \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
30873087
*/
30883088
int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl,
3089-
psa_key_id_t psk );
3089+
mbedtls_svc_key_id_t psk );
30903090
#endif /* MBEDTLS_USE_PSA_CRYPTO */
30913091

30923092
/**

library/cipher_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ typedef enum
130130
typedef struct
131131
{
132132
psa_algorithm_t alg;
133-
psa_key_id_t slot;
133+
mbedtls_svc_key_id_t slot;
134134
mbedtls_cipher_psa_key_ownership slot_state;
135135
} mbedtls_cipher_context_psa;
136136
#endif /* MBEDTLS_USE_PSA_CRYPTO */

library/pk.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info )
151151
* Initialise a PSA-wrapping context
152152
*/
153153
int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx,
154-
const psa_key_id_t key )
154+
const mbedtls_svc_key_id_t key )
155155
{
156156
const mbedtls_pk_info_t * const info = &mbedtls_pk_opaque_info;
157157
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
158-
psa_key_id_t *pk_ctx;
158+
mbedtls_svc_key_id_t *pk_ctx;
159159
psa_key_type_t type;
160160

161161
if( ctx == NULL || ctx->pk_info != NULL )
@@ -175,7 +175,7 @@ int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx,
175175

176176
ctx->pk_info = info;
177177

178-
pk_ctx = (psa_key_id_t *) ctx->pk_ctx;
178+
pk_ctx = (mbedtls_svc_key_id_t *) ctx->pk_ctx;
179179
*pk_ctx = key;
180180

181181
return( 0 );
@@ -598,7 +598,7 @@ mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx )
598598
* Currently only works for EC private keys.
599599
*/
600600
int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk,
601-
psa_key_id_t *key,
601+
mbedtls_svc_key_id_t *key,
602602
psa_algorithm_t hash_alg )
603603
{
604604
#if !defined(MBEDTLS_ECP_C)

library/pk_wrap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg,
560560
mbedtls_ecdsa_context *ctx = ctx_arg;
561561
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
562562
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
563-
psa_key_id_t key_id = 0;
563+
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
564564
psa_status_t status;
565565
mbedtls_pk_context key;
566566
int key_len;
@@ -894,7 +894,7 @@ const mbedtls_pk_info_t mbedtls_rsa_alt_info = {
894894

895895
static void *pk_opaque_alloc_wrap( void )
896896
{
897-
void *ctx = mbedtls_calloc( 1, sizeof( psa_key_id_t ) );
897+
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_svc_key_id_t ) );
898898

899899
/* no _init() function to call, an calloc() already zeroized */
900900

@@ -903,13 +903,13 @@ static void *pk_opaque_alloc_wrap( void )
903903

904904
static void pk_opaque_free_wrap( void *ctx )
905905
{
906-
mbedtls_platform_zeroize( ctx, sizeof( psa_key_id_t ) );
906+
mbedtls_platform_zeroize( ctx, sizeof( mbedtls_svc_key_id_t ) );
907907
mbedtls_free( ctx );
908908
}
909909

910910
static size_t pk_opaque_get_bitlen( const void *ctx )
911911
{
912-
const psa_key_id_t *key = (const psa_key_id_t *) ctx;
912+
const mbedtls_svc_key_id_t *key = (const mbedtls_svc_key_id_t *) ctx;
913913
size_t bits;
914914
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
915915

@@ -1033,7 +1033,7 @@ static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
10331033
((void) p_rng);
10341034
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
10351035
#else /* !MBEDTLS_ECDSA_C */
1036-
const psa_key_id_t *key = (const psa_key_id_t *) ctx;
1036+
const mbedtls_svc_key_id_t *key = (const mbedtls_svc_key_id_t *) ctx;
10371037
psa_algorithm_t alg = PSA_ALG_ECDSA( mbedtls_psa_translate_md( md_alg ) );
10381038
psa_status_t status;
10391039

library/pkwrite.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
198198
if( mbedtls_pk_get_type( key ) == MBEDTLS_PK_OPAQUE )
199199
{
200200
size_t buffer_size;
201-
psa_key_id_t* key_id = (psa_key_id_t*) key->pk_ctx;
201+
mbedtls_svc_key_id_t* key_id = (mbedtls_svc_key_id_t*) key->pk_ctx;
202202

203203
if ( *p < start )
204204
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
@@ -265,11 +265,11 @@ int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *b
265265
{
266266
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
267267
psa_key_type_t key_type;
268-
psa_key_id_t key_id;
268+
mbedtls_svc_key_id_t key_id;
269269
psa_ecc_family_t curve;
270270
size_t bits;
271271

272-
key_id = *((psa_key_id_t*) key->pk_ctx );
272+
key_id = *((mbedtls_svc_key_id_t*) key->pk_ctx );
273273
if( PSA_SUCCESS != psa_get_key_attributes( key_id, &attributes ) )
274274
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
275275
key_type = psa_get_key_type( &attributes );

library/ssl_misc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ struct mbedtls_ssl_handshake_params
609609
#if defined(MBEDTLS_USE_PSA_CRYPTO)
610610
psa_key_type_t ecdh_psa_type;
611611
uint16_t ecdh_bits;
612-
psa_key_id_t ecdh_psa_privkey;
612+
mbedtls_svc_key_id_t ecdh_psa_privkey;
613613
unsigned char ecdh_psa_peerkey[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
614614
size_t ecdh_psa_peerkey_len;
615615
#endif /* MBEDTLS_USE_PSA_CRYPTO */
@@ -630,7 +630,7 @@ struct mbedtls_ssl_handshake_params
630630

631631
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
632632
#if defined(MBEDTLS_USE_PSA_CRYPTO)
633-
psa_key_id_t psk_opaque; /*!< Opaque PSK from the callback */
633+
mbedtls_svc_key_id_t psk_opaque; /*!< Opaque PSK from the callback */
634634
#endif /* MBEDTLS_USE_PSA_CRYPTO */
635635
unsigned char *psk; /*!< PSK from the callback */
636636
size_t psk_len; /*!< Length of PSK from callback */
@@ -1247,7 +1247,7 @@ static inline int mbedtls_ssl_get_psk( const mbedtls_ssl_context *ssl,
12471247
* 2. static PSK configured by \c mbedtls_ssl_conf_psk_opaque()
12481248
* Return an opaque PSK
12491249
*/
1250-
static inline psa_key_id_t mbedtls_ssl_get_opaque_psk(
1250+
static inline mbedtls_svc_key_id_t mbedtls_ssl_get_opaque_psk(
12511251
const mbedtls_ssl_context *ssl )
12521252
{
12531253
if( ! mbedtls_svc_key_id_is_null( ssl->handshake->psk_opaque ) )

library/ssl_tls.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void handle_buffer_resizing( mbedtls_ssl_context *ssl, int downsizing,
333333
#if defined(MBEDTLS_USE_PSA_CRYPTO)
334334

335335
static psa_status_t setup_psa_key_derivation( psa_key_derivation_operation_t* derivation,
336-
psa_key_id_t key,
336+
mbedtls_svc_key_id_t key,
337337
psa_algorithm_t alg,
338338
const unsigned char* seed, size_t seed_length,
339339
const unsigned char* label, size_t label_length,
@@ -393,7 +393,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type,
393393
{
394394
psa_status_t status;
395395
psa_algorithm_t alg;
396-
psa_key_id_t master_key = MBEDTLS_SVC_KEY_ID_INIT;
396+
mbedtls_svc_key_id_t master_key = MBEDTLS_SVC_KEY_ID_INIT;
397397
psa_key_derivation_operation_t derivation =
398398
PSA_KEY_DERIVATION_OPERATION_INIT;
399399

@@ -1223,7 +1223,7 @@ static int ssl_compute_master( mbedtls_ssl_handshake_params *handshake,
12231223
/* Perform PSK-to-MS expansion in a single step. */
12241224
psa_status_t status;
12251225
psa_algorithm_t alg;
1226-
psa_key_id_t psk;
1226+
mbedtls_svc_key_id_t psk;
12271227
psa_key_derivation_operation_t derivation =
12281228
PSA_KEY_DERIVATION_OPERATION_INIT;
12291229
mbedtls_md_type_t hash_alg = handshake->ciphersuite_info->mac;
@@ -3890,7 +3890,7 @@ int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
38903890

38913891
#if defined(MBEDTLS_USE_PSA_CRYPTO)
38923892
int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf,
3893-
psa_key_id_t psk,
3893+
mbedtls_svc_key_id_t psk,
38943894
const unsigned char *psk_identity,
38953895
size_t psk_identity_len )
38963896
{
@@ -3915,7 +3915,7 @@ int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf,
39153915
}
39163916

39173917
int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl,
3918-
psa_key_id_t psk )
3918+
mbedtls_svc_key_id_t psk )
39193919
{
39203920
if( ( mbedtls_svc_key_id_is_null( psk ) ) ||
39213921
( ssl->handshake == NULL ) )

programs/ssl/ssl_client2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ int main( int argc, char *argv[] )
692692
const char *pers = "ssl_client2";
693693

694694
#if defined(MBEDTLS_USE_PSA_CRYPTO)
695-
psa_key_id_t slot = 0;
695+
mbedtls_svc_key_id_t slot = MBEDTLS_SVC_KEY_ID_INIT;
696696
psa_algorithm_t alg = 0;
697697
psa_key_attributes_t key_attributes;
698698
psa_status_t status;
@@ -716,7 +716,7 @@ int main( int argc, char *argv[] )
716716
mbedtls_x509_crt clicert;
717717
mbedtls_pk_context pkey;
718718
#if defined(MBEDTLS_USE_PSA_CRYPTO)
719-
psa_key_id_t key_slot = 0; /* invalid key slot */
719+
mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT; /* invalid key slot */
720720
#endif
721721
#endif /* MBEDTLS_X509_CRT_PARSE_C */
722722
char *p, *q;
@@ -3061,7 +3061,8 @@ int main( int argc, char *argv[] )
30613061
( opt.query_config_mode == DFL_QUERY_CONFIG_MODE ) )
30623062
{
30633063
mbedtls_printf( "Failed to destroy key slot %u - error was %d",
3064-
(unsigned) slot, (int) status );
3064+
(unsigned) MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot ),
3065+
(int) status );
30653066
if( ret == 0 )
30663067
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
30673068
}

0 commit comments

Comments
 (0)