mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Add a couple more tests
This commit is contained in:
@@ -108,6 +108,7 @@ test/default/box8
|
||||
test/default/browser
|
||||
test/default/chacha20
|
||||
test/default/codecs
|
||||
test/default/codecs2
|
||||
test/default/core_ed25519
|
||||
test/default/core_ed25519_h2c
|
||||
test/default/core_keccak1600
|
||||
@@ -131,6 +132,7 @@ test/default/ipcrypt
|
||||
test/default/kdf
|
||||
test/default/kdf_hkdf
|
||||
test/default/kdf_hkdf2
|
||||
test/default/kdf_hkdf3
|
||||
test/default/keygen
|
||||
test/default/kem
|
||||
test/default/kem_mlkem768
|
||||
@@ -181,6 +183,7 @@ test/default/xof_shake128
|
||||
test/default/xof_shake256
|
||||
test/default/xof_turboshake128
|
||||
test/default/xof_turboshake256
|
||||
test/default/xof2
|
||||
test/js.done
|
||||
test/symbols/all-host-symbols.txt
|
||||
test/symbols/internal-host-symbols.txt
|
||||
|
||||
@@ -28,6 +28,7 @@ EXTRA_DIST = \
|
||||
box_seed.exp \
|
||||
chacha20.exp \
|
||||
codecs.exp \
|
||||
codecs2.exp \
|
||||
core_ed25519.exp \
|
||||
core_ed25519_h2c.exp \
|
||||
core_ristretto255.exp \
|
||||
@@ -51,6 +52,7 @@ EXTRA_DIST = \
|
||||
kdf.exp \
|
||||
kdf_hkdf.exp \
|
||||
kdf_hkdf2.exp \
|
||||
kdf_hkdf3.exp \
|
||||
kem.exp \
|
||||
kem_mlkem768.exp \
|
||||
kem_xwing.exp \
|
||||
@@ -100,7 +102,8 @@ EXTRA_DIST = \
|
||||
xof_shake128.exp \
|
||||
xof_shake256.exp \
|
||||
xof_turboshake128.exp \
|
||||
xof_turboshake256.exp
|
||||
xof_turboshake256.exp \
|
||||
xof2.exp
|
||||
|
||||
DISTCLEANFILES = \
|
||||
aead_aegis128l.res \
|
||||
@@ -126,6 +129,7 @@ DISTCLEANFILES = \
|
||||
box_seed.res \
|
||||
chacha20.res \
|
||||
codecs.res \
|
||||
codecs2.res \
|
||||
core_ed25519.res \
|
||||
core_ed25519_h2c.res \
|
||||
core_ristretto255.res \
|
||||
@@ -150,6 +154,7 @@ DISTCLEANFILES = \
|
||||
kdf.res \
|
||||
kdf_hkdf.res \
|
||||
kdf_hkdf2.res \
|
||||
kdf_hkdf3.res \
|
||||
kem.res \
|
||||
kem_mlkem768.res \
|
||||
kem_xwing.res \
|
||||
@@ -199,7 +204,8 @@ DISTCLEANFILES = \
|
||||
xof_shake128.res \
|
||||
xof_shake256.res \
|
||||
xof_turboshake128.res \
|
||||
xof_turboshake256.res
|
||||
xof_turboshake256.res \
|
||||
xof2.res
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DTEST_SRCDIR=\"@srcdir@\" \
|
||||
@@ -235,6 +241,7 @@ TESTS_TARGETS = \
|
||||
box_seed \
|
||||
chacha20 \
|
||||
codecs \
|
||||
codecs2 \
|
||||
core1 \
|
||||
core2 \
|
||||
core3 \
|
||||
@@ -292,7 +299,8 @@ TESTS_TARGETS = \
|
||||
xof_shake128 \
|
||||
xof_shake256 \
|
||||
xof_turboshake128 \
|
||||
xof_turboshake256
|
||||
xof_turboshake256 \
|
||||
xof2
|
||||
|
||||
if !EMSCRIPTEN
|
||||
TESTS_TARGETS += \
|
||||
@@ -376,6 +384,9 @@ chacha20_LDADD = $(TESTS_LDADD)
|
||||
codecs_SOURCE = cmptest.h codecs.c
|
||||
codecs_LDADD = $(TESTS_LDADD)
|
||||
|
||||
codecs2_SOURCE = cmptest.h codecs2.c
|
||||
codecs2_LDADD = $(TESTS_LDADD)
|
||||
|
||||
core_ed25519_SOURCE = cmptest.h core_ed25519.c
|
||||
core_ed25519_LDADD = $(TESTS_LDADD)
|
||||
|
||||
@@ -445,6 +456,9 @@ kdf_hkdf_LDADD = $(TESTS_LDADD)
|
||||
kdf_hkdf2_SOURCE = cmptest.h kdf_hkdf2.c
|
||||
kdf_hkdf2_LDADD = $(TESTS_LDADD)
|
||||
|
||||
kdf_hkdf3_SOURCE = cmptest.h kdf_hkdf3.c
|
||||
kdf_hkdf3_LDADD = $(TESTS_LDADD)
|
||||
|
||||
kem_SOURCE = cmptest.h kem.c
|
||||
kem_LDADD = $(TESTS_LDADD)
|
||||
|
||||
@@ -595,6 +609,9 @@ xof_turboshake128_LDADD = $(TESTS_LDADD)
|
||||
xof_turboshake256_SOURCE = cmptest.h xof_turboshake256.c
|
||||
xof_turboshake256_LDADD = $(TESTS_LDADD)
|
||||
|
||||
xof2_SOURCE = cmptest.h xof2.c
|
||||
xof2_LDADD = $(TESTS_LDADD)
|
||||
|
||||
if !MINIMAL
|
||||
TESTS_TARGETS += \
|
||||
core_ed25519 \
|
||||
@@ -603,6 +620,7 @@ TESTS_TARGETS += \
|
||||
core_ristretto255_h2c \
|
||||
kdf_hkdf \
|
||||
kdf_hkdf2 \
|
||||
kdf_hkdf3 \
|
||||
pwhash_scrypt \
|
||||
stream5 \
|
||||
pwhash_scrypt_ll \
|
||||
|
||||
@@ -636,6 +636,12 @@ main(void)
|
||||
assert(crypto_aead_aegis128l_npubbytes() == crypto_aead_aegis128l_NPUBBYTES);
|
||||
assert(crypto_aead_aegis128l_abytes() == crypto_aead_aegis128l_ABYTES);
|
||||
assert(crypto_aead_aegis128l_messagebytes_max() == crypto_aead_aegis128l_MESSAGEBYTES_MAX);
|
||||
|
||||
{
|
||||
unsigned char k[crypto_aead_aegis128l_KEYBYTES];
|
||||
crypto_aead_aegis128l_keygen(k);
|
||||
assert(!sodium_is_zero(k, sizeof k));
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -717,6 +717,12 @@ main(void)
|
||||
assert(crypto_aead_aegis256_npubbytes() == crypto_aead_aegis256_NPUBBYTES);
|
||||
assert(crypto_aead_aegis256_abytes() == crypto_aead_aegis256_ABYTES);
|
||||
assert(crypto_aead_aegis256_messagebytes_max() == crypto_aead_aegis256_MESSAGEBYTES_MAX);
|
||||
|
||||
{
|
||||
unsigned char k[crypto_aead_aegis256_KEYBYTES];
|
||||
crypto_aead_aegis256_keygen(k);
|
||||
assert(!sodium_is_zero(k, sizeof k));
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -268,7 +268,23 @@ int
|
||||
main(void)
|
||||
{
|
||||
if (crypto_aead_aes256gcm_is_available()) {
|
||||
crypto_aead_aes256gcm_state st;
|
||||
unsigned char key[crypto_aead_aes256gcm_KEYBYTES];
|
||||
unsigned char nonce[crypto_aead_aes256gcm_NPUBBYTES];
|
||||
unsigned char m[16] = { 0 };
|
||||
unsigned char c[16 + crypto_aead_aes256gcm_ABYTES];
|
||||
unsigned long long clen;
|
||||
|
||||
tv();
|
||||
|
||||
crypto_aead_aes256gcm_keygen(key);
|
||||
randombytes_buf(nonce, sizeof nonce);
|
||||
crypto_aead_aes256gcm_beforenm(&st, key);
|
||||
assert(crypto_aead_aes256gcm_encrypt_afternm(
|
||||
c, &clen, m, 16, NULL, 0, NULL, nonce, &st) == 0);
|
||||
assert(clen == 16 + crypto_aead_aes256gcm_ABYTES);
|
||||
assert(crypto_aead_aes256gcm_decrypt_afternm(
|
||||
m, NULL, NULL, c, clen, NULL, 0, nonce, &st) == 0);
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
#define TEST_NAME "codecs2"
|
||||
#include "cmptest.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned char ip_bytes[16];
|
||||
|
||||
assert(sodium_ip2bin(ip_bytes, "fe80::1%eth 0",
|
||||
strlen("fe80::1%eth 0")) == -1);
|
||||
assert(sodium_ip2bin(ip_bytes, "fe80::1%\t",
|
||||
strlen("fe80::1%\t")) == -1);
|
||||
assert(sodium_ip2bin(ip_bytes, "fe80::1%eth\n0",
|
||||
strlen("fe80::1%eth\n0")) == -1);
|
||||
printf("ip2bin: zone with whitespace rejected: OK\n");
|
||||
|
||||
assert(sodium_ip2bin(ip_bytes, "192.168.1.1%zone",
|
||||
strlen("192.168.1.1%zone")) == -1);
|
||||
assert(sodium_ip2bin(ip_bytes, "10.0.0.1%1",
|
||||
strlen("10.0.0.1%1")) == -1);
|
||||
printf("ip2bin: IPv4 with zone rejected: OK\n");
|
||||
|
||||
assert(sodium_ip2bin(ip_bytes, "fe80::1%eth0",
|
||||
strlen("fe80::1%eth0")) == 0);
|
||||
printf("ip2bin: valid IPv6 zone: OK\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
ip2bin: zone with whitespace rejected: OK
|
||||
ip2bin: IPv4 with zone rejected: OK
|
||||
ip2bin: valid IPv6 zone: OK
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
#define TEST_NAME "kdf_hkdf3"
|
||||
#include "cmptest.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned char prk[crypto_kdf_hkdf_sha512_KEYBYTES];
|
||||
unsigned char out[256];
|
||||
int ret;
|
||||
|
||||
crypto_kdf_hkdf_sha512_keygen(prk);
|
||||
assert(!sodium_is_zero(prk, sizeof prk));
|
||||
printf("sha512 keygen: ok\n");
|
||||
|
||||
ret = crypto_kdf_hkdf_sha512_expand(
|
||||
out, crypto_kdf_hkdf_sha512_BYTES_MAX + 1,
|
||||
"ctx", 3, prk);
|
||||
assert(ret == -1);
|
||||
printf("sha512 expand max+1: ok\n");
|
||||
|
||||
crypto_kdf_hkdf_sha512_extract(prk, NULL, 0,
|
||||
(const unsigned char *) "ikm", 3);
|
||||
|
||||
ret = crypto_kdf_hkdf_sha512_expand(out, 100, "ctx", 3, prk);
|
||||
assert(ret == 0);
|
||||
printf("sha512 expand partial block: ok\n");
|
||||
|
||||
{
|
||||
unsigned char prk256[crypto_kdf_hkdf_sha256_KEYBYTES];
|
||||
|
||||
crypto_kdf_hkdf_sha256_keygen(prk256);
|
||||
assert(!sodium_is_zero(prk256, sizeof prk256));
|
||||
printf("sha256 keygen: ok\n");
|
||||
|
||||
ret = crypto_kdf_hkdf_sha256_expand(
|
||||
out, crypto_kdf_hkdf_sha256_BYTES_MAX + 1,
|
||||
"ctx", 3, prk256);
|
||||
assert(ret == -1);
|
||||
printf("sha256 expand max+1: ok\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
sha512 keygen: ok
|
||||
sha512 expand max+1: ok
|
||||
sha512 expand partial block: ok
|
||||
sha256 keygen: ok
|
||||
sha256 expand max+1: ok
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
#define TEST_NAME "xof2"
|
||||
#include "cmptest.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned char out[64];
|
||||
unsigned char out2[64];
|
||||
int ret;
|
||||
|
||||
{
|
||||
crypto_xof_shake128_state state;
|
||||
|
||||
crypto_xof_shake128_init(&state);
|
||||
crypto_xof_shake128_update(&state, (const unsigned char *) "test", 4);
|
||||
crypto_xof_shake128_squeeze(&state, out, 32);
|
||||
|
||||
ret = crypto_xof_shake128_update(&state, (const unsigned char *) "x", 1);
|
||||
assert(ret == -1);
|
||||
crypto_xof_shake128_squeeze(&state, out2, 32);
|
||||
assert(memcmp(out, out2, 32) != 0);
|
||||
}
|
||||
printf("shake128 update-after-squeeze: ok\n");
|
||||
|
||||
{
|
||||
crypto_xof_shake256_state state;
|
||||
|
||||
crypto_xof_shake256_init(&state);
|
||||
crypto_xof_shake256_update(&state, (const unsigned char *) "test", 4);
|
||||
crypto_xof_shake256_squeeze(&state, out, 32);
|
||||
|
||||
ret = crypto_xof_shake256_update(&state, (const unsigned char *) "x", 1);
|
||||
assert(ret == -1);
|
||||
crypto_xof_shake256_squeeze(&state, out2, 32);
|
||||
assert(memcmp(out, out2, 32) != 0);
|
||||
}
|
||||
printf("shake256 update-after-squeeze: ok\n");
|
||||
|
||||
{
|
||||
crypto_xof_turboshake128_state state;
|
||||
|
||||
crypto_xof_turboshake128_init(&state);
|
||||
crypto_xof_turboshake128_update(&state, (const unsigned char *) "test", 4);
|
||||
crypto_xof_turboshake128_squeeze(&state, out, 32);
|
||||
|
||||
ret = crypto_xof_turboshake128_update(&state,
|
||||
(const unsigned char *) "x", 1);
|
||||
assert(ret == -1);
|
||||
crypto_xof_turboshake128_squeeze(&state, out2, 32);
|
||||
assert(memcmp(out, out2, 32) != 0);
|
||||
}
|
||||
printf("turboshake128 update-after-squeeze: ok\n");
|
||||
|
||||
{
|
||||
crypto_xof_turboshake256_state state;
|
||||
|
||||
crypto_xof_turboshake256_init(&state);
|
||||
crypto_xof_turboshake256_update(&state, (const unsigned char *) "test", 4);
|
||||
crypto_xof_turboshake256_squeeze(&state, out, 32);
|
||||
|
||||
ret = crypto_xof_turboshake256_update(&state,
|
||||
(const unsigned char *) "x", 1);
|
||||
assert(ret == -1);
|
||||
crypto_xof_turboshake256_squeeze(&state, out2, 32);
|
||||
assert(memcmp(out, out2, 32) != 0);
|
||||
}
|
||||
printf("turboshake256 update-after-squeeze: ok\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
shake128 update-after-squeeze: ok
|
||||
shake256 update-after-squeeze: ok
|
||||
turboshake128 update-after-squeeze: ok
|
||||
turboshake256 update-after-squeeze: ok
|
||||
Reference in New Issue
Block a user