From 3e8c04a03f4070e23fc737f30c25a79d5958d734 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 25 Jun 2016 01:28:18 +0200 Subject: tests: make fatal --- src/crypto/blake2s.c | 3 ++- src/crypto/blake2s.h | 2 +- src/crypto/chacha20poly1305.c | 3 ++- src/crypto/chacha20poly1305.h | 2 +- src/crypto/curve25519.c | 5 +++-- src/crypto/curve25519.h | 2 +- src/crypto/siphash24.c | 3 ++- src/crypto/siphash24.h | 2 +- src/data.c | 3 ++- src/main.c | 13 +++++++------ src/packets.h | 2 +- src/routing-table.c | 7 +++++-- src/routing-table.h | 2 +- 13 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/crypto/blake2s.c b/src/crypto/blake2s.c index 0a7170e..1182ca9 100644 --- a/src/crypto/blake2s.c +++ b/src/crypto/blake2s.c @@ -804,7 +804,7 @@ static const uint8_t blake2s_keyed_testvecs[][BLAKE2S_OUTBYTES] = { { 0x3F, 0xB7, 0x35, 0x06, 0x1A, 0xBC, 0x51, 0x9D, 0xFE, 0x97, 0x9E, 0x54, 0xC1, 0xEE, 0x5B, 0xFA, 0xD0, 0xA9, 0xD8, 0x58, 0xB3, 0x31, 0x5B, 0xAD, 0x34, 0xBD, 0xE9, 0x99, 0xEF, 0xD7, 0x24, 0xDD } }; -void blake2s_selftest(void) +bool blake2s_selftest(void) { uint8_t key[BLAKE2S_KEYBYTES]; uint8_t buf[ARRAY_SIZE(blake2s_testvecs)]; @@ -836,5 +836,6 @@ void blake2s_selftest(void) if (success) pr_info("blake2s self-tests: pass\n"); + return success; } #endif diff --git a/src/crypto/blake2s.h b/src/crypto/blake2s.h index 1b42141..b48937f 100644 --- a/src/crypto/blake2s.h +++ b/src/crypto/blake2s.h @@ -30,7 +30,7 @@ void blake2s_final(struct blake2s_state *state, uint8_t *out, uint8_t outlen); void blake2s_hmac(uint8_t *out, const uint8_t *in, const uint8_t *key, const uint8_t outlen, const uint64_t inlen, const uint64_t keylen); #ifdef DEBUG -void blake2s_selftest(void); +bool blake2s_selftest(void); #endif #endif diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c index c05fe1c..e4d2e0a 100644 --- a/src/crypto/chacha20poly1305.c +++ b/src/crypto/chacha20poly1305.c @@ -770,7 +770,7 @@ static const struct chacha20poly1305_testvec chacha20poly1305_dec_vectors[] = { .result = "\x49\x6e\x74\x65\x72\x6e\x65\x74\x2d\x44\x72\x61\x66\x74\x73\x20\x61\x72\x65\x20\x64\x72\x61\x66\x74\x20\x64\x6f\x63\x75\x6d\x65\x6e\x74\x73\x20\x76\x61\x6c\x69\x64\x20\x66\x6f\x72\x20\x61\x20\x6d\x61\x78\x69\x6d\x75\x6d\x20\x6f\x66\x20\x73\x69\x78\x20\x6d\x6f\x6e\x74\x68\x73\x20\x61\x6e\x64\x20\x6d\x61\x79\x20\x62\x65\x20\x75\x70\x64\x61\x74\x65\x64\x2c\x20\x72\x65\x70\x6c\x61\x63\x65\x64\x2c\x20\x6f\x72\x20\x6f\x62\x73\x6f\x6c\x65\x74\x65\x64\x20\x62\x79\x20\x6f\x74\x68\x65\x72\x20\x64\x6f\x63\x75\x6d\x65\x6e\x74\x73\x20\x61\x74\x20\x61\x6e\x79\x20\x74\x69\x6d\x65\x2e\x20\x49\x74\x20\x69\x73\x20\x69\x6e\x61\x70\x70\x72\x6f\x70\x72\x69\x61\x74\x65\x20\x74\x6f\x20\x75\x73\x65\x20\x49\x6e\x74\x65\x72\x6e\x65\x74\x2d\x44\x72\x61\x66\x74\x73\x20\x61\x73\x20\x72\x65\x66\x65\x72\x65\x6e\x63\x65\x20\x6d\x61\x74\x65\x72\x69\x61\x6c\x20\x6f\x72\x20\x74\x6f\x20\x63\x69\x74\x65\x20\x74\x68\x65\x6d\x20\x6f\x74\x68\x65\x72\x20\x74\x68\x61\x6e\x20\x61\x73\x20\x2f\xe2\x80\x9c\x77\x6f\x72\x6b\x20\x69\x6e\x20\x70\x72\x6f\x67\x72\x65\x73\x73\x2e\x2f\xe2\x80\x9d" } }; -void chacha20poly1305_selftest(void) +bool chacha20poly1305_selftest(void) { size_t i; uint8_t computed_result[512]; @@ -794,5 +794,6 @@ void chacha20poly1305_selftest(void) } if (success) pr_info("chacha20poly1305 self-tests: pass\n"); + return success; } #endif diff --git a/src/crypto/chacha20poly1305.h b/src/crypto/chacha20poly1305.h index c44a17e..d1986f7 100644 --- a/src/crypto/chacha20poly1305.h +++ b/src/crypto/chacha20poly1305.h @@ -29,7 +29,7 @@ bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *sr const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN]); #ifdef DEBUG -void chacha20poly1305_selftest(void); +bool chacha20poly1305_selftest(void); #endif #endif diff --git a/src/crypto/curve25519.c b/src/crypto/curve25519.c index 8b75aa0..d3d7fa7 100644 --- a/src/crypto/curve25519.c +++ b/src/crypto/curve25519.c @@ -1282,7 +1282,7 @@ static const struct curve25519_test_vector curve25519_test_vectors[] = { .result = { 0 } } }; -void curve25519_selftest(void) +bool curve25519_selftest(void) { bool success = true; size_t i = 0; @@ -1294,11 +1294,12 @@ void curve25519_selftest(void) if (memcmp(out, curve25519_test_vectors[i].result, CURVE25519_POINT_SIZE)) { pr_info("curve25519 self-test %zu: FAIL\n", i + 1); success = false; - return; + break; } } if (success) pr_info("curve25519 self-tests: pass\n"); + return success; } #endif diff --git a/src/crypto/curve25519.h b/src/crypto/curve25519.h index b8f68e7..f16fc30 100644 --- a/src/crypto/curve25519.h +++ b/src/crypto/curve25519.h @@ -14,7 +14,7 @@ void curve25519_generate_secret(uint8_t secret[CURVE25519_POINT_SIZE]); void curve25519_generate_public(uint8_t pub[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE]); #ifdef DEBUG -void curve25519_selftest(void); +bool curve25519_selftest(void); #endif #endif diff --git a/src/crypto/siphash24.c b/src/crypto/siphash24.c index 093c837..5a29a80 100644 --- a/src/crypto/siphash24.c +++ b/src/crypto/siphash24.c @@ -131,7 +131,7 @@ static const uint8_t test_vectors[64][8] = { { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95 } }; -void siphash24_selftest(void) +bool siphash24_selftest(void) { uint8_t in[64], k[16]; uint64_t out; @@ -151,5 +151,6 @@ void siphash24_selftest(void) } if (success) pr_info("siphash24 self-tests: pass\n"); + return success; } #endif diff --git a/src/crypto/siphash24.h b/src/crypto/siphash24.h index 5ce5a3a..f06a87c 100644 --- a/src/crypto/siphash24.h +++ b/src/crypto/siphash24.h @@ -10,7 +10,7 @@ enum siphash24_lengths { uint64_t siphash24(const uint8_t *data, size_t len, const uint8_t key[SIPHASH24_KEY_LEN]); #ifdef DEBUG -void siphash24_selftest(void); +bool siphash24_selftest(void); #endif #endif diff --git a/src/data.c b/src/data.c index 205020c..e10bc60 100644 --- a/src/data.c +++ b/src/data.c @@ -46,7 +46,7 @@ out: } #ifdef DEBUG -void packet_counter_selftest(void) +bool packet_counter_selftest(void) { bool success = true; unsigned int test_num = 0, i; @@ -129,6 +129,7 @@ void packet_counter_selftest(void) if (success) pr_info("nonce counter self-tests: pass\n"); + return success; } #endif diff --git a/src/main.c b/src/main.c index bcc432a..e0116c8 100644 --- a/src/main.c +++ b/src/main.c @@ -17,12 +17,13 @@ static int __init mod_init(void) int ret = 0; #ifdef DEBUG - routing_table_selftest(); - packet_counter_selftest(); - curve25519_selftest(); - chacha20poly1305_selftest(); - blake2s_selftest(); - siphash24_selftest(); + if (!routing_table_selftest() || + !packet_counter_selftest() || + !curve25519_selftest() || + !chacha20poly1305_selftest() || + !blake2s_selftest() || + !siphash24_selftest()) + return -ENOTRECOVERABLE; #endif chacha20poly1305_init(); noise_init(); diff --git a/src/packets.h b/src/packets.h index a34acb9..b0d21b4 100644 --- a/src/packets.h +++ b/src/packets.h @@ -55,7 +55,7 @@ void packet_consume_data(struct sk_buff *skb, size_t offset, struct wireguard_de #define DATA_PACKET_HEAD_ROOM ALIGN(sizeof(struct message_data) + max(sizeof(struct packet_data_encryption_ctx), SKB_HEADER_LEN), 4) #ifdef DEBUG -void packet_counter_selftest(void); +bool packet_counter_selftest(void); #endif #endif diff --git a/src/routing-table.c b/src/routing-table.c index ec98f1d..baa924a 100644 --- a/src/routing-table.c +++ b/src/routing-table.c @@ -537,12 +537,12 @@ static inline struct in6_addr *ip6(uint32_t a, uint32_t b, uint32_t c, uint32_t return &ip; } -void routing_table_selftest(void) +bool routing_table_selftest(void) { struct routing_table t; struct wireguard_peer *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL, *g = NULL, *h = NULL; size_t i = 0; - bool success = true; + bool success = false; struct in6_addr ip; __be64 part; @@ -576,6 +576,7 @@ void routing_table_selftest(void) insert(4, h, 64, 15, 123, 211, 25); /* maskself is required */ #undef insert + success = true; #define test(version, mem, ipa, ipb, ipc, ipd) do { \ bool _s = routing_table_lookup_v##version(&t, ip##version(ipa, ipb, ipc, ipd)) == mem; \ ++i; \ @@ -629,5 +630,7 @@ free: kfree(f); kfree(g); kfree(h); + + return success; } #endif diff --git a/src/routing-table.h b/src/routing-table.h index 2e3a0ba..c4fd05d 100644 --- a/src/routing-table.h +++ b/src/routing-table.h @@ -35,7 +35,7 @@ struct wireguard_peer *routing_table_lookup_dst(struct routing_table *table, str struct wireguard_peer *routing_table_lookup_src(struct routing_table *table, struct sk_buff *skb); #ifdef DEBUG -void routing_table_selftest(void); +bool routing_table_selftest(void); #endif #endif -- cgit v1.2.3-59-g8ed1b