Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72425 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97903 invoked from network); 10 Feb 2014 01:58:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2014 01:58:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.52 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.52 mail-la0-f52.google.com Received: from [209.85.215.52] ([209.85.215.52:37105] helo=mail-la0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/11-25595-45238F25 for ; Sun, 09 Feb 2014 20:58:45 -0500 Received: by mail-la0-f52.google.com with SMTP id c6so4365090lan.11 for ; Sun, 09 Feb 2014 17:58:40 -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=e2dmQ/DRZaHr6mzw/V/d6gA6SOMBtTwM6QsdKCu1pSY=; b=FphPimT5nfZ6kLDqP8e+EeA5j7DaSgnaiev+jFAKAJth6yDIX2PToL2fNcmQoNZ7le wy/mFkhpwcFdM8BEhOzhrhC4h1ZociINfIOSDuJFvJ4L7y4y5D7rZfltNA+j49qBXVuG LrJnxuj3zmckO92BdSAWR2rfsuOl1bViOg+6KhFQ/cSpYXnO5s6IIWNubE7YaaxjOQsh i/IuDwyC5VO41DKq/HKlg5H/5X+Vf3VA+1PtuC60vF0I6dcnK2PV1dLWRocLRuesDevR e7MGwEq9Ow8TIRlQa48r07Q9kGGbkXQfAc4ZBtvmzL7EfBI1mvZHQVTqeOftGZ1yeo5G 1/cQ== X-Received: by 10.152.242.131 with SMTP id wq3mr20081220lac.12.1391997520574; Sun, 09 Feb 2014 17:58:40 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Sun, 9 Feb 2014 17:58:00 -0800 (PST) In-Reply-To: References: <9E3AA302-1EC1-4497-996F-716555CAAB64@rouvenwessling.de> Date: Mon, 10 Feb 2014 10:58:00 +0900 X-Google-Sender-Auth: Q0SEH0lsj8ft0u9rhw5e6_bAGU8 Message-ID: To: =?UTF-8?Q?Rouven_We=C3=9Fling?= Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11336ba0bdfd4004f203adff Subject: Re: [PHP-DEV] [VOTE] Timing attack safe string comparison function From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11336ba0bdfd4004f203adff Content-Type: text/plain; charset=UTF-8 On Mon, Feb 10, 2014 at 10:15 AM, Yasuo Ohgaki wrote: > I took a benchmark. str_compare() is not timing safe. It's there for > reference. > > str_siphash_compare Elapsed: 1.389824 Iterations: 1000000 DataSize: 8 > str_xxhash32_compare Elapsed: 1.241737 Iterations: 1000000 DataSize: 8 > str_md5_compare Elapsed: 3.029127 Iterations: 1000000 DataSize: 8 > str_byte_compare Elapsed: 1.236183 Iterations: 1000000 DataSize: 8 > str_byte_compare2 Elapsed: 1.269901 Iterations: 1000000 DataSize: 8 > str_word_compare Elapsed: 1.273266 Iterations: 1000000 DataSize: 8 > str_compare Elapsed: 1.181425 Iterations: 1000000 DataSize: 8 > > str_byte_compare() is the winner for small data. > I'm a little surprised that str_xxhash32_compare() is the second. > str_word_compare() is marginally slower. > > str_siphash_compare Elapsed: 2.341025 Iterations: 1000000 DataSize: 128 > str_xxhash32_compare Elapsed: 1.560131 Iterations: 1000000 DataSize: 128 > str_md5_compare Elapsed: 6.055007 Iterations: 1000000 DataSize: 128 > str_byte_compare Elapsed: 1.799050 Iterations: 1000000 DataSize: 128 > str_byte_compare2 Elapsed: 2.163229 Iterations: 1000000 DataSize: 128 > str_word_compare Elapsed: 1.337508 Iterations: 1000000 DataSize: 128 > str_compare Elapsed: 1.194582 Iterations: 1000000 DataSize: 128 > > str_word_compare() is the winner for relatively large data. > > It seems str_word_compare() is the way to go. > https://gist.github.com/yohgaki/ede544f290c6cf9fa90d This is the benchmark script. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11336ba0bdfd4004f203adff--