Merge tag 'v6.16-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 26 May 2025 20:47:28 +0000 (13:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 26 May 2025 20:47:28 +0000 (13:47 -0700)
Pull crypto updates from Herbert Xu:
 "API:
   - Fix memcpy_sglist to handle partially overlapping SG lists
   - Use memcpy_sglist to replace null skcipher
   - Rename CRYPTO_TESTS to CRYPTO_BENCHMARK
   - Flip CRYPTO_MANAGER_DISABLE_TEST into CRYPTO_SELFTESTS
   - Hide CRYPTO_MANAGER
   - Add delayed freeing of driver crypto_alg structures

  Compression:
   - Allocate large buffers on first use instead of initialisation in scomp
   - Drop destination linearisation buffer in scomp
   - Move scomp stream allocation into acomp
   - Add acomp scatter-gather walker
   - Remove request chaining
   - Add optional async request allocation

  Hashing:
   - Remove request chaining
   - Add optional async request allocation
   - Move partial block handling into API
   - Add ahash support to hmac
   - Fix shash documentation to disallow usage in hard IRQs

  Algorithms:
   - Remove unnecessary SIMD fallback code on x86 and arm/arm64
   - Drop avx10_256 xts(aes)/ctr(aes) on x86
   - Improve avx-512 optimisations for xts(aes)
   - Move chacha arch implementations into lib/crypto
   - Move poly1305 into lib/crypto and drop unused Crypto API algorithm
   - Disable powerpc/poly1305 as it has no SIMD fallback
   - Move sha256 arch implementations into lib/crypto
   - Convert deflate to acomp
   - Set block size correctly in cbcmac

  Drivers:
   - Do not use sg_dma_len before mapping in sun8i-ss
   - Fix warm-reboot failure by making shutdown do more work in qat
   - Add locking in zynqmp-sha
   - Remove cavium/zip
   - Add support for PCI device 0x17D8 to ccp
   - Add qat_6xxx support in qat
   - Add support for RK3576 in rockchip-rng
   - Add support for i.MX8QM in caam

  Others:
   - Fix irq_fpu_usable/kernel_fpu_begin inconsistency during CPU bring-up
   - Add new SEV/SNP platform shutdown API in ccp"

* tag 'v6.16-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (382 commits)
  x86/fpu: Fix irq_fpu_usable() to return false during CPU onlining
  crypto: qat - add missing header inclusion
  crypto: api - Redo lookup on EEXIST
  Revert "crypto: testmgr - Add hash export format testing"
  crypto: marvell/cesa - Do not chain submitted requests
  crypto: powerpc/poly1305 - add depends on BROKEN for now
  Revert "crypto: powerpc/poly1305 - Add SIMD fallback"
  crypto: ccp - Add missing tee info reg for teev2
  crypto: ccp - Add missing bootloader info reg for pspv5
  crypto: sun8i-ce - move fallback ahash_request to the end of the struct
  crypto: octeontx2 - Use dynamic allocated memory region for lmtst
  crypto: octeontx2 - Initialize cptlfs device info once
  crypto: xts - Only add ecb if it is not already there
  crypto: lrw - Only add ecb if it is not already there
  crypto: testmgr - Add hash export format testing
  crypto: testmgr - Use ahash for generic tfm
  crypto: hmac - Add ahash support
  crypto: testmgr - Ignore EEXIST on shash allocation
  crypto: algapi - Add driver template support to crypto_inst_setname
  crypto: shash - Set reqsize in shash_alg
  ...

17 files changed:
1  2 
MAINTAINERS
arch/arm/lib/Makefile
arch/arm64/configs/defconfig
arch/arm64/lib/Makefile
arch/powerpc/lib/Makefile
arch/powerpc/lib/crc-t10dif.c
arch/powerpc/lib/crc32.c
arch/s390/configs/debug_defconfig
arch/s390/configs/defconfig
arch/s390/lib/Makefile
arch/sparc/lib/Makefile
arch/x86/kvm/svm/sev.c
arch/x86/lib/Makefile
crypto/Makefile
crypto/crc32.c
crypto/crc32c.c
fs/bcachefs/checksum.c

