Skip to contentSkip to conversation

crypto: caam - update xts sector size for large input length

PATCH In review Andrei Botila 3 participants 3 messages Feb 28, 2020 – Mar 6, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: caam - update xts sector size for large input length

From: Andrei Botila <[email protected]>

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 <[email protected]> # v4.12+

---
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(-)
drivers/crypto/caam/caamalg_desc.c +14 -2
index aa9ccca67045..8ebbbd28b1f7 100644
@@ -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);
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

+ dm-devel

Quoted 9 lines · Andrei Botila (OSS)

From: Andrei Botila <[email protected]>

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.

Quoted 3 lines
Fixes c6415a6016bf ("crypto: caam - add support for acipher xts(aes)")
Cc <[email protected]> # v4.12+

Thanks,
Horia

Quoted 43 lines

---
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(-)
drivers/crypto/caam/caamalg_desc.c +14 -2
index aa9ccca67045..8ebbbd28b1f7 100644
@@ -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);
maintainer
#2 lore raw
In reply to Andrei Botila
Quoted 12 lines · Andrei Botila

From: Andrei Botila <[email protected]>

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 <[email protected]> # v4.12+
Quoted 7 lines

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

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt