From: Loup Vaillant Date: Mon, 9 Dec 2019 13:14:21 +0000 (+0100) Subject: Completed test coverage X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=7962cb51f700630ca78bff66ab1518a49d945824;p=Monocypher.git Completed test coverage --- diff --git a/tests/gen/ed_25519_pk.c b/tests/gen/ed_25519_pk.c new file mode 100644 index 0000000..2e2e22a --- /dev/null +++ b/tests/gen/ed_25519_pk.c @@ -0,0 +1,26 @@ +#include +#include "utils.h" + +static void test(u8 seed[32]) +{ + u8 pk[32]; + u8 sk[64]; + crypto_sign_seed_keypair(pk, sk, seed); + print_vector(sk, 32); + print_vector(pk, 32); +} + +int main(void) +{ + SODIUM_INIT; + // random secret keys + FOR (msg_size, 0, 256) { + RANDOM_INPUT(sk, 32); + test(sk); + } + // zero secret key + u8 sk[32] = {0}; + test(sk); + + return 0; +} diff --git a/tests/gen/makefile b/tests/gen/makefile index d1f127d..2a200ea 100644 --- a/tests/gen/makefile +++ b/tests/gen/makefile @@ -3,9 +3,9 @@ CFLAGS = -pedantic -Wall -Wextra .PHONY: all clean -VEC = chacha20 hchacha20 xchacha20 ietf_chacha20 aead_ietf \ - poly1305 blake2b sha512 hmac_sha512 argon2i \ - edDSA edDSA_pk ed_25519 ed_25519_check \ +VEC = chacha20 hchacha20 xchacha20 ietf_chacha20 aead_ietf \ + poly1305 blake2b sha512 hmac_sha512 argon2i \ + edDSA edDSA_pk ed_25519 ed_25519_pk ed_25519_check \ x25519 x25519_pk key_exchange # monokex_xk1 monokex_x VEC2 = $(patsubst %, %.all.vec, $(VEC)) @@ -65,6 +65,7 @@ argon2i.all.vec : argon2i.vec vectors/argon2i edDSA.all.vec : edDSA.vec edDSA_pk.all.vec : edDSA_pk.vec ed_25519.all.vec : ed_25519.vec +ed_25519_pk.all.vec : ed_25519_pk.vec ed_25519_check.all.vec: vectors/ed_25519_check key_exchange.all.vec : vectors/key_exchange monokex_xk1.all.vec : monokex_xk1.vec diff --git a/tests/test.c b/tests/test.c index fd53b29..01acd65 100644 --- a/tests/test.c +++ b/tests/test.c @@ -182,6 +182,11 @@ static void ed_25519(const vector in[], vector *out) } } +static void ed_25519_pk(const vector in[], vector *out) +{ + crypto_ed25519_public_key(out->buf, in->buf); +} + static void ed_25519_check(const vector in[], vector *out) { const vector *public_k = in; @@ -268,6 +273,37 @@ static int p_verify16(){ return p_verify(16, crypto_verify16); } static int p_verify32(){ return p_verify(32, crypto_verify32); } static int p_verify64(){ return p_verify(64, crypto_verify64); } +static int p_chacha20_ctr() +{ + int status = 0; + RANDOM_INPUT(key , 32); + RANDOM_INPUT(nonce, 24); + RANDOM_INPUT(plain, 128); + u8 out_full[128]; + u8 out1 [64]; + u8 out2 [64]; + crypto_chacha20 (out_full, plain , 128, key, nonce); + crypto_chacha20_ctr(out1 , plain + 0, 64, key, nonce, 0); + crypto_chacha20_ctr(out2 , plain + 64, 64, key, nonce, 1); + status |= memcmp(out_full , out1, 64); + status |= memcmp(out_full + 64, out2, 64); + + crypto_ietf_chacha20 (out_full, plain , 128, key, nonce); + crypto_ietf_chacha20_ctr(out1 , plain + 0, 64, key, nonce, 0); + crypto_ietf_chacha20_ctr(out2 , plain + 64, 64, key, nonce, 1); + status |= memcmp(out_full , out1, 64); + status |= memcmp(out_full + 64, out2, 64); + + crypto_xchacha20 (out_full, plain , 128, key, nonce); + crypto_xchacha20_ctr(out1 , plain + 0, 64, key, nonce, 0); + crypto_xchacha20_ctr(out2 , plain + 64, 64, key, nonce, 1); + status |= memcmp(out_full , out1, 64); + status |= memcmp(out_full + 64, out2, 64); + + printf("%s: Chacha20 (ctr)\n", status != 0 ? "FAILED" : "OK"); + return status; +} + // Tests that Chacha20(nullptr) == Chacha20(all-zeroes) static int p_chacha20_stream() { @@ -741,6 +777,7 @@ int main(int argc, char *argv[]) status |= TEST(edDSA , 3); status |= TEST(edDSA_pk , 1); status |= TEST(ed_25519 , 3); + status |= TEST(ed_25519_pk , 1); status |= TEST(ed_25519_check, 3); status |= test_x25519(); @@ -749,6 +786,7 @@ int main(int argc, char *argv[]) status |= p_verify16(); status |= p_verify32(); status |= p_verify64(); + status |= p_chacha20_ctr(); status |= p_chacha20_stream(); status |= p_chacha20_same_ptr(); status |= p_hchacha20();