On Tue, Nov 10, 2009 at 4:28 PM, Bean <bean12...@gmail.com> wrote: > On Tue, Nov 10, 2009 at 1:39 PM, Bean <bean12...@gmail.com> wrote: >> On Tue, Nov 10, 2009 at 5:34 AM, Vladimir 'phcoder' Serbinenko >> <phco...@gmail.com> wrote: >>> But now it has a technical problem: it may read post array definitions. >>> If any of post-array memory is MMIO or absent reading from it may have >>> peculiar consequences >>>> Also, because s1 and s2 have two differents roles, I think it would be >>>> best to give them names that better suits them. ;) >> >> Hi, >> >> Right, I think it'd be better to use fixed size array, perhaps we can >> define a type grub_password_t for it. >> >> BTW, with fixed size array, the following algorithm should run exactly >> the same amount of instruction each time: >> >> typedef char grub_password_t[1024]; >> >> int >> grub_auth_strcmp (const grub_password_t s1, const grub_password_t s2) >> { >> int r1 = 0; >> int r2 = 0; >> int i, *p; >> >> p = &r1; >> for (i = 0; i < sizeof (grub_password_t); i++, s1++, s2++) >> { >> *p |= (*s1 ^ *s2); >> if (*s1 == '\0') >> p = &r2; >> } >> >> return (r1 != 0); >> } > > Hi, > > Oh sorry, this one still have some issue, this should work: > > typedef char grub_password_t[1024]; > > int > grub_auth_strcmp (const grub_password_t s1, const grub_password_t s2) > { > int r1 = 0; > int r2 = 0; > int i, *p1, *p2; > > p1 = p2 = &r1; > for (i = 0; i < sizeof (grub_password_t); i++, s1++, s2++) > { > *p1 |= (*s1 ^ *s2); > if (*s1 == '\0') > p1 = &r2; > else > p2 = &r2; > } > > return (r1 != 0); > }
Hi, Just in case p2 is optimized out by gcc: typedef char grub_password_t[1024]; int grub_auth_strcmp (const grub_password_t s1, const grub_password_t s2) { char r1 = 0; char r2 = 0; char r3 = 0; char *p1, *p2; int i; p1 = &r1; p2 = &r3; for (i = 0; i < sizeof (grub_password_t); i++, s1++, s2++) { *p1 |= (*s1 ^ *s2); if (*s1 == '\0') p1 = &r2; else p2 = &r2; (*p2)++; } return (r1 != 0); } -- Bean My repository: https://launchpad.net/burg Document: https://help.ubuntu.com/community/Burg _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel