Reorganize & simplify mbedtls_pk_sign_ext() handling of wrapped RSA-PSS
@@ -545,42 +545,28 @@ int mbedtls_pk_sign_ext( mbedtls_pk_type_t pk_type,
if( ! mbedtls_pk_can_do( ctx, pk_type ) )
return( MBEDTLS_ERR_PK_TYPE_MISMATCH );
- if( pk_type == MBEDTLS_PK_RSASSA_PSS &&
- mbedtls_pk_get_type( ctx ) == MBEDTLS_PK_OPAQUE )
+ if( pk_type != MBEDTLS_PK_RSASSA_PSS )
{
-#if defined(MBEDTLS_RSA_C)
- const mbedtls_svc_key_id_t *key = (const mbedtls_svc_key_id_t *) ctx->pk_ctx;
- psa_status_t status;
-
- /* PSA has its own RNG */
- (void) f_rng;
- (void) p_rng;
+ return( mbedtls_pk_sign( ctx, md_alg, hash, hash_len,
+ sig, sig_size, sig_len, f_rng, p_rng ) );
+ }
+#if defined(MBEDTLS_RSA_C)
psa_md_alg = mbedtls_psa_translate_md( md_alg );
if( psa_md_alg == 0 )
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
+ if( mbedtls_pk_get_type( ctx ) == MBEDTLS_PK_OPAQUE )
+ {
+ const mbedtls_svc_key_id_t *key = (const mbedtls_svc_key_id_t *) ctx->pk_ctx;
+ psa_status_t status;
+
status = psa_sign_hash( *key, PSA_ALG_RSA_PSS( psa_md_alg ),
hash, hash_len,
sig, sig_size, sig_len );
- if( status != PSA_SUCCESS )
return( mbedtls_pk_error_from_psa_rsa( status ) );
-
- return 0;
-#else
- return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
-#endif /* MBEDTLS_RSA_C */
}
- if( pk_type != MBEDTLS_PK_RSASSA_PSS )
- {
- return( mbedtls_pk_sign( ctx, md_alg, hash, hash_len,
- sig, sig_size, sig_len, f_rng, p_rng ) );
- }
-#if defined(MBEDTLS_RSA_C)
- psa_md_alg = mbedtls_psa_translate_md( md_alg );
- if( psa_md_alg == 0 )
- return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
return( mbedtls_pk_psa_rsa_sign_ext( PSA_ALG_RSA_PSS( psa_md_alg ),
ctx->pk_ctx, hash, hash_len,
sig, sig_size, sig_len ) );
