Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72359 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31974 invoked from network); 7 Feb 2014 01:40:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Feb 2014 01:40:19 -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.215.53 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.53 mail-la0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:59885] helo=mail-la0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/00-31365-18934F25 for ; Thu, 06 Feb 2014 20:40:18 -0500 Received: by mail-la0-f53.google.com with SMTP id e16so2100626lan.40 for ; Thu, 06 Feb 2014 17:40:13 -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=RO7G7HDK569UREmvx5+wjjS+v9I9mLLoHeYBAASSPKs=; b=oUxpu734mUOdf/Jixdd6X6XNY7yHFoW59TK3/vNStO5VBRkGQH02o2NfsRNB9r2vd0 St3E5O+y3uMS5fLHgCY/p4whbppGRw8izim7sDWR/bpgO8ydmR9uwaJASXH+aeDmVMrl ttxw6PBt9ag3yrDudVJF7w4NjvC/n/EtA0u0Zz07FpGoy6FD6aH4z/dpzekvo5YIAceQ xxPZ6ZmwolDe4Gwcv8/8Iosu8dAeLlrIQgKUyn1q2LmJls5crx+3LM+PyRgQL+KLNpKY qCtq8wV7UcKjb2rtiUQjJL3V9ask5uP3+jIFmP1AWdna2xuw73K0AljuxVsPDAdOw0P1 W/cA== X-Received: by 10.112.172.69 with SMTP id ba5mr76113lbc.55.1391737211752; Thu, 06 Feb 2014 17:40:11 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Thu, 6 Feb 2014 17:39:31 -0800 (PST) In-Reply-To: References: <9E3AA302-1EC1-4497-996F-716555CAAB64@rouvenwessling.de> Date: Fri, 7 Feb 2014 10:39:31 +0900 X-Google-Sender-Auth: uqRHkAqAY7EYKBddpDR5nNOzw0Y Message-ID: To: =?UTF-8?Q?Rouven_We=C3=9Fling?= Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c2340420965204f1c71248 Subject: Re: [PHP-DEV] [VOTE] Timing attack safe string comparison function From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c2340420965204f1c71248 Content-Type: text/plain; charset=UTF-8 Hi all, 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. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.netH --001a11c2340420965204f1c71248--