]> git.ipfire.org Git - thirdparty/linux.git/log
thirdparty/linux.git
2 months agocrypto: scompress - Fix scratch allocation failure handling
Herbert Xu [Sat, 15 Mar 2025 12:37:36 +0000 (20:37 +0800)] 
crypto: scompress - Fix scratch allocation failure handling

If the scratch allocation fails, all subsequent allocations will
silently succeed without actually allocating anything.  Fix this
by only incrementing users when the allocation succeeds.

Fixes: 6a8487a1f29f ("crypto: scompress - defer allocation of scratch buffer to first use")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agoubifs: Pass folios to acomp
Herbert Xu [Sat, 15 Mar 2025 10:30:50 +0000 (18:30 +0800)] 
ubifs: Pass folios to acomp

As the acomp interface supports folios, use that instead of mapping
the data in ubifs.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Zhihao Cheng <chengzhihao1@huawei.com> # For xfstests
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agoubifs: Use crypto_acomp interface
Herbert Xu [Sat, 15 Mar 2025 10:30:47 +0000 (18:30 +0800)] 
ubifs: Use crypto_acomp interface

Replace the legacy crypto compression interface with the new acomp
interface.

Remove the compression mutexes and the overallocation for memory
(the offender LZO has been fixed).

Cap the output buffer length for compression to eliminate the
post-compression check for UBIFS_MIN_COMPRESS_DIFF.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Zhihao Cheng <chengzhihao1@huawei.com> # For xfstests
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agoPM: hibernate: Use crypto_acomp interface
Herbert Xu [Sat, 15 Mar 2025 10:30:45 +0000 (18:30 +0800)] 
PM: hibernate: Use crypto_acomp interface

Replace the legacy crypto compression interface with the new acomp
interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agoxfrm: ipcomp: Use crypto_acomp interface
Herbert Xu [Sat, 15 Mar 2025 10:30:43 +0000 (18:30 +0800)] 
xfrm: ipcomp: Use crypto_acomp interface

Replace the legacy comperssion interface with the new acomp
interface.  This is the first user to make full user of the
asynchronous nature of acomp by plugging into the existing xfrm
resume interface.

As a result of SG support by acomp, the linear scratch buffer
in ipcomp can be removed.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: acomp - Add support for folios
Herbert Xu [Sat, 15 Mar 2025 10:30:40 +0000 (18:30 +0800)] 
crypto: acomp - Add support for folios

For many users, it's easier to supply a folio rather than an SG
list since they already have them.  Add support for folios to the
acomp interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: acomp - Add async nondma fallback
Herbert Xu [Sat, 15 Mar 2025 10:30:38 +0000 (18:30 +0800)] 
crypto: acomp - Add async nondma fallback

Add support for passing non-DMA virtual addresses to async drivers
by passing them along to the fallback software algorithm.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: iaa - Use acomp stack fallback
Herbert Xu [Sat, 15 Mar 2025 10:30:36 +0000 (18:30 +0800)] 
crypto: iaa - Use acomp stack fallback

Use ACOMP_REQUEST_ON_STACK instead of allocating legacy fallback
compression transform.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: acomp - Add ACOMP_REQUEST_ALLOC and acomp_request_alloc_extra
Herbert Xu [Sat, 15 Mar 2025 10:30:34 +0000 (18:30 +0800)] 
crypto: acomp - Add ACOMP_REQUEST_ALLOC and acomp_request_alloc_extra

Add ACOMP_REQUEST_ALLOC which is a wrapper around acomp_request_alloc
that falls back to a synchronous stack reqeust if the allocation
fails.

Also add ACOMP_REQUEST_ON_STACK which stores the request on the stack
only.

The request should be freed with acomp_request_free.

Finally add acomp_request_alloc_extra which gives the user extra
memory to use in conjunction with the request.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: scomp - Add chaining and virtual address support
Herbert Xu [Sat, 15 Mar 2025 10:30:31 +0000 (18:30 +0800)] 
crypto: scomp - Add chaining and virtual address support

Add chaining and virtual address support to all scomp algorithms.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: acomp - Remove dst_free
Herbert Xu [Sat, 15 Mar 2025 10:30:29 +0000 (18:30 +0800)] 
crypto: acomp - Remove dst_free

Remove the unused dst_free hook.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - Remove dst_null support
Herbert Xu [Sat, 15 Mar 2025 10:30:27 +0000 (18:30 +0800)] 
crypto: qat - Remove dst_null support

Remove the unused dst_null support.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: iaa - Remove dst_null support
Herbert Xu [Sat, 15 Mar 2025 10:30:24 +0000 (18:30 +0800)] 
crypto: iaa - Remove dst_null support

Remove the unused dst_null support.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: scomp - Remove support for some non-trivial SG lists
Herbert Xu [Sat, 15 Mar 2025 10:30:22 +0000 (18:30 +0800)] 
crypto: scomp - Remove support for some non-trivial SG lists

As the only user of acomp/scomp uses a trivial single-page SG
list, remove support for everything else in preprataion for the
addition of virtual address support.

However, keep support for non-trivial source SG lists as that
user is currently jumping through hoops in order to linearise
the source data.

Limit the source SG linearisation buffer to a single page as
that user never goes over that.  The only other potential user
is also unlikely to exceed that (IPComp) and it can easily do
its own linearisation if necessary.

Also keep the destination SG linearisation for IPComp.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agoxfrm: ipcomp: Call pskb_may_pull in ipcomp_input
Herbert Xu [Sat, 15 Mar 2025 10:30:19 +0000 (18:30 +0800)] 
xfrm: ipcomp: Call pskb_may_pull in ipcomp_input

If a malformed packet is received there may not be enough data
to pull.  This isn't a problem in practice because the caller
has already done xfrm_parse_spi which in effect does the same
thing.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: nx - Fix uninitialised hv_nxc on error
Herbert Xu [Sat, 15 Mar 2025 08:50:42 +0000 (16:50 +0800)] 
crypto: nx - Fix uninitialised hv_nxc on error

The compiler correctly warns that hv_nxc may be used uninitialised
as that will occur when NX-GZIP is unavailable.

Fix it by rearranging the code and delay setting caps_feat until
the final query succeeds.

Fixes: b4ba22114c78 ("crypto/nx: Get NX capabilities for GZIP coprocessor type")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: padlock - Use zero page instead of stack buffer
Herbert Xu [Sat, 15 Mar 2025 08:20:16 +0000 (16:20 +0800)] 
crypto: padlock - Use zero page instead of stack buffer

Use desc instead of a stack buffer in the final function.  This
fixes a compiler warning about buf being uninitialised.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: lib/Kconfig - hide library options
Arnd Bergmann [Fri, 14 Mar 2025 16:05:32 +0000 (17:05 +0100)] 
crypto: lib/Kconfig - hide library options

Any driver that needs these library functions should already be selecting
the corresponding Kconfig symbols, so there is no real point in making
these visible.

The original patch that made these user selectable described problems
with drivers failing to select the code they use, but for consistency
it's better to always use 'select' on a symbol than to mix it with
'depends on'.

Fixes: e56e18985596 ("lib/crypto: add prompts back to crypto libraries")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - remove access to parity register for QAT GEN4
Bairavi Alagappan [Fri, 14 Mar 2025 15:09:31 +0000 (15:09 +0000)] 
crypto: qat - remove access to parity register for QAT GEN4

The firmware already handles parity errors reported by the accelerators
by clearing them through the corresponding SSMSOFTERRORPARITY register.
To ensure consistent behavior and prevent race conditions between the
driver and firmware, remove the logic that checks the SSMSOFTERRORPARITY
registers.

Additionally, change the return type of the function
adf_handle_rf_parr_err() to void, as it consistently returns false.
Parity errors are recoverable and do not necessitate a device reset.

Fixes: 895f7d532c84 ("crypto: qat - add handling of errors from ERRSOU2 for QAT GEN4")
Signed-off-by: Bairavi Alagappan <bairavix.alagappan@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - set parity error mask for qat_420xx
Bairavi Alagappan [Fri, 14 Mar 2025 13:14:29 +0000 (13:14 +0000)] 
crypto: qat - set parity error mask for qat_420xx

The field parerr_wat_wcp_mask in the structure adf_dev_err_mask enables
the detection and reporting of parity errors for the wireless cipher and
wireless authentication accelerators.

Set the parerr_wat_wcp_mask field, which was inadvertently omitted
during the initial enablement of the qat_420xx driver, to ensure that
parity errors are enabled for those accelerators.

In addition, fix the string used to report such errors that was
inadvertently set to "ath_cph" (authentication and cipher).

Fixes: fcf60f4bcf54 ("crypto: qat - add support for 420xx devices")
Signed-off-by: Bairavi Alagappan <bairavix.alagappan@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - optimize allocations for fw authentication
Jack Xu [Fri, 14 Mar 2025 12:57:54 +0000 (12:57 +0000)] 
crypto: qat - optimize allocations for fw authentication

The memory requested to hold the image data for authentication will
never exceed `ICP_QAT_CSS_RSA4K_MAX_IMAGE_LEN`. Therefore, we can
simplify the allocation by always requesting the maximum size needed for
any image.

Also introduce the following checks:
 * Ensure the allocated memory is 8-byte aligned to meet the
   requirements of the authentication firmware.
 * Prevent overflow when constructing the authentication descriptor.

Signed-off-by: Jack Xu <jack.xu@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - remove redundant FW image size check
Jack Xu [Fri, 14 Mar 2025 12:57:53 +0000 (12:57 +0000)] 
crypto: qat - remove redundant FW image size check

The FW image size check is already performed in the function
qat_uclo_check_image() before calling `qat_uclo_map_auth_fw()`.
Therefore, the additional check in `qat_uclo_map_auth_fw()` is redundant
and can be safely removed.

Signed-off-by: Jack Xu <jack.xu@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - remove unused members in suof structure
Jack Xu [Fri, 14 Mar 2025 12:57:52 +0000 (12:57 +0000)] 
crypto: qat - remove unused members in suof structure

Remove the members `css_key` and `css_signature` which are not used for
doing the firmware authentication.

The signed image pointer can be calculated using the pointer to the CSS
header and the length of the CSS header, making these members redundant.

Signed-off-by: Jack Xu <jack.xu@intel.com>
Reviewed-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: hash - Use nth_page instead of doing it by hand
Herbert Xu [Fri, 14 Mar 2025 03:27:23 +0000 (11:27 +0800)] 
crypto: hash - Use nth_page instead of doing it by hand

Use nth_page instead of adding n to the page pointer.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: scatterwalk - Use nth_page instead of doing it by hand
Herbert Xu [Fri, 14 Mar 2025 03:27:20 +0000 (11:27 +0800)] 
crypto: scatterwalk - Use nth_page instead of doing it by hand

Curiously, the Crypto API scatterwalk incremented pages by hand
rather than using nth_page.  Possibly because scatterwalk predates
nth_page (the following commit is from the history tree):

commit 3957f2b34960d85b63e814262a8be7d5ad91444d
Author: James Morris <jmorris@intercode.com.au>
Date:   Sun Feb 2 07:35:32 2003 -0800

    [CRYPTO]: in/out scatterlist support for ciphers.

Fix this by using nth_page.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: tegra - Fix format specifier in tegra_sha_prep_cmd()
Nathan Chancellor [Thu, 13 Mar 2025 15:29:31 +0000 (16:29 +0100)] 
crypto: tegra - Fix format specifier in tegra_sha_prep_cmd()

When building for 32-bit targets, for which ssize_t is 'int' instead of
'long', there is a warning due to an incorrect format specifier:

  In file included from include/linux/printk.h:610,
                   from include/linux/kernel.h:31,
                   from include/linux/clk.h:13,
                   from drivers/crypto/tegra/tegra-se-hash.c:7:
  drivers/crypto/tegra/tegra-se-hash.c: In function 'tegra_sha_prep_cmd':
  drivers/crypto/tegra/tegra-se-hash.c:343:26: error: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'ssize_t' {aka 'int'} [-Werror=format=]
    343 |         dev_dbg(se->dev, "msg len %llu msg left %llu sz %lu cfg %#x",
        |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ...
  drivers/crypto/tegra/tegra-se-hash.c:343:59: note: format string is defined here
    343 |         dev_dbg(se->dev, "msg len %llu msg left %llu sz %lu cfg %#x",
        |                                                         ~~^
        |                                                           |
        |                                                           long unsigned int
        |                                                         %u
  cc1: all warnings being treated as errors

Use '%zd', the proper specifier for ssize_t, to resolve the warning.

Fixes: ff4b7df0b511 ("crypto: tegra - Fix HASH intermediate result handling")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: hash - Fix test underflow in shash_ahash_digest
Herbert Xu [Thu, 13 Mar 2025 05:14:58 +0000 (13:14 +0800)] 
crypto: hash - Fix test underflow in shash_ahash_digest

The test on PAGE_SIZE - offset in shash_ahash_digest can underflow,
leading to execution of the fast path even if the data cannot be
mapped into a single page.

Fix this by splitting the test into four cases:

1) nbytes > sg->length: More than one SG entry, slow path.
2) !IS_ENABLED(CONFIG_HIGHMEM): fast path.
3) nbytes > (unsigned int)PAGE_SIZE - offset: Two highmem pages, slow path.
4) Highmem fast path.

Fixes: 5f7082ed4f48 ("crypto: hash - Export shash through hash")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: krb5 - Use SG miter instead of doing it by hand
Herbert Xu [Thu, 13 Mar 2025 05:14:56 +0000 (13:14 +0800)] 
crypto: krb5 - Use SG miter instead of doing it by hand

The function crypto_shash_update_sg iterates through an SG by
hand.  It fails to handle corner cases such as SG entries longer
than a page.  Fix this by using the SG iterator.

Fixes: 348f5669d1f6 ("crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agolib/scatterlist: Add SG_MITER_LOCAL and use it
Herbert Xu [Thu, 13 Mar 2025 05:14:53 +0000 (13:14 +0800)] 
lib/scatterlist: Add SG_MITER_LOCAL and use it

Add kmap_local support to the scatterlist iterator.  Use it for
all the helper functions in lib/scatterlist.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - introduce fuse array
Suman Kumar Chakraborty [Wed, 12 Mar 2025 11:39:38 +0000 (11:39 +0000)] 
crypto: qat - introduce fuse array

Change the representation of fuses in the accelerator device
structure from a single value to an array.

This allows the structure to accommodate additional fuses that
are required for future generations of QAT hardware.

This does not introduce any functional changes.

Signed-off-by: Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: scatterwalk - simplify map and unmap calling convention
Eric Biggers [Mon, 10 Mar 2025 17:20:16 +0000 (10:20 -0700)] 
crypto: scatterwalk - simplify map and unmap calling convention

Now that the address returned by scatterwalk_map() is always being
stored into the same struct scatter_walk that is passed in, make
scatterwalk_map() do so itself and return void.

Similarly, now that scatterwalk_unmap() is always being passed the
address field within a struct scatter_walk, make scatterwalk_unmap()
take a pointer to struct scatter_walk instead of the address directly.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2 months agocrypto: qat - add macro to write 64-bit values to registers
Suman Kumar Chakraborty [Mon, 10 Mar 2025 16:15:40 +0000 (16:15 +0000)] 
crypto: qat - add macro to write 64-bit values to registers

Introduce the ADF_CSR_WR_LO_HI macro to simplify writing a 64-bit values
to hardware registers.

This macro works by splitting the 64-bit value into two 32-bit segments,
which are then written separately to the specified lower and upper
register offsets.

Update the adf_gen4_set_ssm_wdtimer() function to utilize this newly
introduced macro.

Signed-off-by: Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: testmgr - Remove NULL dst acomp tests
Herbert Xu [Sun, 9 Mar 2025 02:43:24 +0000 (10:43 +0800)] 
crypto: testmgr - Remove NULL dst acomp tests

In preparation for the partial removal of NULL dst acomp support,
remove the tests for them.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: acomp - Add request chaining and virtual addresses
Herbert Xu [Sun, 9 Mar 2025 02:43:21 +0000 (10:43 +0800)] 
crypto: acomp - Add request chaining and virtual addresses

This adds request chaining and virtual address support to the
acomp interface.

It is identical to the ahash interface, except that a new flag
CRYPTO_ACOMP_REQ_NONDMA has been added to indicate that the
virtual addresses are not suitable for DMA.  This is because
all existing and potential acomp users can provide memory that
is suitable for DMA so there is no need for a fall-back copy
path.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: scomp - Disable BH when taking per-cpu spin lock
Herbert Xu [Sun, 9 Mar 2025 02:43:19 +0000 (10:43 +0800)] 
crypto: scomp - Disable BH when taking per-cpu spin lock

Disable BH when taking per-cpu spin locks.  This isn't an issue
right now because the only user zswap calls scomp from process
context.  However, if scomp is called from softirq context the
spin lock may dead-lock.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: acomp - Move stream management into scomp layer
Herbert Xu [Sun, 9 Mar 2025 02:43:17 +0000 (10:43 +0800)] 
crypto: acomp - Move stream management into scomp layer

Rather than allocating the stream memory in the request object,
move it into a per-cpu buffer managed by scomp.  This takes the
stress off the user from having to manage large request objects
and setting up their own per-cpu buffers in order to do so.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: scomp - Remove tfm argument from alloc/free_ctx
Herbert Xu [Sun, 9 Mar 2025 02:43:14 +0000 (10:43 +0800)] 
crypto: scomp - Remove tfm argument from alloc/free_ctx

The tfm argument is completely unused and meaningless as the
same stream object is identical over all transforms of a given
algorithm.  Remove it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: api - Add cra_type->destroy hook
Herbert Xu [Sun, 9 Mar 2025 02:43:12 +0000 (10:43 +0800)] 
crypto: api - Add cra_type->destroy hook

Add a cra_type->destroy hook so that resources can be freed after
the last user of a registered algorithm is gone.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: artpec6 - change from kzalloc to kcalloc in artpec6_crypto_probe()
Ethan Carter Edwards [Sun, 9 Mar 2025 00:30:52 +0000 (19:30 -0500)] 
crypto: artpec6 - change from kzalloc to kcalloc in artpec6_crypto_probe()

We are trying to get rid of all multiplications from allocation
functions to prevent potential integer overflows. Here the
multiplication is probably safe, but using kcalloc() is more
appropriate and improves readability. This patch has no effect
on runtime behavior.

Link: https://github.com/KSPP/linux/issues/162
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
Acked-by: Jesper Nilsson <jesper.nilsson@axis.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: skcipher - Make skcipher_walk src.virt.addr const
Herbert Xu [Sat, 8 Mar 2025 12:53:13 +0000 (20:53 +0800)] 
crypto: skcipher - Make skcipher_walk src.virt.addr const

Mark the src.virt.addr field in struct skcipher_walk as a pointer
to const data.  This guarantees that the user won't modify the data
which should be done through dst.virt.addr to ensure that flushing
is done when necessary.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: skcipher - Eliminate duplicate virt.addr field
Herbert Xu [Sat, 8 Mar 2025 12:45:25 +0000 (20:45 +0800)] 
crypto: skcipher - Eliminate duplicate virt.addr field

Reuse the addr field from struct scatter_walk for skcipher_walk.

Keep the existing virt.addr fields but make them const for the
user to access the mapped address.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: scatterwalk - Add memcpy_sglist
Herbert Xu [Sat, 8 Mar 2025 12:45:23 +0000 (20:45 +0800)] 
crypto: scatterwalk - Add memcpy_sglist

Add memcpy_sglist which copies one SG list to another.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: scatterwalk - Change scatterwalk_next calling convention
Herbert Xu [Sat, 8 Mar 2025 12:45:21 +0000 (20:45 +0800)] 
crypto: scatterwalk - Change scatterwalk_next calling convention

Rather than returning the address and storing the length into an
argument pointer, add an address field to the walk struct and use
that to store the address.  The length is returned directly.

Change the done functions to use this stored address instead of
getting them from the caller.

Split the address into two using a union.  The user should only
access the const version so that it is never changed.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: ccp - Fix uAPI definitions of PSP errors
Dionna Glaze [Sat, 8 Mar 2025 01:10:28 +0000 (12:10 +1100)] 
crypto: ccp - Fix uAPI definitions of PSP errors

Additions to the error enum after explicit 0x27 setting for
SEV_RET_INVALID_KEY leads to incorrect value assignments.

Use explicit values to match the manufacturer specifications more
clearly.

Fixes: 3a45dc2b419e ("crypto: ccp: Define the SEV-SNP commands")
CC: stable@vger.kernel.org
Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Alexey Kardashevskiy <aik@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agodt-bindings: rng: rockchip,rk3588-rng: Drop unnecessary status from example
Krzysztof Kozlowski [Fri, 7 Mar 2025 09:33:09 +0000 (10:33 +0100)] 
dt-bindings: rng: rockchip,rk3588-rng: Drop unnecessary status from example

Device nodes are enabled by default, so no need for 'status = "okay"' in
the DTS example.

Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agoMAINTAINERS: Add Lukas & Ignat & Stefan for asymmetric keys
Lukas Wunner [Wed, 5 Mar 2025 17:14:32 +0000 (18:14 +0100)] 
MAINTAINERS: Add Lukas & Ignat & Stefan for asymmetric keys

Herbert asks for long-term maintenance of everything under
crypto/asymmetric_keys/ and associated algorithms (ECDSA, GOST, RSA) [1].

Ignat has kindly agreed to co-maintain this with me going forward.

Stefan has agreed to be added as reviewer for ECDSA.  He introduced it
in 2021 and has been meticulously providing reviews for 3rd party
patches anyway.

Retain David Howells' maintainer entry until he explicitly requests to
be removed.  He originally introduced asymmetric keys in 2012.

RSA was introduced by Tadeusz Struk as an employee of Intel in 2015,
but he's changed jobs and last contributed to the implementation in 2016.

GOST was introduced by Vitaly Chikunov as an employee of Basealt LLC [2]
(Базальт СПО [3]) in 2019.  This company is an OFAC sanctioned entity
[4][5], which makes employees ineligible as maintainer [6].  It's not
clear if Vitaly is still working for Basealt, he did not immediately
respond to my e-mail.  Since knowledge and use of GOST algorithms is
relatively limited outside the Russian Federation, assign "Odd fixes"
status for now.

[1] https://lore.kernel.org/r/Z8QNJqQKhyyft_gz@gondor.apana.org.au/
[2] https://prohoster.info/ru/blog/novosti-interneta/reliz-yadra-linux-5-2
[3] https://www.basealt.ru/
[4] https://ofac.treasury.gov/recent-actions/20240823
[5] https://sanctionssearch.ofac.treas.gov/Details.aspx?id=50178
[6] https://lore.kernel.org/r/7ee74c1b5b589619a13c6318c9fbd0d6ac7c334a.camel@HansenPartnership.com/

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Acked-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: octeontx2 - suppress auth failure screaming due to negative tests
Shashank Gupta [Wed, 5 Mar 2025 07:57:05 +0000 (13:27 +0530)] 
crypto: octeontx2 - suppress auth failure screaming due to negative tests

This patch addresses an issue where authentication failures were being
erroneously reported due to negative test failures in the "ccm(aes)"
selftest.
pr_debug suppress unnecessary screaming of these tests.

Signed-off-by: Shashank Gupta <shashankg@marvell.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agoMAINTAINERS: add myself to co-maintain ZSTD
David Sterba [Tue, 4 Mar 2025 12:46:58 +0000 (13:46 +0100)] 
MAINTAINERS: add myself to co-maintain ZSTD

Recently the ZSTD tree has been removed from linux-next due to lack of
updates for last year [1]. As there are several users of ZSTD in kernel
we need to keep the code maintained and updated. I'll act as a backup to
get the ZSTD upstream to linux, Nick is OK with that [2].

[1] https://lore.kernel.org/all/20250216224200.50b9dd6a@canb.auug.org.au/
[2] https://github.com/facebook/zstd/issues/4262#issuecomment-2691527952

CC: Nick Terrell <terrelln@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Nick Terrell <terrelln@fb.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: virtio - Erase some sensitive memory when it is freed
Christophe JAILLET [Mon, 3 Mar 2025 19:08:04 +0000 (20:08 +0100)] 
crypto: virtio - Erase some sensitive memory when it is freed

virtcrypto_clear_request() does the same as the code here, but uses
kfree_sensitive() for one of the free operation.

So, better safe than sorry, use virtcrypto_clear_request() directly to
save a few lines of code and cleanly free the memory.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Tested-by: Lei Yang <leiyang@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agoasync_xor: Remove unused 'async_xor_val'
Dr. David Alan Gilbert [Sun, 29 Sep 2024 13:21:48 +0000 (14:21 +0100)] 
async_xor: Remove unused 'async_xor_val'

async_xor_val has been unused since commit
a7c224a820c3 ("md/raid5: convert to new xor compution interface")

Remove it.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: skcipher - fix mismatch between mapping and unmapping order
Eric Biggers [Thu, 6 Mar 2025 03:33:05 +0000 (19:33 -0800)] 
crypto: skcipher - fix mismatch between mapping and unmapping order

Local kunmaps have to be unmapped in the opposite order from which they
were mapped.  My recent change flipped the unmap order in the
SKCIPHER_WALK_DIFF case.  Adjust the mapping side to match.

This fixes a WARN_ON_ONCE that was triggered when running the
crypto-self tests on a 32-bit kernel with
CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP=y.

Fixes: 95dbd711b1d8 ("crypto: skcipher - use the new scatterwalk functions")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: Kconfig - Select LIB generic option
Herbert Xu [Mon, 3 Mar 2025 03:09:06 +0000 (11:09 +0800)] 
crypto: Kconfig - Select LIB generic option

Select the generic LIB options if the Crypto API algorithm is
enabled.  Otherwise this may lead to a build failure as the Crypto
API algorithm always uses the generic implementation.

Fixes: 17ec3e71ba79 ("crypto: lib/Kconfig - Hide arch options from user")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202503022113.79uEtUuy-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202503022115.9OOyDR5A-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: lib/chachapoly - Drop dependency on CRYPTO_ALGAPI
Ard Biesheuvel [Fri, 28 Feb 2025 12:11:38 +0000 (13:11 +0100)] 
crypto: lib/chachapoly - Drop dependency on CRYPTO_ALGAPI

The ChaCha20-Poly1305 library code uses the sg_miter API to process
input presented via scatterlists, except for the special case where the
digest buffer is not covered entirely by the same scatterlist entry as
the last byte of input. In that case, it uses scatterwalk_map_and_copy()
to access the memory in the input scatterlist where the digest is stored.

This results in a dependency on crypto/scatterwalk.c and therefore on
CONFIG_CRYPTO_ALGAPI, which is unnecessary, as the sg_miter API already
provides this functionality via sg_copy_to_buffer(). So use that
instead, and drop the dependencies on CONFIG_CRYPTO_ALGAPI and
CONFIG_CRYPTO.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agodt-bindings: crypto: qcom,prng: document QCS615
Abhinaba Rakshit [Thu, 27 Feb 2025 20:15:54 +0000 (01:45 +0530)] 
dt-bindings: crypto: qcom,prng: document QCS615

Document QCS615 compatible for True Random Number Generator.

Signed-off-by: Abhinaba Rakshit <quic_arakshit@quicinc.com>
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: acomp - Remove acomp request flags
Herbert Xu [Thu, 27 Feb 2025 10:14:57 +0000 (18:14 +0800)] 
crypto: acomp - Remove acomp request flags

The acomp request flags field duplicates the base request flags
and is confusing.  Remove it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: iaa - Test the correct request flag
Herbert Xu [Thu, 27 Feb 2025 10:14:55 +0000 (18:14 +0800)] 
crypto: iaa - Test the correct request flag

Test the correct flags for the MAY_SLEEP bit.

Fixes: 2ec6761df889 ("crypto: iaa - Add support for deflate-iaa compression algorithm")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: lzo - Fix compression buffer overrun
Herbert Xu [Thu, 27 Feb 2025 09:04:46 +0000 (17:04 +0800)] 
crypto: lzo - Fix compression buffer overrun

Unlike the decompression code, the compression code in LZO never
checked for output overruns.  It instead assumes that the caller
always provides enough buffer space, disregarding the buffer length
provided by the caller.

Add a safe compression interface that checks for the end of buffer
before each write.  Use the safe interface in crypto/lzo.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agodt-bindings: crypto: inside-secure,safexcel: Allow dma-coherent
Rob Herring (Arm) [Wed, 26 Feb 2025 21:42:43 +0000 (15:42 -0600)] 
dt-bindings: crypto: inside-secure,safexcel: Allow dma-coherent

Some platforms like Marvell are cache coherent, so allow the
"dma-coherent" property.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: api - Move struct crypto_type into internal.h
Herbert Xu [Tue, 25 Feb 2025 05:03:26 +0000 (13:03 +0800)] 
crypto: api - Move struct crypto_type into internal.h

Move the definition of struct crypto_type into internal.h as it
is only used by API implementors and not algorithm implementors.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Use HMAC fallback when keyslots are full
Akhil R [Mon, 24 Feb 2025 09:16:10 +0000 (14:46 +0530)] 
crypto: tegra - Use HMAC fallback when keyslots are full

The intermediate results for HMAC is stored in the allocated keyslot by
the hardware. Dynamic allocation of keyslot during an operation is hence
not possible. As the number of keyslots are limited in the hardware,
fallback to the HMAC software implementation if keyslots are not available

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Reserve keyslots to allocate dynamically
Akhil R [Mon, 24 Feb 2025 09:16:09 +0000 (14:46 +0530)] 
crypto: tegra - Reserve keyslots to allocate dynamically

The HW supports only storing 15 keys at a time. This limits the number
of tfms that can work without failutes. Reserve keyslots to solve this
and use the reserved ones during the encryption/decryption operation.
This allow users to have the capability of hardware protected keys
and faster operations if there are limited number of tfms while not
halting the operation if there are more tfms.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Set IV to NULL explicitly for AES ECB
Akhil R [Mon, 24 Feb 2025 09:16:08 +0000 (14:46 +0530)] 
crypto: tegra - Set IV to NULL explicitly for AES ECB

It may happen that the variable req->iv may have stale values or
zero sized buffer by default and may end up getting used during
encryption/decryption. This inturn may corrupt the results or break the
operation. Set the req->iv variable to NULL explicitly for algorithms
like AES-ECB where IV is not used.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Fix CMAC intermediate result handling
Akhil R [Mon, 24 Feb 2025 09:16:07 +0000 (14:46 +0530)] 
crypto: tegra - Fix CMAC intermediate result handling

Saving and restoring of the intermediate results are needed if there is
context switch caused by another ongoing request on the same engine.
This is therefore not only to support import/export functionality.
Hence, save and restore the intermediate result for every non-first task.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Fix HASH intermediate result handling
Akhil R [Mon, 24 Feb 2025 09:16:06 +0000 (14:46 +0530)] 
crypto: tegra - Fix HASH intermediate result handling

The intermediate hash values generated during an update task were
handled incorrectly in the driver. The values have a defined format for
each algorithm. Copying and pasting from the HASH_RESULT register
balantly would not work for all the supported algorithms. This incorrect
handling causes failures when there is a context switch between multiple
operations.

To handle the expected format correctly, add a separate buffer for
storing the intermediate results for each request. Remove the previous
copy/paste functions which read/wrote to the registers directly. Instead
configure the hardware to get the intermediate result copied to the
buffer and use host1x path to restore the intermediate hash results.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Transfer HASH init function to crypto engine
Akhil R [Mon, 24 Feb 2025 09:16:05 +0000 (14:46 +0530)] 
crypto: tegra - Transfer HASH init function to crypto engine

Ahash init() function was called asynchronous to the crypto engine queue.
This could corrupt the request context if there is any ongoing operation
for the same request. Queue the init function as well to the crypto
engine queue so that this scenario can be avoided.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - check return value for hash do_one_req
Akhil R [Mon, 24 Feb 2025 09:16:04 +0000 (14:46 +0530)] 
crypto: tegra - check return value for hash do_one_req

Initialize and check the return value in hash *do_one_req() functions
and exit the function if there is an error. This fixes the
'uninitialized variable' warnings reported by testbots.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202412071747.flPux4oB-lkp@intel.com/
Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - finalize crypto req on error
Akhil R [Mon, 24 Feb 2025 09:16:03 +0000 (14:46 +0530)] 
crypto: tegra - finalize crypto req on error

Call the crypto finalize function before exiting *do_one_req() functions.
This allows the driver to take up further requests even if the previous
one fails.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Do not use fixed size buffers
Akhil R [Mon, 24 Feb 2025 09:16:02 +0000 (14:46 +0530)] 
crypto: tegra - Do not use fixed size buffers

Allocate the buffer based on the request instead of a fixed buffer
length. In operations which may require larger buffer size, a fixed
buffer may fail.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: tegra - Use separate buffer for setkey
Akhil R [Mon, 24 Feb 2025 09:16:01 +0000 (14:46 +0530)] 
crypto: tegra - Use separate buffer for setkey

The buffer which sends the commands to host1x was shared for all tasks
in the engine. This causes a problem with the setkey() function as it
gets called asynchronous to the crypto engine queue. Modifying the same
cmdbuf in setkey() will corrupt the ongoing host1x task and in turn
break the encryption/decryption operation. Hence use a separate cmdbuf
for setkey().

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: mxs-dcp - Only set OTP_KEY bit for OTP key
Sven Schwermer [Mon, 24 Feb 2025 07:42:25 +0000 (08:42 +0100)] 
crypto: mxs-dcp - Only set OTP_KEY bit for OTP key

While MXS_DCP_CONTROL0_OTP_KEY is set, the CRYPTO_KEY (DCP_PAES_KEY_OTP)
is used even if the UNIQUE_KEY (DCP_PAES_KEY_UNIQUE) is selected. This
is not clearly documented, but this implementation is consistent with
NXP's downstream kernel fork and optee_os.

Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agoMerge tag 'crypto-krb5-20250303' of git://git.kernel.org/pub/scm/linux/kernel/git...
Herbert Xu [Sat, 8 Mar 2025 07:03:20 +0000 (15:03 +0800)] 
Merge tag 'crypto-krb5-20250303' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git

Pull Kerberos crypto library from David Howells:

crypto: Add Kerberos crypto lib

It does a couple of things:

 (1) Provide an AEAD crypto driver, krb5enc, that mirrors the authenc
     driver, but that hashes the plaintext, not the ciphertext.  This was
     made a separate module rather than just being a part of the authenc
     driver because it has to do all of the constituent operations in the
     opposite order - which impacts the async op handling.

     Testmgr data is provided for AES+SHA2 and Camellia combinations of
     authenc and krb5enc used by the krb5 library.  AES+SHA1 is not
     provided as the RFCs don't contain usable test vectors.

 (2) Provide a Kerberos 5 crypto library.  This is an extract from the
     sunrpc driver as that code can be shared between sunrpc/nfs and
     rxrpc/afs.  This provides encryption, decryption, get MIC and verify
     MIC routines that use and wrap the crypto functions, along with some
     functions to provide layout management.

     This supports AES+SHA1, AES+SHA2 and Camellia encryption types.

     Self-testing is provided that goes further than is possible with
     testmgr, doing subkey derivation as well.

The patches were previously posted here:

    https://lore.kernel.org/r/20250203142343.248839-1-dhowells@redhat.com/

as part of a larger series, but the networking guys would prefer these to
go through the crypto tree.  If you want them reposting independently, I
can do that.

3 months agocrypto/krb5: Implement crypto self-testing
David Howells [Mon, 3 Feb 2025 13:44:37 +0000 (13:44 +0000)] 
crypto/krb5: Implement crypto self-testing

Implement self-testing infrastructure to test the pseudo-random function,
key derivation, encryption and checksumming.

Add the testing data from rfc8009 to test AES + HMAC-SHA2.

Add the testing data from rfc6803 to test Camellia.  Note some encryption
test vectors here are incomplete, lacking the key usage number needed to
derive Ke and Ki, and there are errata for this:

https://www.rfc-editor.org/errata_search.php?rfc=6803

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement the Camellia enctypes from rfc6803
David Howells [Fri, 25 Sep 2020 11:24:50 +0000 (12:24 +0100)] 
crypto/krb5: Implement the Camellia enctypes from rfc6803

Implement the camellia128-cts-cmac and camellia256-cts-cmac enctypes from
rfc6803.

Note that the test vectors in rfc6803 for encryption are incomplete,
lacking the key usage number needed to derive Ke and Ki, and there are
errata for this:

https://www.rfc-editor.org/errata_search.php?rfc=6803

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement the AES enctypes from rfc8009
David Howells [Mon, 3 Feb 2025 13:42:41 +0000 (13:42 +0000)] 
crypto/krb5: Implement the AES enctypes from rfc8009

Implement the aes128-cts-hmac-sha256-128 and aes256-cts-hmac-sha384-192
enctypes from rfc8009, overriding the rfc3961 kerberos 5 simplified crypto
scheme.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement the AES enctypes from rfc3962
David Howells [Thu, 3 Sep 2020 11:05:04 +0000 (12:05 +0100)] 
crypto/krb5: Implement the AES enctypes from rfc3962

Implement the aes128-cts-hmac-sha1-96 and aes256-cts-hmac-sha1-96 enctypes
from rfc3962, using the rfc3961 kerberos 5 simplified crypto scheme.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic
David Howells [Thu, 24 Sep 2020 09:23:48 +0000 (10:23 +0100)] 
crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic

Add functions that sign and verify a message according to rfc3961 sec 5.4,
using Kc to generate a checksum and insert it into the MIC field in the
skbuff in the sign phase then checksum the data and compare it to the MIC
in the verify phase.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt functions
David Howells [Thu, 24 Sep 2020 07:31:06 +0000 (08:31 +0100)] 
crypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt functions

Add functions that encrypt and decrypt a message according to rfc3961 sec
5.3, using Ki to checksum the data to be secured and Ke to encrypt it
during the encryption phase, then decrypting with Ke and verifying the
checksum with Ki in the decryption phase.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Provide RFC3961 setkey packaging functions
David Howells [Fri, 17 Jan 2025 13:20:34 +0000 (13:20 +0000)] 
crypto/krb5: Provide RFC3961 setkey packaging functions

Provide functions to derive keys according to RFC3961 (or load the derived
keys for the selftester where only derived keys are available) and to
package them up appropriately for passing to a krb5enc AEAD setkey or a
hash setkey function.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement the Kerberos5 rfc3961 key derivation
David Howells [Thu, 3 Sep 2020 11:05:04 +0000 (12:05 +0100)] 
crypto/krb5: Implement the Kerberos5 rfc3961 key derivation

Implement the simplified crypto profile for Kerberos 5 rfc3961 with the
pseudo-random function, PRF(), from section 5.3 and the key derivation
function, DK() from section 5.1.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Provide infrastructure and key derivation
David Howells [Thu, 3 Sep 2020 11:05:04 +0000 (12:05 +0100)] 
crypto/krb5: Provide infrastructure and key derivation

Provide key derivation interface functions and a helper to implement the
PRF+ function from rfc4402.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Add an API to perform requests
David Howells [Thu, 9 Jan 2025 09:03:35 +0000 (09:03 +0000)] 
crypto/krb5: Add an API to perform requests

Add an API by which users of the krb5 crypto library can perform crypto
requests, such as encrypt, decrypt, get_mic and verify_mic.  These
functions take the previously prepared crypto objects to work on.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Add an API to alloc and prepare a crypto object
David Howells [Fri, 17 Jan 2025 13:29:24 +0000 (13:29 +0000)] 
crypto/krb5: Add an API to alloc and prepare a crypto object

Add an API by which users of the krb5 crypto library can get an allocated
and keyed crypto object.

For encryption-mode operation, an AEAD object is returned; for
checksum-mode operation, a synchronous hash object is returned.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Add an API to query the layout of the crypto section
David Howells [Thu, 19 Nov 2020 09:46:48 +0000 (09:46 +0000)] 
crypto/krb5: Add an API to query the layout of the crypto section

Provide some functions to allow the called to find out about the layout of
the crypto section:

 (1) Calculate, for a given size of data, how big a buffer will be
     required to hold it and where the data will be within it.

 (2) Calculate, for an amount of buffer, what's the maximum size of data
     that will fit therein, and where it will start.

 (3) Determine where the data will be in a received message.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Implement Kerberos crypto core
David Howells [Tue, 10 Nov 2020 17:00:54 +0000 (17:00 +0000)] 
crypto/krb5: Implement Kerberos crypto core

Provide core structures, an encoding-type registry and basic module and
config bits for a generic Kerberos crypto library.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Test manager data
David Howells [Thu, 9 Jan 2025 20:13:55 +0000 (20:13 +0000)] 
crypto/krb5: Test manager data

Add Kerberos crypto tests to the test manager database.  This covers:

camellia128-cts-cmac samples from RFC6803
camellia256-cts-cmac samples from RFC6803
aes128-cts-hmac-sha256-128 samples from RFC8009
aes256-cts-hmac-sha384-192 samples from RFC8009

but not:

aes128-cts-hmac-sha1-96
aes256-cts-hmac-sha1-96

as the test samples in RFC3962 don't seem to be suitable.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto: Add 'krb5enc' hash and cipher AEAD algorithm
David Howells [Fri, 17 Jan 2025 11:46:23 +0000 (11:46 +0000)] 
crypto: Add 'krb5enc' hash and cipher AEAD algorithm

Add an AEAD template that does hash-then-cipher (unlike authenc that does
cipher-then-hash).  This is required for a number of Kerberos 5 encoding
types.

[!] Note that the net/sunrpc/auth_gss/ implementation gets a pair of
ciphers, one non-CTS and one CTS, using the former to do all the aligned
blocks and the latter to do the last two blocks if they aren't also
aligned.  It may be necessary to do this here too for performance reasons -
but there are considerations both ways:

 (1) firstly, there is an optimised assembly version of cts(cbc(aes)) on
     x86_64 that should be used instead of having two ciphers;

 (2) secondly, none of the hardware offload drivers seem to offer CTS
     support (Intel QAT does not, for instance).

However, I don't know if it's possible to query the crypto API to find out
whether there's an optimised CTS algorithm available.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Add some constants out of sunrpc headers
David Howells [Tue, 10 Nov 2020 23:57:35 +0000 (23:57 +0000)] 
crypto/krb5: Add some constants out of sunrpc headers

Add some constants from the sunrpc headers.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto/krb5: Add API Documentation
David Howells [Fri, 14 Apr 2023 10:35:12 +0000 (11:35 +0100)] 
crypto/krb5: Add API Documentation

Add API documentation for the kerberos crypto library.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org

3 months agocrypto: lib/Kconfig - Hide arch options from user
Herbert Xu [Thu, 27 Feb 2025 07:48:39 +0000 (15:48 +0800)] 
crypto: lib/Kconfig - Hide arch options from user

The ARCH_MAY_HAVE patch missed arm64, mips and s390.  But it may
also lead to arch options being enabled but ineffective because
of modular/built-in conflicts.

As the primary user of all these options wireguard is selecting
the arch options anyway, make the same selections at the lib/crypto
option level and hide the arch options from the user.

Instead of selecting them centrally from lib/crypto, simply set
the default of each arch option as suggested by Eric Biggers.

Change the Crypto API generic algorithms to select the top-level
lib/crypto options instead of the generic one as otherwise there
is no way to enable the arch options (Eric Biggers).  Introduce a
set of INTERNAL options to work around dependency cycles on the
CONFIG_CRYPTO symbol.

Fixes: 1047e21aecdf ("crypto: lib/Kconfig - Fix lib built-in failure when arch is modular")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Arnd Bergmann <arnd@kernel.org>
Closes: https://lore.kernel.org/oe-kbuild-all/202502232152.JC84YDLp-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: skcipher - Use restrict rather than hand-rolling accesses
Herbert Xu [Sun, 23 Feb 2025 06:27:51 +0000 (14:27 +0800)] 
crypto: skcipher - Use restrict rather than hand-rolling accesses

Rather than accessing 'alg' directly to avoid the aliasing issue
which leads to unnecessary reloads, use the __restrict keyword
to explicitly tell the compiler that there is no aliasing.

This generates equivalent if not superior code on x86 with gcc 12.

Note that in skcipher_walk_virt the alg assignment is moved after
might_sleep_if because that function is a compiler barrier and
forces a reload.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: octeontx - Remove unused function otx_cpt_eng_grp_has_eng_type
Dr. David Alan Gilbert [Sun, 23 Feb 2025 00:56:46 +0000 (00:56 +0000)] 
crypto: octeontx - Remove unused function otx_cpt_eng_grp_has_eng_type

otx_cpt_eng_grp_has_eng_type() was added in 2020 by
commit d9110b0b01ff ("crypto: marvell - add support for OCTEON TX CPT
engine")
but has remained unused.

Remove it.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: octeontx2 - Remove unused otx2_cpt_print_uc_dbg_info
Dr. David Alan Gilbert [Sun, 23 Feb 2025 00:53:54 +0000 (00:53 +0000)] 
crypto: octeontx2 - Remove unused otx2_cpt_print_uc_dbg_info

otx2_cpt_print_uc_dbg_info() has been unused since 2023's
commit 82f89f1aa6ca ("crypto: octeontx2 - add devlink option to set t106
mode")

Remove it and the get_engs_info() helper it's the only user of.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agodt-bindings: crypto: Convert fsl,sec-2.0 to YAML
J. Neuschäfer [Thu, 20 Feb 2025 11:57:35 +0000 (12:57 +0100)] 
dt-bindings: crypto: Convert fsl,sec-2.0 to YAML

Convert the Freescale security engine (crypto accelerator) binding from
text form to YAML. The list of compatible strings reflects what was
previously described in prose; not all combinations occur in existing
devicetrees.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: scatterwalk - don't split at page boundaries when !HIGHMEM
Eric Biggers [Wed, 19 Feb 2025 18:23:41 +0000 (10:23 -0800)] 
crypto: scatterwalk - don't split at page boundaries when !HIGHMEM

When !HIGHMEM, the kmap_local_page() in the scatterlist walker does not
actually map anything, and the address it returns is just the address
from the kernel's direct map, where each sg entry's data is virtually
contiguous.  To improve performance, stop unnecessarily clamping data
segments to page boundaries in this case.

For now, still limit segments to PAGE_SIZE.  This is needed to prevent
preemption from being disabled for too long when SIMD is used, and to
support the alignmask case which still uses a page-sized bounce buffer.

Even so, this change still helps a lot in cases where messages cross a
page boundary.  For example, testing IPsec with AES-GCM on x86_64, the
messages are 1424 bytes which is less than PAGE_SIZE, but on the Rx side
over a third cross a page boundary.  These ended up being processed in
three parts, with the middle part going through skcipher_next_slow which
uses a 16-byte bounce buffer.  That was causing a significant amount of
overhead which unnecessarily reduced the performance benefit of the new
x86_64 AES-GCM assembly code.  This change solves the problem; all these
messages now get passed to the assembly code in one part.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: scatterwalk - remove obsolete functions
Eric Biggers [Wed, 19 Feb 2025 18:23:40 +0000 (10:23 -0800)] 
crypto: scatterwalk - remove obsolete functions

Remove various functions that are no longer used.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: skcipher - use the new scatterwalk functions
Eric Biggers [Wed, 19 Feb 2025 18:23:39 +0000 (10:23 -0800)] 
crypto: skcipher - use the new scatterwalk functions

Convert skcipher_walk to use the new scatterwalk functions.

This includes a few changes to exactly where the different parts of the
iteration happen.  For example the dcache flush that previously happened
in scatterwalk_done() now happens in scatterwalk_dst_done() or in
memcpy_to_scatterwalk().  Advancing to the next sg entry now happens
just-in-time in scatterwalk_clamp() instead of in scatterwalk_done().

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agonet/tls: use the new scatterwalk functions
Eric Biggers [Wed, 19 Feb 2025 18:23:38 +0000 (10:23 -0800)] 
net/tls: use the new scatterwalk functions

Replace calls to the deprecated function scatterwalk_copychunks() with
memcpy_from_scatterwalk(), memcpy_to_scatterwalk(), or
scatterwalk_skip() as appropriate.  The new functions generally behave
more as expected and eliminate the need to call scatterwalk_done() or
scatterwalk_pagedone().

However, the new functions intentionally do not advance to the next sg
entry right away, which would have broken chain_to_walk() which is
accessing the fields of struct scatter_walk directly.  To avoid this,
replace chain_to_walk() with scatterwalk_get_sglist() which supports the
needed functionality.

Cc: Boris Pismenny <borisp@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: x86/aegis - use the new scatterwalk functions
Eric Biggers [Wed, 19 Feb 2025 18:23:37 +0000 (10:23 -0800)] 
crypto: x86/aegis - use the new scatterwalk functions

In crypto_aegis128_aesni_process_ad(), use scatterwalk_next() which
consolidates scatterwalk_clamp() and scatterwalk_map().  Use
scatterwalk_done_src() which consolidates scatterwalk_unmap(),
scatterwalk_advance(), and scatterwalk_done().

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: x86/aes-gcm - use the new scatterwalk functions
Eric Biggers [Wed, 19 Feb 2025 18:23:36 +0000 (10:23 -0800)] 
crypto: x86/aes-gcm - use the new scatterwalk functions

In gcm_process_assoc(), use scatterwalk_next() which consolidates
scatterwalk_clamp() and scatterwalk_map().  Use scatterwalk_done_src()
which consolidates scatterwalk_unmap(), scatterwalk_advance(), and
scatterwalk_done().

Also rename some variables to avoid implying that anything is actually
mapped (it's not), or that the loop is going page by page (it is for
now, but nothing actually requires that to be the case).

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
3 months agocrypto: stm32 - use the new scatterwalk functions
Eric Biggers [Wed, 19 Feb 2025 18:23:35 +0000 (10:23 -0800)] 
crypto: stm32 - use the new scatterwalk functions

Replace calls to the deprecated function scatterwalk_copychunks() with
memcpy_from_scatterwalk(), memcpy_to_scatterwalk(), scatterwalk_skip(),
or scatterwalk_start_at_pos() as appropriate.

Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Maxime Méré <maxime.mere@foss.st.com>
Cc: Thomas Bourgoin <thomas.bourgoin@foss.st.com>
Cc: linux-stm32@st-md-mailman.stormreply.com
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>