Skip to content

Commit c2a24a7

Browse files
committed
Merge tag 'v5.20-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto updates from Herbert Xu: "API: - Make proc files report fips module name and version Algorithms: - Move generic SHA1 code into lib/crypto - Implement Chinese Remainder Theorem for RSA - Remove blake2s - Add XCTR with x86/arm64 acceleration - Add POLYVAL with x86/arm64 acceleration - Add HCTR2 - Add ARIA Drivers: - Add support for new CCP/PSP device ID in ccp" * tag 'v5.20-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (89 commits) crypto: tcrypt - Remove the static variable initialisations to NULL crypto: arm64/poly1305 - fix a read out-of-bound crypto: hisilicon/zip - Use the bitmap API to allocate bitmaps crypto: hisilicon/sec - fix auth key size error crypto: ccree - Remove a useless dma_supported() call crypto: ccp - Add support for new CCP/PSP device ID crypto: inside-secure - Add missing MODULE_DEVICE_TABLE for of crypto: hisilicon/hpre - don't use GFP_KERNEL to alloc mem during softirq crypto: testmgr - some more fixes to RSA test vectors cyrpto: powerpc/aes - delete the rebundant word "block" in comments hwrng: via - Fix comment typo crypto: twofish - Fix comment typo crypto: rmd160 - fix Kconfig "its" grammar crypto: keembay-ocs-ecc - Drop if with an always false condition Documentation: qat: rewrite description Documentation: qat: Use code block for qat sysfs example crypto: lib - add module license to libsha1 crypto: lib - make the sha1 library optional crypto: lib - move lib/sha1.c into lib/crypto/ crypto: fips - make proc files report fips module name and version ...
2 parents a0b09f2 + af5d35b commit c2a24a7

114 files changed

Lines changed: 9140 additions & 1203 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
What: /sys/bus/pci/devices/<BDF>/qat/state
2+
Date: June 2022
3+
KernelVersion: 5.20
4+
Contact: qat-linux@intel.com
5+
Description: (RW) Reports the current state of the QAT device. Write to
6+
the file to start or stop the device.
7+
8+
The values are:
9+
10+
* up: the device is up and running
11+
* down: the device is down
12+
13+
14+
It is possible to transition the device from up to down only
15+
if the device is up and vice versa.
16+
17+
This attribute is only available for qat_4xxx devices.
18+
19+
What: /sys/bus/pci/devices/<BDF>/qat/cfg_services
20+
Date: June 2022
21+
KernelVersion: 5.20
22+
Contact: qat-linux@intel.com
23+
Description: (RW) Reports the current configuration of the QAT device.
24+
Write to the file to change the configured services.
25+
26+
The values are:
27+
28+
* sym;asym: the device is configured for running crypto
29+
services
30+
* dc: the device is configured for running compression services
31+
32+
It is possible to set the configuration only if the device
33+
is in the `down` state (see /sys/bus/pci/devices/<BDF>/qat/state)
34+
35+
The following example shows how to change the configuration of
36+
a device configured for running crypto services in order to
37+
run data compression::
38+
39+
# cat /sys/bus/pci/devices/<BDF>/qat/state
40+
up
41+
# cat /sys/bus/pci/devices/<BDF>/qat/cfg_services
42+
sym;asym
43+
# echo down > /sys/bus/pci/devices/<BDF>/qat/state
44+
# echo dc > /sys/bus/pci/devices/<BDF>/qat/cfg_services
45+
# echo up > /sys/bus/pci/devices/<BDF>/qat/state
46+
# cat /sys/bus/pci/devices/<BDF>/qat/cfg_services
47+
dc
48+
49+
This attribute is only available for qat_4xxx devices.

Documentation/filesystems/fscrypt.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ Currently, the following pairs of encryption modes are supported:
337337
- AES-256-XTS for contents and AES-256-CTS-CBC for filenames
338338
- AES-128-CBC for contents and AES-128-CTS-CBC for filenames
339339
- Adiantum for both contents and filenames
340+
- AES-256-XTS for contents and AES-256-HCTR2 for filenames (v2 policies only)
340341

341342
If unsure, you should use the (AES-256-XTS, AES-256-CTS-CBC) pair.
342343

@@ -357,6 +358,17 @@ To use Adiantum, CONFIG_CRYPTO_ADIANTUM must be enabled. Also, fast
357358
implementations of ChaCha and NHPoly1305 should be enabled, e.g.
358359
CONFIG_CRYPTO_CHACHA20_NEON and CONFIG_CRYPTO_NHPOLY1305_NEON for ARM.
359360

361+
AES-256-HCTR2 is another true wide-block encryption mode that is intended for
362+
use on CPUs with dedicated crypto instructions. AES-256-HCTR2 has the property
363+
that a bitflip in the plaintext changes the entire ciphertext. This property
364+
makes it desirable for filename encryption since initialization vectors are
365+
reused within a directory. For more details on AES-256-HCTR2, see the paper
366+
"Length-preserving encryption with HCTR2"
367+
(https://eprint.iacr.org/2021/1441.pdf). To use AES-256-HCTR2,
368+
CONFIG_CRYPTO_HCTR2 must be enabled. Also, fast implementations of XCTR and
369+
POLYVAL should be enabled, e.g. CRYPTO_POLYVAL_ARM64_CE and
370+
CRYPTO_AES_ARM64_CE_BLK for ARM64.
371+
360372
New encryption modes can be added relatively easily, without changes
361373
to individual filesystems. However, authenticated encryption (AE)
362374
modes are not currently supported because of the difficulty of dealing
@@ -404,11 +416,11 @@ alternatively has the file's nonce (for `DIRECT_KEY policies`_) or
404416
inode number (for `IV_INO_LBLK_64 policies`_) included in the IVs.
405417
Thus, IV reuse is limited to within a single directory.
406418

407-
With CTS-CBC, the IV reuse means that when the plaintext filenames
408-
share a common prefix at least as long as the cipher block size (16
409-
bytes for AES), the corresponding encrypted filenames will also share
410-
a common prefix. This is undesirable. Adiantum does not have this
411-
weakness, as it is a wide-block encryption mode.
419+
With CTS-CBC, the IV reuse means that when the plaintext filenames share a
420+
common prefix at least as long as the cipher block size (16 bytes for AES), the
421+
corresponding encrypted filenames will also share a common prefix. This is
422+
undesirable. Adiantum and HCTR2 do not have this weakness, as they are
423+
wide-block encryption modes.
412424

413425
All supported filenames encryption modes accept any plaintext length
414426
>= 16 bytes; cipher block alignment is not required. However,

MAINTAINERS

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9079,16 +9079,25 @@ S: Supported
90799079
F: Documentation/admin-guide/perf/hns3-pmu.rst
90809080
F: drivers/perf/hisilicon/hns3_pmu.c
90819081

9082-
HISILICON QM AND ZIP Controller DRIVER
9082+
HISILICON QM DRIVER
9083+
M: Weili Qian <qianweili@huawei.com>
90839084
M: Zhou Wang <wangzhou1@hisilicon.com>
90849085
L: linux-crypto@vger.kernel.org
90859086
S: Maintained
9086-
F: Documentation/ABI/testing/debugfs-hisi-zip
9087+
F: drivers/crypto/hisilicon/Kconfig
9088+
F: drivers/crypto/hisilicon/Makefile
90879089
F: drivers/crypto/hisilicon/qm.c
90889090
F: drivers/crypto/hisilicon/sgl.c
9089-
F: drivers/crypto/hisilicon/zip/
90909091
F: include/linux/hisi_acc_qm.h
90919092

9093+
HISILICON ZIP Controller DRIVER
9094+
M: Yang Shen <shenyang39@huawei.com>
9095+
M: Zhou Wang <wangzhou1@hisilicon.com>
9096+
L: linux-crypto@vger.kernel.org
9097+
S: Maintained
9098+
F: Documentation/ABI/testing/debugfs-hisi-zip
9099+
F: drivers/crypto/hisilicon/zip/
9100+
90929101
HISILICON ROCE DRIVER
90939102
M: Wenpeng Liang <liangwenpeng@huawei.com>
90949103
M: Weihang Li <liweihang@huawei.com>

arch/arm/crypto/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ config CRYPTO_SHA512_ARM
6363
using optimized ARM assembler and NEON, when available.
6464

6565
config CRYPTO_BLAKE2S_ARM
66-
tristate "BLAKE2s digest algorithm (ARM)"
66+
bool "BLAKE2s digest algorithm (ARM)"
6767
select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
6868
help
6969
BLAKE2s digest algorithm optimized with ARM scalar instructions. This

arch/arm/crypto/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o
99
obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o
1010
obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o
1111
obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o
12-
obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += blake2s-arm.o
13-
obj-$(if $(CONFIG_CRYPTO_BLAKE2S_ARM),y) += libblake2s-arm.o
12+
obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += libblake2s-arm.o
1413
obj-$(CONFIG_CRYPTO_BLAKE2B_NEON) += blake2b-neon.o
1514
obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha-neon.o
1615
obj-$(CONFIG_CRYPTO_POLY1305_ARM) += poly1305-arm.o
@@ -32,7 +31,6 @@ sha256-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha256_neon_glue.o
3231
sha256-arm-y := sha256-core.o sha256_glue.o $(sha256-arm-neon-y)
3332
sha512-arm-neon-$(CONFIG_KERNEL_MODE_NEON) := sha512-neon-glue.o
3433
sha512-arm-y := sha512-core.o sha512-glue.o $(sha512-arm-neon-y)
35-
blake2s-arm-y := blake2s-shash.o
3634
libblake2s-arm-y:= blake2s-core.o blake2s-glue.o
3735
blake2b-neon-y := blake2b-neon-core.o blake2b-neon-glue.o
3836
sha1-arm-ce-y := sha1-ce-core.o sha1-ce-glue.o

arch/arm/crypto/blake2s-shash.c

Lines changed: 0 additions & 75 deletions
This file was deleted.

arch/arm64/crypto/Kconfig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ config CRYPTO_GHASH_ARM64_CE
7171
select CRYPTO_HASH
7272
select CRYPTO_GF128MUL
7373
select CRYPTO_LIB_AES
74+
select CRYPTO_AEAD
75+
76+
config CRYPTO_POLYVAL_ARM64_CE
77+
tristate "POLYVAL using ARMv8 Crypto Extensions (for HCTR2)"
78+
depends on KERNEL_MODE_NEON
79+
select CRYPTO_POLYVAL
7480

7581
config CRYPTO_CRCT10DIF_ARM64_CE
7682
tristate "CRCT10DIF digest algorithm using PMULL instructions"
@@ -96,13 +102,13 @@ config CRYPTO_AES_ARM64_CE_CCM
96102
select CRYPTO_LIB_AES
97103

98104
config CRYPTO_AES_ARM64_CE_BLK
99-
tristate "AES in ECB/CBC/CTR/XTS modes using ARMv8 Crypto Extensions"
105+
tristate "AES in ECB/CBC/CTR/XTS/XCTR modes using ARMv8 Crypto Extensions"
100106
depends on KERNEL_MODE_NEON
101107
select CRYPTO_SKCIPHER
102108
select CRYPTO_AES_ARM64_CE
103109

104110
config CRYPTO_AES_ARM64_NEON_BLK
105-
tristate "AES in ECB/CBC/CTR/XTS modes using NEON instructions"
111+
tristate "AES in ECB/CBC/CTR/XTS/XCTR modes using NEON instructions"
106112
depends on KERNEL_MODE_NEON
107113
select CRYPTO_SKCIPHER
108114
select CRYPTO_LIB_AES

arch/arm64/crypto/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ sm4-neon-y := sm4-neon-glue.o sm4-neon-core.o
3232
obj-$(CONFIG_CRYPTO_GHASH_ARM64_CE) += ghash-ce.o
3333
ghash-ce-y := ghash-ce-glue.o ghash-ce-core.o
3434

35+
obj-$(CONFIG_CRYPTO_POLYVAL_ARM64_CE) += polyval-ce.o
36+
polyval-ce-y := polyval-ce-glue.o polyval-ce-core.o
37+
3538
obj-$(CONFIG_CRYPTO_CRCT10DIF_ARM64_CE) += crct10dif-ce.o
3639
crct10dif-ce-y := crct10dif-ce-core.o crct10dif-ce-glue.o
3740

arch/arm64/crypto/aes-glue.c

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
#define aes_essiv_cbc_encrypt ce_aes_essiv_cbc_encrypt
3535
#define aes_essiv_cbc_decrypt ce_aes_essiv_cbc_decrypt
3636
#define aes_ctr_encrypt ce_aes_ctr_encrypt
37+
#define aes_xctr_encrypt ce_aes_xctr_encrypt
3738
#define aes_xts_encrypt ce_aes_xts_encrypt
3839
#define aes_xts_decrypt ce_aes_xts_decrypt
3940
#define aes_mac_update ce_aes_mac_update
40-
MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 Crypto Extensions");
41+
MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS/XCTR using ARMv8 Crypto Extensions");
4142
#else
4243
#define MODE "neon"
4344
#define PRIO 200
@@ -50,16 +51,18 @@ MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 Crypto Extensions");
5051
#define aes_essiv_cbc_encrypt neon_aes_essiv_cbc_encrypt
5152
#define aes_essiv_cbc_decrypt neon_aes_essiv_cbc_decrypt
5253
#define aes_ctr_encrypt neon_aes_ctr_encrypt
54+
#define aes_xctr_encrypt neon_aes_xctr_encrypt
5355
#define aes_xts_encrypt neon_aes_xts_encrypt
5456
#define aes_xts_decrypt neon_aes_xts_decrypt
5557
#define aes_mac_update neon_aes_mac_update
56-
MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 NEON");
58+
MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS/XCTR using ARMv8 NEON");
5759
#endif
5860
#if defined(USE_V8_CRYPTO_EXTENSIONS) || !IS_ENABLED(CONFIG_CRYPTO_AES_ARM64_BS)
5961
MODULE_ALIAS_CRYPTO("ecb(aes)");
6062
MODULE_ALIAS_CRYPTO("cbc(aes)");
6163
MODULE_ALIAS_CRYPTO("ctr(aes)");
6264
MODULE_ALIAS_CRYPTO("xts(aes)");
65+
MODULE_ALIAS_CRYPTO("xctr(aes)");
6366
#endif
6467
MODULE_ALIAS_CRYPTO("cts(cbc(aes))");
6568
MODULE_ALIAS_CRYPTO("essiv(cbc(aes),sha256)");
@@ -89,6 +92,9 @@ asmlinkage void aes_cbc_cts_decrypt(u8 out[], u8 const in[], u32 const rk[],
8992
asmlinkage void aes_ctr_encrypt(u8 out[], u8 const in[], u32 const rk[],
9093
int rounds, int bytes, u8 ctr[]);
9194

95+
asmlinkage void aes_xctr_encrypt(u8 out[], u8 const in[], u32 const rk[],
96+
int rounds, int bytes, u8 ctr[], int byte_ctr);
97+
9298
asmlinkage void aes_xts_encrypt(u8 out[], u8 const in[], u32 const rk1[],
9399
int rounds, int bytes, u32 const rk2[], u8 iv[],
94100
int first);
@@ -442,6 +448,52 @@ static int __maybe_unused essiv_cbc_decrypt(struct skcipher_request *req)
442448
return err ?: cbc_decrypt_walk(req, &walk);
443449
}
444450

451+
static int __maybe_unused xctr_encrypt(struct skcipher_request *req)
452+
{
453+
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
454+
struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
455+
int err, rounds = 6 + ctx->key_length / 4;
456+
struct skcipher_walk walk;
457+
unsigned int byte_ctr = 0;
458+
459+
err = skcipher_walk_virt(&walk, req, false);
460+
461+
while (walk.nbytes > 0) {
462+
const u8 *src = walk.src.virt.addr;
463+
unsigned int nbytes = walk.nbytes;
464+
u8 *dst = walk.dst.virt.addr;
465+
u8 buf[AES_BLOCK_SIZE];
466+
467+
/*
468+
* If given less than 16 bytes, we must copy the partial block
469+
* into a temporary buffer of 16 bytes to avoid out of bounds
470+
* reads and writes. Furthermore, this code is somewhat unusual
471+
* in that it expects the end of the data to be at the end of
472+
* the temporary buffer, rather than the start of the data at
473+
* the start of the temporary buffer.
474+
*/
475+
if (unlikely(nbytes < AES_BLOCK_SIZE))
476+
src = dst = memcpy(buf + sizeof(buf) - nbytes,
477+
src, nbytes);
478+
else if (nbytes < walk.total)
479+
nbytes &= ~(AES_BLOCK_SIZE - 1);
480+
481+
kernel_neon_begin();
482+
aes_xctr_encrypt(dst, src, ctx->key_enc, rounds, nbytes,
483+
walk.iv, byte_ctr);
484+
kernel_neon_end();
485+
486+
if (unlikely(nbytes < AES_BLOCK_SIZE))
487+
memcpy(walk.dst.virt.addr,
488+
buf + sizeof(buf) - nbytes, nbytes);
489+
byte_ctr += nbytes;
490+
491+
err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
492+
}
493+
494+
return err;
495+
}
496+
445497
static int __maybe_unused ctr_encrypt(struct skcipher_request *req)
446498
{
447499
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
@@ -457,6 +509,14 @@ static int __maybe_unused ctr_encrypt(struct skcipher_request *req)
457509
u8 *dst = walk.dst.virt.addr;
458510
u8 buf[AES_BLOCK_SIZE];
459511

512+
/*
513+
* If given less than 16 bytes, we must copy the partial block
514+
* into a temporary buffer of 16 bytes to avoid out of bounds
515+
* reads and writes. Furthermore, this code is somewhat unusual
516+
* in that it expects the end of the data to be at the end of
517+
* the temporary buffer, rather than the start of the data at
518+
* the start of the temporary buffer.
519+
*/
460520
if (unlikely(nbytes < AES_BLOCK_SIZE))
461521
src = dst = memcpy(buf + sizeof(buf) - nbytes,
462522
src, nbytes);
@@ -669,6 +729,22 @@ static struct skcipher_alg aes_algs[] = { {
669729
.setkey = skcipher_aes_setkey,
670730
.encrypt = ctr_encrypt,
671731
.decrypt = ctr_encrypt,
732+
}, {
733+
.base = {
734+
.cra_name = "xctr(aes)",
735+
.cra_driver_name = "xctr-aes-" MODE,
736+
.cra_priority = PRIO,
737+
.cra_blocksize = 1,
738+
.cra_ctxsize = sizeof(struct crypto_aes_ctx),
739+
.cra_module = THIS_MODULE,
740+
},
741+
.min_keysize = AES_MIN_KEY_SIZE,
742+
.max_keysize = AES_MAX_KEY_SIZE,
743+
.ivsize = AES_BLOCK_SIZE,
744+
.chunksize = AES_BLOCK_SIZE,
745+
.setkey = skcipher_aes_setkey,
746+
.encrypt = xctr_encrypt,
747+
.decrypt = xctr_encrypt,
672748
}, {
673749
.base = {
674750
.cra_name = "xts(aes)",

0 commit comments

Comments
 (0)