From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1N7ZIr-0002Dw-Th for mharc-grub-devel@gnu.org; Mon, 09 Nov 2009 13:49:25 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N7ZIp-00029g-Ar for grub-devel@gnu.org; Mon, 09 Nov 2009 13:49:23 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N7ZIk-000216-HZ for grub-devel@gnu.org; Mon, 09 Nov 2009 13:49:22 -0500 Received: from [199.232.76.173] (port=37079 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7ZIk-00020s-7b for grub-devel@gnu.org; Mon, 09 Nov 2009 13:49:18 -0500 Received: from mail-pw0-f47.google.com ([209.85.160.47]:37142) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N7ZIj-00053X-Kp for grub-devel@gnu.org; Mon, 09 Nov 2009 13:49:17 -0500 Received: by pwi9 with SMTP id 9so413534pwi.26 for ; Mon, 09 Nov 2009 10:49:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=tZb/P6oKFp0FtPxnYJbVEV9UCnNaPbdoS6ljvPjCjNw=; b=bp+8b/OkE2ZUMiQ+u7zoGMllFroeDW9k7dOn948RzLLU3AQ9pbTMvctCRAtACeHzgb p7iwAnd51IhPH0BftPrluowyjff1yPRGADd5/Hw9UC1bWqDrJ4OjMaQtqq+3x62K+3ah Frzj+dxVEl6/AK24OS8pQx5c8kvfxQDMscAdg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=SBMeY1bjreaxN3po2O6KtI+FtTwc61sz8QnWStvkJuLOJqSis29EVUud7QcE0194CL HfRpGvv51M3ZhkW/6kD1/9Awm7R4Dn9HOoRx3VltM7TeHpxUXVNnRzbXuVdUbrTmNncu 7rssn/2fjLpkvXPxrWaTKOke/MSoSYVsjj+TI= MIME-Version: 1.0 Received: by 10.140.161.14 with SMTP id j14mr465978rve.246.1257792556898; Mon, 09 Nov 2009 10:49:16 -0800 (PST) In-Reply-To: <4AF86387.7090307@gmail.com> References: <20091109010422.GA23417@thorin> <4AF81E2C.2090700@gmail.com> <4AF82868.6090803@gmail.com> <4AF85568.7080105@duboucher.eu> <20091109181010.GA7372@thorin> <4AF85C54.3080302@gmail.com> <20091109182518.GA14767@thorin> <4AF86387.7090307@gmail.com> Date: Tue, 10 Nov 2009 02:49:16 +0800 Message-ID: From: Bean To: The development of GNU GRUB Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: Imminent bugfix release (1.97.1) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Nov 2009 18:49:23 -0000 On Tue, Nov 10, 2009 at 2:46 AM, Vladimir 'phcoder' Serbinenko wrote: > Bean wrote: >> On Tue, Nov 10, 2009 at 2:25 AM, Robert Millan wrote: >> >>> On Mon, Nov 09, 2009 at 07:15:48PM +0100, Vladimir 'phcoder' Serbinenko= wrote: >>> >>>> Robert Millan wrote: >>>> >>>>> Actually, modern CPUs are very complex and the number of operations (= or >>>>> time taken by them) isn't easy to predict. >>>>> >>>>> >>>>> >>>> It's generally a good practice to do exactly same operations >>>> independently of result just store the result in a separate variable >>>> it's how RSA is correctly implemented >>>> >>>> =A0 for (n =3D grub_strlen (s1); n >=3D 0; n--) >>>> =A0 { >>>> =A0 =A0 if (*s1 !=3D *s2) >>>> =A0 =A0 =A0 ret |=3D 1; >>>> =A0 =A0 else >>>> =A0 =A0 =A0 ret |=3D 0; >>>> >>> Uhm I didn't check, but I'd suspect -Os would optimize this out. >>> >>> Anyhow, if we move the fixed time wait to the outer loop, it should no >>> longer be a problem. >>> >>> We could also check the approach taken by e.g. su from coreutils. >>> >> >> Hi, >> >> How about this one: >> >> int >> grub_auth_strcmp (const char *s1, const char *s2) >> { >> =A0 int result =3D 0; >> >> =A0 for (; *s1 !=3D 0; s1++, s2++) >> =A0 =A0 result +=3D (*s1 !=3D *s2); >> >> =A0 return (result !=3D 0); >> } >> >> >> > Welcome to club: try it with > "abc", "abcdef" > They will match :(. Exactly the same problem as with my code but I like > the approach. Perhaps: > > int > grub_auth_strcmp (const char *s1, const char *s2) > { > =A0int result =3D 0; > > =A0for (; *s1 !=3D 0; s1++, s2++) > =A0 =A0result +=3D (*s1 !=3D *s2); > > =A0return !(result =3D=3D 0 && *s2 =3D=3D 0); > } Hi, This one work: int auth_strcmp (const char *s1, const char *s2) { int result =3D 0; while (1) { result +=3D (*s1 !=3D *s2); if (*s1 =3D=3D 0) break; s1++; s2++; } return (result !=3D 0); } The trick is to compare the ending '\0' as well, so that partial match is not satisfied. --=20 Bean My repository: https://launchpad.net/burg Document: https://help.ubuntu.com/community/Burg