Add implemetation of ECP keypair export function

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2022-03-18 13:52:26 +01:00
parent 8d4bc5eeb9
commit 711d0f5e29
2 changed files with 44 additions and 0 deletions

View file

@ -1278,6 +1278,26 @@ int mbedtls_ecp_check_pub_priv(
const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
/**
* \brief This function exports generic key-pair parameters.
*
* \param kp The key pair to export from.
* \param grp Slot for exported ECP group.
* It must point to an initialized ECP group.
* \param d Slot for the exported secret value.
* It must point to an initialized mpi.
* \param Q Slot for the exported public value.
* It must point to an initialized ECP point.
*
* \return \c 0 on success,
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
* \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if key id doesn't
* correspond to a known group.
* \return Another negative error code on other kinds of failure.
*/
int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp,
mbedtls_mpi *d, mbedtls_ecp_point *Q);
#if defined(MBEDTLS_SELF_TEST)
/**

View file

@ -3356,6 +3356,30 @@ cleanup:
return( ret );
}
/*
* Export generic key-pair parameters.
*/
int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp,
mbedtls_mpi *d, mbedtls_ecp_point *Q)
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
ECP_VALIDATE_RET( key != NULL );
ECP_VALIDATE_RET( grp != NULL );
ECP_VALIDATE_RET( d != NULL );
ECP_VALIDATE_RET( Q != NULL );
if( ( ret = mbedtls_ecp_group_copy( grp, &key->grp ) ) != 0 )
return ret;
if( ( ret = mbedtls_mpi_copy( d, &key->d ) ) != 0 )
return ret;
if( ( ret = mbedtls_ecp_copy( Q, &key->Q ) ) != 0 )
return ret;
return 0;
}
#if defined(MBEDTLS_SELF_TEST)
/*