diff --cc MAINTAINERS
Simple merge
Simple merge
index c4ce2c67c0e067a711b6fbe13a3814cb18727816,4166bc4d3cec0ff21a0e2f39c3a18a7e36f7a35e..370ad70b4be846996fe43c6cea83c5f2a8b5710f
@@@ -1729,15 -1729,14 +1729,14 @@@ CONFIG_NLS_CODEPAGE_437=
  CONFIG_NLS_ISO8859_1=y
  CONFIG_SECURITY=y
  CONFIG_CRYPTO_USER=y
- CONFIG_CRYPTO_TEST=m
 +CONFIG_CRYPTO_CHACHA20=m
+ CONFIG_CRYPTO_BENCHMARK=m
  CONFIG_CRYPTO_ECHAINIV=y
  CONFIG_CRYPTO_MICHAEL_MIC=m
  CONFIG_CRYPTO_ANSI_CPRNG=y
  CONFIG_CRYPTO_USER_API_RNG=m
 -CONFIG_CRYPTO_CHACHA20_NEON=m
  CONFIG_CRYPTO_GHASH_ARM64_CE=y
  CONFIG_CRYPTO_SHA1_ARM64_CE=y
- CONFIG_CRYPTO_SHA2_ARM64_CE=y
  CONFIG_CRYPTO_SHA512_ARM64_CE=m
  CONFIG_CRYPTO_SHA3_ARM64=m
  CONFIG_CRYPTO_SM3_ARM64_CE=m
Simple merge
Simple merge
index 4253842cc50d3be2cf3b4910fb15366aa7d8fd2a,0000000000000000000000000000000000000000..be23ded3a9df69be979f0a0d5fd24f30d59a8f16
mode 100644,000000..100644
--- /dev/null
@@@ -1,83 -1,0 +1,83 @@@
- #include <linux/crc-t10dif.h>
 +// SPDX-License-Identifier: GPL-2.0-or-later
 +/*
 + * Calculate a CRC T10-DIF with vpmsum acceleration
 + *
 + * Copyright 2017, Daniel Axtens, IBM Corporation.
 + * [based on crc32c-vpmsum_glue.c]
 + */
 +
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/string.h>
- #include <linux/kernel.h>
++#include <asm/switch_to.h>
 +#include <crypto/internal/simd.h>
- #include <asm/simd.h>
- #include <asm/switch_to.h>
 +#include <linux/cpufeature.h>
++#include <linux/crc-t10dif.h>
++#include <linux/jump_label.h>
++#include <linux/kernel.h>
++#include <linux/module.h>
++#include <linux/preempt.h>
++#include <linux/uaccess.h>
 +
 +#define VMX_ALIGN             16
 +#define VMX_ALIGN_MASK                (VMX_ALIGN-1)
 +
 +#define VECTOR_BREAKPOINT     64
 +
 +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto);
 +
 +u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
 +
 +u16 crc_t10dif_arch(u16 crci, const u8 *p, size_t len)
 +{
 +      unsigned int prealign;
 +      unsigned int tail;
 +      u32 crc = crci;
 +
 +      if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) ||
 +          !static_branch_likely(&have_vec_crypto) || !crypto_simd_usable())
 +              return crc_t10dif_generic(crc, p, len);
 +
 +      if ((unsigned long)p & VMX_ALIGN_MASK) {
 +              prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK);
 +              crc = crc_t10dif_generic(crc, p, prealign);
 +              len -= prealign;
 +              p += prealign;
 +      }
 +
 +      if (len & ~VMX_ALIGN_MASK) {
 +              crc <<= 16;
 +              preempt_disable();
 +              pagefault_disable();
 +              enable_kernel_altivec();
 +              crc = __crct10dif_vpmsum(crc, p, len & ~VMX_ALIGN_MASK);
 +              disable_kernel_altivec();
 +              pagefault_enable();
 +              preempt_enable();
 +              crc >>= 16;
 +      }
 +
 +      tail = len & VMX_ALIGN_MASK;
 +      if (tail) {
 +              p += len & ~VMX_ALIGN_MASK;
 +              crc = crc_t10dif_generic(crc, p, tail);
 +      }
 +
 +      return crc & 0xffff;
 +}
 +EXPORT_SYMBOL(crc_t10dif_arch);
 +
 +static int __init crc_t10dif_powerpc_init(void)
 +{
 +      if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
 +          (cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
 +              static_branch_enable(&have_vec_crypto);
 +      return 0;
 +}
 +subsys_initcall(crc_t10dif_powerpc_init);
 +
 +static void __exit crc_t10dif_powerpc_exit(void)
 +{
 +}
 +module_exit(crc_t10dif_powerpc_exit);
 +
 +MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
 +MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions");
 +MODULE_LICENSE("GPL");
index 77e5a37006f000398697ecfb77902626d9d0a2d3,0000000000000000000000000000000000000000..0d9befb6e7b83e2c9f3ccb5a2c600d54b3f60102
mode 100644,000000..100644
--- /dev/null
@@@ -1,92 -1,0 +1,93 @@@
- #include <linux/crc32.h>
 +// SPDX-License-Identifier: GPL-2.0-only
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/kernel.h>
++#include <asm/switch_to.h>
 +#include <crypto/internal/simd.h>
- #include <asm/simd.h>
- #include <asm/switch_to.h>
 +#include <linux/cpufeature.h>
++#include <linux/crc32.h>
++#include <linux/jump_label.h>
++#include <linux/kernel.h>
++#include <linux/module.h>
++#include <linux/preempt.h>
++#include <linux/uaccess.h>
 +
 +#define VMX_ALIGN             16
 +#define VMX_ALIGN_MASK                (VMX_ALIGN-1)
 +
 +#define VECTOR_BREAKPOINT     512
 +
 +static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_vec_crypto);
 +
 +u32 __crc32c_vpmsum(u32 crc, const u8 *p, size_t len);
 +
 +u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
 +{
 +      return crc32_le_base(crc, p, len);
 +}
 +EXPORT_SYMBOL(crc32_le_arch);
 +
 +u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
 +{
 +      unsigned int prealign;
 +      unsigned int tail;
 +
 +      if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) ||
 +          !static_branch_likely(&have_vec_crypto) || !crypto_simd_usable())
 +              return crc32c_base(crc, p, len);
 +
 +      if ((unsigned long)p & VMX_ALIGN_MASK) {
 +              prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK);
 +              crc = crc32c_base(crc, p, prealign);
 +              len -= prealign;
 +              p += prealign;
 +      }
 +
 +      if (len & ~VMX_ALIGN_MASK) {
 +              preempt_disable();
 +              pagefault_disable();
 +              enable_kernel_altivec();
 +              crc = __crc32c_vpmsum(crc, p, len & ~VMX_ALIGN_MASK);
 +              disable_kernel_altivec();
 +              pagefault_enable();
 +              preempt_enable();
 +      }
 +
 +      tail = len & VMX_ALIGN_MASK;
 +      if (tail) {
 +              p += len & ~VMX_ALIGN_MASK;
 +              crc = crc32c_base(crc, p, tail);
 +      }
 +
 +      return crc;
 +}
 +EXPORT_SYMBOL(crc32c_arch);
 +
 +u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
 +{
 +      return crc32_be_base(crc, p, len);
 +}
 +EXPORT_SYMBOL(crc32_be_arch);
 +
 +static int __init crc32_powerpc_init(void)
 +{
 +      if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
 +          (cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
 +              static_branch_enable(&have_vec_crypto);
 +      return 0;
 +}
 +subsys_initcall(crc32_powerpc_init);
 +
 +static void __exit crc32_powerpc_exit(void)
 +{
 +}
 +module_exit(crc32_powerpc_exit);
 +
 +u32 crc32_optimizations(void)
 +{
 +      if (static_key_enabled(&have_vec_crypto))
 +              return CRC32C_OPTIMIZATION;
 +      return 0;
 +}
 +EXPORT_SYMBOL(crc32_optimizations);
 +
 +MODULE_AUTHOR("Anton Blanchard <anton@samba.org>");
 +MODULE_DESCRIPTION("CRC32C using vector polynomial multiply-sum instructions");
 +MODULE_LICENSE("GPL");
index 24b22f6a9e9959d5898421627829e80ac64224ff,bc960b1eabaef67914189bbc1475e4ad0f1ade28..8ecad727497e1351dc66cc3f0f571143e1479ed8
@@@ -751,14 -741,12 +751,14 @@@ CONFIG_IMA=
  CONFIG_IMA_DEFAULT_HASH_SHA256=y
  CONFIG_IMA_WRITE_POLICY=y
  CONFIG_IMA_APPRAISE=y
 +CONFIG_FORTIFY_SOURCE=y
 +CONFIG_HARDENED_USERCOPY=y
  CONFIG_BUG_ON_DATA_CORRUPTION=y
  CONFIG_CRYPTO_USER=m
- # CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set
+ CONFIG_CRYPTO_SELFTESTS=y
  CONFIG_CRYPTO_PCRYPT=m
  CONFIG_CRYPTO_CRYPTD=m
- CONFIG_CRYPTO_TEST=m
+ CONFIG_CRYPTO_BENCHMARK=m
  CONFIG_CRYPTO_DH=m
  CONFIG_CRYPTO_ECDH=m
  CONFIG_CRYPTO_ECDSA=m
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc crypto/Makefile
index 186f968baa39efae66c1c7834931029937733136,0b4641c5bbe1fecb7eda0c558b433dfebda3e73e..017df3a2e4bb3174edbf0ed7c8876c02511dc203
@@@ -148,16 -148,14 +148,16 @@@ obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.
  obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
  obj-$(CONFIG_CRYPTO_SEED) += seed.o
  obj-$(CONFIG_CRYPTO_ARIA) += aria_generic.o
- obj-$(CONFIG_CRYPTO_CHACHA20) += chacha_generic.o
- obj-$(CONFIG_CRYPTO_POLY1305) += poly1305_generic.o
+ obj-$(CONFIG_CRYPTO_CHACHA20) += chacha.o
+ CFLAGS_chacha.o += -DARCH=$(ARCH)
  obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
  obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 -obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o
 -obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o
 -CFLAGS_crc32c_generic.o += -DARCH=$(ARCH)
 -CFLAGS_crc32_generic.o += -DARCH=$(ARCH)
 +obj-$(CONFIG_CRYPTO_CRC32C) += crc32c-cryptoapi.o
 +crc32c-cryptoapi-y := crc32c.o
 +CFLAGS_crc32c.o += -DARCH=$(ARCH)
 +obj-$(CONFIG_CRYPTO_CRC32) += crc32-cryptoapi.o
 +crc32-cryptoapi-y := crc32.o
 +CFLAGS_crc32.o += -DARCH=$(ARCH)
  obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
  obj-$(CONFIG_CRYPTO_KRB5ENC) += krb5enc.o
  obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o
diff --cc crypto/crc32.c
index 783a30b27398f5a9ffaa418b3fe9bd939db52ce2,0000000000000000000000000000000000000000..cc371d42601fda164c23ce4c63d328d687ff5b65
mode 100644,000000..100644
--- /dev/null
@@@ -1,182 -1,0 +1,182 @@@
- subsys_initcall(crc32_mod_init);
 +// SPDX-License-Identifier: GPL-2.0-only
 +/*
 + * Copyright 2012 Xyratex Technology Limited
 + */
 +
 +/*
 + * This is crypto api shash wrappers to crc32_le.
 + */
 +
 +#include <linux/unaligned.h>
 +#include <linux/crc32.h>
 +#include <crypto/internal/hash.h>
 +#include <linux/init.h>
 +#include <linux/module.h>
 +#include <linux/string.h>
 +#include <linux/kernel.h>
 +
 +#define CHKSUM_BLOCK_SIZE     1
 +#define CHKSUM_DIGEST_SIZE    4
 +
 +/** No default init with ~0 */
 +static int crc32_cra_init(struct crypto_tfm *tfm)
 +{
 +      u32 *key = crypto_tfm_ctx(tfm);
 +
 +      *key = 0;
 +
 +      return 0;
 +}
 +
 +/*
 + * Setting the seed allows arbitrary accumulators and flexible XOR policy
 + * If your algorithm starts with ~0, then XOR with ~0 before you set
 + * the seed.
 + */
 +static int crc32_setkey(struct crypto_shash *hash, const u8 *key,
 +                      unsigned int keylen)
 +{
 +      u32 *mctx = crypto_shash_ctx(hash);
 +
 +      if (keylen != sizeof(u32))
 +              return -EINVAL;
 +      *mctx = get_unaligned_le32(key);
 +      return 0;
 +}
 +
 +static int crc32_init(struct shash_desc *desc)
 +{
 +      u32 *mctx = crypto_shash_ctx(desc->tfm);
 +      u32 *crcp = shash_desc_ctx(desc);
 +
 +      *crcp = *mctx;
 +
 +      return 0;
 +}
 +
 +static int crc32_update(struct shash_desc *desc, const u8 *data,
 +                      unsigned int len)
 +{
 +      u32 *crcp = shash_desc_ctx(desc);
 +
 +      *crcp = crc32_le_base(*crcp, data, len);
 +      return 0;
 +}
 +
 +static int crc32_update_arch(struct shash_desc *desc, const u8 *data,
 +                           unsigned int len)
 +{
 +      u32 *crcp = shash_desc_ctx(desc);
 +
 +      *crcp = crc32_le(*crcp, data, len);
 +      return 0;
 +}
 +
 +/* No final XOR 0xFFFFFFFF, like crc32_le */
 +static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len,
 +                       u8 *out)
 +{
 +      put_unaligned_le32(crc32_le_base(*crcp, data, len), out);
 +      return 0;
 +}
 +
 +static int __crc32_finup_arch(u32 *crcp, const u8 *data, unsigned int len,
 +                            u8 *out)
 +{
 +      put_unaligned_le32(crc32_le(*crcp, data, len), out);
 +      return 0;
 +}
 +
 +static int crc32_finup(struct shash_desc *desc, const u8 *data,
 +                     unsigned int len, u8 *out)
 +{
 +      return __crc32_finup(shash_desc_ctx(desc), data, len, out);
 +}
 +
 +static int crc32_finup_arch(struct shash_desc *desc, const u8 *data,
 +                     unsigned int len, u8 *out)
 +{
 +      return __crc32_finup_arch(shash_desc_ctx(desc), data, len, out);
 +}
 +
 +static int crc32_final(struct shash_desc *desc, u8 *out)
 +{
 +      u32 *crcp = shash_desc_ctx(desc);
 +
 +      put_unaligned_le32(*crcp, out);
 +      return 0;
 +}
 +
 +static int crc32_digest(struct shash_desc *desc, const u8 *data,
 +                      unsigned int len, u8 *out)
 +{
 +      return __crc32_finup(crypto_shash_ctx(desc->tfm), data, len, out);
 +}
 +
 +static int crc32_digest_arch(struct shash_desc *desc, const u8 *data,
 +                           unsigned int len, u8 *out)
 +{
 +      return __crc32_finup_arch(crypto_shash_ctx(desc->tfm), data, len, out);
 +}
 +
 +static struct shash_alg algs[] = {{
 +      .setkey                 = crc32_setkey,
 +      .init                   = crc32_init,
 +      .update                 = crc32_update,
 +      .final                  = crc32_final,
 +      .finup                  = crc32_finup,
 +      .digest                 = crc32_digest,
 +      .descsize               = sizeof(u32),
 +      .digestsize             = CHKSUM_DIGEST_SIZE,
 +
 +      .base.cra_name          = "crc32",
 +      .base.cra_driver_name   = "crc32-generic",
 +      .base.cra_priority      = 100,
 +      .base.cra_flags         = CRYPTO_ALG_OPTIONAL_KEY,
 +      .base.cra_blocksize     = CHKSUM_BLOCK_SIZE,
 +      .base.cra_ctxsize       = sizeof(u32),
 +      .base.cra_module        = THIS_MODULE,
 +      .base.cra_init          = crc32_cra_init,
 +}, {
 +      .setkey                 = crc32_setkey,
 +      .init                   = crc32_init,
 +      .update                 = crc32_update_arch,
 +      .final                  = crc32_final,
 +      .finup                  = crc32_finup_arch,
 +      .digest                 = crc32_digest_arch,
 +      .descsize               = sizeof(u32),
 +      .digestsize             = CHKSUM_DIGEST_SIZE,
 +
 +      .base.cra_name          = "crc32",
 +      .base.cra_driver_name   = "crc32-" __stringify(ARCH),
 +      .base.cra_priority      = 150,
 +      .base.cra_flags         = CRYPTO_ALG_OPTIONAL_KEY,
 +      .base.cra_blocksize     = CHKSUM_BLOCK_SIZE,
 +      .base.cra_ctxsize       = sizeof(u32),
 +      .base.cra_module        = THIS_MODULE,
 +      .base.cra_init          = crc32_cra_init,
 +}};
 +
 +static int num_algs;
 +
 +static int __init crc32_mod_init(void)
 +{
 +      /* register the arch flavor only if it differs from the generic one */
 +      num_algs = 1 + ((crc32_optimizations() & CRC32_LE_OPTIMIZATION) != 0);
 +
 +      return crypto_register_shashes(algs, num_algs);
 +}
 +
 +static void __exit crc32_mod_fini(void)
 +{
 +      crypto_unregister_shashes(algs, num_algs);
 +}
 +
++module_init(crc32_mod_init);
 +module_exit(crc32_mod_fini);
 +
 +MODULE_AUTHOR("Alexander Boyko <alexander_boyko@xyratex.com>");
 +MODULE_DESCRIPTION("CRC32 calculations wrapper for lib/crc32");
 +MODULE_LICENSE("GPL");
 +MODULE_ALIAS_CRYPTO("crc32");
 +MODULE_ALIAS_CRYPTO("crc32-generic");
diff --cc crypto/crc32c.c
index b1a36d32dc50cdab9511212f0cf12326ddcb19d3,0000000000000000000000000000000000000000..e5377898414a2cbfc34b72ca5be579efe0a0eb17
mode 100644,000000..100644
--- /dev/null
@@@ -1,222 -1,0 +1,222 @@@
- subsys_initcall(crc32c_mod_init);
 +// SPDX-License-Identifier: GPL-2.0-or-later
 +/*
 + * Cryptographic API.
 + *
 + * CRC32C chksum
 + *
 + *@Article{castagnoli-crc,
 + * author =       { Guy Castagnoli and Stefan Braeuer and Martin Herrman},
 + * title =        {{Optimization of Cyclic Redundancy-Check Codes with 24
 + *                 and 32 Parity Bits}},
 + * journal =      IEEE Transactions on Communication,
 + * year =         {1993},
 + * volume =       {41},
 + * number =       {6},
 + * pages =        {},
 + * month =        {June},
 + *}
 + * Used by the iSCSI driver, possibly others, and derived from
 + * the iscsi-crc.c module of the linux-iscsi driver at
 + * http://linux-iscsi.sourceforge.net.
 + *
 + * Following the example of lib/crc32, this function is intended to be
 + * flexible and useful for all users.  Modules that currently have their
 + * own crc32c, but hopefully may be able to use this one are:
 + *  net/sctp (please add all your doco to here if you change to
 + *            use this one!)
 + *  <endoflist>
 + *
 + * Copyright (c) 2004 Cisco Systems, Inc.
 + * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
 + */
 +
 +#include <linux/unaligned.h>
 +#include <crypto/internal/hash.h>
 +#include <linux/init.h>
 +#include <linux/module.h>
 +#include <linux/string.h>
 +#include <linux/kernel.h>
 +#include <linux/crc32.h>
 +
 +#define CHKSUM_BLOCK_SIZE     1
 +#define CHKSUM_DIGEST_SIZE    4
 +
 +struct chksum_ctx {
 +      u32 key;
 +};
 +
 +struct chksum_desc_ctx {
 +      u32 crc;
 +};
 +
 +/*
 + * Steps through buffer one byte at a time, calculates reflected
 + * crc using table.
 + */
 +
 +static int chksum_init(struct shash_desc *desc)
 +{
 +      struct chksum_ctx *mctx = crypto_shash_ctx(desc->tfm);
 +      struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 +
 +      ctx->crc = mctx->key;
 +
 +      return 0;
 +}
 +
 +/*
 + * Setting the seed allows arbitrary accumulators and flexible XOR policy
 + * If your algorithm starts with ~0, then XOR with ~0 before you set
 + * the seed.
 + */
 +static int chksum_setkey(struct crypto_shash *tfm, const u8 *key,
 +                       unsigned int keylen)
 +{
 +      struct chksum_ctx *mctx = crypto_shash_ctx(tfm);
 +
 +      if (keylen != sizeof(mctx->key))
 +              return -EINVAL;
 +      mctx->key = get_unaligned_le32(key);
 +      return 0;
 +}
 +
 +static int chksum_update(struct shash_desc *desc, const u8 *data,
 +                       unsigned int length)
 +{
 +      struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 +
 +      ctx->crc = crc32c_base(ctx->crc, data, length);
 +      return 0;
 +}
 +
 +static int chksum_update_arch(struct shash_desc *desc, const u8 *data,
 +                            unsigned int length)
 +{
 +      struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 +
 +      ctx->crc = crc32c(ctx->crc, data, length);
 +      return 0;
 +}
 +
 +static int chksum_final(struct shash_desc *desc, u8 *out)
 +{
 +      struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 +
 +      put_unaligned_le32(~ctx->crc, out);
 +      return 0;
 +}
 +
 +static int __chksum_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out)
 +{
 +      put_unaligned_le32(~crc32c_base(*crcp, data, len), out);
 +      return 0;
 +}
 +
 +static int __chksum_finup_arch(u32 *crcp, const u8 *data, unsigned int len,
 +                             u8 *out)
 +{
 +      put_unaligned_le32(~crc32c(*crcp, data, len), out);
 +      return 0;
 +}
 +
 +static int chksum_finup(struct shash_desc *desc, const u8 *data,
 +                      unsigned int len, u8 *out)
 +{
 +      struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 +
 +      return __chksum_finup(&ctx->crc, data, len, out);
 +}
 +
 +static int chksum_finup_arch(struct shash_desc *desc, const u8 *data,
 +                           unsigned int len, u8 *out)
 +{
 +      struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 +
 +      return __chksum_finup_arch(&ctx->crc, data, len, out);
 +}
 +
 +static int chksum_digest(struct shash_desc *desc, const u8 *data,
 +                       unsigned int length, u8 *out)
 +{
 +      struct chksum_ctx *mctx = crypto_shash_ctx(desc->tfm);
 +
 +      return __chksum_finup(&mctx->key, data, length, out);
 +}
 +
 +static int chksum_digest_arch(struct shash_desc *desc, const u8 *data,
 +                            unsigned int length, u8 *out)
 +{
 +      struct chksum_ctx *mctx = crypto_shash_ctx(desc->tfm);
 +
 +      return __chksum_finup_arch(&mctx->key, data, length, out);
 +}
 +
 +static int crc32c_cra_init(struct crypto_tfm *tfm)
 +{
 +      struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
 +
 +      mctx->key = ~0;
 +      return 0;
 +}
 +
 +static struct shash_alg algs[] = {{
 +      .digestsize             = CHKSUM_DIGEST_SIZE,
 +      .setkey                 = chksum_setkey,
 +      .init                   = chksum_init,
 +      .update                 = chksum_update,
 +      .final                  = chksum_final,
 +      .finup                  = chksum_finup,
 +      .digest                 = chksum_digest,
 +      .descsize               = sizeof(struct chksum_desc_ctx),
 +
 +      .base.cra_name          = "crc32c",
 +      .base.cra_driver_name   = "crc32c-generic",
 +      .base.cra_priority      = 100,
 +      .base.cra_flags         = CRYPTO_ALG_OPTIONAL_KEY,
 +      .base.cra_blocksize     = CHKSUM_BLOCK_SIZE,
 +      .base.cra_ctxsize       = sizeof(struct chksum_ctx),
 +      .base.cra_module        = THIS_MODULE,
 +      .base.cra_init          = crc32c_cra_init,
 +}, {
 +      .digestsize             = CHKSUM_DIGEST_SIZE,
 +      .setkey                 = chksum_setkey,
 +      .init                   = chksum_init,
 +      .update                 = chksum_update_arch,
 +      .final                  = chksum_final,
 +      .finup                  = chksum_finup_arch,
 +      .digest                 = chksum_digest_arch,
 +      .descsize               = sizeof(struct chksum_desc_ctx),
 +
 +      .base.cra_name          = "crc32c",
 +      .base.cra_driver_name   = "crc32c-" __stringify(ARCH),
 +      .base.cra_priority      = 150,
 +      .base.cra_flags         = CRYPTO_ALG_OPTIONAL_KEY,
 +      .base.cra_blocksize     = CHKSUM_BLOCK_SIZE,
 +      .base.cra_ctxsize       = sizeof(struct chksum_ctx),
 +      .base.cra_module        = THIS_MODULE,
 +      .base.cra_init          = crc32c_cra_init,
 +}};
 +
 +static int num_algs;
 +
 +static int __init crc32c_mod_init(void)
 +{
 +      /* register the arch flavor only if it differs from the generic one */
 +      num_algs = 1 + ((crc32_optimizations() & CRC32C_OPTIMIZATION) != 0);
 +
 +      return crypto_register_shashes(algs, num_algs);
 +}
 +
 +static void __exit crc32c_mod_fini(void)
 +{
 +      crypto_unregister_shashes(algs, num_algs);
 +}
 +
++module_init(crc32c_mod_init);
 +module_exit(crc32c_mod_fini);
 +
 +MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
 +MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations wrapper for lib/crc32c");
 +MODULE_LICENSE("GPL");
 +MODULE_ALIAS_CRYPTO("crc32c");
 +MODULE_ALIAS_CRYPTO("crc32c-generic");
index ff5ab8ada777a4942498044166b7d0532402bec1,a4df8eba75f3ebc82c3a163af97a5fd12d0e071e..d3e2e4f776c695dc59df3ffb6ab5374b6367aff0
@@@ -106,14 -106,14 +106,14 @@@ static void bch2_chacha20_init(struct c
        memzero_explicit(key_words, sizeof(key_words));
  }
  
 -static void bch2_chacha20(const struct bch_key *key, struct nonce nonce,
 -                        void *data, size_t len)
 +void bch2_chacha20(const struct bch_key *key, struct nonce nonce,
 +                 void *data, size_t len)
  {
-       u32 state[CHACHA_STATE_WORDS];
+       struct chacha_state state;
  
-       bch2_chacha20_init(state, key, nonce);
-       chacha20_crypt(state, data, data, len);
-       memzero_explicit(state, sizeof(state));
+       bch2_chacha20_init(&state, key, nonce);
+       chacha20_crypt(&state, data, data, len);
+       chacha_zeroize_state(&state);
  }
  
  static void bch2_poly1305_init(struct poly1305_desc_ctx *desc,