Add special return code for ecdsa length mismatch
diff --git a/library/ecdsa.c b/library/ecdsa.c
index c9ab62f..6e45f2f 100644
--- a/library/ecdsa.c
+++ b/library/ecdsa.c
@@ -422,11 +422,14 @@
( ret = asn1_get_mpi( &p, end, &ctx->s ) ) != 0 )
return( POLARSSL_ERR_ECP_BAD_INPUT_DATA + ret );
- if( p != end )
- return( POLARSSL_ERR_ECP_BAD_INPUT_DATA +
- POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
+ if( ( ret = ecdsa_verify( &ctx->grp, hash, hlen,
+ &ctx->Q, &ctx->r, &ctx->s ) ) != 0 )
+ return( ret );
- return( ecdsa_verify( &ctx->grp, hash, hlen, &ctx->Q, &ctx->r, &ctx->s ) );
+ if( p != end )
+ return( POLARSSL_ERR_ECP_SIG_LEN_MISMATCH );
+
+ return( 0 );
}
/*
diff --git a/library/error.c b/library/error.c
index 3cc3aa3..2e6bba6 100644
--- a/library/error.c
+++ b/library/error.c
@@ -245,6 +245,8 @@
snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
snprintf( buf, buflen, "ECP - Invalid private or public key" );
+ if( use_ret == -(POLARSSL_ERR_ECP_SIG_LEN_MISMATCH) )
+ snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
#endif /* POLARSSL_ECP_C */
#if defined(POLARSSL_MD_C)