Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72422 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91680 invoked from network); 10 Feb 2014 00:25:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2014 00:25:11 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:57953] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/00-25595-56C18F25 for ; Sun, 09 Feb 2014 19:25:10 -0500 Received: by mail-lb0-f177.google.com with SMTP id 10so2770639lbg.36 for ; Sun, 09 Feb 2014 16:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=uzOFc84HVOs12VTQ5uq/2XfEpAupT6qHivWWiU8sv64=; b=itxsCKJyLN6/wIgXJdawTASj53f5skatCMSBgl+Sg0N+8PXy6qxFW9ZIiJxsM/2i/5 8iqptXEvQ/p/VX9rYoVQ1HzKpjeEbtivbIMb7moFZ5q3tVmvYo71B/Rd3izAAGjQo2NE 3mO8FANxuMvR7qxg20iqOIEQ9Is0GypYKx6b4Q6Y2AWa+nWhPDB5RUe/aMICdryUC7WH EIH5A/HOgmI6TM12fSNwQP3DninAO+ebkMliZrX+phUYdqM26x1/PSrygqlM498Y0n18 /riMjZUHmaNDFxPCwae8PCJ2oURuiwj5y8WsdDHidx9vxGh+nbakem12T8a4awvfH/yO ETyg== X-Received: by 10.112.140.202 with SMTP id ri10mr18660047lbb.9.1391991905834; Sun, 09 Feb 2014 16:25:05 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Sun, 9 Feb 2014 16:24:25 -0800 (PST) In-Reply-To: References: <9E3AA302-1EC1-4497-996F-716555CAAB64@rouvenwessling.de> Date: Mon, 10 Feb 2014 09:24:25 +0900 X-Google-Sender-Auth: 5e88VEeQoehzcU-Zsd2SXTT-Sl4 Message-ID: To: =?UTF-8?Q?Rouven_We=C3=9Fling?= Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c25dea13dc8104f2025f3a Subject: Re: [PHP-DEV] [VOTE] Timing attack safe string comparison function From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c25dea13dc8104f2025f3a Content-Type: text/plain; charset=UTF-8 On Fri, Feb 7, 2014 at 10:39 AM, Yasuo Ohgaki wrote: > On Fri, Feb 7, 2014 at 8:05 AM, Yasuo Ohgaki 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 --001a11c25dea13dc8104f2025f3a--