From a91f2d36b5819c4f76d513ffbc5e3344b796b5f4 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 25 Sep 2018 23:01:32 +0200 Subject: crypto: rename DEBUG to SELFTEST Also we make selftest errors of type err, so that they're obvious in dmesg. --- src/crypto/Kbuild.include | 1 + src/crypto/zinc/blake2s/blake2s.c | 10 +++---- src/crypto/zinc/chacha20/chacha20.c | 2 +- src/crypto/zinc/chacha20poly1305.c | 2 +- src/crypto/zinc/curve25519/curve25519.c | 2 +- src/crypto/zinc/poly1305/poly1305.c | 2 +- src/crypto/zinc/selftest/blake2s.h | 6 ++-- src/crypto/zinc/selftest/chacha20.h | 45 ++++++++++++++--------------- src/crypto/zinc/selftest/chacha20poly1305.h | 28 +++++++++--------- src/crypto/zinc/selftest/curve25519.h | 8 ++--- src/crypto/zinc/selftest/poly1305.h | 12 ++++---- 11 files changed, 59 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/crypto/Kbuild.include b/src/crypto/Kbuild.include index 0ccae77..7ac24dd 100644 --- a/src/crypto/Kbuild.include +++ b/src/crypto/Kbuild.include @@ -44,3 +44,4 @@ ccflags-$(CONFIG_ZINC_ARCH_ARM) += -DCONFIG_ZINC_ARCH_ARM ccflags-$(CONFIG_ZINC_ARCH_ARM64) += -DCONFIG_ZINC_ARCH_ARM64 ccflags-$(CONFIG_ZINC_ARCH_MIPS) += -DCONFIG_ZINC_ARCH_MIPS ccflags-$(CONFIG_ZINC_ARCH_MIPS64) += -DCONFIG_ZINC_ARCH_MIPS64 +ccflags-$(CONFIG_WIREGUARD_DEBUG) += -DCONFIG_ZINC_SELFTEST diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c index 5ce74c1..bd7146b 100644 --- a/src/crypto/zinc/blake2s/blake2s.c +++ b/src/crypto/zinc/blake2s/blake2s.c @@ -86,7 +86,7 @@ void blake2s_init(struct blake2s_state *state, const size_t outlen) .depth = 1 }; -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST BUG_ON(!outlen || outlen > BLAKE2S_HASH_SIZE); #endif blake2s_init_param(state, ¶m); @@ -102,7 +102,7 @@ void blake2s_init_key(struct blake2s_state *state, const size_t outlen, .depth = 1 }; u8 block[BLAKE2S_BLOCK_SIZE] = { 0 }; -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST BUG_ON(!outlen || outlen > BLAKE2S_HASH_SIZE || !key || !keylen || keylen > BLAKE2S_KEY_SIZE); #endif @@ -135,7 +135,7 @@ static inline void blake2s_compress(struct blake2s_state *state, u32 v[16]; int i; -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST BUG_ON(nblocks > 1 && inc != BLAKE2S_BLOCK_SIZE); #endif @@ -232,7 +232,7 @@ EXPORT_SYMBOL(blake2s_update); void blake2s_final(struct blake2s_state *state, u8 *out, const size_t outlen) { -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST BUG_ON(!out || !outlen || outlen > BLAKE2S_HASH_SIZE); #endif blake2s_set_lastblock(state); @@ -294,7 +294,7 @@ static int __init mod_init(void) { if (!nosimd) blake2s_fpu_init(); -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST if (!blake2s_selftest()) return -ENOTRECOVERABLE; #endif diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c index dc9770b..2f576d6 100644 --- a/src/crypto/zinc/chacha20/chacha20.c +++ b/src/crypto/zinc/chacha20/chacha20.c @@ -170,7 +170,7 @@ static int __init mod_init(void) { if (!nosimd) chacha20_fpu_init(); -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST if (!chacha20_selftest()) return -ENOTRECOVERABLE; #endif diff --git a/src/crypto/zinc/chacha20poly1305.c b/src/crypto/zinc/chacha20poly1305.c index 2d975c3..9860c3c 100644 --- a/src/crypto/zinc/chacha20poly1305.c +++ b/src/crypto/zinc/chacha20poly1305.c @@ -347,7 +347,7 @@ int __init chacha20poly1305_mod_init(void) static int __init mod_init(void) #endif { -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST if (!chacha20poly1305_selftest()) return -ENOTRECOVERABLE; #endif diff --git a/src/crypto/zinc/curve25519/curve25519.c b/src/crypto/zinc/curve25519/curve25519.c index a1f35aa..6b1b18e 100644 --- a/src/crypto/zinc/curve25519/curve25519.c +++ b/src/crypto/zinc/curve25519/curve25519.c @@ -98,7 +98,7 @@ static int __init mod_init(void) { if (!nosimd) curve25519_fpu_init(); -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST if (!curve25519_selftest()) return -ENOTRECOVERABLE; #endif diff --git a/src/crypto/zinc/poly1305/poly1305.c b/src/crypto/zinc/poly1305/poly1305.c index f64b501..d094ca7 100644 --- a/src/crypto/zinc/poly1305/poly1305.c +++ b/src/crypto/zinc/poly1305/poly1305.c @@ -146,7 +146,7 @@ static int __init mod_init(void) { if (!nosimd) poly1305_fpu_init(); -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST if (!poly1305_selftest()) return -ENOTRECOVERABLE; #endif diff --git a/src/crypto/zinc/selftest/blake2s.h b/src/crypto/zinc/selftest/blake2s.h index b15cc56..e6f8b2a 100644 --- a/src/crypto/zinc/selftest/blake2s.h +++ b/src/crypto/zinc/selftest/blake2s.h @@ -3,7 +3,7 @@ * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ -#ifdef DEBUG +#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, @@ -2075,7 +2075,7 @@ static bool __init blake2s_selftest(void) for (i = 0; i < ARRAY_SIZE(blake2s_keyed_testvecs); ++i) { blake2s(hash, buf, key, BLAKE2S_HASH_SIZE, i, BLAKE2S_KEY_SIZE); if (memcmp(hash, blake2s_keyed_testvecs[i], BLAKE2S_HASH_SIZE)) { - pr_info("blake2s keyed self-test %zu: FAIL\n", i + 1); + pr_err("blake2s keyed self-test %zu: FAIL\n", i + 1); success = false; } } @@ -2083,7 +2083,7 @@ static bool __init blake2s_selftest(void) for (i = 0; i < ARRAY_SIZE(blake2s_testvecs); ++i) { blake2s(hash, buf, NULL, BLAKE2S_HASH_SIZE, i, 0); if (memcmp(hash, blake2s_testvecs[i], BLAKE2S_HASH_SIZE)) { - pr_info("blake2s unkeyed self-test %zu: FAIL\n", i + i); + pr_err("blake2s unkeyed self-test %zu: FAIL\n", i + i); success = false; } } diff --git a/src/crypto/zinc/selftest/chacha20.h b/src/crypto/zinc/selftest/chacha20.h index 397a4b9..16add65 100644 --- a/src/crypto/zinc/selftest/chacha20.h +++ b/src/crypto/zinc/selftest/chacha20.h @@ -3,8 +3,7 @@ * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ -#ifdef DEBUG - +#ifdef CONFIG_ZINC_SELFTEST struct chacha20_testvec { const u8 *input, *output, *key; u64 nonce; @@ -2529,7 +2528,7 @@ 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) { - pr_info("chacha20 self-test malloc: FAIL\n"); + pr_err("chacha20 self-test malloc: FAIL\n"); success = false; goto out; } @@ -2545,14 +2544,14 @@ static bool __init chacha20_selftest(void) chacha20_testvecs[i].ilen, &simd_context); if (memcmp(computed_output, chacha20_testvecs[i].output, chacha20_testvecs[i].ilen)) { - pr_info("chacha20 self-test %zu: FAIL\n", i + 1); + pr_err("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); + pr_err("chacha20 self-test %zu (zero check): FAIL\n", + i + 1); success = false; } } @@ -2569,20 +2568,20 @@ static bool __init chacha20_selftest(void) chacha20_testvecs[i].ilen, &simd_context); if (memcmp(computed_output + 1, chacha20_testvecs[i].output, chacha20_testvecs[i].ilen)) { - pr_info("chacha20 self-test %zu (unaligned): FAIL\n", - i + 1); + pr_err("chacha20 self-test %zu (unaligned): FAIL\n", + i + 1); success = false; } if (computed_output[0]) { - pr_info("chacha20 self-test %zu (unaligned, zero check): FAIL\n", - i + 1); + pr_err("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); + pr_err("chacha20 self-test %zu (unaligned, zero check): FAIL\n", + i + 1); success = false; } } @@ -2602,15 +2601,15 @@ static bool __init chacha20_selftest(void) &simd_context); if (memcmp(computed_output, chacha20_testvecs[i].output, chacha20_testvecs[i].ilen)) { - pr_info("chacha20 self-test %zu (chunked): FAIL\n", - i + 1); + pr_err("chacha20 self-test %zu (chunked): 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 (chunked, zero check): FAIL\n", - i + 1); + pr_err("chacha20 self-test %zu (chunked, zero check): FAIL\n", + i + 1); success = false; } } @@ -2632,22 +2631,22 @@ next_test: if (memcmp(computed_output + j, chacha20_testvecs[i].output, chacha20_testvecs[i].ilen)) { - pr_info("chacha20 self-test %zu (unaligned, slide %zu): FAIL\n", - i + 1, j); + pr_err("chacha20 self-test %zu (unaligned, slide %zu): FAIL\n", + 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); + pr_err("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); + pr_err("chacha20 self-test %zu (unaligned, slide %zu, zero check): FAIL\n", + i + 1, j); success = false; } } @@ -2660,7 +2659,7 @@ next_test: cpu_to_le32_array(derived_key, ARRAY_SIZE(derived_key)); if (memcmp(derived_key, hchacha20_testvecs[i].output, CHACHA20_KEY_SIZE)) { - pr_info("hchacha20 self-test %zu: FAIL\n", i + 1); + pr_err("hchacha20 self-test %zu: FAIL\n", i + 1); success = false; } } diff --git a/src/crypto/zinc/selftest/chacha20poly1305.h b/src/crypto/zinc/selftest/chacha20poly1305.h index 0510a8e..9f42252 100644 --- a/src/crypto/zinc/selftest/chacha20poly1305.h +++ b/src/crypto/zinc/selftest/chacha20poly1305.h @@ -3,7 +3,7 @@ * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST struct chacha20poly1305_testvec { const u8 *input, *output, *assoc, *nonce, *key; size_t ilen, alen, nlen; @@ -8889,7 +8889,7 @@ static bool __init chacha20poly1305_selftest(void) heap_src = kmalloc(MAXIMUM_TEST_BUFFER_LEN, GFP_KERNEL); computed_output = kmalloc(MAXIMUM_TEST_BUFFER_LEN, GFP_KERNEL); if (!heap_src || !computed_output) { - pr_info("chacha20poly1305 self-test malloc: FAIL\n"); + pr_err("chacha20poly1305 self-test malloc: FAIL\n"); success = false; goto out; } @@ -8908,8 +8908,8 @@ static bool __init chacha20poly1305_selftest(void) chacha20poly1305_enc_vectors[i].output, chacha20poly1305_enc_vectors[i].ilen + POLY1305_MAC_SIZE)) { - pr_info("chacha20poly1305 encryption self-test %zu: FAIL\n", - i + 1); + pr_err("chacha20poly1305 encryption self-test %zu: FAIL\n", + i + 1); success = false; } } @@ -8936,8 +8936,8 @@ static bool __init chacha20poly1305_selftest(void) chacha20poly1305_enc_vectors[i].output, chacha20poly1305_enc_vectors[i].ilen + POLY1305_MAC_SIZE)) { - pr_info("chacha20poly1305 sg encryption self-test %zu: FAIL\n", - i + 1); + pr_err("chacha20poly1305 sg encryption self-test %zu: FAIL\n", + i + 1); success = false; } } @@ -8957,8 +8957,8 @@ static bool __init chacha20poly1305_selftest(void) chacha20poly1305_dec_vectors[i].output, chacha20poly1305_dec_vectors[i].ilen - POLY1305_MAC_SIZE))) { - pr_info("chacha20poly1305 decryption self-test %zu: FAIL\n", - i + 1); + pr_err("chacha20poly1305 decryption self-test %zu: FAIL\n", + i + 1); success = false; } } @@ -8983,8 +8983,8 @@ static bool __init chacha20poly1305_selftest(void) memcmp(computed_output, chacha20poly1305_dec_vectors[i].output, chacha20poly1305_dec_vectors[i].ilen - POLY1305_MAC_SIZE))) { - pr_info("chacha20poly1305 sg decryption self-test %zu: FAIL\n", - i + 1); + pr_err("chacha20poly1305 sg decryption self-test %zu: FAIL\n", + i + 1); success = false; } } @@ -9002,8 +9002,8 @@ static bool __init chacha20poly1305_selftest(void) xchacha20poly1305_enc_vectors[i].output, xchacha20poly1305_enc_vectors[i].ilen + POLY1305_MAC_SIZE)) { - pr_info("xchacha20poly1305 encryption self-test %zu: FAIL\n", - i + 1); + pr_err("xchacha20poly1305 encryption self-test %zu: FAIL\n", + i + 1); success = false; } } @@ -9022,8 +9022,8 @@ static bool __init chacha20poly1305_selftest(void) xchacha20poly1305_dec_vectors[i].output, xchacha20poly1305_dec_vectors[i].ilen - POLY1305_MAC_SIZE))) { - pr_info("xchacha20poly1305 decryption self-test %zu: FAIL\n", - i + 1); + pr_err("xchacha20poly1305 decryption self-test %zu: FAIL\n", + i + 1); success = false; } } diff --git a/src/crypto/zinc/selftest/curve25519.h b/src/crypto/zinc/selftest/curve25519.h index f529b7b..8ea9f92 100644 --- a/src/crypto/zinc/selftest/curve25519.h +++ b/src/crypto/zinc/selftest/curve25519.h @@ -3,7 +3,7 @@ * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST struct curve25519_test_vector { u8 private[CURVE25519_KEY_SIZE]; u8 public[CURVE25519_KEY_SIZE]; @@ -1293,7 +1293,7 @@ static bool __init curve25519_selftest(void) if (ret != curve25519_test_vectors[i].valid || memcmp(out, curve25519_test_vectors[i].result, CURVE25519_KEY_SIZE)) { - pr_info("curve25519 self-test %zu: FAIL\n", i + 1); + pr_err("curve25519 self-test %zu: FAIL\n", i + 1); success = false; } } @@ -1303,8 +1303,8 @@ static bool __init curve25519_selftest(void) ret = curve25519_generate_public(out, in); ret2 = curve25519(out2, in, (u8[CURVE25519_KEY_SIZE]){ 9 }); if (ret != ret2 || memcmp(out, out2, CURVE25519_KEY_SIZE)) { - pr_info("curve25519 basepoint self-test %zu: FAIL: input - 0x", - i + 1); + pr_err("curve25519 basepoint self-test %zu: FAIL: input - 0x", + i + 1); for (j = CURVE25519_KEY_SIZE; j-- > 0;) printk(KERN_CONT "%02x", in[j]); printk(KERN_CONT "\n"); diff --git a/src/crypto/zinc/selftest/poly1305.h b/src/crypto/zinc/selftest/poly1305.h index e806ab2..9c12feb 100644 --- a/src/crypto/zinc/selftest/poly1305.h +++ b/src/crypto/zinc/selftest/poly1305.h @@ -3,7 +3,7 @@ * Copyright (C) 2015-2018 Jason A. Donenfeld . All Rights Reserved. */ -#ifdef DEBUG +#ifdef CONFIG_ZINC_SELFTEST struct poly1305_testvec { const u8 *input, *output, *key; size_t ilen; @@ -1057,7 +1057,7 @@ static bool __init poly1305_selftest(void) poly1305_final(&poly1305, out, &simd_context); if (memcmp(out, poly1305_testvecs[i].output, POLY1305_MAC_SIZE)) { - pr_info("poly1305 self-test %zu: FAIL\n", i + 1); + pr_err("poly1305 self-test %zu: FAIL\n", i + 1); success = false; } simd_relax(&simd_context); @@ -1078,8 +1078,8 @@ static bool __init poly1305_selftest(void) poly1305_final(&poly1305, out, &simd_context); if (memcmp(out, poly1305_testvecs[i].output, POLY1305_MAC_SIZE)) { - pr_info("poly1305 self-test %zu (split %zu): FAIL\n", - i + 1, j); + pr_err("poly1305 self-test %zu (split %zu): FAIL\n", + i + 1, j); success = false; } @@ -1095,8 +1095,8 @@ static bool __init poly1305_selftest(void) poly1305_final(&poly1305, out, &simd_context); if (memcmp(out, poly1305_testvecs[i].output, POLY1305_MAC_SIZE)) { - pr_info("poly1305 self-test %zu (split %zu, mixed simd): FAIL\n", - i + 1, j); + pr_err("poly1305 self-test %zu (split %zu, mixed simd): FAIL\n", + i + 1, j); success = false; } simd_relax(&simd_context); -- cgit v1.2.3-59-g8ed1b