mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 00:45:41 +01:00
Optimise unneccesary cf table accesses away
Also fix missed bare access of base_64_dec_map Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
86cb928e54
commit
6a66737433
@ -238,6 +238,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
|||||||
size_t i, n;
|
size_t i, n;
|
||||||
uint32_t j, x;
|
uint32_t j, x;
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
|
unsigned char dec_map_lookup;
|
||||||
|
|
||||||
/* First pass: check for validity and get output length */
|
/* First pass: check for validity and get output length */
|
||||||
for( i = n = j = 0; i < slen; i++ )
|
for( i = n = j = 0; i < slen; i++ )
|
||||||
@ -268,11 +269,12 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
|||||||
if( src[i] == '=' && ++j > 2 )
|
if( src[i] == '=' && ++j > 2 )
|
||||||
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
if( src[i] > 127 ||
|
dec_map_lookup = mbedtls_base64_table_lookup( base64_dec_map, sizeof( base64_dec_map ), src[i] );
|
||||||
mbedtls_base64_table_lookup( base64_dec_map, sizeof( base64_dec_map ), src[i] ) == 127 )
|
|
||||||
|
if( src[i] > 127 || dec_map_lookup == 127 )
|
||||||
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
if( base64_dec_map[src[i]] < 64 && j != 0 )
|
if( dec_map_lookup < 64 && j != 0 )
|
||||||
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
@ -302,9 +304,10 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
|||||||
if( *src == '\r' || *src == '\n' || *src == ' ' )
|
if( *src == '\r' || *src == '\n' || *src == ' ' )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
j -= ( mbedtls_base64_table_lookup(base64_dec_map, sizeof( base64_dec_map ), *src ) == 64 );
|
dec_map_lookup = mbedtls_base64_table_lookup(base64_dec_map, sizeof( base64_dec_map ), *src );
|
||||||
x = ( x << 6 ) |
|
|
||||||
( mbedtls_base64_table_lookup( base64_dec_map, sizeof( base64_dec_map ), *src ) & 0x3F );
|
j -= ( dec_map_lookup == 64 );
|
||||||
|
x = ( x << 6 ) | ( dec_map_lookup & 0x3F );
|
||||||
|
|
||||||
if( ++n == 4 )
|
if( ++n == 4 )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user