diff mbox series

[05/15] crypto: skcipher - Add twopass attribute

Message ID d9b505744d7974a5c27eaa86e815f42cec82e6bd.1707815065.git.herbert@gondor.apana.org.au
State New
Headers show
Series crypto: Add twopass lskcipher for adiantum | expand

Commit Message

Herbert Xu Dec. 5, 2023, 6:09 a.m. UTC
Algorithms such as adiantum requires two passes over the input
and therefore cannot support incremental processing.  Add a new
attribute to identify them.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 crypto/lskcipher.c        |  2 ++
 crypto/skcipher.c         |  2 ++
 include/crypto/skcipher.h | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)
diff mbox series

Patch

diff --git a/crypto/lskcipher.c b/crypto/lskcipher.c
index 260666f34500..bc54cfc2734d 100644
--- a/crypto/lskcipher.c
+++ b/crypto/lskcipher.c
@@ -301,6 +301,8 @@  static void __maybe_unused crypto_lskcipher_show(
 	seq_printf(m, "chunksize    : %u\n", skcipher->co.chunksize);
 	seq_printf(m, "statesize    : %u\n", skcipher->co.statesize);
 	seq_printf(m, "tailsize     : %u\n", skcipher->co.tailsize);
+	seq_printf(m, "incremental  : %s\n", skcipher->co.twopass ?
+					     "no" : "yes");
 }
 
 static int __maybe_unused crypto_lskcipher_report(
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 600ec5735ce0..40e836be354e 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -837,6 +837,8 @@  static void crypto_skcipher_show(struct seq_file *m, struct crypto_alg *alg)
 	seq_printf(m, "walksize     : %u\n", skcipher->walksize);
 	seq_printf(m, "statesize    : %u\n", skcipher->statesize);
 	seq_printf(m, "tailsize     : %u\n", skcipher->tailsize);
+	seq_printf(m, "incremental  : %s\n", skcipher->twopass ?
+					     "no" : "yes");
 }
 
 static int __maybe_unused crypto_skcipher_report(
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
index 6223d81fed76..3833a2ab1951 100644
--- a/include/crypto/skcipher.h
+++ b/include/crypto/skcipher.h
@@ -105,6 +105,7 @@  struct crypto_istat_cipher {
  * @statesize: Size of the internal state for the algorithm.
  * @tailsize: Minimum number of bytes to withhold until the end of operation.
  *	      Used by algorithms such as CTS to support chaining.
+ * @twopass: The algorithm needs two passes over the input, e.g., adiantum.
  * @stat: Statistics for cipher algorithm
  * @base: Definition of a generic crypto algorithm.
  */
@@ -115,6 +116,7 @@  struct crypto_istat_cipher {
 	unsigned int chunksize;		\
 	unsigned int statesize;		\
 	unsigned int tailsize;		\
+	bool twopass;			\
 					\
 	SKCIPHER_ALG_COMMON_STAT	\
 					\
@@ -576,6 +578,36 @@  static inline unsigned int crypto_lskcipher_tailsize(
 	return crypto_lskcipher_alg(tfm)->co.tailsize;
 }
 
+/**
+ * crypto_skcipher_isincremental() - check incremental ability
+ * @tfm: cipher handle
+ *
+ * Most skcipher algorithms can accept data in an incremental fashion.
+ * However, some such as adiantum cannot as they need to pass through
+ * the data twice.
+ *
+ * Return: true if algorithm can accept data incrementally.
+ */
+static inline bool crypto_skcipher_isincremental(struct crypto_skcipher *tfm)
+{
+	return !crypto_skcipher_alg_common(tfm)->twopass;
+}
+
+/**
+ * crypto_lskcipher_isincremental() - check incremental ability
+ * @tfm: cipher handle
+ *
+ * Most lskcipher algorithms can accept data in an incremental fashion.
+ * However, some such as adiantum cannot as they need to pass through
+ * the data twice.
+ *
+ * Return: true if algorithm can accept data incrementally.
+ */
+static inline bool crypto_lskcipher_isincremental(struct crypto_lskcipher *tfm)
+{
+	return !crypto_lskcipher_alg(tfm)->co.twopass;
+}
+
 static inline unsigned int crypto_sync_skcipher_blocksize(
 	struct crypto_sync_skcipher *tfm)
 {