From: Eric Biggers <ebiggers@kernel.org>
To: Nathan Huckleberry <nhuck@google.com>
Cc: linux-crypto@vger.kernel.org, linux-fscrypt@vger.kernel.org,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-arm-kernel@lists.infradead.org,
Paul Crowley <paulcrowley@google.com>,
Sami Tolvanen <samitolvanen@google.com>,
Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [PATCH v6 6/9] crypto: arm64/aes-xctr: Improve readability of XCTR and CTR modes
Date: Thu, 5 May 2022 22:41:00 -0700 [thread overview]
Message-ID: <YnS07JPEoeFlsRAQ@sol.localdomain> (raw)
In-Reply-To: <20220504001823.2483834-7-nhuck@google.com>
On Wed, May 04, 2022 at 12:18:20AM +0000, Nathan Huckleberry wrote:
> Added some clarifying comments, changed the register allocations to make
> the code clearer, and added register aliases.
>
> Signed-off-by: Nathan Huckleberry <nhuck@google.com>
I was a bit surprised to see this after the xctr support patch rather than
before. Doing the cleanup first would make adding and reviewing the xctr
support easier. But it's not a big deal; if you already tested it this way you
can just leave it as-is if you want.
A few minor comments below.
> + /*
> + * Set up the counter values in v0-v4.
> + *
> + * If we are encrypting less than MAX_STRIDE blocks, the tail block
> + * handling code expects the last keystream block to be in v4. For
> + * example: if encrypting two blocks with MAX_STRIDE=5, then v3 and v4
> + * should have the next two counter blocks.
> + */
The first two mentions of v4 should actually be v{MAX_STRIDE-1}, as it is
actually v4 for MAX_STRIDE==5 and v3 for MAX_STRIDE==4.
> @@ -355,16 +383,16 @@ AES_FUNC_END(aes_cbc_cts_decrypt)
> mov v3.16b, vctr.16b
> ST5( mov v4.16b, vctr.16b )
> .if \xctr
> - sub x6, x11, #MAX_STRIDE - 1
> - sub x7, x11, #MAX_STRIDE - 2
> - sub x8, x11, #MAX_STRIDE - 3
> - sub x9, x11, #MAX_STRIDE - 4
> -ST5( sub x10, x11, #MAX_STRIDE - 5 )
> - eor x6, x6, x12
> - eor x7, x7, x12
> - eor x8, x8, x12
> - eor x9, x9, x12
> - eor x10, x10, x12
> + sub x6, CTR, #MAX_STRIDE - 1
> + sub x7, CTR, #MAX_STRIDE - 2
> + sub x8, CTR, #MAX_STRIDE - 3
> + sub x9, CTR, #MAX_STRIDE - 4
> +ST5( sub x10, CTR, #MAX_STRIDE - 5 )
> + eor x6, x6, IV_PART
> + eor x7, x7, IV_PART
> + eor x8, x8, IV_PART
> + eor x9, x9, IV_PART
> + eor x10, x10, IV_PART
The eor into x10 should be enclosed by ST5(), since it's dead code otherwise.
> + /*
> + * If there are at least MAX_STRIDE blocks left, XOR the plaintext with
> + * keystream and store. Otherwise jump to tail handling.
> + */
Technically this could be XOR-ing with either the plaintext or the ciphertext.
Maybe write "data" instead.
> .Lctrtail1x\xctr:
> - sub x7, x6, #16
> - csel x6, x6, x7, eq
> - add x1, x1, x6
> - add x0, x0, x6
> - ld1 {v5.16b}, [x1]
> - ld1 {v6.16b}, [x0]
> + /*
> + * Handle <= 16 bytes of plaintext
> + */
> + sub x8, x7, #16
> + csel x7, x7, x8, eq
> + add IN, IN, x7
> + add OUT, OUT, x7
> + ld1 {v5.16b}, [IN]
> + ld1 {v6.16b}, [OUT]
> ST5( mov v3.16b, v4.16b )
> encrypt_block v3, w3, x2, x8, w7
w3 and x2 should be ROUNDS_W and KEY, respectively.
This code also has the very unusual property that it reads and writes before the
buffers given. Specifically, for bytes < 16, it access the 16 bytes beginning
at &in[bytes - 16] and &dst[bytes - 16]. Mentioning this explicitly would be
very helpful, particularly in the function comments for aes_ctr_encrypt() and
aes_xctr_encrypt(), and maybe in the C code, so that anyone calling these
functions has this in mind.
Anyway, with the above addressed feel free to add:
Reviewed-by: Eric Biggers <ebiggers@google.com>
- Eric
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Nathan Huckleberry <nhuck@google.com>
Cc: linux-crypto@vger.kernel.org, linux-fscrypt@vger.kernel.org,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-arm-kernel@lists.infradead.org,
Paul Crowley <paulcrowley@google.com>,
Sami Tolvanen <samitolvanen@google.com>,
Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [PATCH v6 6/9] crypto: arm64/aes-xctr: Improve readability of XCTR and CTR modes
Date: Thu, 5 May 2022 22:41:00 -0700 [thread overview]
Message-ID: <YnS07JPEoeFlsRAQ@sol.localdomain> (raw)
In-Reply-To: <20220504001823.2483834-7-nhuck@google.com>
On Wed, May 04, 2022 at 12:18:20AM +0000, Nathan Huckleberry wrote:
> Added some clarifying comments, changed the register allocations to make
> the code clearer, and added register aliases.
>
> Signed-off-by: Nathan Huckleberry <nhuck@google.com>
I was a bit surprised to see this after the xctr support patch rather than
before. Doing the cleanup first would make adding and reviewing the xctr
support easier. But it's not a big deal; if you already tested it this way you
can just leave it as-is if you want.
A few minor comments below.
> + /*
> + * Set up the counter values in v0-v4.
> + *
> + * If we are encrypting less than MAX_STRIDE blocks, the tail block
> + * handling code expects the last keystream block to be in v4. For
> + * example: if encrypting two blocks with MAX_STRIDE=5, then v3 and v4
> + * should have the next two counter blocks.
> + */
The first two mentions of v4 should actually be v{MAX_STRIDE-1}, as it is
actually v4 for MAX_STRIDE==5 and v3 for MAX_STRIDE==4.
> @@ -355,16 +383,16 @@ AES_FUNC_END(aes_cbc_cts_decrypt)
> mov v3.16b, vctr.16b
> ST5( mov v4.16b, vctr.16b )
> .if \xctr
> - sub x6, x11, #MAX_STRIDE - 1
> - sub x7, x11, #MAX_STRIDE - 2
> - sub x8, x11, #MAX_STRIDE - 3
> - sub x9, x11, #MAX_STRIDE - 4
> -ST5( sub x10, x11, #MAX_STRIDE - 5 )
> - eor x6, x6, x12
> - eor x7, x7, x12
> - eor x8, x8, x12
> - eor x9, x9, x12
> - eor x10, x10, x12
> + sub x6, CTR, #MAX_STRIDE - 1
> + sub x7, CTR, #MAX_STRIDE - 2
> + sub x8, CTR, #MAX_STRIDE - 3
> + sub x9, CTR, #MAX_STRIDE - 4
> +ST5( sub x10, CTR, #MAX_STRIDE - 5 )
> + eor x6, x6, IV_PART
> + eor x7, x7, IV_PART
> + eor x8, x8, IV_PART
> + eor x9, x9, IV_PART
> + eor x10, x10, IV_PART
The eor into x10 should be enclosed by ST5(), since it's dead code otherwise.
> + /*
> + * If there are at least MAX_STRIDE blocks left, XOR the plaintext with
> + * keystream and store. Otherwise jump to tail handling.
> + */
Technically this could be XOR-ing with either the plaintext or the ciphertext.
Maybe write "data" instead.
> .Lctrtail1x\xctr:
> - sub x7, x6, #16
> - csel x6, x6, x7, eq
> - add x1, x1, x6
> - add x0, x0, x6
> - ld1 {v5.16b}, [x1]
> - ld1 {v6.16b}, [x0]
> + /*
> + * Handle <= 16 bytes of plaintext
> + */
> + sub x8, x7, #16
> + csel x7, x7, x8, eq
> + add IN, IN, x7
> + add OUT, OUT, x7
> + ld1 {v5.16b}, [IN]
> + ld1 {v6.16b}, [OUT]
> ST5( mov v3.16b, v4.16b )
> encrypt_block v3, w3, x2, x8, w7
w3 and x2 should be ROUNDS_W and KEY, respectively.
This code also has the very unusual property that it reads and writes before the
buffers given. Specifically, for bytes < 16, it access the 16 bytes beginning
at &in[bytes - 16] and &dst[bytes - 16]. Mentioning this explicitly would be
very helpful, particularly in the function comments for aes_ctr_encrypt() and
aes_xctr_encrypt(), and maybe in the C code, so that anyone calling these
functions has this in mind.
Anyway, with the above addressed feel free to add:
Reviewed-by: Eric Biggers <ebiggers@google.com>
- Eric
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-05-06 5:41 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 0:18 [PATCH v6 0/9] crypto: HCTR2 support Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-04 0:18 ` [PATCH v6 1/9] crypto: xctr - Add XCTR support Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-04 0:18 ` [PATCH v6 2/9] crypto: polyval - Add POLYVAL support Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-04 0:18 ` [PATCH v6 3/9] crypto: hctr2 - Add HCTR2 support Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-04 0:18 ` [PATCH v6 4/9] crypto: x86/aesni-xctr: Add accelerated implementation of XCTR Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-05 4:45 ` Eric Biggers
2022-05-05 4:45 ` Eric Biggers
2022-05-04 0:18 ` [PATCH v6 5/9] crypto: arm64/aes-xctr: " Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-06 5:49 ` Eric Biggers
2022-05-06 5:49 ` Eric Biggers
2022-05-04 0:18 ` [PATCH v6 6/9] crypto: arm64/aes-xctr: Improve readability of XCTR and CTR modes Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-05 6:49 ` Ard Biesheuvel
2022-05-05 6:49 ` Ard Biesheuvel
2022-05-06 5:41 ` Eric Biggers [this message]
2022-05-06 5:41 ` Eric Biggers
2022-05-06 21:22 ` Nathan Huckleberry
2022-05-06 21:22 ` Nathan Huckleberry
2022-05-04 0:18 ` [PATCH v6 7/9] crypto: x86/polyval: Add PCLMULQDQ accelerated implementation of POLYVAL Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-05 5:08 ` Eric Biggers
2022-05-05 5:08 ` Eric Biggers
2022-05-04 0:18 ` [PATCH v6 8/9] crypto: arm64/polyval: Add PMULL " Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
2022-05-05 5:56 ` Eric Biggers
2022-05-05 5:56 ` Eric Biggers
2022-05-04 0:18 ` [PATCH v6 9/9] fscrypt: Add HCTR2 support for filename encryption Nathan Huckleberry
2022-05-04 0:18 ` Nathan Huckleberry
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=YnS07JPEoeFlsRAQ@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=ardb@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=nhuck@google.com \
--cc=paulcrowley@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 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.