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

Add a test for crypto_scalarmult_ed25519

This commit is contained in:
Frank Denis 2017-11-15 16:57:29 +01:00
parent 7653df070c
commit a60d877327
4 changed files with 58 additions and 0 deletions

1
.gitignore vendored
View File

@ -128,6 +128,7 @@ test/default/pwhash_scrypt
test/default/pwhash_scrypt_ll test/default/pwhash_scrypt_ll
test/default/randombytes test/default/randombytes
test/default/scalarmult test/default/scalarmult
test/default/scalarmult_ed25519
test/default/scalarmult2 test/default/scalarmult2
test/default/scalarmult5 test/default/scalarmult5
test/default/scalarmult6 test/default/scalarmult6

View File

@ -50,6 +50,7 @@ EXTRA_DIST = \
pwhash_scrypt_ll.exp \ pwhash_scrypt_ll.exp \
randombytes.exp \ randombytes.exp \
scalarmult.exp \ scalarmult.exp \
scalarmult_ed25519.exp \
scalarmult2.exp \ scalarmult2.exp \
scalarmult5.exp \ scalarmult5.exp \
scalarmult6.exp \ scalarmult6.exp \
@ -124,6 +125,7 @@ DISTCLEANFILES = \
pwhash_scrypt_ll.res \ pwhash_scrypt_ll.res \
randombytes.res \ randombytes.res \
scalarmult.res \ scalarmult.res \
scalarmult_ed25519.res \
scalarmult2.res \ scalarmult2.res \
scalarmult5.res \ scalarmult5.res \
scalarmult6.res \ scalarmult6.res \
@ -199,6 +201,7 @@ CLEANFILES = \
pwhash_scrypt_ll.final \ pwhash_scrypt_ll.final \
randombytes.final \ randombytes.final \
scalarmult.final \ scalarmult.final \
scalarmult_ed25519.final \
scalarmult2.final \ scalarmult2.final \
scalarmult5.final \ scalarmult5.final \
scalarmult6.final \ scalarmult6.final \
@ -269,6 +272,7 @@ CLEANFILES = \
pwhash_scrypt_ll.nexe \ pwhash_scrypt_ll.nexe \
randombytes.nexe \ randombytes.nexe \
scalarmult.nexe \ scalarmult.nexe \
scalarmult_ed25519.nexe \
scalarmult2.nexe \ scalarmult2.nexe \
scalarmult5.nexe \ scalarmult5.nexe \
scalarmult6.nexe \ scalarmult6.nexe \
@ -523,6 +527,9 @@ randombytes_LDADD = $(TESTS_LDADD)
scalarmult_SOURCE = cmptest.h scalarmult.c scalarmult_SOURCE = cmptest.h scalarmult.c
scalarmult_LDADD = $(TESTS_LDADD) scalarmult_LDADD = $(TESTS_LDADD)
scalarmult_ed25519_SOURCE = cmptest.h scalarmult_ed25519.c
scalarmult_ed25519_LDADD = $(TESTS_LDADD)
scalarmult2_SOURCE = cmptest.h scalarmult2.c scalarmult2_SOURCE = cmptest.h scalarmult2.c
scalarmult2_LDADD = $(TESTS_LDADD) scalarmult2_LDADD = $(TESTS_LDADD)
@ -603,6 +610,7 @@ TESTS_TARGETS += \
core_ed25519 \ core_ed25519 \
pwhash_scrypt \ pwhash_scrypt \
pwhash_scrypt_ll \ pwhash_scrypt_ll \
scalarmult_ed25519 \
siphashx24 \ siphashx24 \
xchacha20 xchacha20
endif endif

View File

@ -0,0 +1,48 @@
#define TEST_NAME "scalarmult_ed25519"
#include "cmptest.h"
int
main(void)
{
static const unsigned char B[32] = {
0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
};
unsigned char *n, *p, *q, *q2;
n = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_SCALARBYTES);
p = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_BYTES);
q = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_BYTES);
q2 = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_BYTES);
randombytes_buf(n, crypto_scalarmult_ed25519_SCALARBYTES);
if (crypto_scalarmult_ed25519_base(q, n) != 0) {
printf("crypto_scalarmult_ed25519_base() failed\n");
}
memcpy(p, B, crypto_scalarmult_ed25519_BYTES);
if (crypto_scalarmult_ed25519(q2, n, p) != 0) {
printf("crypto_scalarmult_ed25519() failed\n");
}
if (memcmp(q, q2, crypto_scalarmult_ed25519_BYTES) != 0) {
printf("crypto_scalarmult_ed25519_base(n) != crypto_scalarmult_ed25519(n, 9)\n");
}
memset(n, 0, crypto_scalarmult_ed25519_BYTES);
if (crypto_scalarmult_ed25519_base(q, n) != 0) {
printf("crypto_scalarmult_ed25519_base() didn't fail\n");
}
if (crypto_scalarmult_ed25519(q2, n, p) != 0) {
printf("crypto_scalarmult_ed25519() didn't fail\n");
}
sodium_free(q2);
sodium_free(q);
sodium_free(p);
sodium_free(n);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1 @@
OK