mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-24 11:28:04 +00:00
Improve mbedtls_asn1_write_int to support values >255
mbedtls_asn1_write_int had an undocumented restriction to values that fit in a single octet. Fix this. Negative integers are still not supported.
This commit is contained in:
parent
3a032c36c1
commit
1dbab67ce8
|
@ -236,17 +236,20 @@ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val )
|
||||||
int ret;
|
int ret;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
if( *p - start < 1 )
|
do
|
||||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
|
||||||
|
|
||||||
len += 1;
|
|
||||||
*--(*p) = val;
|
|
||||||
|
|
||||||
if( val > 0 && **p & 0x80 )
|
|
||||||
{
|
{
|
||||||
if( *p - start < 1 )
|
if( *p - start < 1 )
|
||||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||||
|
len += 1;
|
||||||
|
*--(*p) = val & 0xff;
|
||||||
|
val >>= 8;
|
||||||
|
}
|
||||||
|
while( val > 0 );
|
||||||
|
|
||||||
|
if( **p & 0x80 )
|
||||||
|
{
|
||||||
|
if( *p - start < 1 )
|
||||||
|
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||||
*--(*p) = 0x00;
|
*--(*p) = 0x00;
|
||||||
len += 1;
|
len += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue