diff --git a/include/mbedtls/pk.h b/include/mbedtls/pk.h index f7fa4d31a..36fdea5be 100644 --- a/include/mbedtls/pk.h +++ b/include/mbedtls/pk.h @@ -475,7 +475,7 @@ int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, * * \return Maximum size in bytes of a signature made with this key. */ -size_t mbedtls_pk_signature_size( const mbedtls_pk_context *ctx ); +size_t mbedtls_pk_get_signature_size( const mbedtls_pk_context *ctx ); /** * \brief Decrypt message (including padding if relevant). diff --git a/include/mbedtls/pk_info.h b/include/mbedtls/pk_info.h index d1d95ef4f..a8b735fd1 100644 --- a/include/mbedtls/pk_info.h +++ b/include/mbedtls/pk_info.h @@ -120,9 +120,11 @@ struct mbedtls_pk_info_t * usage restrictions into account. */ int (*can_do)( const void * ctx, mbedtls_pk_type_t type ); - /** Signature size + /** Upper bound of the signature length * - * mbedtls_pk_signature_size() returns this value. + * mbedtls_pk_get_signature_size() returns this value. + * + * In case of an error, or an unsupported key type, 0 should be returned. * * Opaque implementations may omit this method if they do not support * signature. */ diff --git a/library/pk.c b/library/pk.c index 52bcb8669..4213001e8 100644 --- a/library/pk.c +++ b/library/pk.c @@ -357,7 +357,7 @@ size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx ) /* * Maximum signature size */ -size_t mbedtls_pk_signature_size( const mbedtls_pk_context *ctx ) +size_t mbedtls_pk_get_signature_size( const mbedtls_pk_context *ctx ) { if( ctx == NULL || ctx->pk_info == NULL ) return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index bd92f0c99..e660e1192 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -100,7 +100,7 @@ static void pk_rsa_match( mbedtls_rsa_context *raw, TEST_ASSERT( mbedtls_pk_can_do( tested_ctx, MBEDTLS_PK_RSA ) ); TEST_ASSERT( mbedtls_pk_get_bitlen( tested_ctx ) == RSA_KEY_SIZE ); TEST_ASSERT( mbedtls_pk_get_len( tested_ctx ) == RSA_KEY_LEN ); - TEST_ASSERT( mbedtls_pk_signature_size( tested_ctx ) == RSA_KEY_LEN ); + TEST_ASSERT( mbedtls_pk_get_signature_size( tested_ctx ) == RSA_KEY_LEN ); /* Test signature */ TEST_ASSERT( mbedtls_pk_sign( tested_ctx, MBEDTLS_MD_NONE, hash, sizeof hash, @@ -533,7 +533,7 @@ void pk_sign_verify( int type, int sign_ret, int verify_ret ) TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, sizeof hash, sig, &sig_len, rnd_std_rand, NULL ) == sign_ret ); if( sign_ret == 0 ) - TEST_ASSERT( sig_len <= mbedtls_pk_signature_size( &pk ) ); + TEST_ASSERT( sig_len <= mbedtls_pk_get_signature_size( &pk ) ); TEST_ASSERT( mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256, hash, sizeof hash, sig, sig_len ) == verify_ret ); @@ -774,7 +774,7 @@ void pk_opaque_mock( ) TEST_ASSERT( mbedtls_pk_get_bitlen( &ctx ) == OPAQUE_MOCK_BITLEN ); TEST_ASSERT( mbedtls_pk_can_do( &ctx, OPAQUE_MOCK_CAN_DO ) == 1 ); TEST_ASSERT( mbedtls_pk_can_do( &ctx, OPAQUE_MOCK_CAN_DO ^ 1 ) == 0 ); - TEST_ASSERT( mbedtls_pk_signature_size( &ctx ) == OPAQUE_MOCK_SIGNATURE_SIZE ); + TEST_ASSERT( mbedtls_pk_get_signature_size( &ctx ) == OPAQUE_MOCK_SIGNATURE_SIZE ); TEST_ASSERT( mbedtls_pk_verify( &ctx, OPAQUE_MOCK_MD_ALG, opaque_mock_hash, sizeof( opaque_mock_hash ), @@ -881,7 +881,7 @@ void pk_opaque_minimal( ) TEST_ASSERT( mbedtls_pk_get_bitlen( &ctx ) == OPAQUE_MOCK_BITLEN ); TEST_ASSERT( mbedtls_pk_can_do( &ctx, OPAQUE_MOCK_CAN_DO ) == 1 ); TEST_ASSERT( mbedtls_pk_can_do( &ctx, OPAQUE_MOCK_CAN_DO ^ 1 ) == 0 ); - TEST_ASSERT( mbedtls_pk_signature_size( &ctx ) == 0 ); + TEST_ASSERT( mbedtls_pk_get_signature_size( &ctx ) == 0 ); TEST_ASSERT( mbedtls_pk_verify( &ctx, OPAQUE_MOCK_MD_ALG, NULL, 0, NULL, 0 ) ==