Skip to content

Commit 13d83ea

Browse files
committed
Merge tag 'libcrypto-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux
Pull crypto library updates from Eric Biggers: - Add support for verifying ML-DSA signatures. ML-DSA (Module-Lattice-Based Digital Signature Algorithm) is a recently-standardized post-quantum (quantum-resistant) signature algorithm. It was known as Dilithium pre-standardization. The first use case in the kernel will be module signing. But there are also other users of RSA and ECDSA signatures in the kernel that might want to upgrade to ML-DSA eventually. - Improve the AES library: - Make the AES key expansion and single block encryption and decryption functions use the architecture-optimized AES code. Enable these optimizations by default. - Support preparing an AES key for encryption-only, using about half as much memory as a bidirectional key. - Replace the existing two generic implementations of AES with a single one. - Simplify how Adiantum message hashing is implemented. Remove the "nhpoly1305" crypto_shash in favor of direct lib/crypto/ support for NH hashing, and enable optimizations by default. * tag 'libcrypto-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux: (53 commits) lib/crypto: mldsa: Clarify the documentation for mldsa_verify() slightly lib/crypto: aes: Drop 'volatile' from aes_sbox and aes_inv_sbox lib/crypto: aes: Remove old AES en/decryption functions lib/crypto: aesgcm: Use new AES library API lib/crypto: aescfb: Use new AES library API crypto: omap - Use new AES library API crypto: inside-secure - Use new AES library API crypto: drbg - Use new AES library API crypto: crypto4xx - Use new AES library API crypto: chelsio - Use new AES library API crypto: ccp - Use new AES library API crypto: x86/aes-gcm - Use new AES library API crypto: arm64/ghash - Use new AES library API crypto: arm/ghash - Use new AES library API staging: rtl8723bs: core: Use new AES library API net: phy: mscc: macsec: Use new AES library API chelsio: Use new AES library API Bluetooth: SMP: Use new AES library API crypto: x86/aes - Remove the superseded AES-NI crypto_cipher lib/crypto: x86/aes: Add AES-NI optimization ...
2 parents 3514965 + ffd42b6 commit 13d83ea

141 files changed

Lines changed: 6659 additions & 5255 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.

Documentation/filesystems/fscrypt.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,6 @@ API, but the filenames mode still does.
455455
- Adiantum
456456
- Mandatory:
457457
- CONFIG_CRYPTO_ADIANTUM
458-
- Recommended:
459-
- arm32: CONFIG_CRYPTO_NHPOLY1305_NEON
460-
- arm64: CONFIG_CRYPTO_NHPOLY1305_NEON
461-
- x86: CONFIG_CRYPTO_NHPOLY1305_SSE2
462-
- x86: CONFIG_CRYPTO_NHPOLY1305_AVX2
463458

464459
- AES-128-CBC-ESSIV and AES-128-CBC-CTS:
465460
- Mandatory:

arch/arm/configs/milbeaut_m10v_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ CONFIG_CRYPTO_SELFTESTS=y
9898
CONFIG_CRYPTO_AES=y
9999
CONFIG_CRYPTO_SEQIV=m
100100
CONFIG_CRYPTO_GHASH_ARM_CE=m
101-
CONFIG_CRYPTO_AES_ARM=m
102101
CONFIG_CRYPTO_AES_ARM_BS=m
103102
CONFIG_CRYPTO_AES_ARM_CE=m
104103
# CONFIG_CRYPTO_HW is not set

arch/arm/configs/multi_v7_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=m
12861286
CONFIG_CRYPTO_USER_API_RNG=m
12871287
CONFIG_CRYPTO_USER_API_AEAD=m
12881288
CONFIG_CRYPTO_GHASH_ARM_CE=m
1289-
CONFIG_CRYPTO_AES_ARM=m
1289+
CONFIG_CRYPTO_AES=m
12901290
CONFIG_CRYPTO_AES_ARM_BS=m
12911291
CONFIG_CRYPTO_AES_ARM_CE=m
12921292
CONFIG_CRYPTO_DEV_SUN4I_SS=m

arch/arm/configs/omap2plus_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ CONFIG_NLS_ISO8859_1=y
706706
CONFIG_SECURITY=y
707707
CONFIG_CRYPTO_MICHAEL_MIC=y
708708
CONFIG_CRYPTO_GHASH_ARM_CE=m
709-
CONFIG_CRYPTO_AES_ARM=m
709+
CONFIG_CRYPTO_AES=m
710710
CONFIG_CRYPTO_AES_ARM_BS=m
711711
CONFIG_CRYPTO_DEV_OMAP=m
712712
CONFIG_CRYPTO_DEV_OMAP_SHAM=m

arch/arm/configs/pxa_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ CONFIG_CRYPTO_ANUBIS=m
657657
CONFIG_CRYPTO_XCBC=m
658658
CONFIG_CRYPTO_DEFLATE=y
659659
CONFIG_CRYPTO_LZO=y
660-
CONFIG_CRYPTO_AES_ARM=m
660+
CONFIG_CRYPTO_AES=m
661661
CONFIG_FONTS=y
662662
CONFIG_FONT_8x8=y
663663
CONFIG_FONT_8x16=y

arch/arm/crypto/Kconfig

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,9 @@ config CRYPTO_GHASH_ARM_CE
2323
that is part of the ARMv8 Crypto Extensions, or a slower variant that
2424
uses the vmull.p8 instruction that is part of the basic NEON ISA.
2525

26-
config CRYPTO_NHPOLY1305_NEON
27-
tristate "Hash functions: NHPoly1305 (NEON)"
28-
depends on KERNEL_MODE_NEON
29-
select CRYPTO_NHPOLY1305
30-
help
31-
NHPoly1305 hash function (Adiantum)
32-
33-
Architecture: arm using:
34-
- NEON (Advanced SIMD) extensions
35-
36-
config CRYPTO_AES_ARM
37-
tristate "Ciphers: AES"
38-
select CRYPTO_ALGAPI
39-
select CRYPTO_AES
40-
help
41-
Block ciphers: AES cipher algorithms (FIPS-197)
42-
43-
Architecture: arm
44-
45-
On ARM processors without the Crypto Extensions, this is the
46-
fastest AES implementation for single blocks. For multiple
47-
blocks, the NEON bit-sliced implementation is usually faster.
48-
49-
This implementation may be vulnerable to cache timing attacks,
50-
since it uses lookup tables. However, as countermeasures it
51-
disables IRQs and preloads the tables; it is hoped this makes
52-
such attacks very difficult.
53-
5426
config CRYPTO_AES_ARM_BS
5527
tristate "Ciphers: AES, modes: ECB/CBC/CTR/XTS (bit-sliced NEON)"
5628
depends on KERNEL_MODE_NEON
57-
select CRYPTO_AES_ARM
5829
select CRYPTO_SKCIPHER
5930
select CRYPTO_LIB_AES
6031
help

arch/arm/crypto/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
# Arch-specific CryptoAPI modules.
44
#
55

6-
obj-$(CONFIG_CRYPTO_AES_ARM) += aes-arm.o
76
obj-$(CONFIG_CRYPTO_AES_ARM_BS) += aes-arm-bs.o
8-
obj-$(CONFIG_CRYPTO_NHPOLY1305_NEON) += nhpoly1305-neon.o
97

108
obj-$(CONFIG_CRYPTO_AES_ARM_CE) += aes-arm-ce.o
119
obj-$(CONFIG_CRYPTO_GHASH_ARM_CE) += ghash-arm-ce.o
1210

13-
aes-arm-y := aes-cipher-core.o aes-cipher-glue.o
1411
aes-arm-bs-y := aes-neonbs-core.o aes-neonbs-glue.o
1512
aes-arm-ce-y := aes-ce-core.o aes-ce-glue.o
1613
ghash-arm-ce-y := ghash-ce-core.o ghash-ce-glue.o
17-
nhpoly1305-neon-y := nh-neon-core.o nhpoly1305-neon-glue.o

arch/arm/crypto/aes-cipher-glue.c

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

