diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-05 03:13:30 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-06 02:19:47 +0200 |
commit | 15278beaa6f5a416725f9be9212323e8c19e57c4 (patch) | |
tree | 4020d614248eb3fb95ac4cab11feeaddfafd4cb0 /src/crypto/zinc/selftest/run.h | |
parent | ff0f6e667ff877cd605d2b107c897b039f9829d9 (diff) |
crypto: test all SIMD combinations
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc/selftest/run.h')
-rw-r--r-- | src/crypto/zinc/selftest/run.h | 49 |
1 files changed, 49 insertions, 0 deletions
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 |