mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-04-25 19:46:33 +00:00
mbedtls_asn1_get_int: explain the logic
No behavior change.
This commit is contained in:
parent
0370b1bd7d
commit
9fd9794d10
|
@ -149,14 +149,22 @@ int mbedtls_asn1_get_int( unsigned char **p,
|
||||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
if( len == 0 || ( **p & 0x80 ) != 0 )
|
/* len==0 is malformed (0 must be represented as 020100). */
|
||||||
|
if( len == 0 )
|
||||||
|
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||||
|
/* This is a cryptography library. Reject negative integers. */
|
||||||
|
if( ( **p & 0x80 ) != 0 )
|
||||||
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||||
|
|
||||||
|
/* Skip leading zeros. */
|
||||||
while( len > 0 && **p == 0 )
|
while( len > 0 && **p == 0 )
|
||||||
{
|
{
|
||||||
++( *p );
|
++( *p );
|
||||||
--len;
|
--len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Reject integers that don't fit in an int. This code assumes that
|
||||||
|
* the int type has no padding bit. */
|
||||||
if( len > sizeof( int ) )
|
if( len > sizeof( int ) )
|
||||||
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue