diff mbox series

crypto: cipher - move API definition to internal header file

Message ID 20200109222108.15228-1-ardb@kernel.org (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series crypto: cipher - move API definition to internal header file | expand

Commit Message

Ard Biesheuvel Jan. 9, 2020, 10:21 p.m. UTC
The single block cipher API is not intended for general use, and so it
should not be exposed to users outside of the crypto subsystem via the
public header files. So create a new internal header file and move the
definitions there.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 Documentation/crypto/api-skcipher.rst         |   9 -
 arch/arm/crypto/aes-neonbs-glue.c             |   1 +
 arch/s390/crypto/aes_s390.c                   |   1 +
 crypto/adiantum.c                             |   1 +
 crypto/ansi_cprng.c                           |   1 +
 crypto/cbc.c                                  |   1 +
 crypto/ccm.c                                  |   1 +
 crypto/cfb.c                                  |   1 +
 crypto/cipher.c                               |   1 +
 crypto/cmac.c                                 |   1 +
 crypto/ctr.c                                  |   1 +
 crypto/drbg.c                                 |   1 +
 crypto/ecb.c                                  |   1 +
 crypto/essiv.c                                |   1 +
 crypto/keywrap.c                              |   1 +
 crypto/ofb.c                                  |   1 +
 crypto/pcbc.c                                 |   1 +
 crypto/skcipher.c                             |   1 +
 crypto/vmac.c                                 |   1 +
 crypto/xcbc.c                                 |   1 +
 crypto/xts.c                                  |   1 +
 drivers/crypto/geode-aes.c                    |   1 +
 .../crypto/inside-secure/safexcel_cipher.c    |   1 +
 drivers/crypto/inside-secure/safexcel_hash.c  |   1 +
 include/crypto/algapi.h                       |  29 ---
 include/crypto/internal/cipher.h              | 206 ++++++++++++++++++
 include/linux/crypto.h                        | 163 --------------
 27 files changed, 229 insertions(+), 201 deletions(-)
 create mode 100644 include/crypto/internal/cipher.h

Comments

kernel test robot Jan. 10, 2020, 7:20 p.m. UTC | #1
Hi Ard,

I love your patch! Yet something to improve:

[auto build test ERROR on cryptodev/master]
[cannot apply to crypto/master v5.5-rc5 next-20200109]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Ard-Biesheuvel/crypto-cipher-move-API-definition-to-internal-header-file/20200110-193618
base:   https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 7.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.5.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/crypto/vmx/aes.c: In function 'p8_aes_init':
>> drivers/crypto/vmx/aes.c:33:13: error: implicit declaration of function 'crypto_alloc_cipher'; did you mean 'crypto_alloc_comp'? [-Werror=implicit-function-declaration]
     fallback = crypto_alloc_cipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
                ^~~~~~~~~~~~~~~~~~~
                crypto_alloc_comp
>> drivers/crypto/vmx/aes.c:33:11: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     fallback = crypto_alloc_cipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
              ^
>> drivers/crypto/vmx/aes.c:41:2: error: implicit declaration of function 'crypto_cipher_set_flags'; did you mean 'crypto_tfm_set_flags'? [-Werror=implicit-function-declaration]
     crypto_cipher_set_flags(fallback,
     ^~~~~~~~~~~~~~~~~~~~~~~
     crypto_tfm_set_flags
>> drivers/crypto/vmx/aes.c:42:5: error: implicit declaration of function 'crypto_cipher_get_flags'; did you mean 'crypto_tfm_get_flags'? [-Werror=implicit-function-declaration]
        crypto_cipher_get_flags((struct
        ^~~~~~~~~~~~~~~~~~~~~~~
        crypto_tfm_get_flags
   drivers/crypto/vmx/aes.c: In function 'p8_aes_exit':
>> drivers/crypto/vmx/aes.c:55:3: error: implicit declaration of function 'crypto_free_cipher'; did you mean 'crypto_free_comp'? [-Werror=implicit-function-declaration]
      crypto_free_cipher(ctx->fallback);
      ^~~~~~~~~~~~~~~~~~
      crypto_free_comp
   drivers/crypto/vmx/aes.c: In function 'p8_aes_setkey':
>> drivers/crypto/vmx/aes.c:75:9: error: implicit declaration of function 'crypto_cipher_setkey'; did you mean 'crypto_aes_set_key'? [-Werror=implicit-function-declaration]
     ret |= crypto_cipher_setkey(ctx->fallback, key, keylen);
            ^~~~~~~~~~~~~~~~~~~~
            crypto_aes_set_key
   drivers/crypto/vmx/aes.c: In function 'p8_aes_encrypt':
>> drivers/crypto/vmx/aes.c:85:3: error: implicit declaration of function 'crypto_cipher_encrypt_one'; did you mean 'crypto_stats_skcipher_encrypt'? [-Werror=implicit-function-declaration]
      crypto_cipher_encrypt_one(ctx->fallback, dst, src);
      ^~~~~~~~~~~~~~~~~~~~~~~~~
      crypto_stats_skcipher_encrypt
   drivers/crypto/vmx/aes.c: In function 'p8_aes_decrypt':
>> drivers/crypto/vmx/aes.c:102:3: error: implicit declaration of function 'crypto_cipher_decrypt_one'; did you mean 'crypto_comp_decompress'? [-Werror=implicit-function-declaration]
      crypto_cipher_decrypt_one(ctx->fallback, dst, src);
      ^~~~~~~~~~~~~~~~~~~~~~~~~
      crypto_comp_decompress
   cc1: some warnings being treated as errors

vim +33 drivers/crypto/vmx/aes.c

8676590a159320 Marcelo H. Cerri          2015-02-06   26  
8676590a159320 Marcelo H. Cerri          2015-02-06   27  static int p8_aes_init(struct crypto_tfm *tfm)
8676590a159320 Marcelo H. Cerri          2015-02-06   28  {
78557e77b25a98 Tudor-Dan Ambarus         2017-06-16   29  	const char *alg = crypto_tfm_alg_name(tfm);
8676590a159320 Marcelo H. Cerri          2015-02-06   30  	struct crypto_cipher *fallback;
8676590a159320 Marcelo H. Cerri          2015-02-06   31  	struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
8676590a159320 Marcelo H. Cerri          2015-02-06   32  
8676590a159320 Marcelo H. Cerri          2015-02-06  @33  	fallback = crypto_alloc_cipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
8676590a159320 Marcelo H. Cerri          2015-02-06   34  	if (IS_ERR(fallback)) {
4beb106045976b Herbert Xu                2015-06-15   35  		printk(KERN_ERR
4beb106045976b Herbert Xu                2015-06-15   36  		       "Failed to allocate transformation for '%s': %ld\n",
8676590a159320 Marcelo H. Cerri          2015-02-06   37  		       alg, PTR_ERR(fallback));
8676590a159320 Marcelo H. Cerri          2015-02-06   38  		return PTR_ERR(fallback);
8676590a159320 Marcelo H. Cerri          2015-02-06   39  	}
8676590a159320 Marcelo H. Cerri          2015-02-06   40  
8676590a159320 Marcelo H. Cerri          2015-02-06  @41  	crypto_cipher_set_flags(fallback,
4beb106045976b Herbert Xu                2015-06-15  @42  				crypto_cipher_get_flags((struct
4beb106045976b Herbert Xu                2015-06-15   43  							 crypto_cipher *)
4beb106045976b Herbert Xu                2015-06-15   44  							tfm));
8676590a159320 Marcelo H. Cerri          2015-02-06   45  	ctx->fallback = fallback;
8676590a159320 Marcelo H. Cerri          2015-02-06   46  
8676590a159320 Marcelo H. Cerri          2015-02-06   47  	return 0;
8676590a159320 Marcelo H. Cerri          2015-02-06   48  }
8676590a159320 Marcelo H. Cerri          2015-02-06   49  
8676590a159320 Marcelo H. Cerri          2015-02-06   50  static void p8_aes_exit(struct crypto_tfm *tfm)
8676590a159320 Marcelo H. Cerri          2015-02-06   51  {
8676590a159320 Marcelo H. Cerri          2015-02-06   52  	struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
8676590a159320 Marcelo H. Cerri          2015-02-06   53  
8676590a159320 Marcelo H. Cerri          2015-02-06   54  	if (ctx->fallback) {
8676590a159320 Marcelo H. Cerri          2015-02-06  @55  		crypto_free_cipher(ctx->fallback);
8676590a159320 Marcelo H. Cerri          2015-02-06   56  		ctx->fallback = NULL;
8676590a159320 Marcelo H. Cerri          2015-02-06   57  	}
8676590a159320 Marcelo H. Cerri          2015-02-06   58  }
8676590a159320 Marcelo H. Cerri          2015-02-06   59  
8676590a159320 Marcelo H. Cerri          2015-02-06   60  static int p8_aes_setkey(struct crypto_tfm *tfm, const u8 *key,
8676590a159320 Marcelo H. Cerri          2015-02-06   61  			 unsigned int keylen)
8676590a159320 Marcelo H. Cerri          2015-02-06   62  {
8676590a159320 Marcelo H. Cerri          2015-02-06   63  	int ret;
8676590a159320 Marcelo H. Cerri          2015-02-06   64  	struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
8676590a159320 Marcelo H. Cerri          2015-02-06   65  
5f76eea88dcbe7 David Hildenbrand         2015-05-11   66  	preempt_disable();
8676590a159320 Marcelo H. Cerri          2015-02-06   67  	pagefault_disable();
2d6f0600b2cd75 Leonidas Da Silva Barbosa 2015-07-13   68  	enable_kernel_vsx();
8676590a159320 Marcelo H. Cerri          2015-02-06   69  	ret = aes_p8_set_encrypt_key(key, keylen * 8, &ctx->enc_key);
694e0db6600c12 Eric Biggers              2019-04-09   70  	ret |= aes_p8_set_decrypt_key(key, keylen * 8, &ctx->dec_key);
dc4fbba11e4661 Anton Blanchard           2015-10-29   71  	disable_kernel_vsx();
8676590a159320 Marcelo H. Cerri          2015-02-06   72  	pagefault_enable();
5f76eea88dcbe7 David Hildenbrand         2015-05-11   73  	preempt_enable();
8676590a159320 Marcelo H. Cerri          2015-02-06   74  
694e0db6600c12 Eric Biggers              2019-04-09  @75  	ret |= crypto_cipher_setkey(ctx->fallback, key, keylen);
694e0db6600c12 Eric Biggers              2019-04-09   76  
694e0db6600c12 Eric Biggers              2019-04-09   77  	return ret ? -EINVAL : 0;
8676590a159320 Marcelo H. Cerri          2015-02-06   78  }
8676590a159320 Marcelo H. Cerri          2015-02-06   79  
8676590a159320 Marcelo H. Cerri          2015-02-06   80  static void p8_aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
8676590a159320 Marcelo H. Cerri          2015-02-06   81  {
8676590a159320 Marcelo H. Cerri          2015-02-06   82  	struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
8676590a159320 Marcelo H. Cerri          2015-02-06   83  
626ddb2fbe7931 Eric Biggers              2019-04-12   84  	if (!crypto_simd_usable()) {
8676590a159320 Marcelo H. Cerri          2015-02-06  @85  		crypto_cipher_encrypt_one(ctx->fallback, dst, src);
8676590a159320 Marcelo H. Cerri          2015-02-06   86  	} else {
5f76eea88dcbe7 David Hildenbrand         2015-05-11   87  		preempt_disable();
8676590a159320 Marcelo H. Cerri          2015-02-06   88  		pagefault_disable();
2d6f0600b2cd75 Leonidas Da Silva Barbosa 2015-07-13   89  		enable_kernel_vsx();
8676590a159320 Marcelo H. Cerri          2015-02-06   90  		aes_p8_encrypt(src, dst, &ctx->enc_key);
dc4fbba11e4661 Anton Blanchard           2015-10-29   91  		disable_kernel_vsx();
8676590a159320 Marcelo H. Cerri          2015-02-06   92  		pagefault_enable();
5f76eea88dcbe7 David Hildenbrand         2015-05-11   93  		preempt_enable();
8676590a159320 Marcelo H. Cerri          2015-02-06   94  	}
8676590a159320 Marcelo H. Cerri          2015-02-06   95  }
8676590a159320 Marcelo H. Cerri          2015-02-06   96  
8676590a159320 Marcelo H. Cerri          2015-02-06   97  static void p8_aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
8676590a159320 Marcelo H. Cerri          2015-02-06   98  {
8676590a159320 Marcelo H. Cerri          2015-02-06   99  	struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
8676590a159320 Marcelo H. Cerri          2015-02-06  100  
626ddb2fbe7931 Eric Biggers              2019-04-12  101  	if (!crypto_simd_usable()) {
8676590a159320 Marcelo H. Cerri          2015-02-06 @102  		crypto_cipher_decrypt_one(ctx->fallback, dst, src);
8676590a159320 Marcelo H. Cerri          2015-02-06  103  	} else {
5f76eea88dcbe7 David Hildenbrand         2015-05-11  104  		preempt_disable();
8676590a159320 Marcelo H. Cerri          2015-02-06  105  		pagefault_disable();
2d6f0600b2cd75 Leonidas Da Silva Barbosa 2015-07-13  106  		enable_kernel_vsx();
8676590a159320 Marcelo H. Cerri          2015-02-06  107  		aes_p8_decrypt(src, dst, &ctx->dec_key);
dc4fbba11e4661 Anton Blanchard           2015-10-29  108  		disable_kernel_vsx();
8676590a159320 Marcelo H. Cerri          2015-02-06  109  		pagefault_enable();
5f76eea88dcbe7 David Hildenbrand         2015-05-11  110  		preempt_enable();
8676590a159320 Marcelo H. Cerri          2015-02-06  111  	}
8676590a159320 Marcelo H. Cerri          2015-02-06  112  }
8676590a159320 Marcelo H. Cerri          2015-02-06  113  

:::::: The code at line 33 was first introduced by commit
:::::: 8676590a159320a9de2a1818df14a3bac3f065a1 crypto: vmx - Adding AES routines for VMX module

:::::: TO: Marcelo H. Cerri <mhcerri@linux.vnet.ibm.com>
:::::: CC: Herbert Xu <herbert@gondor.apana.org.au>

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation
diff mbox series

Patch

diff --git a/Documentation/crypto/api-skcipher.rst b/Documentation/crypto/api-skcipher.rst
index 1aaf8985894b..563d5bb06a7a 100644
--- a/Documentation/crypto/api-skcipher.rst
+++ b/Documentation/crypto/api-skcipher.rst
@@ -24,12 +24,3 @@  Symmetric Key Cipher Request Handle
 
 .. kernel-doc:: include/crypto/skcipher.h
    :functions: crypto_skcipher_reqsize skcipher_request_set_tfm skcipher_request_alloc skcipher_request_free skcipher_request_set_callback skcipher_request_set_crypt
-
-Single Block Cipher API
------------------------
-
-.. kernel-doc:: include/linux/crypto.h
-   :doc: Single Block Cipher API
-
-.. kernel-doc:: include/linux/crypto.h
-   :functions: crypto_alloc_cipher crypto_free_cipher crypto_has_cipher crypto_cipher_blocksize crypto_cipher_setkey crypto_cipher_encrypt_one crypto_cipher_decrypt_one
diff --git a/arch/arm/crypto/aes-neonbs-glue.c b/arch/arm/crypto/aes-neonbs-glue.c
index e85839a8aaeb..03a7a37d6393 100644
--- a/arch/arm/crypto/aes-neonbs-glue.c
+++ b/arch/arm/crypto/aes-neonbs-glue.c
@@ -10,6 +10,7 @@ 
 #include <crypto/aes.h>
 #include <crypto/cbc.h>
 #include <crypto/ctr.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/simd.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 1c23d84a9097..33c606521412 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -21,6 +21,7 @@ 
 #include <crypto/algapi.h>
 #include <crypto/ghash.h>
 #include <crypto/internal/aead.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
 #include <linux/err.h>
diff --git a/crypto/adiantum.c b/crypto/adiantum.c
index 4d7a6cac82ed..49c94d147184 100644
--- a/crypto/adiantum.c
+++ b/crypto/adiantum.c
@@ -32,6 +32,7 @@ 
 
 #include <crypto/b128ops.h>
 #include <crypto/chacha.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/hash.h>
 #include <crypto/internal/poly1305.h>
 #include <crypto/internal/skcipher.h>
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index c475c1129ff2..4320a961d013 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -7,6 +7,7 @@ 
  *  (C) Neil Horman <nhorman@tuxdriver.com>
  */
 
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/rng.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/cbc.c b/crypto/cbc.c
index e6f6273a7d39..45fe3117cd39 100644
--- a/crypto/cbc.c
+++ b/crypto/cbc.c
@@ -7,6 +7,7 @@ 
 
 #include <crypto/algapi.h>
 #include <crypto/cbc.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/ccm.c b/crypto/ccm.c
index 241ecdc5c4e0..731fb0fe3dda 100644
--- a/crypto/ccm.c
+++ b/crypto/ccm.c
@@ -6,6 +6,7 @@ 
  */
 
 #include <crypto/internal/aead.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/hash.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
diff --git a/crypto/cfb.c b/crypto/cfb.c
index 4e5219bbcd19..343263554876 100644
--- a/crypto/cfb.c
+++ b/crypto/cfb.c
@@ -20,6 +20,7 @@ 
  */
 
 #include <crypto/algapi.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/cipher.c b/crypto/cipher.c
index fd78150deb1c..6ae67731f81e 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -9,6 +9,7 @@ 
  */
 
 #include <crypto/algapi.h>
+#include <crypto/internal/cipher.h>
 #include <linux/kernel.h>
 #include <linux/crypto.h>
 #include <linux/errno.h>
diff --git a/crypto/cmac.c b/crypto/cmac.c
index 143a6544c873..66177a217cb4 100644
--- a/crypto/cmac.c
+++ b/crypto/cmac.c
@@ -11,6 +11,7 @@ 
  *   Author: Kazunori Miyazawa <miyazawa@linux-ipv6.org>
  */
 
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/hash.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
diff --git a/crypto/ctr.c b/crypto/ctr.c
index a8feab621c6c..2192d72eec1d 100644
--- a/crypto/ctr.c
+++ b/crypto/ctr.c
@@ -7,6 +7,7 @@ 
 
 #include <crypto/algapi.h>
 #include <crypto/ctr.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/drbg.c b/crypto/drbg.c
index b6929eb5f565..bcb22065caf4 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -98,6 +98,7 @@ 
  */
 
 #include <crypto/drbg.h>
+#include <crypto/internal/cipher.h>
 #include <linux/kernel.h>
 
 /***************************************************************
diff --git a/crypto/ecb.c b/crypto/ecb.c
index 69a687cbdf21..71fbb0543d64 100644
--- a/crypto/ecb.c
+++ b/crypto/ecb.c
@@ -6,6 +6,7 @@ 
  */
 
 #include <crypto/algapi.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/essiv.c b/crypto/essiv.c
index 20d7c1fdbf5d..c19524e323ff 100644
--- a/crypto/essiv.c
+++ b/crypto/essiv.c
@@ -31,6 +31,7 @@ 
 #include <crypto/authenc.h>
 #include <crypto/internal/aead.h>
 #include <crypto/internal/hash.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
 #include <linux/module.h>
diff --git a/crypto/keywrap.c b/crypto/keywrap.c
index 0355cce21b1e..1b87e6d3a5e6 100644
--- a/crypto/keywrap.c
+++ b/crypto/keywrap.c
@@ -85,6 +85,7 @@ 
 #include <linux/crypto.h>
 #include <linux/scatterlist.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 
 struct crypto_kw_block {
diff --git a/crypto/ofb.c b/crypto/ofb.c
index 2ec68e3f2c55..7fc426935b45 100644
--- a/crypto/ofb.c
+++ b/crypto/ofb.c
@@ -8,6 +8,7 @@ 
  */
 
 #include <crypto/algapi.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/pcbc.c b/crypto/pcbc.c
index ae921fb74dc9..7ab6003eeaa5 100644
--- a/crypto/pcbc.c
+++ b/crypto/pcbc.c
@@ -10,6 +10,7 @@ 
  */
 
 #include <crypto/algapi.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <linux/err.h>
 #include <linux/init.h>
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index 7221def7b9a7..fab5e39e9fac 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -10,6 +10,7 @@ 
  */
 
 #include <crypto/internal/aead.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
 #include <linux/bug.h>
diff --git a/crypto/vmac.c b/crypto/vmac.c
index 2d906830df96..0cba941ec368 100644
--- a/crypto/vmac.c
+++ b/crypto/vmac.c
@@ -36,6 +36,7 @@ 
 #include <linux/scatterlist.h>
 #include <asm/byteorder.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/hash.h>
 
 /*
diff --git a/crypto/xcbc.c b/crypto/xcbc.c
index 598ec88abf0f..9bc998699180 100644
--- a/crypto/xcbc.c
+++ b/crypto/xcbc.c
@@ -6,6 +6,7 @@ 
  * 	Kazunori Miyazawa <miyazawa@linux-ipv6.org>
  */
 
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/hash.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
diff --git a/crypto/xts.c b/crypto/xts.c
index 29efa15f1495..91e3eb63f00e 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -7,6 +7,7 @@ 
  * Based on ecb.c
  * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
  */
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
 #include <linux/err.h>
diff --git a/drivers/crypto/geode-aes.c b/drivers/crypto/geode-aes.c
index f4f18bfc2247..a25fb9783c7e 100644
--- a/drivers/crypto/geode-aes.c
+++ b/drivers/crypto/geode-aes.c
@@ -10,6 +10,7 @@ 
 #include <linux/spinlock.h>
 #include <crypto/algapi.h>
 #include <crypto/aes.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 
 #include <linux/io.h>
diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c
index 0c5e80c3f6e3..159653985388 100644
--- a/drivers/crypto/inside-secure/safexcel_cipher.c
+++ b/drivers/crypto/inside-secure/safexcel_cipher.c
@@ -24,6 +24,7 @@ 
 #include <crypto/xts.h>
 #include <crypto/skcipher.h>
 #include <crypto/internal/aead.h>
+#include <crypto/internal/cipher.h>
 #include <crypto/internal/skcipher.h>
 
 #include "safexcel.h"
diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c
index 43962bc709c6..648ea63c9224 100644
--- a/drivers/crypto/inside-secure/safexcel_hash.c
+++ b/drivers/crypto/inside-secure/safexcel_hash.c
@@ -12,6 +12,7 @@ 
 #include <crypto/sha3.h>
 #include <crypto/skcipher.h>
 #include <crypto/sm3.h>
+#include <crypto/internal/cipher.h>
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmapool.h>
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index e115f9215ed5..a278ceaaeb6f 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -191,41 +191,12 @@  struct crypto_cipher_spawn {
 	struct crypto_spawn base;
 };
 
-static inline int crypto_grab_cipher(struct crypto_cipher_spawn *spawn,
-				     struct crypto_instance *inst,
-				     const char *name, u32 type, u32 mask)
-{
-	type &= ~CRYPTO_ALG_TYPE_MASK;
-	type |= CRYPTO_ALG_TYPE_CIPHER;
-	mask |= CRYPTO_ALG_TYPE_MASK;
-	return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
-}
-
-static inline void crypto_drop_cipher(struct crypto_cipher_spawn *spawn)
-{
-	crypto_drop_spawn(&spawn->base);
-}
-
 static inline struct crypto_alg *crypto_spawn_cipher_alg(
 	struct crypto_cipher_spawn *spawn)
 {
 	return spawn->base.alg;
 }
 
-static inline struct crypto_cipher *crypto_spawn_cipher(
-	struct crypto_cipher_spawn *spawn)
-{
-	u32 type = CRYPTO_ALG_TYPE_CIPHER;
-	u32 mask = CRYPTO_ALG_TYPE_MASK;
-
-	return __crypto_cipher_cast(crypto_spawn_tfm(&spawn->base, type, mask));
-}
-
-static inline struct cipher_alg *crypto_cipher_alg(struct crypto_cipher *tfm)
-{
-	return &crypto_cipher_tfm(tfm)->__crt_alg->cra_cipher;
-}
-
 static inline struct crypto_async_request *crypto_get_backlog(
 	struct crypto_queue *queue)
 {
diff --git a/include/crypto/internal/cipher.h b/include/crypto/internal/cipher.h
new file mode 100644
index 000000000000..0784fa2e3531
--- /dev/null
+++ b/include/crypto/internal/cipher.h
@@ -0,0 +1,206 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
+ * Copyright (c) 2002 David S. Miller (davem@redhat.com)
+ * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
+ */
+
+#ifndef _CRYPTO_INTERNAL_CIPHER_H
+#define _CRYPTO_INTERNAL_CIPHER_H
+
+#include <linux/crypto.h>
+#include <crypto/algapi.h>
+
+struct crypto_cipher {
+	struct crypto_tfm base;
+};
+
+/**
+ * DOC: Single Block Cipher API
+ *
+ * The single block cipher API is used with the ciphers of type
+ * CRYPTO_ALG_TYPE_CIPHER (listed as type "cipher" in /proc/crypto).
+ *
+ * Using the single block cipher API calls, operations with the basic cipher
+ * primitive can be implemented. These cipher primitives exclude any block
+ * chaining operations including IV handling.
+ *
+ * The purpose of this single block cipher API is to support the implementation
+ * of templates or other concepts that only need to perform the cipher operation
+ * on one block at a time. Templates invoke the underlying cipher primitive
+ * block-wise and process either the input or the output data of these cipher
+ * operations.
+ */
+
+static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
+{
+	return (struct crypto_cipher *)tfm;
+}
+
+/**
+ * crypto_alloc_cipher() - allocate single block cipher handle
+ * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
+ *	     single block cipher
+ * @type: specifies the type of the cipher
+ * @mask: specifies the mask for the cipher
+ *
+ * Allocate a cipher handle for a single block cipher. The returned struct
+ * crypto_cipher is the cipher handle that is required for any subsequent API
+ * invocation for that single block cipher.
+ *
+ * Return: allocated cipher handle in case of success; IS_ERR() is true in case
+ *	   of an error, PTR_ERR() returns the error code.
+ */
+static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
+							u32 type, u32 mask)
+{
+	type &= ~CRYPTO_ALG_TYPE_MASK;
+	type |= CRYPTO_ALG_TYPE_CIPHER;
+	mask |= CRYPTO_ALG_TYPE_MASK;
+
+	return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
+}
+
+static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
+{
+	return &tfm->base;
+}
+
+/**
+ * crypto_free_cipher() - zeroize and free the single block cipher handle
+ * @tfm: cipher handle to be freed
+ */
+static inline void crypto_free_cipher(struct crypto_cipher *tfm)
+{
+	crypto_free_tfm(crypto_cipher_tfm(tfm));
+}
+
+/**
+ * crypto_has_cipher() - Search for the availability of a single block cipher
+ * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
+ *	     single block cipher
+ * @type: specifies the type of the cipher
+ * @mask: specifies the mask for the cipher
+ *
+ * Return: true when the single block cipher is known to the kernel crypto API;
+ *	   false otherwise
+ */
+static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
+{
+	type &= ~CRYPTO_ALG_TYPE_MASK;
+	type |= CRYPTO_ALG_TYPE_CIPHER;
+	mask |= CRYPTO_ALG_TYPE_MASK;
+
+	return crypto_has_alg(alg_name, type, mask);
+}
+
+/**
+ * crypto_cipher_blocksize() - obtain block size for cipher
+ * @tfm: cipher handle
+ *
+ * The block size for the single block cipher referenced with the cipher handle
+ * tfm is returned. The caller may use that information to allocate appropriate
+ * memory for the data returned by the encryption or decryption operation
+ *
+ * Return: block size of cipher
+ */
+static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
+{
+	return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
+}
+
+static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
+{
+	return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
+}
+
+static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
+{
+	return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
+}
+
+static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
+					   u32 flags)
+{
+	crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
+}
+
+static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
+					     u32 flags)
+{
+	crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
+}
+
+/**
+ * crypto_cipher_setkey() - set key for cipher
+ * @tfm: cipher handle
+ * @key: buffer holding the key
+ * @keylen: length of the key in bytes
+ *
+ * The caller provided key is set for the single block cipher referenced by the
+ * cipher handle.
+ *
+ * Note, the key length determines the cipher type. Many block ciphers implement
+ * different cipher modes depending on the key size, such as AES-128 vs AES-192
+ * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
+ * is performed.
+ *
+ * Return: 0 if the setting of the key was successful; < 0 if an error occurred
+ */
+int crypto_cipher_setkey(struct crypto_cipher *tfm,
+			 const u8 *key, unsigned int keylen);
+
+/**
+ * crypto_cipher_encrypt_one() - encrypt one block of plaintext
+ * @tfm: cipher handle
+ * @dst: points to the buffer that will be filled with the ciphertext
+ * @src: buffer holding the plaintext to be encrypted
+ *
+ * Invoke the encryption operation of one block. The caller must ensure that
+ * the plaintext and ciphertext buffers are at least one block in size.
+ */
+void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
+			       u8 *dst, const u8 *src);
+
+/**
+ * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
+ * @tfm: cipher handle
+ * @dst: points to the buffer that will be filled with the plaintext
+ * @src: buffer holding the ciphertext to be decrypted
+ *
+ * Invoke the decryption operation of one block. The caller must ensure that
+ * the plaintext and ciphertext buffers are at least one block in size.
+ */
+void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
+			       u8 *dst, const u8 *src);
+
+static inline int crypto_grab_cipher(struct crypto_cipher_spawn *spawn,
+				     struct crypto_instance *inst,
+				     const char *name, u32 type, u32 mask)
+{
+	type &= ~CRYPTO_ALG_TYPE_MASK;
+	type |= CRYPTO_ALG_TYPE_CIPHER;
+	mask |= CRYPTO_ALG_TYPE_MASK;
+	return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
+}
+
+static inline void crypto_drop_cipher(struct crypto_cipher_spawn *spawn)
+{
+	crypto_drop_spawn(&spawn->base);
+}
+
+static inline struct crypto_cipher *crypto_spawn_cipher(
+	struct crypto_cipher_spawn *spawn)
+{
+	u32 type = CRYPTO_ALG_TYPE_CIPHER;
+	u32 mask = CRYPTO_ALG_TYPE_MASK;
+
+	return __crypto_cipher_cast(crypto_spawn_tfm(&spawn->base, type, mask));
+}
+
+static inline struct cipher_alg *crypto_cipher_alg(struct crypto_cipher *tfm)
+{
+	return &crypto_cipher_tfm(tfm)->__crt_alg->cra_cipher;
+}
+
+#endif
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 763863dbc079..defe6bd76232 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -603,10 +603,6 @@  struct crypto_tfm {
 	void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
 };
 
-struct crypto_cipher {
-	struct crypto_tfm base;
-};
-
 struct crypto_comp {
 	struct crypto_tfm base;
 };
@@ -710,165 +706,6 @@  static inline unsigned int crypto_tfm_ctx_alignment(void)
 	return __alignof__(tfm->__crt_ctx);
 }
 
