linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: caam - update xts sector size for large input length
@ 2020-02-28 10:46 Andrei Botila
  2020-03-02  9:36 ` Horia Geanta
  2020-03-06  1:52 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Andrei Botila @ 2020-02-28 10:46 UTC (permalink / raw)
  To: Horia Geanta, Aymen Sghaier, Herbert Xu, David S. Miller
  Cc: linux-crypto, linux-kernel, Andrei Botila, stable

From: Andrei Botila <andrei.botila@nxp.com>

Since in the software implementation of XTS-AES there is
no notion of sector every input length is processed the same way.
CAAM implementation has the notion of sector which causes different
results between the software implementation and the one in CAAM
for input lengths bigger than 512 bytes.
Increase sector size to maximum value on 16 bits.

Fixes: c6415a6016bf ("crypto: caam - add support for acipher xts(aes)")
Cc: <stable@vger.kernel.org> # v4.12+
Signed-off-by: Andrei Botila <andrei.botila@nxp.com>
---
This patch needs to be applied from v4.12+ because dm-crypt has added support
for 4K sector size at that version. The commit was
8f0009a225171 ("dm-crypt: optionally support larger encryption sector size").

 drivers/crypto/caam/caamalg_desc.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/caamalg_desc.c b/drivers/crypto/caam/caamalg_desc.c
index aa9ccca67045..8ebbbd28b1f7 100644
--- a/drivers/crypto/caam/caamalg_desc.c
+++ b/drivers/crypto/caam/caamalg_desc.c
@@ -1518,7 +1518,13 @@ EXPORT_SYMBOL(cnstr_shdsc_skcipher_decap);
  */
 void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata)
 {
-	__be64 sector_size = cpu_to_be64(512);
+	/*
+	 * Set sector size to a big value, practically disabling
+	 * sector size segmentation in xts implementation. We cannot
+	 * take full advantage of this HW feature with existing
+	 * crypto API / dm-crypt SW architecture.
+	 */
+	__be64 sector_size = cpu_to_be64(BIT(15));
 	u32 *key_jump_cmd;
 
 	init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
@@ -1571,7 +1577,13 @@ EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_encap);
  */
 void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata)
 {
-	__be64 sector_size = cpu_to_be64(512);
+	/*
+	 * Set sector size to a big value, practically disabling
+	 * sector size segmentation in xts implementation. We cannot
+	 * take full advantage of this HW feature with existing
+	 * crypto API / dm-crypt SW architecture.
+	 */
+	__be64 sector_size = cpu_to_be64(BIT(15));
 	u32 *key_jump_cmd;
 
 	init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: caam - update xts sector size for large input length
  2020-02-28 10:46 [PATCH] crypto: caam - update xts sector size for large input length Andrei Botila
@ 2020-03-02  9:36 ` Horia Geanta
  2020-03-06  1:52 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Horia Geanta @ 2020-03-02  9:36 UTC (permalink / raw)
  To: Andrei Botila (OSS), Aymen Sghaier, Herbert Xu, David S. Miller
  Cc: linux-crypto, linux-kernel, Andrei Botila, stable, dm-devel

+ dm-devel

On 2/28/2020 12:47 PM, Andrei Botila (OSS) wrote:
> From: Andrei Botila <andrei.botila@nxp.com>
> 
> Since in the software implementation of XTS-AES there is
> no notion of sector every input length is processed the same way.
> CAAM implementation has the notion of sector which causes different
> results between the software implementation and the one in CAAM
> for input lengths bigger than 512 bytes.
> Increase sector size to maximum value on 16 bits.
> 
> Fixes: c6415a6016bf ("crypto: caam - add support for acipher xts(aes)")
> Cc: <stable@vger.kernel.org> # v4.12+
> Signed-off-by: Andrei Botila <andrei.botila@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Thanks,
Horia

> ---
> This patch needs to be applied from v4.12+ because dm-crypt has added support
> for 4K sector size at that version. The commit was
> 8f0009a225171 ("dm-crypt: optionally support larger encryption sector size").
> 
>  drivers/crypto/caam/caamalg_desc.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/caam/caamalg_desc.c b/drivers/crypto/caam/caamalg_desc.c
> index aa9ccca67045..8ebbbd28b1f7 100644
> --- a/drivers/crypto/caam/caamalg_desc.c
> +++ b/drivers/crypto/caam/caamalg_desc.c
> @@ -1518,7 +1518,13 @@ EXPORT_SYMBOL(cnstr_shdsc_skcipher_decap);
>   */
>  void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata)
>  {
> -	__be64 sector_size = cpu_to_be64(512);
> +	/*
> +	 * Set sector size to a big value, practically disabling
> +	 * sector size segmentation in xts implementation. We cannot
> +	 * take full advantage of this HW feature with existing
> +	 * crypto API / dm-crypt SW architecture.
> +	 */
> +	__be64 sector_size = cpu_to_be64(BIT(15));
>  	u32 *key_jump_cmd;
>  
>  	init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
> @@ -1571,7 +1577,13 @@ EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_encap);
>   */
>  void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata)
>  {
> -	__be64 sector_size = cpu_to_be64(512);
> +	/*
> +	 * Set sector size to a big value, practically disabling
> +	 * sector size segmentation in xts implementation. We cannot
> +	 * take full advantage of this HW feature with existing
> +	 * crypto API / dm-crypt SW architecture.
> +	 */
> +	__be64 sector_size = cpu_to_be64(BIT(15));
>  	u32 *key_jump_cmd;
>  
>  	init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: caam - update xts sector size for large input length
  2020-02-28 10:46 [PATCH] crypto: caam - update xts sector size for large input length Andrei Botila
  2020-03-02  9:36 ` Horia Geanta
@ 2020-03-06  1:52 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2020-03-06  1:52 UTC (permalink / raw)
  To: Andrei Botila
  Cc: Horia Geanta, Aymen Sghaier, David S. Miller, linux-crypto,
	linux-kernel, Andrei Botila, stable

On Fri, Feb 28, 2020 at 12:46:48PM +0200, Andrei Botila wrote:
> From: Andrei Botila <andrei.botila@nxp.com>
> 
> Since in the software implementation of XTS-AES there is
> no notion of sector every input length is processed the same way.
> CAAM implementation has the notion of sector which causes different
> results between the software implementation and the one in CAAM
> for input lengths bigger than 512 bytes.
> Increase sector size to maximum value on 16 bits.
> 
> Fixes: c6415a6016bf ("crypto: caam - add support for acipher xts(aes)")
> Cc: <stable@vger.kernel.org> # v4.12+
> Signed-off-by: Andrei Botila <andrei.botila@nxp.com>
> ---
> This patch needs to be applied from v4.12+ because dm-crypt has added support
> for 4K sector size at that version. The commit was
> 8f0009a225171 ("dm-crypt: optionally support larger encryption sector size").
> 
>  drivers/crypto/caam/caamalg_desc.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-06  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28 10:46 [PATCH] crypto: caam - update xts sector size for large input length Andrei Botila
2020-03-02  9:36 ` Horia Geanta
2020-03-06  1:52 ` Herbert Xu

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).