Re: [VOTE] Timing attack safe string comparison function

From: Date: Mon, 10 Feb 2014 00:24:25 +0000
Subject: Re: [VOTE] Timing attack safe string comparison function
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-72422@lists.php.net to get a copy of this message
On Fri, Feb 7, 2014 at 10:39 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > On Fri, Feb 7, 2014 at 8:05 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: > >> I made SipHash version of str_compare() as a sample. >> There is timing safe php_compare(), which is stolen from BSD. >> >> >> https://github.com/yohgaki/php-src/compare/PHP-5.6-rfc-hash-compare >> >> [yohgaki@dev github-php-src]$ ./php-bin -r 'var_dump(str_compare("abc", >> "abc"));' >> bool(true) >> [yohgaki@dev github-php-src]$ ./php-bin -r >> 'var_dump(str_compare("asfasdf", "slkjojoeiwrj"));' >> bool(false) >> >> It's quick patch made less than 30 min. >> So it can be improved, I suppose. >> > > I thought it would be better to compare performance difference. > Added more functions to play with. > There are > > bool str_siphash_compare(str, str) - siphash. timing safe. (64bit) > bool str_xxhash32_compare(str, str) - xxhash. timing safe. (32bit) > bool str_md5_compare(str, str) - md5. Timing safe (128bit) > bool str_byte_compare(str, str) - Byte compare. Timing safe. No division. > bool str_byte_compare2(str, str) - Byte compare. Timing safe. With > division. (Modulo as this RFC) > bool str_compare(str, str) - plain strncmp(). Not timing safe. > > I didn't took bench mark and did minimum tests. > I appreciate if anyone take benchmark. > Added yet another function to compare suggested by Lester. bool str_word_compare(str, str) This function compares data word by word rather than byte by byte. It supposed to be faster for large data. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#72422) next »