1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

PK: add nice interface functions

Also fix a const-corectness issue.
This commit is contained in:
Manuel Pégourié-Gonnard
2013-08-14 15:56:19 +02:00
parent 765db07dfb
commit b3d9187cea
9 changed files with 111 additions and 28 deletions

View File

@ -124,3 +124,39 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
return( 0 );
}
/*
* Tell if a PK can do the operations of the given type
*/
int pk_can_do( pk_context *ctx, pk_type_t type )
{
/* null of NONE context can't do anything */
if( ctx == NULL || ctx->info == NULL )
return( 0 );
return( ctx->info->can_do( type ) );
}
/*
* Verify a signature
*/
int pk_verify( pk_context *ctx,
const unsigned char *hash, const md_info_t *md_info,
const unsigned char *sig, size_t sig_len )
{
if( ctx == NULL || ctx->info == NULL )
return( POLARSSL_ERR_PK_TYPE_MISMATCH ); // TODO
return( ctx->info->verify_func( ctx->data, hash, md_info, sig, sig_len ) );
}
/*
* Get key size in bits
*/
size_t pk_get_size( const pk_context *ctx )
{
if( ctx == NULL || ctx->info == NULL )
return( 0 );
return( ctx->info->get_size( ctx->data ) );
}