From 12277ee6b50254664afe1bc9fa2510f2c14dfe49 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 6 May 2019 12:40:21 +0200 Subject: [PATCH] More tests --- .../crypto_sign/ed25519/ref10/obsolete.c | 2 ++ test/default/core_ristretto255.c | 18 ++++++++++++++++++ test/default/scalarmult_ed25519.c | 12 ++++++++++++ test/default/scalarmult_ristretto255.c | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c b/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c index 03440cfa..64ded79e 100644 --- a/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +++ b/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c @@ -10,6 +10,7 @@ #include "randombytes.h" #include "utils.h" +/* LCOV_EXCL_START */ int crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk, unsigned char *sk) @@ -114,3 +115,4 @@ crypto_sign_edwards25519sha512batch_open(unsigned char *m, return 0; } +/* LCOV_EXCL_END */ diff --git a/test/default/core_ristretto255.c b/test/default/core_ristretto255.c index 10ada0a9..a3973604 100644 --- a/test/default/core_ristretto255.c +++ b/test/default/core_ristretto255.c @@ -167,6 +167,24 @@ tv3(void) if (crypto_scalarmult_ristretto255(s2, l, s2) == 0) { printf("s*l != inf (3)\n"); } + if (crypto_core_ristretto255_add(s2, s, s_) != 0) { + printf("addition failed"); + } + if (crypto_core_ristretto255_sub(s2, s2, s_) != 0) { + printf("substraction failed"); + } + if (crypto_core_ristretto255_is_valid_point(s2) == 0) { + printf("invalid point"); + } + if (memcmp(s, s2, crypto_core_ristretto255_BYTES) != 0) { + printf("s2 + s - s_ != s\n"); + } + if (crypto_core_ristretto255_sub(s2, s2, s) != 0) { + printf("substraction failed"); + } + if (crypto_core_ristretto255_is_valid_point(s2) == -1) { + printf("s + s' - s - s' != 0"); + } } sodium_free(s2); diff --git a/test/default/scalarmult_ed25519.c b/test/default/scalarmult_ed25519.c index 26d431ae..795647b5 100644 --- a/test/default/scalarmult_ed25519.c +++ b/test/default/scalarmult_ed25519.c @@ -83,6 +83,18 @@ main(void) if (memcmp(q, q2, crypto_scalarmult_ed25519_BYTES) == 0) { printf("clamping not applied\n"); } + + n[0] = 9; + if (crypto_scalarmult_ed25519_base(q, n) != 0) { + printf("crypto_scalarmult_ed25519_base() failed\n"); + } + if (crypto_scalarmult_ed25519_base_noclamp(q2, n) != 0) { + printf("crypto_scalarmult_ed25519_base_noclamp() failed\n"); + } + if (memcmp(q, q2, crypto_scalarmult_ed25519_BYTES) == 0) { + printf("clamping not applied\n"); + } + n[0] = 8; n[31] = 64; if (crypto_scalarmult_ed25519_noclamp(q2, n, p) != 0) { diff --git a/test/default/scalarmult_ristretto255.c b/test/default/scalarmult_ristretto255.c index 96a813cb..1acd1216 100644 --- a/test/default/scalarmult_ristretto255.c +++ b/test/default/scalarmult_ristretto255.c @@ -32,6 +32,10 @@ main(void) assert(memcmp(p, p2, crypto_scalarmult_ristretto255_BYTES) == 0); sodium_increment(n, crypto_scalarmult_ristretto255_SCALARBYTES); } + + memset(p, 0xfe, crypto_scalarmult_ristretto255_BYTES); + assert(crypto_scalarmult_ristretto255(guard_page, n, p) == -1); + sodium_free(hex); sodium_free(p2); sodium_free(p);