From 1e06b32f45bf8a0cda18cd047421f7713f9c8354 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 15 Nov 2017 01:44:55 +0100 Subject: [PATCH] Add a couple more tests for ed25519_is_valid_point() --- test/default/core_ed25519.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/default/core_ed25519.c b/test/default/core_ed25519.c index 6154b7ce..ed7aeff2 100644 --- a/test/default/core_ed25519.c +++ b/test/default/core_ed25519.c @@ -1,7 +1,25 @@ - #define TEST_NAME "core_ed25519" #include "cmptest.h" +static void +add_l(unsigned char * const S) +{ + static const unsigned char l[32] = + { 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, + 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 }; + unsigned char c = 0U; + unsigned int i; + unsigned int s; + + for (i = 0U; i < 32U; i++) { + s = S[i] + l[i] + c; + S[i] = (unsigned char) s; + c = (s >> 8) & 1; + } +} + int main(void) { @@ -63,6 +81,22 @@ main(void) printf("crypto_scalarmult_ed25519() is inconsistent with crypto_core_ed25519_add()\n"); } + assert(crypto_core_ed25519_is_valid_point(p) == 1); + add_l(p); + assert(crypto_core_ed25519_is_valid_point(p) == 0); + + memset(p, 0, crypto_core_ed25519_BYTES); + assert(crypto_core_ed25519_is_valid_point(p) == 0); + + p[0] = 1; + assert(crypto_core_ed25519_is_valid_point(p) == 0); + + p[0] = 2; + assert(crypto_core_ed25519_is_valid_point(p) == 0); + + p[0] = 9; + assert(crypto_core_ed25519_is_valid_point(p) == 1); + sodium_free(sc); sodium_free(p3); sodium_free(p2);