[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-dev] memcmp() & co. timing info disclosures?



On Sat, 7 May 2011 00:57:12 -0400
Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:

> On Sat, May 7, 2011 at 12:47 AM, Robert Ransom <rransom.8774@xxxxxxxxx> wrote:
> > On Fri, 6 May 2011 23:14:58 -0400
> > Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
> >
> >> Also, as I said on the bug, doing a memcmp in constant time is harder
> >> than doing eq/neq. ÂI *think* that all of the cases where we care
> >> about memcmp returning a tristate -1/0/1 result, we don't need
> >> data-independence... but in case we *do* need one, we'll have to do
> >> some malarkey like
> >>
> >> int memcmp(const void *m1, const void *m2, size_t n)
> >> {
> >> /*XXX I don't know if this is even right; I haven't tested it at all */
> >> Â const uint8_t *b1 = m1, *b2 = m2;
> >> Â int retval = 0;
> >>
> >> Â while (n--) {
> >> Â Â const uint8_t v1 = b1[n], v2 = b2[n];
> >> Â Â int diff = (int)v1 - (int)v2;
> >> Â Â retval = (v1 == v2) * retval + diff;
> >> Â }
> >>
> >> Â return retval;
> >> }
> >>
> >> which frankly makes me sad. ÂI bet there's a better way to go.
> >
> > See attached. ÂThis one is also untested (and I didn't even put the
> > â#include <stdint.h>â in the file), but it *should* work.
> >
> > My technique for calculating equal_p came from my uint32-based
> > crypto_verify function in my previous message, which was in turn based
> > partly on DJB's crypto_verify functions and partly on a disassembly of
> > what GCC compiled DJB's functions to on a Fedora 12 AMD64 box. ÂBut I
> > couldn't tell that the technique was correct, so this time I added
> > comments to it.
> 
> Clever!  It does look it *should* work.  Somewhere along the line we
> should test the heck out of it and more sure it does.

It worked for me once I fixed it so it would compile.  See
<http://repo.or.cz/w/tor-utils/rransom.git/shortlog/refs/heads/tor-safe-memcmp>.


Robert Ransom

Attachment: signature.asc
Description: PGP signature

_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev