From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id A460B5A026F for ; Fri, 29 Sep 2023 17:19:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696000791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GqI4i9u6JQFbOrgi4/luozum1J/MwqLW4J7hLLvBteo=; b=cwy8c8IKL7b2aEOQQ/qKaef2cs+ljSGFZlM6dYN275Lnd5PkLWH+r4O7XrBurDLH/K+j7N H9YffUah6qcFXh59vtULBC/ypQjpgdq9avQsrVT2yzmpKZw721LaDKv8ET7ttl/u/4V9L0 HlJU/ocQSTfhY7ndTrehSW4ICWRZxwA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-JDDvKZDCO1m3OReSDCPxBA-1; Fri, 29 Sep 2023 11:19:48 -0400 X-MC-Unique: JDDvKZDCO1m3OReSDCPxBA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07EC41C0CCB4; Fri, 29 Sep 2023 15:19:48 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25E16492C37; Fri, 29 Sep 2023 15:19:46 +0000 (UTC) Date: Fri, 29 Sep 2023 17:19:44 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 06/10] siphash: Use more hygienic state initialiser Message-ID: <20230929171944.16bca51f@elisabeth> In-Reply-To: References: <20230922140630.3184256-1-david@gibson.dropbear.id.au> <20230922140630.3184256-7-david@gibson.dropbear.id.au> <20230927190450.6f827040@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: W464RS2KM3VG6MFV5AIXHPJ773KU5MNX X-Message-ID-Hash: W464RS2KM3VG6MFV5AIXHPJ773KU5MNX X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 28 Sep 2023 11:20:21 +1000 David Gibson 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 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 > > > --- > > > 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