summaryrefslogtreecommitdiffhomepage
path: root/src/crypto/zinc
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-27 02:24:17 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-02 03:41:49 +0200
commit791c515a0da6020820786a63324db9af51896e33 (patch)
tree122dcda9f3d18a21bf3bb5c0612de5aa2f6d311e /src/crypto/zinc
parent488b7567098aee76b3d55e4bc6d4e642fb2e526d (diff)
chacha20: test multiple page span in selftest
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc')
-rw-r--r--src/crypto/zinc/chacha20/chacha20.c1
-rw-r--r--src/crypto/zinc/selftest/chacha20.h29
2 files changed, 27 insertions, 3 deletions
diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c
index 2f576d6..e3fcbe8 100644
--- a/src/crypto/zinc/chacha20/chacha20.c
+++ b/src/crypto/zinc/chacha20/chacha20.c
@@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
+#include <linux/vmalloc.h>
#include <crypto/algapi.h>
#if defined(CONFIG_ZINC_ARCH_X86_64)
diff --git a/src/crypto/zinc/selftest/chacha20.h b/src/crypto/zinc/selftest/chacha20.h
index 6c270c8..8622aef 100644
--- a/src/crypto/zinc/selftest/chacha20.h
+++ b/src/crypto/zinc/selftest/chacha20.h
@@ -2515,10 +2515,13 @@ static const struct hchacha20_testvec hchacha20_testvecs[] __initconst = {{
static bool __init chacha20_selftest(void)
{
- enum { MAXIMUM_TEST_BUFFER_LEN = 1UL << 10 };
+ enum {
+ MAXIMUM_TEST_BUFFER_LEN = 1UL << 10,
+ OUTRAGEOUSLY_HUGE_BUFFER_LEN = PAGE_SIZE * 35 + 17 /* 143k */
+ };
size_t i, j, k;
u32 derived_key[CHACHA20_KEY_WORDS];
- u8 *offset_input = NULL, *computed_output = NULL;
+ u8 *offset_input = NULL, *computed_output = NULL, *massive_input = NULL;
u8 offset_key[CHACHA20_KEY_SIZE + 1]
__aligned(__alignof__(unsigned long));
struct chacha20_ctx state;
@@ -2527,7 +2530,8 @@ static bool __init chacha20_selftest(void)
offset_input = kmalloc(MAXIMUM_TEST_BUFFER_LEN + 1, GFP_KERNEL);
computed_output = kmalloc(MAXIMUM_TEST_BUFFER_LEN + 1, GFP_KERNEL);
- if (!computed_output || !offset_input) {
+ massive_input = vzalloc(OUTRAGEOUSLY_HUGE_BUFFER_LEN);
+ if (!computed_output || !offset_input || !massive_input) {
pr_err("chacha20 self-test malloc: FAIL\n");
success = false;
goto out;
@@ -2668,6 +2672,24 @@ next_test:
success = false;
}
}
+ memset(&state, 0, sizeof(state));
+ chacha20_init(&state, chacha20_testvecs[0].key,
+ chacha20_testvecs[0].nonce);
+ chacha20(&state, massive_input, massive_input,
+ OUTRAGEOUSLY_HUGE_BUFFER_LEN, &simd_context);
+ chacha20_init(&state, chacha20_testvecs[0].key,
+ chacha20_testvecs[0].nonce);
+ chacha20(&state, massive_input, massive_input,
+ OUTRAGEOUSLY_HUGE_BUFFER_LEN,
+ (simd_context_t []){ HAVE_NO_SIMD });
+ for (k = 0; k < OUTRAGEOUSLY_HUGE_BUFFER_LEN; ++k) {
+ if (massive_input[k]) {
+ pr_err("chacha20 self-test massive: FAIL\n");
+ success = false;
+ break;
+ }
+ }
+
simd_put(&simd_context);
if (success)
pr_info("chacha20 self-tests: pass\n");
@@ -2675,6 +2697,7 @@ next_test:
out:
kfree(offset_input);
kfree(computed_output);
+ vfree(massive_input);
return success;
}
#endif