diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-25 15:56:36 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-25 15:56:36 +0200 |
commit | d2e7b340a979ed8d0945539c6dbf5d19c022a26b (patch) | |
tree | 107094e8cbffd896246dc021e1648440c26919af /src/crypto | |
parent | 17f64817393f6f36f012da8a5b3a6bd60d4c1e1d (diff) |
chacha20: add bounds checking to selftests
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/zinc/selftest/chacha20.h | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/crypto/zinc/selftest/chacha20.h b/src/crypto/zinc/selftest/chacha20.h index fefcb75..397a4b9 100644 --- a/src/crypto/zinc/selftest/chacha20.h +++ b/src/crypto/zinc/selftest/chacha20.h @@ -2517,7 +2517,7 @@ static const struct hchacha20_testvec hchacha20_testvecs[] __initconst = {{ static bool __init chacha20_selftest(void) { enum { MAXIMUM_TEST_BUFFER_LEN = 1UL << 10 }; - size_t i, j; + size_t i, j, k; u32 derived_key[CHACHA20_KEY_WORDS]; u8 *offset_input = NULL, *computed_output = NULL; u8 offset_key[CHACHA20_KEY_SIZE + 1] @@ -2548,6 +2548,14 @@ static bool __init chacha20_selftest(void) pr_info("chacha20 self-test %zu: FAIL\n", i + 1); success = false; } + for (k = chacha20_testvecs[i].ilen; + k < MAXIMUM_TEST_BUFFER_LEN + 1; ++k) { + if (computed_output[k]) { + pr_info("chacha20 self-test %zu (zero check): FAIL\n", + i + 1); + success = false; + } + } /* Unaligned case */ memset(computed_output, 0, MAXIMUM_TEST_BUFFER_LEN + 1); @@ -2565,6 +2573,19 @@ static bool __init chacha20_selftest(void) i + 1); success = false; } + if (computed_output[0]) { + pr_info("chacha20 self-test %zu (unaligned, zero check): FAIL\n", + i + 1); + success = false; + } + for (k = chacha20_testvecs[i].ilen + 1; + k < MAXIMUM_TEST_BUFFER_LEN + 1; ++k) { + if (computed_output[k]) { + pr_info("chacha20 self-test %zu (unaligned, zero check): FAIL\n", + i + 1); + success = false; + } + } /* Chunked case */ if (chacha20_testvecs[i].ilen <= CHACHA20_BLOCK_SIZE) @@ -2585,6 +2606,14 @@ static bool __init chacha20_selftest(void) i + 1); success = false; } + for (k = chacha20_testvecs[i].ilen; + k < MAXIMUM_TEST_BUFFER_LEN + 1; ++k) { + if (computed_output[k]) { + pr_info("chacha20 self-test %zu (chunked, zero check): FAIL\n", + i + 1); + success = false; + } + } next_test: /* Sliding unaligned case */ @@ -2607,6 +2636,21 @@ next_test: i + 1, j); success = false; } + for (k = j; k < j; ++k) { + if (computed_output[k]) { + pr_info("chacha20 self-test %zu (unaligned, slide %zu, zero check): FAIL\n", + i + 1, j); + success = false; + } + } + for (k = chacha20_testvecs[i].ilen + j; + k < MAXIMUM_TEST_BUFFER_LEN + 1; ++k) { + if (computed_output[k]) { + pr_info("chacha20 self-test %zu (unaligned, slide %zu, zero check): FAIL\n", + i + 1, j); + success = false; + } + } } } for (i = 0; i < ARRAY_SIZE(hchacha20_testvecs); ++i) { |