netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers3@gmail.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	David Laight <David.Laight@aculab.com>,
	Eric Dumazet <eric.dumazet@gmail.com>
Subject: Re: [PATCH net-next 1/4] siphash: add cryptographically secure PRF
Date: Fri, 6 Jan 2017 20:04:59 -0800	[thread overview]
Message-ID: <20170107040459.GA575@zzz> (raw)
In-Reply-To: <20170106201055.13765-2-Jason@zx2c4.com>

Hi Jason, just a few comments:

On Fri, Jan 06, 2017 at 09:10:52PM +0100, Jason A. Donenfeld wrote:
> +#define SIPHASH_ALIGNMENT __alignof__(u64)
> +typedef u64 siphash_key_t[2];

I was confused by all the functions passing siphash_key_t "by value" until I saw
that it's actually typedefed to u64[2].  Have you considered making it a struct
instead, something like this?

typedef struct {
	u64 v[2];
} siphash_key_t;

Then it would be strongly typed and thus harder to misuse, and all the functions
would take 'const siphash_key_t *' instead of 'const siphash_key_t' which would
make it clear that the key is passed by pointer not by value.

> +static inline u64 ___siphash_aligned(const __le64 *data, size_t len, const siphash_key_t key)
> +{
> +	if (__builtin_constant_p(len) && len == 4)
> +		return siphash_1u32(le32_to_cpu(data[0]), key);

Small bug here: data[0] is not valid if len is 4.  This can be fixed by casting
to a le32 pointer:

		return siphash_1u32(le32_to_cpup((const __le32 *)data), key);
	
> +static int __init siphash_test_init(void)
> +{
> +	u8 in[64] __aligned(SIPHASH_ALIGNMENT);
> +	u8 in_unaligned[65];

It seems that in_unaligned+1 is meant to be misaligned, but that's not
guaranteed because in_unaligned has no alignment restriction, so it could
theoretically be misaligned in a way that makes in_unaligned+1 aligned.  So it
should be 'in_unaligned[65] __aligned(SIPHASH_ALIGNMENT)'.

There are also a lot of checkpatch warnings produced by this patch.  It looks
like many of them can be ignored, but there may be some that should be
addressed.

- Eric

  parent reply	other threads:[~2017-01-07  4:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06 18:37 [PATCH net-next 1/4] siphash: add cryptographically secure PRF Jason A. Donenfeld
2017-01-06 18:37 ` [PATCH net-next 2/4] siphash: implement HalfSipHash1-3 for hash tables Jason A. Donenfeld
2017-01-06 18:37 ` [PATCH net-next 3/4] secure_seq: use SipHash in place of MD5 Jason A. Donenfeld
2017-01-06 18:37 ` [PATCH net-next 4/4] syncookies: use SipHash in place of SHA1 Jason A. Donenfeld
2017-01-06 19:57 ` [PATCH net-next 1/4] siphash: add cryptographically secure PRF David Miller
2017-01-06 20:03   ` Jason A. Donenfeld
2017-01-06 20:10   ` [PATCH net-next 0/4] Introduce The SipHash PRF Jason A. Donenfeld
2017-01-06 20:10     ` [PATCH net-next 1/4] siphash: add cryptographically secure PRF Jason A. Donenfeld
2017-01-06 20:32       ` Jean-Philippe Aumasson
2017-01-06 20:41         ` David Miller
2017-01-07  4:04       ` Eric Biggers [this message]
2017-01-07 13:11         ` Jason A. Donenfeld
2017-01-12 15:04         ` Herbert Xu
2017-01-12 18:30           ` Jason A. Donenfeld
2017-01-06 20:10     ` [PATCH net-next 2/4] siphash: implement HalfSipHash1-3 for hash tables Jason A. Donenfeld
2017-01-06 20:33       ` Jean-Philippe Aumasson
2017-01-06 20:10     ` [PATCH net-next 3/4] secure_seq: use SipHash in place of MD5 Jason A. Donenfeld
2017-01-06 20:10     ` [PATCH net-next 4/4] syncookies: use SipHash in place of SHA1 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=20170107040459.GA575@zzz \
    --to=ebiggers3@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=Jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jeanphilippe.aumasson@gmail.com \
    --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 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 NNTP newsgroup(s).