mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
public: add Q_strcmp_constant_time
This commit is contained in:
@@ -261,6 +261,21 @@ qboolean Q_stricmpext( const char *pattern, const char *text )
|
|||||||
return Q_strnicmpext( pattern, text, ~((size_t)0) );
|
return Q_strnicmpext( pattern, text, ~((size_t)0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Q_strcmp_constant_time( const char *s1, const char *s2 )
|
||||||
|
{
|
||||||
|
if( !s1 || !s2 )
|
||||||
|
return ( s1 ? 1 : 0 ) - ( s2 ? 1 : 0 );
|
||||||
|
|
||||||
|
size_t l1 = strlen( s1 );
|
||||||
|
size_t l2 = strlen( s2 );
|
||||||
|
size_t diff = l1 ^ l2;
|
||||||
|
|
||||||
|
for( size_t i = 0; i < l1 && i < l2; i++ )
|
||||||
|
diff |= s1[i] ^ s2[i];
|
||||||
|
|
||||||
|
return diff != 0;
|
||||||
|
}
|
||||||
|
|
||||||
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen )
|
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen )
|
||||||
{
|
{
|
||||||
const byte *i;
|
const byte *i;
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ static inline int Q_buildnum_compat( void )
|
|||||||
//
|
//
|
||||||
// crtlib.c
|
// crtlib.c
|
||||||
//
|
//
|
||||||
|
int Q_strcmp_constant_time( const char *s1, const char *s2 );
|
||||||
void Q_strnlwr( const char *in, char *out, size_t size_out );
|
void Q_strnlwr( const char *in, char *out, size_t size_out );
|
||||||
#define Q_strlen( str ) (( str ) ? strlen(( str )) : 0 )
|
#define Q_strlen( str ) (( str ) ? strlen(( str )) : 0 )
|
||||||
int Q_atoi_hex( int sign, const char *str );
|
int Q_atoi_hex( int sign, const char *str );
|
||||||
|
|||||||
Reference in New Issue
Block a user