summaryrefslogtreecommitdiffhomepage
path: root/src/crypto/zinc/selftest
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/zinc/selftest')
-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
6 files changed, 49 insertions, 22 deletions
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