Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72236 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11446 invoked from network); 5 Feb 2014 02:59:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2014 02:59:28 -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.174 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.174 mail-lb0-f174.google.com Received: from [209.85.217.174] ([209.85.217.174:53629] helo=mail-lb0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/50-08465-E09A1F25 for ; Tue, 04 Feb 2014 21:59:27 -0500 Received: by mail-lb0-f174.google.com with SMTP id l4so7086197lbv.19 for ; Tue, 04 Feb 2014 18:59:23 -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=Eu3sU0B6VdioVtwP7nKiNqgJwfYErPWm0QRlrvYEV18=; b=WHCZH99Vjcc4F/b5BhC2Z3xLOVutrvVwUCzprPdf8qYhDBKdfqVk2PhKf+RfiJAIb1 Ktcv15DspvY9TmN7KIersqKOsLtd90wGnxC5a7qWeY3j+CCpaRw9H6FLuZB1Zt4i6KY7 5PyziL9JzM6vhOtMT5/IdqXiH2ZO5Cjnrfl7vsXL5fzQHRR0ZlIXKx5lWTO0t9QllQDk NQY9/mHRsJ0ez+hDMfvuYzTZ63AKl5J04eqqmzkYixixOqQ7GdnWc4IJHKlll1RPHUZl y+uO6AByrFzQQIgDUVdkW6NmjZnUp9ct4iKHbskJQOJreQ9/3gspYVSfb0iPOpppluNh 1uzA== X-Received: by 10.152.170.135 with SMTP id am7mr20308679lac.23.1391569163143; Tue, 04 Feb 2014 18:59:23 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Tue, 4 Feb 2014 18:58:42 -0800 (PST) In-Reply-To: References: <9E3AA302-1EC1-4497-996F-716555CAAB64@rouvenwessling.de> <52F0139C.2060102@sugarcrm.com> Date: Wed, 5 Feb 2014 11:58:42 +0900 X-Google-Sender-Auth: yJ1Ty2XVqwH5242HYGrQRU0Ew3E Message-ID: To: Stas Malyshev Cc: Nikita Popov , =?UTF-8?Q?Rouven_We=C3=9Fling?= , PHP internals Content-Type: multipart/alternative; boundary=089e0122797aa64ec504f19ff10f Subject: Re: [PHP-DEV] [VOTE] Timing attack safe string comparison function From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e0122797aa64ec504f19ff10f Content-Type: text/plain; charset=UTF-8 Hi all, It could be optimized a little since 256 is too much for now. How about make MAX returns max of 3 values? len = MAX(known_len, user_len, 64); On Tue, Feb 4, 2014 at 1:06 PM, Yasuo Ohgaki wrote: > + /** > + * If known_string has a length of 0 we set the length to 1, > + * this will cause us to compare all bytes of userString with the null > byte which fails > + */ > + mod_len = MAX(known_len, 1); > len = MAX(known_len, 256); > len = MAX(known_len, user_len, 64); > + > + /* This is security sensitive code. Do not optimize this for speed. */ > + result = known_len - user_len; > > + for (j = 0; j < user_len; j++) { > > for (j = 0; j < len; j++) { > > > + result |= known_str[j % mod_len] ^ user_str[j]; > > result |= known_str[j % known_len] ^ user_str[j % user_len]; > + } > 64 is long enough for SHA-256 and if parameter is longer than that it will be used. Even if user used it to compare 'raw password', they are protected well from timing attack. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --089e0122797aa64ec504f19ff10f--