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

Add test vectors for the string to curve operation

This commit is contained in:
Frank Denis 2020-03-31 13:40:42 +02:00
parent 3a736f4d19
commit c8d604e1f1
4 changed files with 117 additions and 0 deletions

1
.gitignore vendored
View File

@ -114,6 +114,7 @@ test/default/core4
test/default/core5 test/default/core5
test/default/core6 test/default/core6
test/default/core_ed25519 test/default/core_ed25519
test/default/core_ed25519_h2c
test/default/core_ristretto255 test/default/core_ristretto255
test/default/ed25519_convert test/default/ed25519_convert
test/default/generichash test/default/generichash

View File

@ -27,6 +27,7 @@ EXTRA_DIST = \
chacha20.exp \ chacha20.exp \
codecs.exp \ codecs.exp \
core_ed25519.exp \ core_ed25519.exp \
core_ed25519_h2c.exp \
core_ristretto255.exp \ core_ristretto255.exp \
core1.exp \ core1.exp \
core2.exp \ core2.exp \
@ -108,6 +109,7 @@ DISTCLEANFILES = \
chacha20.res \ chacha20.res \
codecs.res \ codecs.res \
core_ed25519.res \ core_ed25519.res \
core_ed25519_h2c.res \
core_ristretto255.res \ core_ristretto255.res \
core1.res \ core1.res \
core2.res \ core2.res \
@ -327,6 +329,9 @@ codecs_LDADD = $(TESTS_LDADD)
core_ed25519_SOURCE = cmptest.h core_ed25519.c core_ed25519_SOURCE = cmptest.h core_ed25519.c
core_ed25519_LDADD = $(TESTS_LDADD) core_ed25519_LDADD = $(TESTS_LDADD)
core_ed25519_h2c_SOURCE = cmptest.h core_ed25519_h2c.c
core_ed25519_h2c_LDADD = $(TESTS_LDADD)
core_ristretto255_SOURCE = cmptest.h core_ristretto255.c core_ristretto255_SOURCE = cmptest.h core_ristretto255.c
core_ristretto255_LDADD = $(TESTS_LDADD) core_ristretto255_LDADD = $(TESTS_LDADD)
@ -495,6 +500,7 @@ xchacha20_LDADD = $(TESTS_LDADD)
if !MINIMAL if !MINIMAL
TESTS_TARGETS += \ TESTS_TARGETS += \
core_ed25519 \ core_ed25519 \
core_ed25519_h2c \
core_ristretto255 \ core_ristretto255 \
pwhash_scrypt \ pwhash_scrypt \
pwhash_scrypt_ll \ pwhash_scrypt_ll \

View File

@ -0,0 +1,109 @@
#define TEST_NAME "core_ed25519_h2c"
#include "cmptest.h"
typedef struct TestData_ {
int ro;
const char *msg;
const char tv_y[64];
} TestData;
static TestData test_data[] = {
{ 0, "",
"115fe9c145cec75332210f75537f89a5af2e9e81928ab63225fcf0db4b9f0b41" },
{ 0, "abc",
"2a78994752306e4a4eb1c629b3c8625cc26f143f1fe35fc728d295222eba7890" },
{ 0, "abcdef0123456789",
"0ca9e2b900bcdfc8b26d705040b6b6a6fd6bfadfd43982a2a59e1d069898ae6b" },
{ 0,
"a512_"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa",
"511dee3fcc3a422738c453a58acdeafc08fc76f862e97d678adb26f03d0963b5" },
{ 1, "",
"1af40833bed99ac42f445e9494dbcc489561b3995a40e3864a1b1bdb6ed6ecd0" },
{ 1, "abc",
"7bdb83b6322c4977ffbb69b18df168b56eec733a0254cac0e85eb790460ee4b2" },
{ 1, "abcdef0123456789",
"2dd85e9585fba5ab3c22a07cf07b2cf4a19b10dcab49e1a4c8f952461e644bbc" },
{ 1,
"a512_"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa",
"160e08388e85b6bcbec8f321ed1de259ffe88dc547a1ce506d61b30fd2378fc5" }
};
int
main(void)
{
unsigned char *expected_yr, *expected_y, *y;
char * expected_y_hex, *y_hex;
size_t i, j;
expected_yr = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
expected_y = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
y = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
expected_y_hex =
(char *) sodium_malloc(crypto_core_ed25519_BYTES * 2U + 1U);
y_hex = (char *) sodium_malloc(crypto_core_ed25519_BYTES * 2U + 1U);
for (i = 0U; i < (sizeof test_data) / (sizeof test_data[0]); i++) {
sodium_hex2bin(expected_yr, crypto_core_ed25519_BYTES,
test_data[i].tv_y, (size_t) -1U, NULL, NULL, NULL);
for (j = 0; j < crypto_core_ed25519_BYTES; j++) {
expected_y[j] = expected_yr[crypto_core_ed25519_BYTES - 1U - j];
}
if (test_data[i].ro == 0) {
if (crypto_core_ed25519_from_string(
y, "TESTGEN", (const unsigned char *) test_data[i].msg,
strlen(test_data[i].msg)) != 0) {
printf("crypto_core_ed25519_from_string() failed\n");
}
} else {
if (crypto_core_ed25519_from_string_ro(
y, "TESTGEN", (const unsigned char *) test_data[i].msg,
strlen(test_data[i].msg)) != 0) {
printf("crypto_core_ed25519_from_string_ro() failed\n");
}
}
y[crypto_core_ed25519_BYTES - 1U] &= 0x7f;
if (memcmp(y, expected_y, crypto_core_ed25519_BYTES) != 0) {
sodium_bin2hex(expected_y_hex, crypto_core_ed25519_BYTES * 2U + 1U,
expected_y, crypto_core_ed25519_BYTES);
sodium_bin2hex(y_hex, crypto_core_ed25519_BYTES * 2U + 1U, y,
crypto_core_ed25519_BYTES);
printf("Test #%u failed - expected [%s] got [%s]\n", (unsigned) i,
expected_y_hex, y_hex);
}
}
if (crypto_core_ed25519_from_string(y, NULL, (const unsigned char *) "msg",
3U) != 0 ||
crypto_core_ed25519_from_string(y, "", guard_page, 0U) != 0 ||
crypto_core_ed25519_from_string_ro(
y, NULL, (const unsigned char *) "msg", 3U) != 0 ||
crypto_core_ed25519_from_string_ro(y, "", guard_page, 0U) != 0) {
printf("Failed with empty parameters");
}
sodium_free(y_hex);
sodium_free(expected_y_hex);
sodium_free(y);
sodium_free(expected_y);
sodium_free(expected_yr);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1 @@
OK