arch/arm/crypto/aes-cipher.h

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

arch/arm/crypto/aes-neonbs-glue.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <crypto/scatterwalk.h>
1313
#include <crypto/xts.h>
1414
#include <linux/module.h>
15-
#include "aes-cipher.h"
1615

1716
MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
1817
MODULE_DESCRIPTION("Bit sliced AES using NEON instructions");
@@ -48,13 +47,13 @@ struct aesbs_ctx {
4847

4948
struct aesbs_cbc_ctx {
5049
struct aesbs_ctx key;
51-
struct crypto_aes_ctx fallback;
50+
struct aes_enckey fallback;
5251
};
5352

5453
struct aesbs_xts_ctx {
5554
struct aesbs_ctx key;
56-
struct crypto_aes_ctx fallback;
57-
struct crypto_aes_ctx tweak_key;
55+
struct aes_key fallback;
56+
struct aes_enckey tweak_key;
5857
};
5958

6059
static int aesbs_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
@@ -122,14 +121,19 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
122121
struct aesbs_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
123122
int err;
124123

125-
err = aes_expandkey(&ctx->fallback, in_key, key_len);
124+
err = aes_prepareenckey(&ctx->fallback, in_key, key_len);
126125
if (err)
127126
return err;
128127

129128
ctx->key.rounds = 6 + key_len / 4;
130129

130+
/*
131+
* Note: this assumes that the arm implementation of the AES library
132+
* stores the standard round keys in k.rndkeys.
133+
*/
131134
kernel_neon_begin();
132-
aesbs_convert_key(ctx->key.rk, ctx->fallback.key_enc, ctx->key.rounds);
135+
aesbs_convert_key(ctx->key.rk, ctx->fallback.k.rndkeys,
136+
ctx->key.rounds);
133137
kernel_neon_end();
134138

135139
return 0;
@@ -152,8 +156,7 @@ static int cbc_encrypt(struct skcipher_request *req)
152156

153157
do {
154158
crypto_xor_cpy(dst, src, prev, AES_BLOCK_SIZE);
155-
__aes_arm_encrypt(ctx->fallback.key_enc,
156-
ctx->key.rounds, dst, dst);
159+
aes_encrypt(&ctx->fallback, dst, dst);
157160
prev = dst;
158161
src += AES_BLOCK_SIZE;
159162
dst += AES_BLOCK_SIZE;
@@ -239,10 +242,10 @@ static int aesbs_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
239242
return err;
240243

241244
key_len /= 2;
242-
err = aes_expandkey(&ctx->fallback, in_key, key_len);
245+
err = aes_preparekey(&ctx->fallback, in_key, key_len);
243246
if (err)
244247
return err;
245-
err = aes_expandkey(&ctx->tweak_key, in_key + key_len, key_len);
248+
err = aes_prepareenckey(&ctx->tweak_key, in_key + key_len, key_len);
246249
if (err)
247250
return err;
248251

@@ -279,7 +282,7 @@ static int __xts_crypt(struct skcipher_request *req, bool encrypt,
279282
if (err)
280283
return err;
281284

282-
__aes_arm_encrypt(ctx->tweak_key.key_enc, rounds, walk.iv, walk.iv);
285+
aes_encrypt(&ctx->tweak_key, walk.iv, walk.iv);
283286

284287
while (walk.nbytes >= AES_BLOCK_SIZE) {
285288
unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
@@ -311,9 +314,9 @@ static int __xts_crypt(struct skcipher_request *req, bool encrypt,
311314
crypto_xor(buf, req->iv, AES_BLOCK_SIZE);
312315

313316
if (encrypt)
314-
__aes_arm_encrypt(ctx->fallback.key_enc, rounds, buf, buf);
317+
aes_encrypt(&ctx->fallback, buf, buf);
315318
else
316-
__aes_arm_decrypt(ctx->fallback.key_dec, rounds, buf, buf);
319+
aes_decrypt(&ctx->fallback, buf, buf);
317320

318321
crypto_xor(buf, req->iv, AES_BLOCK_SIZE);
319322

0 commit comments

Comments
 (0)