Skip to content

Commit 8394bfe

Browse files
zx2c4herbertx
authored andcommitted
crypto: arch - conditionalize crypto api in arch glue for lib code
For glue code that's used by Zinc, the actual Crypto API functions might not necessarily exist, and don't need to exist either. Before this patch, there are valid build configurations that lead to a unbuildable kernel. This fixes it to conditionalize those symbols on the existence of the proper config entry. Signed-off-by: Jason A. Donenfeld <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 4ee812f commit 8394bfe

File tree

11 files changed

+53
-32
lines changed

11 files changed

+53
-32
lines changed

arch/arm/crypto/chacha-glue.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,13 @@ static struct skcipher_alg neon_algs[] = {
286286

287287
static int __init chacha_simd_mod_init(void)
288288
{
289-
int err;
289+
int err = 0;
290290

291-
err = crypto_register_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
292-
if (err)
293-
return err;
291+
if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER)) {
292+
err = crypto_register_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
293+
if (err)
294+
return err;
295+
}
294296

295297
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON)) {
296298
int i;
@@ -310,18 +312,22 @@ static int __init chacha_simd_mod_init(void)
310312
static_branch_enable(&use_neon);
311313
}
312314

313-
err = crypto_register_skciphers(neon_algs, ARRAY_SIZE(neon_algs));
314-
if (err)
315-
crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
315+
if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER)) {
316+
err = crypto_register_skciphers(neon_algs, ARRAY_SIZE(neon_algs));
317+
if (err)
318+
crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
319+
}
316320
}
317321
return err;
318322
}
319323

320324
static void __exit chacha_simd_mod_fini(void)
321325
{
322-
crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
323-
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON))
324-
crypto_unregister_skciphers(neon_algs, ARRAY_SIZE(neon_algs));
326+
if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER)) {
327+
crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
328+
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON))
329+
crypto_unregister_skciphers(neon_algs, ARRAY_SIZE(neon_algs));
330+
}
325331
}
326332

327333
module_init(chacha_simd_mod_init);

arch/arm/crypto/curve25519-glue.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ static int __init mod_init(void)
108108
{
109109
if (elf_hwcap & HWCAP_NEON) {
110110
static_branch_enable(&have_neon);
111-
return crypto_register_kpp(&curve25519_alg);
111+
return IS_REACHABLE(CONFIG_CRYPTO_KPP) ?
112+
crypto_register_kpp(&curve25519_alg) : 0;
112113
}
113114
return 0;
114115
}
115116

116117
static void __exit mod_exit(void)
117118
{
118-
if (elf_hwcap & HWCAP_NEON)
119+
if (IS_REACHABLE(CONFIG_CRYPTO_KPP) && elf_hwcap & HWCAP_NEON)
119120
crypto_unregister_kpp(&curve25519_alg);
120121
}
121122

arch/arm/crypto/poly1305-glue.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,19 @@ static int __init arm_poly1305_mod_init(void)
249249
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
250250
(elf_hwcap & HWCAP_NEON))
251251
static_branch_enable(&have_neon);
252-
else
252+
else if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
253253
/* register only the first entry */
254254
return crypto_register_shash(&arm_poly1305_algs[0]);
255255

256-
return crypto_register_shashes(arm_poly1305_algs,
257-
ARRAY_SIZE(arm_poly1305_algs));
256+
return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
257+
crypto_register_shashes(arm_poly1305_algs,
258+
ARRAY_SIZE(arm_poly1305_algs)) : 0;
258259
}
259260

260261
static void __exit arm_poly1305_mod_exit(void)
261262
{
263+
if (!IS_REACHABLE(CONFIG_CRYPTO_HASH))
264+
return;
262265
if (!static_branch_likely(&have_neon)) {
263266
crypto_unregister_shash(&arm_poly1305_algs[0]);
264267
return;

arch/arm64/crypto/chacha-neon-glue.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,13 @@ static int __init chacha_simd_mod_init(void)
211211

212212
static_branch_enable(&have_neon);
213213

214-
return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
214+
return IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) ?
215+
crypto_register_skciphers(algs, ARRAY_SIZE(algs)) : 0;
215216
}
216217

217218
static void __exit chacha_simd_mod_fini(void)
218219
{
219-
if (cpu_have_named_feature(ASIMD))
220+
if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) && cpu_have_named_feature(ASIMD))
220221
crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
221222
}
222223

arch/arm64/crypto/poly1305-glue.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ static int __init neon_poly1305_mod_init(void)
220220

221221
static_branch_enable(&have_neon);
222222

223-
return crypto_register_shash(&neon_poly1305_alg);
223+
return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
224+
crypto_register_shash(&neon_poly1305_alg) : 0;
224225
}
225226

226227
static void __exit neon_poly1305_mod_exit(void)
227228
{
228-
if (cpu_have_named_feature(ASIMD))
229+
if (IS_REACHABLE(CONFIG_CRYPTO_HASH) && cpu_have_named_feature(ASIMD))
229230
crypto_unregister_shash(&neon_poly1305_alg);
230231
}
231232

arch/mips/crypto/chacha-glue.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ static struct skcipher_alg algs[] = {
128128

129129
static int __init chacha_simd_mod_init(void)
130130
{
131-
return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
131+
return IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) ?
132+
crypto_register_skciphers(algs, ARRAY_SIZE(algs)) : 0;
132133
}
133134

134135
static void __exit chacha_simd_mod_fini(void)
135136
{
136-
crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
137+
if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER))
138+
crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
137139
}
138140

139141
module_init(chacha_simd_mod_init);

arch/mips/crypto/poly1305-glue.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ static struct shash_alg mips_poly1305_alg = {
187187

188188
static int __init mips_poly1305_mod_init(void)
189189
{
190-
return crypto_register_shash(&mips_poly1305_alg);
190+
return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
191+
crypto_register_shash(&mips_poly1305_alg) : 0;
191192
}
192193

193194
static void __exit mips_poly1305_mod_exit(void)
194195
{
195-
crypto_unregister_shash(&mips_poly1305_alg);
196+
if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
197+
crypto_unregister_shash(&mips_poly1305_alg);
196198
}
197199

198200
module_init(mips_poly1305_mod_init);

arch/x86/crypto/blake2s-glue.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,14 @@ static int __init blake2s_mod_init(void)
210210
XFEATURE_MASK_AVX512, NULL))
211211
static_branch_enable(&blake2s_use_avx512);
212212

213-
return crypto_register_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs));
213+
return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
214+
crypto_register_shashes(blake2s_algs,
215+
ARRAY_SIZE(blake2s_algs)) : 0;
214216
}
215217

216218
static void __exit blake2s_mod_exit(void)
217219
{
218-
if (boot_cpu_has(X86_FEATURE_SSSE3))
220+
if (IS_REACHABLE(CONFIG_CRYPTO_HASH) && boot_cpu_has(X86_FEATURE_SSSE3))
219221
crypto_unregister_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs));
220222
}
221223

arch/x86/crypto/chacha_glue.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,13 @@ static int __init chacha_simd_mod_init(void)
299299
boot_cpu_has(X86_FEATURE_AVX512BW)) /* kmovq */
300300
static_branch_enable(&chacha_use_avx512vl);
301301
}
302-
return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
302+
return IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) ?
303+
crypto_register_skciphers(algs, ARRAY_SIZE(algs)) : 0;
303304
}
304305

305306
static void __exit chacha_simd_mod_fini(void)
306307
{
307-
if (boot_cpu_has(X86_FEATURE_SSSE3))
308+
if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) && boot_cpu_has(X86_FEATURE_SSSE3))
308309
crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
309310
}
310311

arch/x86/crypto/curve25519-x86_64.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,13 +2457,14 @@ static int __init curve25519_mod_init(void)
24572457
static_branch_enable(&curve25519_use_adx);
24582458
else
24592459
return 0;
2460-
return crypto_register_kpp(&curve25519_alg);
2460+
return IS_REACHABLE(CONFIG_CRYPTO_KPP) ?
2461+
crypto_register_kpp(&curve25519_alg) : 0;
24612462
}
24622463

24632464
static void __exit curve25519_mod_exit(void)
24642465
{
2465-
if (boot_cpu_has(X86_FEATURE_BMI2) ||
2466-
boot_cpu_has(X86_FEATURE_ADX))
2466+
if (IS_REACHABLE(CONFIG_CRYPTO_KPP) &&
2467+
(boot_cpu_has(X86_FEATURE_BMI2) || boot_cpu_has(X86_FEATURE_ADX)))
24672468
crypto_unregister_kpp(&curve25519_alg);
24682469
}
24692470

0 commit comments

Comments
 (0)