Commit 8394bfec authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Herbert Xu
Browse files

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: default avatarJason A. Donenfeld <Jason@zx2c4.com>
Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 4ee812f6
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -286,11 +286,13 @@ static struct skcipher_alg neon_algs[] = {

static int __init chacha_simd_mod_init(void)
{
	int err;
	int err = 0;

	if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER)) {
		err = crypto_register_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
		if (err)
			return err;
	}

	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON)) {
		int i;
@@ -310,19 +312,23 @@ static int __init chacha_simd_mod_init(void)
			static_branch_enable(&use_neon);
		}

		if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER)) {
			err = crypto_register_skciphers(neon_algs, ARRAY_SIZE(neon_algs));
			if (err)
				crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
		}
	}
	return err;
}

static void __exit chacha_simd_mod_fini(void)
{
	if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER)) {
		crypto_unregister_skciphers(arm_algs, ARRAY_SIZE(arm_algs));
		if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON))
			crypto_unregister_skciphers(neon_algs, ARRAY_SIZE(neon_algs));
	}
}

module_init(chacha_simd_mod_init);
module_exit(chacha_simd_mod_fini);
+3 −2
Original line number Diff line number Diff line
@@ -108,14 +108,15 @@ static int __init mod_init(void)
{
	if (elf_hwcap & HWCAP_NEON) {
		static_branch_enable(&have_neon);
		return crypto_register_kpp(&curve25519_alg);
		return IS_REACHABLE(CONFIG_CRYPTO_KPP) ?
			crypto_register_kpp(&curve25519_alg) : 0;
	}
	return 0;
}

static void __exit mod_exit(void)
{
	if (elf_hwcap & HWCAP_NEON)
	if (IS_REACHABLE(CONFIG_CRYPTO_KPP) && elf_hwcap & HWCAP_NEON)
		crypto_unregister_kpp(&curve25519_alg);
}

+6 −3
Original line number Diff line number Diff line
@@ -249,16 +249,19 @@ static int __init arm_poly1305_mod_init(void)
	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
	    (elf_hwcap & HWCAP_NEON))
		static_branch_enable(&have_neon);
	else
	else if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
		/* register only the first entry */
		return crypto_register_shash(&arm_poly1305_algs[0]);

	return crypto_register_shashes(arm_poly1305_algs,
				       ARRAY_SIZE(arm_poly1305_algs));
	return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
		crypto_register_shashes(arm_poly1305_algs,
					ARRAY_SIZE(arm_poly1305_algs)) : 0;
}

static void __exit arm_poly1305_mod_exit(void)
{
	if (!IS_REACHABLE(CONFIG_CRYPTO_HASH))
		return;
	if (!static_branch_likely(&have_neon)) {
		crypto_unregister_shash(&arm_poly1305_algs[0]);
		return;
+3 −2
Original line number Diff line number Diff line
@@ -211,12 +211,13 @@ static int __init chacha_simd_mod_init(void)

	static_branch_enable(&have_neon);

	return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
	return IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) ?
		crypto_register_skciphers(algs, ARRAY_SIZE(algs)) : 0;
}

static void __exit chacha_simd_mod_fini(void)
{
	if (cpu_have_named_feature(ASIMD))
	if (IS_REACHABLE(CONFIG_CRYPTO_SKCIPHER) && cpu_have_named_feature(ASIMD))
		crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
}

+3 −2
Original line number Diff line number Diff line
@@ -220,12 +220,13 @@ static int __init neon_poly1305_mod_init(void)

	static_branch_enable(&have_neon);

	return crypto_register_shash(&neon_poly1305_alg);
	return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
		crypto_register_shash(&neon_poly1305_alg) : 0;
}

static void __exit neon_poly1305_mod_exit(void)
{
	if (cpu_have_named_feature(ASIMD))
	if (IS_REACHABLE(CONFIG_CRYPTO_HASH) && cpu_have_named_feature(ASIMD))
		crypto_unregister_shash(&neon_poly1305_alg);
}

Loading