[PATCH] crypto: aegis128 - deal with missing simd.h header on some architecures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The generic aegis128 driver has been updated to support using SIMD
intrinsics to implement the core AES based transform, and this has
been wired up for ARM and arm64, which both provide a simd.h header.

As it turns out, most architectures don't provide this header, even
though a version of it exists in include/asm-generic, and this is
not taken into account by the aegis128 driver, resulting in build
failures on those architectures.

So update the aegis128 code to only import simd.h (and the related
header in internal/crypto) if the SIMD functionality is enabled for
this driver.

Reported-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@xxxxxxxxxx>
---
 crypto/aegis128-core.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/crypto/aegis128-core.c b/crypto/aegis128-core.c
index f815b4685156..d46a12872d35 100644
--- a/crypto/aegis128-core.c
+++ b/crypto/aegis128-core.c
@@ -8,7 +8,6 @@
 
 #include <crypto/algapi.h>
 #include <crypto/internal/aead.h>
-#include <crypto/internal/simd.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
 #include <linux/err.h>
@@ -16,7 +15,11 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/scatterlist.h>
+
+#ifdef CONFIG_CRYPTO_AEGIS128_SIMD
+#include <crypto/internal/simd.h>
 #include <asm/simd.h>
+#endif
 
 #include "aegis.h"
 
@@ -44,6 +47,15 @@ struct aegis128_ops {
 
 static bool have_simd;
 
+static bool aegis128_do_simd(void)
+{
+#ifdef CONFIG_CRYPTO_AEGIS128_SIMD
+	if (have_simd)
+		return crypto_simd_usable();
+#endif
+	return false;
+}
+
 bool crypto_aegis128_have_simd(void);
 void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg);
 void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst,
@@ -66,7 +78,7 @@ static void crypto_aegis128_update(struct aegis_state *state)
 static void crypto_aegis128_update_a(struct aegis_state *state,
 				     const union aegis_block *msg)
 {
-	if (have_simd && crypto_simd_usable()) {
+	if (aegis128_do_simd()) {
 		crypto_aegis128_update_simd(state, msg);
 		return;
 	}
@@ -77,7 +89,7 @@ static void crypto_aegis128_update_a(struct aegis_state *state,
 
 static void crypto_aegis128_update_u(struct aegis_state *state, const void *msg)
 {
-	if (have_simd && crypto_simd_usable()) {
+	if (aegis128_do_simd()) {
 		crypto_aegis128_update_simd(state, msg);
 		return;
 	}
@@ -396,7 +408,7 @@ static int crypto_aegis128_encrypt(struct aead_request *req)
 	unsigned int authsize = crypto_aead_authsize(tfm);
 	unsigned int cryptlen = req->cryptlen;
 
-	if (have_simd && crypto_simd_usable())
+	if (aegis128_do_simd())
 		ops = &(struct aegis128_ops){
 			.skcipher_walk_init = skcipher_walk_aead_encrypt,
 			.crypt_chunk = crypto_aegis128_encrypt_chunk_simd };
@@ -424,7 +436,7 @@ static int crypto_aegis128_decrypt(struct aead_request *req)
 	scatterwalk_map_and_copy(tag.bytes, req->src, req->assoclen + cryptlen,
 				 authsize, 0);
 
-	if (have_simd && crypto_simd_usable())
+	if (aegis128_do_simd())
 		ops = &(struct aegis128_ops){
 			.skcipher_walk_init = skcipher_walk_aead_decrypt,
 			.crypt_chunk = crypto_aegis128_decrypt_chunk_simd };
-- 
2.17.1




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux