mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-11 01:25:41 +00:00
pkwrite: add opaque key handling for public key exporting
Return early from mbedtls_pk_write_pubkey_der - public opaque key exporting is expected to contain all of the needed data, therefore it shouldn't be written again.
This commit is contained in:
parent
23a1ccd23f
commit
5fec0860f9
|
@ -46,6 +46,9 @@
|
||||||
#include "mbedtls/pem.h"
|
#include "mbedtls/pem.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
|
#include "psa/crypto.h"
|
||||||
|
#endif
|
||||||
#if defined(MBEDTLS_PLATFORM_C)
|
#if defined(MBEDTLS_PLATFORM_C)
|
||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
#else
|
#else
|
||||||
|
@ -161,6 +164,23 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
|
||||||
MBEDTLS_ASN1_CHK_ADD( len, pk_write_ec_pubkey( p, start, mbedtls_pk_ec( *key ) ) );
|
MBEDTLS_ASN1_CHK_ADD( len, pk_write_ec_pubkey( p, start, mbedtls_pk_ec( *key ) ) );
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
|
if( mbedtls_pk_get_type( key ) == MBEDTLS_PK_OPAQUE )
|
||||||
|
{
|
||||||
|
size_t buffer_size = *p - start;
|
||||||
|
psa_key_slot_t* key_slot = ( psa_key_slot_t* ) key->pk_ctx;
|
||||||
|
if ( psa_export_public_key( *key_slot, start, buffer_size, &len )
|
||||||
|
!= PSA_SUCCESS )
|
||||||
|
{
|
||||||
|
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memmove( *p - len, start, len );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||||
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
|
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
|
||||||
|
|
||||||
return( (int) len );
|
return( (int) len );
|
||||||
|
@ -177,6 +197,10 @@ int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *key, unsigned char *buf, si
|
||||||
|
|
||||||
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_pk_write_pubkey( &c, buf, key ) );
|
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_pk_write_pubkey( &c, buf, key ) );
|
||||||
|
|
||||||
|
if( mbedtls_pk_get_type( key ) == MBEDTLS_PK_OPAQUE )
|
||||||
|
{
|
||||||
|
return( (int) len );
|
||||||
|
}
|
||||||
if( c - buf < 1 )
|
if( c - buf < 1 )
|
||||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue