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

More tests

This commit is contained in:
Frank Denis 2019-05-06 13:02:20 +02:00
parent 011343e88c
commit 6d9e2f0c84
2 changed files with 49 additions and 2 deletions

View File

@ -81,14 +81,21 @@ void tv2(void)
assert(crypto_box_curve25519xchacha20poly1305_sealbytes() == assert(crypto_box_curve25519xchacha20poly1305_sealbytes() ==
crypto_box_curve25519xchacha20poly1305_SEALBYTES); crypto_box_curve25519xchacha20poly1305_SEALBYTES);
} }
#else
static
void tv2(void)
{
printf("0\n-1\n-1\n-1\n");
}
#endif #endif
int int
main(void) main(void)
{ {
tv1(); tv1();
#ifndef SODIUM_LIBRARY_MINIMAL
tv2(); tv2();
#endif
return 0; return 0;
} }

View File

@ -206,12 +206,52 @@ tv3(void)
sodium_free(r); sodium_free(r);
} }
static void
tv4(void)
{
unsigned char *r;
unsigned char *s1;
unsigned char *s2;
unsigned char *s3;
unsigned char *s4;
r = (unsigned char *) sodium_malloc(crypto_core_ristretto255_NONREDUCEDSCALARBYTES);
s1 = (unsigned char *) sodium_malloc(crypto_core_ristretto255_SCALARBYTES);
s2 = (unsigned char *) sodium_malloc(crypto_core_ristretto255_SCALARBYTES);
s3 = (unsigned char *) sodium_malloc(crypto_core_ristretto255_SCALARBYTES);
s4 = (unsigned char *) sodium_malloc(crypto_core_ristretto255_SCALARBYTES);
crypto_core_ristretto255_scalar_random(s1);
randombytes_buf(r, crypto_core_ristretto255_NONREDUCEDSCALARBYTES);
crypto_core_ristretto255_scalar_reduce(s2, r);
memcpy(s4, s1, crypto_core_ristretto255_SCALARBYTES);
crypto_core_ristretto255_scalar_add(s3, s1, s2);
crypto_core_ristretto255_scalar_sub(s4, s1, s2);
crypto_core_ristretto255_scalar_add(s2, s3, s4);
crypto_core_ristretto255_scalar_sub(s2, s2, s1);
crypto_core_ristretto255_scalar_mul(s2, s3, s2);
crypto_core_ristretto255_scalar_invert(s4, s3);
crypto_core_ristretto255_scalar_mul(s2, s2, s4);
crypto_core_ristretto255_scalar_negate(s1, s1);
crypto_core_ristretto255_scalar_add(s2, s2, s1);
crypto_core_ristretto255_scalar_complement(s1, s2);
s1[0]--;
assert(sodium_is_zero(s1, crypto_core_ristretto255_SCALARBYTES));
sodium_free(s1);
sodium_free(s2);
sodium_free(s3);
sodium_free(s4);
sodium_free(r);
}
int int
main(void) main(void)
{ {
tv1(); tv1();
tv2(); tv2();
tv3(); tv3();
tv4();
assert(crypto_core_ristretto255_BYTES == crypto_core_ristretto255_bytes()); assert(crypto_core_ristretto255_BYTES == crypto_core_ristretto255_bytes());
assert(crypto_core_ristretto255_SCALARBYTES == crypto_core_ristretto255_scalarbytes()); assert(crypto_core_ristretto255_SCALARBYTES == crypto_core_ristretto255_scalarbytes());