Specific return code for PK sig length mismatch
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index 61e78fe..2a4da03 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -64,11 +64,20 @@
const unsigned char *hash, size_t hash_len,
const unsigned char *sig, size_t sig_len )
{
- if( sig_len != ((rsa_context *) ctx)->len )
+ int ret;
+
+ if( sig_len < ((rsa_context *) ctx)->len )
return( POLARSSL_ERR_RSA_VERIFY_FAILED );
- return( rsa_pkcs1_verify( (rsa_context *) ctx, NULL, NULL,
- RSA_PUBLIC, md_alg, (unsigned int) hash_len, hash, sig ) );
+ if( ( ret = rsa_pkcs1_verify( (rsa_context *) ctx, NULL, NULL,
+ RSA_PUBLIC, md_alg,
+ (unsigned int) hash_len, hash, sig ) ) != 0 )
+ return( ret );
+
+ if( sig_len > ((rsa_context *) ctx)->len )
+ return( POLARSSL_ERR_PK_SIG_LEN_MISMATCH );
+
+ return( 0 );
}
static int rsa_sign_wrap( void *ctx, md_type_t md_alg,
@@ -292,10 +301,16 @@
const unsigned char *hash, size_t hash_len,
const unsigned char *sig, size_t sig_len )
{
+ int ret;
((void) md_alg);
- return( ecdsa_read_signature( (ecdsa_context *) ctx,
- hash, hash_len, sig, sig_len ) );
+ ret = ecdsa_read_signature( (ecdsa_context *) ctx,
+ hash, hash_len, sig, sig_len );
+
+ if( ret == POLARSSL_ERR_ECP_SIG_LEN_MISMATCH )
+ return( POLARSSL_ERR_PK_SIG_LEN_MISMATCH );
+
+ return( ret );
}
static int ecdsa_sign_wrap( void *ctx, md_type_t md_alg,