mbedtls_asn1_get_int: allow leading zeros properly
Allow any number of leading zeros, not just based on sizeof(int).
diff --git a/library/asn1parse.c b/library/asn1parse.c
index 171c340..20e8177 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -149,11 +149,18 @@
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
return( ret );
- if( len == 0 || len > sizeof( int ) || ( **p & 0x80 ) != 0 )
+ if( len == 0 || ( **p & 0x80 ) != 0 )
+ return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
+
+ while( len > 0 && **p == 0 )
+ {
+ ++( *p );
+ --len;
+ }
+ if( len > sizeof( int ) )
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
*val = 0;
-
while( len-- > 0 )
{
*val = ( *val << 8 ) | **p;