1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -07:00

Add an obsolete test, add a deterministic one for from_uniform()

This commit is contained in:
Frank Denis 2020-03-30 12:24:29 +02:00
parent 1e7562f59b
commit 092bf7cfd1
2 changed files with 30 additions and 9 deletions

View File

@ -48,6 +48,7 @@ main(void)
unsigned char *p, *p2, *p3;
unsigned char *sc, *sc2, *sc3;
unsigned char *sc64;
unsigned char *seed;
char *hex;
unsigned int i, j;
@ -62,15 +63,6 @@ main(void)
if (crypto_core_ed25519_is_valid_point(p) == 0) {
printf("crypto_core_ed25519_from_uniform() returned an invalid point\n");
}
randombytes_buf(h, crypto_core_ed25519_HASHBYTES);
if (crypto_core_ed25519_from_hash(p, h) != 0) {
printf("crypto_core_ed25519_from_hash() failed\n");
}
if (crypto_core_ed25519_is_valid_point(p) == 0) {
printf("crypto_core_ed25519_from_hash() returned an invalid point\n");
}
crypto_core_ed25519_random(p);
if (crypto_core_ed25519_is_valid_point(p) == 0) {
printf("crypto_core_ed25519_random() returned an invalid point\n");
@ -387,6 +379,20 @@ main(void)
crypto_core_ed25519_scalar_mul(sc3, sc, sc2);
assert(memcmp(sc3, sc, crypto_core_ed25519_SCALARBYTES) != 0);
}
seed = (unsigned char *) sodium_malloc(randombytes_SEEDBYTES);
for (i = 0; i < 15; i++) {
randombytes_buf_deterministic(r, crypto_core_ed25519_UNIFORMBYTES, seed);
if (crypto_core_ed25519_from_uniform(p, r) != 0) {
printf("crypto_core_ed25519_from_uniform() failed\n");
}
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
p, crypto_core_ed25519_BYTES);
printf("from_uniform_deterministic (%u): %s\n", i, hex);
sodium_increment(seed, randombytes_SEEDBYTES);
}
sodium_free(seed);
sodium_free(hex);
sodium_free(sc64);
sodium_free(sc3);

View File

@ -15,4 +15,19 @@ sub1: f67c79849de0253ba142949e1db6224b13121212121212121212121212121202
add2: b02e8581ce62f69922427c23f970f7e951525252525252525252525252525202
sub2: 3da570db4b001cbeb35a7b7fe588e72aaeadadadadadadadadadadadadadad0d
mul: 4453ef38408c06677c1b810e4bf8b1991f01c88716fbfa2f075a518b77da400b
from_uniform_deterministic (0): b18e62cf804b022fec392b0e2d6539d0f059732616c11913f510f73ae2544ebc
from_uniform_deterministic (1): b9d23004e78c58e22da72e109550133e3d3bb9e46afcc066b82326319653d62c
from_uniform_deterministic (2): 14063782c8b8a677dce09c4e51719b1cf942bf71bc765c1ec9832a8b4446983c
from_uniform_deterministic (3): 02d6dbac70f6a14de72f4e17386016b08d6506336a086f10e719fbad8831d550
from_uniform_deterministic (4): 11c851408e7892c2eae37584423a8f9c797e3649d45946b53e64319318a750b0
from_uniform_deterministic (5): d4b9eaf70ffdc238c88725e294bdd02a6ce85577c5e7add7ca07041873019842
from_uniform_deterministic (6): 740a6141079285c1b9e84ed463dcce5d3d40a167fa13129463eaf97d2a7bf654
from_uniform_deterministic (7): e504a3e00bbf506cbe388784d85e85b10c428c37eba04ebd19a60948b71ad2cf
from_uniform_deterministic (8): 67cd50902c40c943f22c479c587fb3e5da2f8f1ad402049ac49ddc45ec20884c
from_uniform_deterministic (9): 658bffa23b425a91268ee17559073c4b1548209054ed7cf00ffe582696dda8dc
from_uniform_deterministic (10): b55b93e7a0fe554f86f1f4c991871a27756fee359a8c6bb7554ec91d5d552c49
from_uniform_deterministic (11): fbc2bb45df1d806489a5a6415898c719c45c932d3467b6ce948ee80c0e8122c9
from_uniform_deterministic (12): 93164e57b5e3ae6826ac9e0c31ddecf94e21a39a29ba9d1d24e9e588fe065d95
from_uniform_deterministic (13): 16824d74c9482890dc57b0ec843a0a5231b581d2ce3909934d7658389f169093
from_uniform_deterministic (14): 2f5b0336c7f0af520badeae99450f92835c27224ab4cd117f55b176afb6f0001
OK