From: Richard Walmsley Date: Sat, 29 Feb 2020 21:53:35 +0000 (+1300) Subject: Perform a full overlapping range for test. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6784cb92d41637e565c3c04873919c8a2e9039c0;p=Monocypher.git Perform a full overlapping range for test. Also done the same for x25519 and included copyright details. --- diff --git a/doc/man/man3/crypto_key_exchange.3monocypher b/doc/man/man3/crypto_key_exchange.3monocypher index c626b83..d02ac3e 100644 --- a/doc/man/man3/crypto_key_exchange.3monocypher +++ b/doc/man/man3/crypto_key_exchange.3monocypher @@ -11,6 +11,7 @@ .\" Copyright (c) 2017-2019 Loup Vaillant .\" Copyright (c) 2017-2018 Michael Savage .\" Copyright (c) 2017, 2019 Fabio Scotoni +.\" Copyright (c) 2020 Richard Walmsley .\" All rights reserved. .\" .\" @@ -40,7 +41,8 @@ .\" .\" ---------------------------------------------------------------------------- .\" -.\" Written in 2017-2019 by Loup Vaillant, Michael Savage and Fabio Scotoni +.\" Written in 2017-2020 by Loup Vaillant, Michael Savage, Fabio Scotoni and +.\" Richard Walmsley .\" .\" To the extent possible under law, the author(s) have dedicated all copyright .\" and related neighboring rights to this software to the public domain diff --git a/doc/man/man3/crypto_x25519.3monocypher b/doc/man/man3/crypto_x25519.3monocypher index fed0d23..8a4562c 100644 --- a/doc/man/man3/crypto_x25519.3monocypher +++ b/doc/man/man3/crypto_x25519.3monocypher @@ -11,6 +11,7 @@ .\" Copyright (c) 2017-2019 Loup Vaillant .\" Copyright (c) 2017-2018 Michael Savage .\" Copyright (c) 2017, 2019 Fabio Scotoni +.\" Copyright (c) 2020 Richard Walmsley .\" All rights reserved. .\" .\" @@ -40,7 +41,8 @@ .\" .\" ---------------------------------------------------------------------------- .\" -.\" Written in 2017-2019 by Loup Vaillant, Michael Savage and Fabio Scotoni +.\" Written in 2017-2020 by Loup Vaillant, Michael Savage, Fabio Scotoni and +.\" Richard Walmsley .\" .\" To the extent possible under law, the author(s) have dedicated all copyright .\" and related neighboring rights to this software to the public domain @@ -106,6 +108,11 @@ for advice about generating random bytes (use the operating system's random number generator). .It Fa their_public_key The public key of the other party. +.Pp +.Fa raw_shared_secret +and +.Fa your_secret_key +may overlap if your secret is no longer required. .El .Sh RETURN VALUES .Fn crypto_x25519 diff --git a/tests/test.c b/tests/test.c index b1f026c..44c72fd 100644 --- a/tests/test.c +++ b/tests/test.c @@ -9,7 +9,7 @@ // // ------------------------------------------------------------------------ // -// Copyright (c) 2017-2019, Loup Vaillant +// Copyright (c) 2017-2020, Loup Vaillant and Richard Walmsley // All rights reserved. // // @@ -39,7 +39,7 @@ // // ------------------------------------------------------------------------ // -// Written in 2017-2019 by Loup Vaillant +// Written in 2017-2020 by Loup Vaillant and Richard Walmsley // // To the extent possible under law, the author(s) have dedicated all copyright // and related neighboring rights to this software to the public domain @@ -660,17 +660,37 @@ static int p_argon2i_overlap() return status; } +// Tests that the shared key and secret key buffers of crypto_x25519 can overlap. +static int p_x25519_overlap() +{ + int status = 0; + FOR (i, 0, 62) { + u8 overlapping[94]; + u8 seperate[32]; + RANDOM_INPUT(sk, 32); + RANDOM_INPUT(pk, 32); + memcpy(overlapping + 31, sk, 32); + crypto_x25519(overlapping + i, overlapping + 31, pk); + crypto_x25519(seperate, sk, pk); + status |= memcmp(seperate, overlapping + i, 32); + } + printf("%s: x25519 (overlaping i/o)\n", status != 0 ? "FAILED" : "OK"); + return status; +} + // Tests that the shared key and secret key buffers of crypto_key_exchange can overlap. static int p_key_exchange_overlap() { int status = 0; - FOR (i, 0, 5) { - u8 buf[32]; + FOR (i, 0, 62) { + u8 overlapping[94]; + u8 seperate[32]; RANDOM_INPUT(sk, 32); RANDOM_INPUT(pk, 32); - crypto_key_exchange(buf, sk, pk); - crypto_key_exchange(sk, sk, pk); - status |= memcmp(buf, sk, 32); + memcpy(overlapping + 31, sk, 32); + crypto_key_exchange(overlapping + i, overlapping + 31, pk); + crypto_key_exchange(seperate, sk, pk); + status |= memcmp(seperate, overlapping + i, 32); } printf("%s: key_exchange (overlaping i/o)\n", status != 0 ? "FAILED" : "OK"); return status; @@ -869,6 +889,7 @@ int main(int argc, char *argv[]) status |= p_hmac_sha512_overlap(); status |= p_argon2i_easy(); status |= p_argon2i_overlap(); + status |= p_x25519_overlap(); status |= p_key_exchange_overlap(); status |= p_eddsa_roundtrip(); status |= p_eddsa_random();