All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Hannes Frederic Sowa <hannes@stressinduktion.org>,
	David Laight <David.Laight@aculab.com>
Cc: Netdev <netdev@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>,
	Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	"Daniel J . Bernstein" <djb@cr.yp.to>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Eric Biggers <ebiggers3@gmail.com>
Subject: Re: [PATCH v2 1/4] siphash: add cryptographically secure hashtable function
Date: Thu, 15 Dec 2016 19:50:36 +0100	[thread overview]
Message-ID: <CAHmME9pTLFu3-4n6m_OMj5jVWGE-+yC-4CnkynD--H4Nt8_cpA@mail.gmail.com> (raw)
In-Reply-To: <924ef794-eae0-2a6b-508b-069718339edc@stressinduktion.org>

Hi David & Hannes,

This conversation is veering off course. I think this doesn't really
matter at all. Gcc converts u64 into essentially a pair of u32 on
32-bit platforms, so the alignment requirements for 32-bit is at a
maximum 32 bits. On 64-bit platforms the alignment requirements are
related at a maximum to the biggest register size, so 64-bit
alignment. For this reason, no matter the behavior of __aligned(8),
we're okay. Likewise, even without __aligned(8), if gcc aligns structs
by their biggest member, then we get 4 byte alignment on 32-bit and 8
byte alignment on 64-bit, which is fine. There's no 32-bit platform
that will trap on a 64-bit unaligned access because there's no such
thing as a 64-bit access there. In short, we're fine.

(The reason in6_addr aligns itself to 4 bytes on 64-bit platforms is
that it's defined as being u32 blah[4]. If we added a u64 blah[2],
we'd get 8 byte alignment, but that's not in the header. Feel free to
start a new thread about this issue if you feel this ought to be added
for whatever reason.)

One optimization that's been suggested on this list is that instead of
u8 key[16] and requiring the alignment attribute, I should just use
u64 key[2]. This seems reasonable to me, and it will also save the
endian conversion call. These keys generally aren't transmitted over a
network, so I don't think a byte-wise encoding is particularly
important.

The other suggestion I've seen is that I make the functions take a
const void * instead of a const u8 * for the data, in order to save
ugly casts. I'll do this too.

Meanwhile Linus has condemned our 4dwords/2qwords naming, and I'll
need to think of something different. The best I can think of right
now is siphash_4_u32/siphash_2_u64, but I don't find it especially
pretty. Open to suggestions.

Regards,
Jason

WARNING: multiple messages have this Message-ID (diff)
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Hannes Frederic Sowa <hannes@stressinduktion.org>,
	David Laight <David.Laight@aculab.com>
Cc: Netdev <netdev@vger.kernel.org>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>,
	Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	"Daniel J . Bernstein" <djb@cr.yp.to>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Eric Biggers <ebiggers3@gmail.com>
Subject: [kernel-hardening] Re: [PATCH v2 1/4] siphash: add cryptographically secure hashtable function
Date: Thu, 15 Dec 2016 19:50:36 +0100	[thread overview]
Message-ID: <CAHmME9pTLFu3-4n6m_OMj5jVWGE-+yC-4CnkynD--H4Nt8_cpA@mail.gmail.com> (raw)
In-Reply-To: <924ef794-eae0-2a6b-508b-069718339edc@stressinduktion.org>

Hi David & Hannes,

This conversation is veering off course. I think this doesn't really
matter at all. Gcc converts u64 into essentially a pair of u32 on
32-bit platforms, so the alignment requirements for 32-bit is at a
maximum 32 bits. On 64-bit platforms the alignment requirements are
related at a maximum to the biggest register size, so 64-bit
alignment. For this reason, no matter the behavior of __aligned(8),
we're okay. Likewise, even without __aligned(8), if gcc aligns structs
by their biggest member, then we get 4 byte alignment on 32-bit and 8
byte alignment on 64-bit, which is fine. There's no 32-bit platform
that will trap on a 64-bit unaligned access because there's no such
thing as a 64-bit access there. In short, we're fine.