-/**
- * DOC: Single Block Cipher API
- *
- * The single block cipher API is used with the ciphers of type
- * CRYPTO_ALG_TYPE_CIPHER (listed as type "cipher" in /proc/crypto).
- *
- * Using the single block cipher API calls, operations with the basic cipher
- * primitive can be implemented. These cipher primitives exclude any block
- * chaining operations including IV handling.
- *
- * The purpose of this single block cipher API is to support the implementation
- * of templates or other concepts that only need to perform the cipher operation
- * on one block at a time. Templates invoke the underlying cipher primitive
- * block-wise and process either the input or the output data of these cipher
- * operations.
- */
-
-static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
-{
-	return (struct crypto_cipher *)tfm;
-}
-
-/**
- * crypto_alloc_cipher() - allocate single block cipher handle
- * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
- *	     single block cipher
- * @type: specifies the type of the cipher
- * @mask: specifies the mask for the cipher
- *
- * Allocate a cipher handle for a single block cipher. The returned struct
- * crypto_cipher is the cipher handle that is required for any subsequent API
- * invocation for that single block cipher.
- *
- * Return: allocated cipher handle in case of success; IS_ERR() is true in case
- *	   of an error, PTR_ERR() returns the error code.
- */
-static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
-							u32 type, u32 mask)
-{
-	type &= ~CRYPTO_ALG_TYPE_MASK;
-	type |= CRYPTO_ALG_TYPE_CIPHER;
-	mask |= CRYPTO_ALG_TYPE_MASK;
-
-	return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
-}
-
-static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
-{
-	return &tfm->base;
-}
-
-/**
- * crypto_free_cipher() - zeroize and free the single block cipher handle
- * @tfm: cipher handle to be freed
- */
-static inline void crypto_free_cipher(struct crypto_cipher *tfm)
-{
-	crypto_free_tfm(crypto_cipher_tfm(tfm));
-}
-
-/**
- * crypto_has_cipher() - Search for the availability of a single block cipher
- * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
- *	     single block cipher
- * @type: specifies the type of the cipher
- * @mask: specifies the mask for the cipher
- *
- * Return: true when the single block cipher is known to the kernel crypto API;
- *	   false otherwise
- */
-static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
-{
-	type &= ~CRYPTO_ALG_TYPE_MASK;
-	type |= CRYPTO_ALG_TYPE_CIPHER;
-	mask |= CRYPTO_ALG_TYPE_MASK;
-
-	return crypto_has_alg(alg_name, type, mask);
-}
-
-/**
- * crypto_cipher_blocksize() - obtain block size for cipher
- * @tfm: cipher handle
- *
- * The block size for the single block cipher referenced with the cipher handle
- * tfm is returned. The caller may use that information to allocate appropriate
- * memory for the data returned by the encryption or decryption operation
- *
- * Return: block size of cipher
- */
-static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
-{
-	return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
-}
-
-static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
-{
-	return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
-}
-
-static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
-{
-	return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
-}
-
-static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
-					   u32 flags)
-{
-	crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
-}
-
-static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
-					     u32 flags)
-{
-	crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
-}
-
-/**
- * crypto_cipher_setkey() - set key for cipher
- * @tfm: cipher handle
- * @key: buffer holding the key
- * @keylen: length of the key in bytes
- *
- * The caller provided key is set for the single block cipher referenced by the
- * cipher handle.
- *
- * Note, the key length determines the cipher type. Many block ciphers implement
- * different cipher modes depending on the key size, such as AES-128 vs AES-192
- * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
- * is performed.
- *
- * Return: 0 if the setting of the key was successful; < 0 if an error occurred
- */
-int crypto_cipher_setkey(struct crypto_cipher *tfm,
-			 const u8 *key, unsigned int keylen);
-
-/**
- * crypto_cipher_encrypt_one() - encrypt one block of plaintext
- * @tfm: cipher handle
- * @dst: points to the buffer that will be filled with the ciphertext
- * @src: buffer holding the plaintext to be encrypted
- *
- * Invoke the encryption operation of one block. The caller must ensure that
- * the plaintext and ciphertext buffers are at least one block in size.
- */
-void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
-			       u8 *dst, const u8 *src);
-
-/**
- * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
- * @tfm: cipher handle
- * @dst: points to the buffer that will be filled with the plaintext
- * @src: buffer holding the ciphertext to be decrypted
- *
- * Invoke the decryption operation of one block. The caller must ensure that
- * the plaintext and ciphertext buffers are at least one block in size.
- */
-void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
-			       u8 *dst, const u8 *src);
-
 static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
 {
 	return (struct crypto_comp *)tfm;