1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-23 20:15:19 -07:00

More tests

This commit is contained in:
Frank Denis 2019-05-06 12:40:21 +02:00
parent 141de9be13
commit 12277ee6b5
4 changed files with 36 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include "randombytes.h" #include "randombytes.h"
#include "utils.h" #include "utils.h"
/* LCOV_EXCL_START */
int int
crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk, crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk,
unsigned char *sk) unsigned char *sk)
@ -114,3 +115,4 @@ crypto_sign_edwards25519sha512batch_open(unsigned char *m,
return 0; return 0;
} }
/* LCOV_EXCL_END */

View File

@ -167,6 +167,24 @@ tv3(void)
if (crypto_scalarmult_ristretto255(s2, l, s2) == 0) { if (crypto_scalarmult_ristretto255(s2, l, s2) == 0) {
printf("s*l != inf (3)\n"); 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); sodium_free(s2);

View File

@ -83,6 +83,18 @@ main(void)
if (memcmp(q, q2, crypto_scalarmult_ed25519_BYTES) == 0) { if (memcmp(q, q2, crypto_scalarmult_ed25519_BYTES) == 0) {
printf("clamping not applied\n"); 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[0] = 8;
n[31] = 64; n[31] = 64;
if (crypto_scalarmult_ed25519_noclamp(q2, n, p) != 0) { if (crypto_scalarmult_ed25519_noclamp(q2, n, p) != 0) {

View File

@ -32,6 +32,10 @@ main(void)
assert(memcmp(p, p2, crypto_scalarmult_ristretto255_BYTES) == 0); assert(memcmp(p, p2, crypto_scalarmult_ristretto255_BYTES) == 0);
sodium_increment(n, crypto_scalarmult_ristretto255_SCALARBYTES); 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(hex);
sodium_free(p2); sodium_free(p2);
sodium_free(p); sodium_free(p);