(The reason in6_addr aligns itself to 4 bytes on 64-bit platforms is
that it's defined as being u32 blah[4]. If we added a u64 blah[2],
we'd get 8 byte alignment, but that's not in the header. Feel free to
start a new thread about this issue if you feel this ought to be added
for whatever reason.)

One optimization that's been suggested on this list is that instead of
u8 key[16] and requiring the alignment attribute, I should just use
u64 key[2]. This seems reasonable to me, and it will also save the
endian conversion call. These keys generally aren't transmitted over a
network, so I don't think a byte-wise encoding is particularly
important.

The other suggestion I've seen is that I make the functions take a
const void * instead of a const u8 * for the data, in order to save
ugly casts. I'll do this too.

Meanwhile Linus has condemned our 4dwords/2qwords naming, and I'll
need to think of something different. The best I can think of right
now is siphash_4_u32/siphash_2_u64, but I don't find it especially
pretty. Open to suggestions.

Regards,
Jason

  reply	other threads:[~2016-12-15 18:50 UTC|newest]

Thread overview: 171+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-14  3:59 [PATCH v2 1/4] siphash: add cryptographically secure hashtable function Jason A. Donenfeld
2016-12-14  3:59 ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14  3:59 ` [PATCH v2 2/4] siphash: add convenience functions for jhash converts Jason A. Donenfeld
2016-12-14  3:59   ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14  3:59 ` [PATCH v2 3/4] secure_seq: use siphash24 instead of md5_transform Jason A. Donenfeld
2016-12-14  3:59   ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 12:53   ` Jason A. Donenfeld
2016-12-14 12:53     ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 13:16     ` Hannes Frederic Sowa
2016-12-14 13:16       ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-14 13:44       ` Jason A. Donenfeld
2016-12-14 13:44         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 14:47         ` David Laight
2016-12-14 14:47           ` [kernel-hardening] " David Laight
2016-12-14 14:47           ` David Laight
2016-12-14 17:49           ` Jason A. Donenfeld
2016-12-14 17:49             ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 17:49             ` Jason A. Donenfeld
2016-12-14 17:56     ` David Miller
2016-12-14 17:56       ` [kernel-hardening] " David Miller
2016-12-14 18:06       ` Jason A. Donenfeld
2016-12-14 18:06         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 19:22         ` Hannes Frederic Sowa
2016-12-14 19:22           ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-14 19:38           ` Jason A. Donenfeld
2016-12-14 19:38             ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 20:27             ` Hannes Frederic Sowa
2016-12-14 20:27               ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-14 20:12     ` Tom Herbert
2016-12-14 20:12       ` [kernel-hardening] " Tom Herbert
2016-12-14 21:01       ` Jason A. Donenfeld
2016-12-14 21:01         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14  3:59 ` [PATCH v2 4/4] random: use siphash24 instead of md5 for get_random_int/long Jason A. Donenfeld
2016-12-14  3:59   ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 11:21 ` [PATCH v2 1/4] siphash: add cryptographically secure hashtable function Hannes Frederic Sowa
2016-12-14 11:21   ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-14 13:10   ` Jason A. Donenfeld
2016-12-14 13:10     ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 15:09     ` Hannes Frederic Sowa
2016-12-14 15:09       ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-14 19:47       ` Jason A. Donenfeld
2016-12-14 19:47         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  7:57     ` Herbert Xu
2016-12-15  7:57       ` [kernel-hardening] " Herbert Xu
2016-12-15  8:15       ` Daniel Micay
2016-12-14 12:46 ` Jason A. Donenfeld
2016-12-14 12:46   ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 22:03   ` Hannes Frederic Sowa
2016-12-14 22:03     ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-14 23:29     ` Jason A. Donenfeld
2016-12-14 23:29       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  8:31       ` Hannes Frederic Sowa
2016-12-15  8:31         ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 11:04     ` David Laight
2016-12-15 11:04       ` [kernel-hardening] " David Laight
2016-12-15 11:04       ` David Laight
2016-12-15 12:23       ` Hannes Frederic Sowa
2016-12-15 12:23         ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 12:23         ` Hannes Frederic Sowa
2016-12-15 12:28         ` David Laight
2016-12-15 12:28           ` [kernel-hardening] " David Laight
2016-12-15 12:28           ` David Laight
2016-12-15 12:50           ` Hannes Frederic Sowa
2016-12-15 12:50             ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 12:50             ` Hannes Frederic Sowa
2016-12-15 13:56             ` David Laight
2016-12-15 13:56               ` [kernel-hardening] " David Laight
2016-12-15 13:56               ` David Laight
2016-12-15 14:56               ` Hannes Frederic Sowa
2016-12-15 14:56                 ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 14:56                 ` Hannes Frederic Sowa
2016-12-15 15:41                 ` David Laight
2016-12-15 15:41                   ` [kernel-hardening] " David Laight
2016-12-15 15:41                   ` David Laight
2016-12-15 15:53                   ` Hannes Frederic Sowa
2016-12-15 15:53                     ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 15:53                     ` Hannes Frederic Sowa
2016-12-15 18:50                     ` Jason A. Donenfeld [this message]
2016-12-15 18:50                       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15 18:50                       ` Jason A. Donenfeld
2016-12-15 20:31                       ` Hannes Frederic Sowa
2016-12-15 20:31                         ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 20:31                         ` Hannes Frederic Sowa
2016-12-15 20:43                         ` Jason A. Donenfeld
2016-12-15 20:43                           ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15 20:43                           ` Jason A. Donenfeld
2016-12-15 21:04                           ` Peter Zijlstra
2016-12-15 21:04                             ` [kernel-hardening] " Peter Zijlstra
2016-12-15 21:04                             ` Peter Zijlstra
2016-12-15 21:09                             ` Hannes Frederic Sowa
2016-12-15 21:09                               ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 21:09                               ` Hannes Frederic Sowa
2016-12-15 21:17                           ` Hannes Frederic Sowa
2016-12-15 21:17                             ` [kernel-hardening] " Hannes Frederic Sowa
2016-12-15 21:17                             ` Hannes Frederic Sowa
2016-12-15 21:09                       ` Peter Zijlstra
2016-12-15 21:09                         ` [kernel-hardening] " Peter Zijlstra
2016-12-15 21:09                         ` Peter Zijlstra
2016-12-15 21:11                         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15 21:14                           ` Linus Torvalds
2016-12-15 21:14                             ` Linus Torvalds
2016-12-14 18:46 ` [PATCH v3 1/3] " Jason A. Donenfeld
2016-12-14 18:46   ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 18:46   ` [PATCH v3 2/3] secure_seq: use siphash24 instead of md5_transform Jason A. Donenfeld
2016-12-14 18:46     ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 21:44     ` kbuild test robot
2016-12-14 21:44       ` [kernel-hardening] " kbuild test robot
2016-12-14 18:46   ` [PATCH v3 3/3] random: use siphash24 instead of md5 for get_random_int/long Jason A. Donenfeld
2016-12-14 18:46     ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 21:56     ` kbuild test robot
2016-12-14 21:56       ` [kernel-hardening] " kbuild test robot
2016-12-14 21:57     ` kbuild test robot
2016-12-14 21:57       ` [kernel-hardening] " kbuild test robot
2016-12-15 10:14     ` David Laight
2016-12-15 10:14       ` [kernel-hardening] " David Laight
2016-12-15 10:14       ` David Laight
2016-12-15 18:51       ` Jason A. Donenfeld
2016-12-15 18:51         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15 18:51         ` Jason A. Donenfeld
2016-12-14 19:18   ` [PATCH v3 1/3] siphash: add cryptographically secure hashtable function Tom Herbert
2016-12-14 19:18     ` [kernel-hardening] " Tom Herbert
2016-12-14 19:35     ` Jason A. Donenfeld
2016-12-14 19:35       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 20:55       ` Jason A. Donenfeld
2016-12-14 20:55         ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 21:35         ` Tom Herbert
2016-12-14 21:35           ` [kernel-hardening] " Tom Herbert
2016-12-14 22:56           ` Jason A. Donenfeld
2016-12-14 22:56             ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 23:14             ` Tom Herbert
2016-12-14 23:14               ` [kernel-hardening] " Tom Herbert
2016-12-14 23:17               ` Jason A. Donenfeld
2016-12-14 23:17                 ` [kernel-hardening] " Jason A. Donenfeld
2016-12-18  0:06                 ` Christian Kujau
2016-12-18  0:06                   ` [kernel-hardening] " Christian Kujau
2016-12-14 23:30             ` Linus Torvalds
2016-12-14 23:30               ` [kernel-hardening] " Linus Torvalds
2016-12-14 23:30               ` Linus Torvalds
2016-12-14 23:34               ` Jason A. Donenfeld
2016-12-14 23:34                 ` [kernel-hardening] " Jason A. Donenfeld
2016-12-14 23:34                 ` Jason A. Donenfeld
2016-12-15  0:10                 ` Linus Torvalds
2016-12-15  0:10                   ` [kernel-hardening] " Linus Torvalds
2016-12-15  0:10                   ` Linus Torvalds
2016-12-15 10:22                   ` David Laight
2016-12-15 10:22                     ` [kernel-hardening] " David Laight
2016-12-15 10:22                     ` David Laight
2016-12-14 21:15   ` kbuild test robot
2016-12-14 21:15     ` [kernel-hardening] " kbuild test robot
2016-12-14 21:21     ` Jason A. Donenfeld
2016-12-14 21:21       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  1:46   ` [PATCH v4 1/4] " Jason A. Donenfeld
2016-12-15  1:46     ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  1:46     ` [PATCH v4 2/4] siphash: add N[qd]word helpers Jason A. Donenfeld
2016-12-15  1:46       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  1:46     ` [PATCH v4 3/4] secure_seq: use siphash instead of md5_transform Jason A. Donenfeld
2016-12-15  1:46       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  1:46     ` [PATCH v4 4/4] random: use siphash instead of MD5 for get_random_int/long Jason A. Donenfeld
2016-12-15  1:46       ` [kernel-hardening] " Jason A. Donenfeld
2016-12-15  4:23     ` [PATCH v4 1/4] siphash: add cryptographically secure hashtable function kbuild test robot
2016-12-15  4:23       ` [kernel-hardening] " kbuild test robot
2016-12-15 21:25 [PATCH v2 " Jason A. Donenfeld
2016-12-15 21:25 ` Jason A. Donenfeld
2016-12-15 21:45 ` Hannes Frederic Sowa
2016-12-15 21:45   ` Hannes Frederic Sowa
2016-12-15 23:43   ` Jason A. Donenfeld
2016-12-15 23:43     ` Jason A. Donenfeld
2016-12-16  0:03     ` Hannes Frederic Sowa
2016-12-16  0:03       ` Hannes Frederic Sowa
2016-12-15 23:47   ` Jason A. Donenfeld
2016-12-15 23:47     ` Jason A. Donenfeld

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=CAHmME9pTLFu3-4n6m_OMj5jVWGE-+yC-4CnkynD--H4Nt8_cpA@mail.gmail.com \
    --to=jason@zx2c4.com \
    --cc=David.Laight@aculab.com \
    --cc=djb@cr.yp.to \
    --cc=ebiggers3@gmail.com \
    --cc=hannes@stressinduktion.org \
    --cc=jeanphilippe.aumasson@gmail.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.