public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 06/10] siphash: Use more hygienic state initialiser
Date: Fri, 29 Sep 2023 17:19:44 +0200	[thread overview]
Message-ID: <20230929171944.16bca51f@elisabeth> (raw)
In-Reply-To: <ZRTU1dVFfp6ppMu/@zatzit>

On Thu, 28 Sep 2023 11:20:21 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Wed, Sep 27, 2023 at 07:04:50PM +0200, Stefano Brivio wrote:
> > On Sat, 23 Sep 2023 00:06:26 +1000
> > David Gibson <david@gibson.dropbear.id.au> wrote:
> >   
> > > The PREAMBLE macro sets up the SipHash initial internal state.  It also
> > > defines that state as a variable, which isn't macro hygeinic.  With
> > > previous changes simplifying this premable, it's now possible to replace it
> > > with a macro which simply expands to a C initialisedrfor that state.
> > > 
> > > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > > ---
> > >  siphash.c | 29 ++++++++++++-----------------
> > >  1 file changed, 12 insertions(+), 17 deletions(-)
> > > 
> > > diff --git a/siphash.c b/siphash.c
> > > index 6932da2..21c560d 100644
> > > --- a/siphash.c
> > > +++ b/siphash.c
> > > @@ -58,15 +58,12 @@
> > >  
> > >  #define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
> > >  
> > > -#define PREAMBLE							  \
> > > -	uint64_t v[4] = { 0x736f6d6570736575ULL, 0x646f72616e646f6dULL,	  \
> > > -			  0x6c7967656e657261ULL, 0x7465646279746573ULL }; \
> > > -	int __i;							  \
> > > -									  \
> > > -	do {								  \
> > > -		for (__i = sizeof(v) / sizeof(v[0]) - 1; __i >= 0; __i--) \
> > > -			v[__i] ^= k[__i % 2];				  \
> > > -	} while (0)
> > > +#define SIPHASH_INIT(k) {						\
> > > +		0x736f6d6570736575ULL ^ (k)[0],				\
> > > +		0x646f72616e646f6dULL ^ (k)[1],				\
> > > +		0x6c7967656e657261ULL ^ (k)[0],				\
> > > +		0x7465646279746573ULL ^ (k)[1]				\  
> > 
> > I don't think it actually matters (given the rationale for the choice
> > of these constants given in the paper), but earlier this was equivalent
> > to:
> > 
> >   0x736f6d6570736575ULL ^ (k)[1],
> >   0x646f72616e646f6dULL ^ (k)[0],
> >   0x6c7967656e657261ULL ^ (k)[1],
> >   0x7465646279746573ULL ^ (k)[0]  
> 
> No... I don't think it was.  We had:
> 	for (__i = sizeof(v) / sizeof(v[0]) - 1; __i >= 0; __i--)                                                
> 		v[__i] ^= k[__i % 2];
> 
> So in the first iteration __i == 3, so we get v[3] ^= k[1], and v[3]
> is 0x7465646279746573.

Oops, sorry, I missed the fact that I was actually starting from the
end of the array.

> > and it matched both reference implementations linked in the file
> > header.  
> 
> Again, I don't think that's correct.  In
> https://github.com/veorq/SipHash.git we have:
> 	v3 ^= k1;
> 	v2 ^= k0;
> 	v1 ^= k1;
> 	v0 ^= k0;
> 
> In both cases the order of operations is reversed, but since they're
> independent that doesn't matter.  But the point is that the reference
> implementation has v0 <-> k0 and v3 <-> k1, rather than the other way
> around.

Right.

-- 
Stefano


  reply	other threads:[~2023-09-29 15:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 14:06 [PATCH 00/10] siphash: cleanups and fixes David Gibson
2023-09-22 14:06 ` [PATCH 01/10] siphash: Make siphash functions consistently return 64-bit results David Gibson
2023-09-22 14:06 ` [PATCH 02/10] siphash: Make sip round calculations an inline function rather than macro David Gibson
2023-09-22 14:06 ` [PATCH 03/10] siphash: Add siphash_feed() helper David Gibson
2023-09-22 14:06 ` [PATCH 04/10] siphash: Clean up hash finalisation with posthash_final() function David Gibson
2023-09-22 14:06 ` [PATCH 05/10] siphash: Fix bug in state initialisation David Gibson
2023-09-22 14:06 ` [PATCH 06/10] siphash: Use more hygienic state initialiser David Gibson
2023-09-27 17:04   ` Stefano Brivio
2023-09-28  1:20     ` David Gibson
2023-09-29 15:19       ` Stefano Brivio [this message]
2023-09-22 14:06 ` [PATCH 07/10] siphash: Use specific structure for internal state David Gibson
2023-09-22 14:06 ` [PATCH 08/10] siphash: Make internal helpers public David Gibson
2023-09-22 14:06 ` [PATCH 09/10] siphash, checksum: Move TBAA explanation to checksum.c David Gibson
2023-09-22 14:06 ` [PATCH 10/10] siphash: Use incremental rather than all-at-once siphash functions David Gibson
2023-09-26  6:23   ` David Gibson
2023-09-26  7:02     ` David Gibson
2023-09-27 17:05       ` Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230929171944.16bca51f@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).