public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Nathan Huckleberry <nhuck@google.com>
Cc: fstests@vger.kernel.org, linux-fscrypt@vger.kernel.org,
	Sami Tolvanen <samitolvanen@google.com>
Subject: Re: [RFC PATCH v4 1/2] fscrypt-crypt-util: add HCTR2 implementation
Date: Tue, 19 Jul 2022 12:49:14 -0700	[thread overview]
Message-ID: <YtcKugK3KWHri1t3@sol.localdomain> (raw)
In-Reply-To: <20220601071811.1353635-2-nhuck@google.com>

On Wed, Jun 01, 2022 at 12:18:10AM -0700, Nathan Huckleberry wrote:
> diff --git a/src/fscrypt-crypt-util.c b/src/fscrypt-crypt-util.c
[...]
> +void gf2_128_mul_polyval(ble128 *r, const ble128 *b)
> +{

This function should be static.

> +/*----------------------------------------------------------------------------*
> + *                                 POLYVAL                                     *
> + *----------------------------------------------------------------------------*/

This could use a link to a specification, similar to the other more "unusual"
algorithms in this file.  Try:

		git grep -A1 'Reference:' src/fscrypt-crypt-util.c

Likewise for HCTR2.  The commit message has a link to the HCTR2 paper, but it
should be in the code itself too.  

> +static void polyval_update(const u8 key[POLYVAL_KEY_SIZE],
> +			   const u8 *msg, size_t msglen,
> +			   u8 accumulator[POLYVAL_BLOCK_SIZE])
> +{
> +	ble128 h;
> +	ble128 aligned_accumulator;
> +	size_t chunk_size;
> +	// x^{-128} = x^127 + x^124 + x^121 + x^114 + 1
> +	static const ble128 inv128 = {
> +		cpu_to_le64(1),
> +		cpu_to_le64(0x9204ULL << 48)
> +	};
> +
> +	memcpy(&h, key, POLYVAL_BLOCK_SIZE);
> +	memcpy(&aligned_accumulator, accumulator, POLYVAL_BLOCK_SIZE);
> +	gf2_128_mul_polyval(&h, &inv128);
> +
> +	while (msglen > 0) {
> +		chunk_size = MIN(POLYVAL_BLOCK_SIZE, msglen);
> +		xor((u8 *)&aligned_accumulator, (u8 *)&aligned_accumulator, msg,
> +		    chunk_size);
> +		gf2_128_mul_polyval(&aligned_accumulator, &h);
> +		msg += chunk_size;
> +		msglen -= chunk_size;
> +	}

The partial block support is unnecessary, so POLYVAL_BLOCK_SIZE could be used
instead of chunk_size, and an assertion ASSERT(msglen % POLYVAL_BLOCK_SIZE ==
0) could be added.  See poly1305() in the same file which works similarly.

Otherwise this looks good, thanks!

- Eric

  reply	other threads:[~2022-07-19 19:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01  7:18 [RFC PATCH v4 0/2] generic: test HCTR2 filename encryption Nathan Huckleberry
2022-06-01  7:18 ` [RFC PATCH v4 1/2] fscrypt-crypt-util: add HCTR2 implementation Nathan Huckleberry
2022-07-19 19:49   ` Eric Biggers [this message]
2022-06-01  7:18 ` [RFC PATCH v4 2/2] generic: add tests for fscrypt policies with HCTR2 Nathan Huckleberry
2022-07-19 19:51   ` Eric Biggers

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=YtcKugK3KWHri1t3@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=nhuck@google.com \
    --cc=samitolvanen@google.com \
    /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