summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crypto/zinc/blake2s/blake2s-x86_64-glue.c1
-rw-r--r--src/crypto/zinc/blake2s/blake2s.c7
-rw-r--r--src/crypto/zinc/chacha20/chacha20-arm-glue.c2
-rw-r--r--src/crypto/zinc/chacha20/chacha20-mips-glue.c2
-rw-r--r--src/crypto/zinc/chacha20/chacha20-x86_64-glue.c3
-rw-r--r--src/crypto/zinc/chacha20/chacha20.c7
-rw-r--r--src/crypto/zinc/chacha20poly1305.c7
-rw-r--r--src/crypto/zinc/curve25519/curve25519-arm-glue.c2
-rw-r--r--src/crypto/zinc/curve25519/curve25519-x86_64-glue.c2
-rw-r--r--src/crypto/zinc/curve25519/curve25519.c7
-rw-r--r--src/crypto/zinc/poly1305/poly1305-arm-glue.c1
-rw-r--r--src/crypto/zinc/poly1305/poly1305-mips-glue.c1
-rw-r--r--src/crypto/zinc/poly1305/poly1305-x86_64-glue.c2
-rw-r--r--src/crypto/zinc/poly1305/poly1305.c7
-rw-r--r--src/crypto/zinc/selftest/blake2s.c5
-rw-r--r--src/crypto/zinc/selftest/chacha20.c4
-rw-r--r--src/crypto/zinc/selftest/chacha20poly1305.c4
-rw-r--r--src/crypto/zinc/selftest/curve25519.c4
-rw-r--r--src/crypto/zinc/selftest/poly1305.c5
-rw-r--r--src/crypto/zinc/selftest/run.h49
20 files changed, 82 insertions, 40 deletions
diff --git a/src/crypto/zinc/blake2s/blake2s-x86_64-glue.c b/src/crypto/zinc/blake2s/blake2s-x86_64-glue.c
index 7be9809..1319480 100644
--- a/src/crypto/zinc/blake2s/blake2s-x86_64-glue.c
+++ b/src/crypto/zinc/blake2s/blake2s-x86_64-glue.c
@@ -17,6 +17,7 @@ asmlinkage void blake2s_compress_avx512(struct blake2s_state *state,
static bool blake2s_use_avx __ro_after_init;
static bool blake2s_use_avx512 __ro_after_init;
+static bool *const blake2s_nobs[] __initconst = { &blake2s_use_avx512 };
static void __init blake2s_fpu_init(void)
{
diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c
index fe4d4b4..311c3fd 100644
--- a/src/crypto/zinc/blake2s/blake2s.c
+++ b/src/crypto/zinc/blake2s/blake2s.c
@@ -10,6 +10,7 @@
*/
#include <zinc/blake2s.h>
+#include "../selftest/run.h"
#include <linux/types.h>
#include <linux/string.h>
@@ -112,6 +113,7 @@ EXPORT_SYMBOL(blake2s_init_key);
#if defined(CONFIG_ZINC_ARCH_X86_64)
#include "blake2s-x86_64-glue.c"
#else
+static bool *const blake2s_nobs[] __initconst = { };
static void __init blake2s_fpu_init(void)
{
}
@@ -283,10 +285,9 @@ static int __init mod_init(void)
{
if (!nosimd)
blake2s_fpu_init();
-#ifdef CONFIG_ZINC_SELFTEST
- if (WARN_ON(!blake2s_selftest()))
+ if (!selftest_run("blake2s", blake2s_selftest, blake2s_nobs,
+ ARRAY_SIZE(blake2s_nobs)))
return -ENOTRECOVERABLE;
-#endif
return 0;
}
diff --git a/src/crypto/zinc/chacha20/chacha20-arm-glue.c b/src/crypto/zinc/chacha20/chacha20-arm-glue.c
index a397d84..a0da95d 100644
--- a/src/crypto/zinc/chacha20/chacha20-arm-glue.c
+++ b/src/crypto/zinc/chacha20/chacha20-arm-glue.c
@@ -17,7 +17,7 @@ asmlinkage void chacha20_neon(u8 *out, const u8 *in, const size_t len,
const u32 key[8], const u32 counter[4]);
static bool chacha20_use_neon __ro_after_init;
-
+static bool *const chacha20_nobs[] __initconst = { &chacha20_use_neon };
static void __init chacha20_fpu_init(void)
{
#if defined(CONFIG_ZINC_ARCH_ARM64)
diff --git a/src/crypto/zinc/chacha20/chacha20-mips-glue.c b/src/crypto/zinc/chacha20/chacha20-mips-glue.c
index 04235ca..917d8fa 100644
--- a/src/crypto/zinc/chacha20/chacha20-mips-glue.c
+++ b/src/crypto/zinc/chacha20/chacha20-mips-glue.c
@@ -5,7 +5,7 @@
asmlinkage void chacha20_mips(u32 state[16], u8 *out, const u8 *in,
const size_t len);
-
+static bool *const chacha20_nobs[] __initconst = { };
static void __init chacha20_fpu_init(void)
{
}
diff --git a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c
index b89d5e1..f5a9c21 100644
--- a/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c
+++ b/src/crypto/zinc/chacha20/chacha20-x86_64-glue.c
@@ -23,6 +23,9 @@ static bool chacha20_use_ssse3 __ro_after_init;
static bool chacha20_use_avx2 __ro_after_init;
static bool chacha20_use_avx512 __ro_after_init;
static bool chacha20_use_avx512vl __ro_after_init;
+static bool *const chacha20_nobs[] __initconst = {
+ &chacha20_use_ssse3, &chacha20_use_avx2, &chacha20_use_avx512,
+ &chacha20_use_avx512vl };
static void __init chacha20_fpu_init(void)
{
diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c
index bc7e9be..971391c 100644
--- a/src/crypto/zinc/chacha20/chacha20.c
+++ b/src/crypto/zinc/chacha20/chacha20.c
@@ -8,6 +8,7 @@
*/
#include <zinc/chacha20.h>
+#include "../selftest/run.h"
#include <linux/kernel.h>
#include <linux/module.h>
@@ -22,6 +23,7 @@
#elif defined(CONFIG_ZINC_ARCH_MIPS)
#include "chacha20-mips-glue.c"
#else
+static bool *const chacha20_nobs[] __initconst = { };
static void __init chacha20_fpu_init(void)
{
}
@@ -171,10 +173,9 @@ static int __init mod_init(void)
{
if (!nosimd)
chacha20_fpu_init();
-#ifdef CONFIG_ZINC_SELFTEST
- if (WARN_ON(!chacha20_selftest()))
+ if (!selftest_run("chacha20", chacha20_selftest, chacha20_nobs,
+ ARRAY_SIZE(chacha20_nobs)))
return -ENOTRECOVERABLE;
-#endif
return 0;
}
diff --git a/src/crypto/zinc/chacha20poly1305.c b/src/crypto/zinc/chacha20poly1305.c
index 6c8ff3a..6f709e0 100644
--- a/src/crypto/zinc/chacha20poly1305.c
+++ b/src/crypto/zinc/chacha20poly1305.c
@@ -10,6 +10,8 @@
#include <zinc/chacha20poly1305.h>
#include <zinc/chacha20.h>
#include <zinc/poly1305.h>
+#include "selftest/run.h"
+
#include <asm/unaligned.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -347,10 +349,9 @@ int __init chacha20poly1305_mod_init(void)
static int __init mod_init(void)
#endif
{
-#ifdef CONFIG_ZINC_SELFTEST
- if (WARN_ON(!chacha20poly1305_selftest()))
+ if (!selftest_run("chacha20poly1305", chacha20poly1305_selftest,
+ NULL, 0))
return -ENOTRECOVERABLE;
-#endif
return 0;
}
diff --git a/src/crypto/zinc/curve25519/curve25519-arm-glue.c b/src/crypto/zinc/curve25519/curve25519-arm-glue.c
index cea06f3..c71c981 100644
--- a/src/crypto/zinc/curve25519/curve25519-arm-glue.c
+++ b/src/crypto/zinc/curve25519/curve25519-arm-glue.c
@@ -12,7 +12,7 @@ asmlinkage void curve25519_neon(u8 mypublic[CURVE25519_KEY_SIZE],
const u8 basepoint[CURVE25519_KEY_SIZE]);
static bool curve25519_use_neon __ro_after_init;
-
+static bool *const curve25519_nobs[] __initconst = { &curve25519_use_neon };
static void __init curve25519_fpu_init(void)
{
curve25519_use_neon = elf_hwcap & HWCAP_NEON;
diff --git a/src/crypto/zinc/curve25519/curve25519-x86_64-glue.c b/src/crypto/zinc/curve25519/curve25519-x86_64-glue.c
index 34ff1d8..a0e35bb 100644
--- a/src/crypto/zinc/curve25519/curve25519-x86_64-glue.c
+++ b/src/crypto/zinc/curve25519/curve25519-x86_64-glue.c
@@ -10,6 +10,8 @@
static bool curve25519_use_bmi2 __ro_after_init;
static bool curve25519_use_adx __ro_after_init;
+static bool *const curve25519_nobs[] __initconst = {
+ &curve25519_use_bmi2, &curve25519_use_adx };
static void __init curve25519_fpu_init(void)
{
diff --git a/src/crypto/zinc/curve25519/curve25519.c b/src/crypto/zinc/curve25519/curve25519.c
index 5fd4040..64efa60 100644
--- a/src/crypto/zinc/curve25519/curve25519.c
+++ b/src/crypto/zinc/curve25519/curve25519.c
@@ -10,6 +10,7 @@
*/
#include <zinc/curve25519.h>
+#include "../selftest/run.h"
#include <asm/unaligned.h>
#include <linux/version.h>
@@ -24,6 +25,7 @@
#elif defined(CONFIG_ZINC_ARCH_ARM)
#include "curve25519-arm-glue.c"
#else
+static bool *const curve25519_nobs[] __initconst = { };
static void __init curve25519_fpu_init(void)
{
}
@@ -98,10 +100,9 @@ static int __init mod_init(void)
{
if (!nosimd)
curve25519_fpu_init();
-#ifdef CONFIG_ZINC_SELFTEST
- if (WARN_ON(!curve25519_selftest()))
+ if (!selftest_run("curve25519", curve25519_selftest, curve25519_nobs,
+ ARRAY_SIZE(curve25519_nobs)))
return -ENOTRECOVERABLE;
-#endif
return 0;
}
diff --git a/src/crypto/zinc/poly1305/poly1305-arm-glue.c b/src/crypto/zinc/poly1305/poly1305-arm-glue.c
index f91066f..f4f08ec 100644
--- a/src/crypto/zinc/poly1305/poly1305-arm-glue.c
+++ b/src/crypto/zinc/poly1305/poly1305-arm-glue.c
@@ -15,6 +15,7 @@ asmlinkage void poly1305_blocks_neon(void *ctx, const u8 *inp, const size_t len,
asmlinkage void poly1305_emit_neon(void *ctx, u8 mac[16], const u32 nonce[4]);
static bool poly1305_use_neon __ro_after_init;
+static bool *const poly1305_nobs[] __initconst = { &poly1305_use_neon };
static void __init poly1305_fpu_init(void)
{
diff --git a/src/crypto/zinc/poly1305/poly1305-mips-glue.c b/src/crypto/zinc/poly1305/poly1305-mips-glue.c
index 3a72d61..1eba951 100644
--- a/src/crypto/zinc/poly1305/poly1305-mips-glue.c
+++ b/src/crypto/zinc/poly1305/poly1305-mips-glue.c
@@ -8,6 +8,7 @@ asmlinkage void poly1305_blocks_mips(void *ctx, const u8 *inp, const size_t len,
const u32 padbit);
asmlinkage void poly1305_emit_mips(void *ctx, u8 mac[16], const u32 nonce[4]);
+static bool *const poly1305_nobs[] __initconst = { };
static void __init poly1305_fpu_init(void)
{
}
diff --git a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.c b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.c
index 3641dc8..0229aca 100644
--- a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.c
+++ b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.c
@@ -25,6 +25,8 @@ asmlinkage void poly1305_blocks_avx512(void *ctx, const u8 *inp,
static bool poly1305_use_avx __ro_after_init;
static bool poly1305_use_avx2 __ro_after_init;
static bool poly1305_use_avx512 __ro_after_init;
+static bool *const poly1305_nobs[] __initconst = {
+ &poly1305_use_avx, &poly1305_use_avx2, &poly1305_use_avx512 };
static void __init poly1305_fpu_init(void)
{
diff --git a/src/crypto/zinc/poly1305/poly1305.c b/src/crypto/zinc/poly1305/poly1305.c
index 88f94cd..6da8bf1 100644
--- a/src/crypto/zinc/poly1305/poly1305.c
+++ b/src/crypto/zinc/poly1305/poly1305.c
@@ -8,6 +8,7 @@
*/
#include <zinc/poly1305.h>
+#include "../selftest/run.h"
#include <asm/unaligned.h>
#include <linux/kernel.h>
@@ -39,6 +40,7 @@ static inline bool poly1305_emit_arch(void *ctx, u8 mac[POLY1305_MAC_SIZE],
{
return false;
}
+static bool *const poly1305_nobs[] __initconst = { };
static void __init poly1305_fpu_init(void)
{
}
@@ -146,10 +148,9 @@ static int __init mod_init(void)
{
if (!nosimd)
poly1305_fpu_init();
-#ifdef CONFIG_ZINC_SELFTEST
- if (WARN_ON(!poly1305_selftest()))
+ if (!selftest_run("poly1305", poly1305_selftest, poly1305_nobs,
+ ARRAY_SIZE(poly1305_nobs)))
return -ENOTRECOVERABLE;
-#endif
return 0;
}
diff --git a/src/crypto/zinc/selftest/blake2s.c b/src/crypto/zinc/selftest/blake2s.c
index 80b8e19..7325a42 100644
--- a/src/crypto/zinc/selftest/blake2s.c
+++ b/src/crypto/zinc/selftest/blake2s.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
-#ifdef CONFIG_ZINC_SELFTEST
static const u8 blake2s_testvecs[][BLAKE2S_HASH_SIZE] __initconst = {
{ 0x69, 0x21, 0x7a, 0x30, 0x79, 0x90, 0x80, 0x94,
0xe1, 0x11, 0x21, 0xd0, 0x42, 0x35, 0x4a, 0x7c,
@@ -2087,9 +2086,5 @@ static bool __init blake2s_selftest(void)
success = false;
}
}
-
- if (success)
- pr_info("blake2s self-tests: pass\n");
return success;
}
-#endif
diff --git a/src/crypto/zinc/selftest/chacha20.c b/src/crypto/zinc/selftest/chacha20.c
index a76600b..b8c9c70 100644
--- a/src/crypto/zinc/selftest/chacha20.c
+++ b/src/crypto/zinc/selftest/chacha20.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
-#ifdef CONFIG_ZINC_SELFTEST
struct chacha20_testvec {
const u8 *input, *output, *key;
u64 nonce;
@@ -2690,8 +2689,6 @@ next_test:
}
simd_put(&simd_context);
- if (success)
- pr_info("chacha20 self-tests: pass\n");
out:
kfree(offset_input);
@@ -2699,4 +2696,3 @@ out:
vfree(massive_input);
return success;
}
-#endif
diff --git a/src/crypto/zinc/selftest/chacha20poly1305.c b/src/crypto/zinc/selftest/chacha20poly1305.c
index fceadb0..571befe 100644
--- a/src/crypto/zinc/selftest/chacha20poly1305.c
+++ b/src/crypto/zinc/selftest/chacha20poly1305.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
-#ifdef CONFIG_ZINC_SELFTEST
struct chacha20poly1305_testvec {
const u8 *input, *output, *assoc, *nonce, *key;
size_t ilen, alen, nlen;
@@ -9027,12 +9026,9 @@ static bool __init chacha20poly1305_selftest(void)
success = false;
}
}
- if (success)
- pr_info("chacha20poly1305 self-tests: pass\n");
out:
kfree(heap_src);
kfree(computed_output);
return success;
}
-#endif
diff --git a/src/crypto/zinc/selftest/curve25519.c b/src/crypto/zinc/selftest/curve25519.c
index 933d65e..fa653d4 100644
--- a/src/crypto/zinc/selftest/curve25519.c
+++ b/src/crypto/zinc/selftest/curve25519.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
-#ifdef CONFIG_ZINC_SELFTEST
struct curve25519_test_vector {
u8 private[CURVE25519_KEY_SIZE];
u8 public[CURVE25519_KEY_SIZE];
@@ -1312,8 +1311,5 @@ static bool __init curve25519_selftest(void)
}
}
- if (success)
- pr_info("curve25519 self-tests: pass\n");
return success;
}
-#endif
diff --git a/src/crypto/zinc/selftest/poly1305.c b/src/crypto/zinc/selftest/poly1305.c
index be0dff6..6b1f872 100644
--- a/src/crypto/zinc/selftest/poly1305.c
+++ b/src/crypto/zinc/selftest/poly1305.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
-#ifdef CONFIG_ZINC_SELFTEST
struct poly1305_testvec {
const u8 *input, *output, *key;
size_t ilen;
@@ -1104,9 +1103,5 @@ static bool __init poly1305_selftest(void)
}
simd_put(&simd_context);
- if (success)
- pr_info("poly1305 self-tests: pass\n");
-
return success;
}
-#endif
diff --git a/src/crypto/zinc/selftest/run.h b/src/crypto/zinc/selftest/run.h
new file mode 100644
index 0000000..4cbafe2
--- /dev/null
+++ b/src/crypto/zinc/selftest/run.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+/*
+ * Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ */
+
+#ifndef _ZINC_SELFTEST_RUN_H
+#define _ZINC_SELFTEST_RUN_H
+
+#include <linux/kernel.h>
+#include <linux/printk.h>
+#include <linux/bug.h>
+
+static inline bool selftest_run(const char *name, bool (*selftest)(void),
+ bool *const nobs[], unsigned int nobs_len)
+{
+ unsigned long subset = 0, set = 0;
+ unsigned int i;
+ bool ret = true;
+
+ BUILD_BUG_ON(!__builtin_constant_p(nobs_len) ||
+ nobs_len >= BITS_PER_LONG);
+
+ if (!IS_ENABLED(CONFIG_ZINC_SELFTEST))
+ return true;
+
+ for (i = 0; i < nobs_len; ++i)
+ set |= ((unsigned long)*nobs[i]) << i;
+
+ do {
+ for (i = 0; i < nobs_len; ++i)
+ *nobs[i] = (subset >> i) & 1;
+ if (!selftest()) {
+ pr_err("%s self-test combo 0x%lx: FAIL\n", name,
+ subset);
+ ret = false;
+ }
+ subset = (subset - set) & set;
+ } while (subset);
+
+ for (i = 0; i < nobs_len; ++i)
+ *nobs[i] = (set >> i) & 1;
+
+ if (ret)
+ pr_info("%s self-tests: pass\n", name);
+
+ return !WARN_ON(!ret);
+}
+
+#endif