pk_info: Make signature_size mandatory
All pk implementations must supply a signature_size method if they
support signing.
Move the function together with the other metadata functions.
diff --git a/library/pk.c b/library/pk.c
index d8801b5..52bcb86 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -363,9 +363,9 @@
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
if( ctx->pk_info->signature_size_func == NULL )
- return( ( ctx->pk_info->get_bitlen( ctx->pk_ctx ) + 7 ) / 8 );
- else
- return( ctx->pk_info->signature_size_func( ctx->pk_ctx ) );
+ return( 0 );
+
+ return( ctx->pk_info->signature_size_func( ctx->pk_ctx ) );
}
/*
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index 393fdeb..17df304 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -119,6 +119,12 @@
md_alg, (unsigned int) hash_len, hash, sig ) );
}
+static size_t rsa_signature_size( const void *ctx_arg )
+{
+ const mbedtls_rsa_context *ctx = ctx_arg;
+ return( ctx->len );
+}
+
static int rsa_decrypt_wrap( void *ctx,
const unsigned char *input, size_t ilen,
unsigned char *output, size_t *olen, size_t osize,
@@ -187,6 +193,7 @@
"RSA",
rsa_get_bitlen,
rsa_can_do,
+ rsa_signature_size,
rsa_verify_wrap,
rsa_sign_wrap,
rsa_decrypt_wrap,
@@ -195,7 +202,6 @@
rsa_alloc_wrap,
rsa_free_wrap,
rsa_debug,
- NULL,
};
#endif /* MBEDTLS_RSA_C */
@@ -305,11 +311,13 @@
eckey_get_bitlen,
eckey_can_do,
#if defined(MBEDTLS_ECDSA_C)
+ ecdsa_signature_size,
eckey_verify_wrap,
eckey_sign_wrap,
#else
NULL,
NULL,
+ NULL,
#endif
NULL,
NULL,
@@ -317,11 +325,6 @@
eckey_alloc_wrap,
eckey_free_wrap,
eckey_debug,
-#if defined(MBEDTLS_ECDSA_C)
- ecdsa_signature_size,
-#else
- NULL,
-#endif
};
/*
@@ -343,11 +346,11 @@
NULL,
NULL,
NULL,
+ NULL,
eckey_check_pair,
eckey_alloc_wrap, /* Same underlying key structure */
eckey_free_wrap, /* Same underlying key structure */
eckey_debug, /* Same underlying key structure */
- NULL,
};
#endif /* MBEDTLS_ECP_C */
@@ -404,6 +407,7 @@
"ECDSA",
eckey_get_bitlen, /* Compatible key structures */
ecdsa_can_do,
+ ecdsa_signature_size,
ecdsa_verify_wrap,
ecdsa_sign_wrap,
NULL,
@@ -412,7 +416,6 @@
ecdsa_alloc_wrap,
ecdsa_free_wrap,
eckey_debug, /* Compatible key structures */
- ecdsa_signature_size,
};
#endif /* MBEDTLS_ECDSA_C */
@@ -452,6 +455,13 @@
md_alg, (unsigned int) hash_len, hash, sig ) );
}
+static size_t rsa_alt_signature_size( const void *ctx )
+{
+ const mbedtls_rsa_alt_context *rsa_alt = (const mbedtls_rsa_alt_context *) ctx;
+
+ return( rsa_alt->key_len_func( rsa_alt->key ) );
+}
+
static int rsa_alt_decrypt_wrap( void *ctx,
const unsigned char *input, size_t ilen,
unsigned char *output, size_t *olen, size_t osize,
@@ -520,6 +530,7 @@
"RSA-alt",
rsa_alt_get_bitlen,
rsa_alt_can_do,
+ rsa_alt_signature_size,
NULL,
rsa_alt_sign_wrap,
rsa_alt_decrypt_wrap,
@@ -532,7 +543,6 @@
rsa_alt_alloc_wrap,
rsa_alt_free_wrap,
NULL,
- NULL,
};
#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */