Add libsodium to the tree and build what's needed from source.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3859 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-03-08 03:42:47 +00:00
parent efc5eb2aff
commit 352f33f5a1
584 changed files with 140249 additions and 2 deletions

506
deps/libsodium/test/default/Makefile.am vendored Normal file
View File

@ -0,0 +1,506 @@
EXTRA_DIST = \
cmptest.h \
wasi-test-wrapper.sh \
wintest.bat \
pre.js.inc \
aead_aes256gcm.exp \
aead_aes256gcm2.exp \
aead_chacha20poly1305.exp \
aead_chacha20poly13052.exp \
aead_xchacha20poly1305.exp \
auth.exp \
auth2.exp \
auth3.exp \
auth5.exp \
auth6.exp \
auth7.exp \
box.exp \
box2.exp \
box7.exp \
box8.exp \
box_easy.exp \
box_easy2.exp \
box_seal.exp \
box_seed.exp \
chacha20.exp \
codecs.exp \
core_ed25519.exp \
core_ristretto255.exp \
core1.exp \
core2.exp \
core3.exp \
core4.exp \
core5.exp \
core6.exp \
ed25519_convert.exp \
generichash.exp \
generichash2.exp \
generichash3.exp \
hash.exp \
hash3.exp \
kdf.exp \
keygen.exp \
kx.exp \
metamorphic.exp \
misuse.exp \
onetimeauth.exp \
onetimeauth2.exp \
onetimeauth7.exp \
pwhash_argon2i.exp \
pwhash_argon2id.exp \
pwhash_scrypt.exp \
pwhash_scrypt_ll.exp \
randombytes.exp \
scalarmult.exp \
scalarmult_ed25519.exp \
scalarmult_ristretto255.exp \
scalarmult2.exp \
scalarmult5.exp \
scalarmult6.exp \
scalarmult7.exp \
scalarmult8.exp \
secretbox.exp \
secretbox2.exp \
secretbox7.exp \
secretbox8.exp \
secretbox_easy.exp \
secretbox_easy2.exp \
secretstream.exp \
shorthash.exp \
sign.exp \
siphashx24.exp \
sodium_core.exp \
sodium_utils.exp \
sodium_utils2.exp \
sodium_utils3.exp \
sodium_version.exp \
stream.exp \
stream2.exp \
stream3.exp \
stream4.exp \
verify1.exp \
xchacha20.exp
DISTCLEANFILES = \
aead_aes256gcm.res \
aead_aes256gcm2.res \
aead_chacha20poly1305.res \
aead_chacha20poly13052.res \
aead_xchacha20poly1305.res \
auth.res \
auth2.res \
auth3.res \
auth5.res \
auth6.res \
auth7.res \
box.res \
box2.res \
box7.res \
box8.res \
box_easy.res \
box_easy2.res \
box_seal.res \
box_seed.res \
chacha20.res \
codecs.res \
core_ed25519.res \
core_ristretto255.res \
core1.res \
core2.res \
core3.res \
core4.res \
core5.res \
core6.res \
ed25519_convert.res \
generichash.res \
generichash2.res \
generichash3.res \
hash.res \
hash2.res \
hash3.res \
kdf.res \
keygen.res \
kx.res \
metamorphic.res \
misuse.res \
onetimeauth.res \
onetimeauth2.res \
onetimeauth7.res \
pwhash_argon2i.res \
pwhash_argon2id.res \
pwhash_scrypt.res \
pwhash_scrypt_ll.res \
randombytes.res \
scalarmult.res \
scalarmult_ed25519.res \
scalarmult_ristretto255.res \
scalarmult2.res \
scalarmult5.res \
scalarmult6.res \
scalarmult7.res \
scalarmult8.res \
secretbox.res \
secretbox2.res \
secretbox7.res \
secretbox8.res \
secretbox_easy.res \
secretbox_easy2.res \
secretstream.res \
shorthash.res \
sign.res \
siphashx24.res \
sodium_core.res \
sodium_utils.res \
sodium_utils2.res \
sodium_utils3.res \
sodium_version.res \
stream.res \
stream2.res \
stream3.res \
stream4.res \
verify1.res \
xchacha20.res
AM_CPPFLAGS = \
-DTEST_SRCDIR=\"@srcdir@\" \
-I$(top_srcdir)/src/libsodium/include \
-I$(top_srcdir)/src/libsodium/include/sodium \
-I$(top_builddir)/src/libsodium/include \
-I$(top_builddir)/src/libsodium/include/sodium \
-I$(top_srcdir)/test/quirks
AM_LDFLAGS = @TEST_LDFLAGS@
TESTS_TARGETS = \
aead_aes256gcm \
aead_aes256gcm2 \
aead_chacha20poly1305 \
aead_chacha20poly13052 \
aead_xchacha20poly1305 \
auth \
auth2 \
auth3 \
auth5 \
auth6 \
auth7 \
box \
box2 \
box7 \
box8 \
box_easy \
box_easy2 \
box_seal \
box_seed \
chacha20 \
codecs \
core1 \
core2 \
core3 \
core4 \
core5 \
core6 \
ed25519_convert \
generichash \
generichash2 \
generichash3 \
hash \
hash3 \
kdf \
keygen \
kx \
metamorphic \
misuse \
onetimeauth \
onetimeauth2 \
onetimeauth7 \
pwhash_argon2i \
pwhash_argon2id \
randombytes \
scalarmult \
scalarmult2 \
scalarmult5 \
scalarmult6 \
scalarmult7 \
scalarmult8 \
secretbox \
secretbox2 \
secretbox7 \
secretbox8 \
secretbox_easy \
secretbox_easy2 \
secretstream \
shorthash \
sign \
sodium_core \
sodium_utils \
sodium_version \
stream \
stream2 \
stream3 \
stream4 \
verify1
if !EMSCRIPTEN
TESTS_TARGETS += \
sodium_utils2 \
sodium_utils3
endif
check_PROGRAMS = $(TESTS_TARGETS)
TESTS = $(TESTS_TARGETS)
TESTS_LDADD = \
${top_builddir}/src/libsodium/libsodium.la
aead_aes256gcm_SOURCE = cmptest.h aead_aes256gcm.c
aead_aes256gcm_LDADD = $(TESTS_LDADD)
aead_aes256gcm2_SOURCE = cmptest.h aead_aes256gcm2.c
aead_aes256gcm2_LDADD = $(TESTS_LDADD)
aead_chacha20poly1305_SOURCE = cmptest.h aead_chacha20poly1305.c
aead_chacha20poly1305_LDADD = $(TESTS_LDADD)
aead_chacha20poly13052_SOURCE = cmptest.h aead_chacha20poly13052.c
aead_chacha20poly13052_LDADD = $(TESTS_LDADD)
aead_xchacha20poly1305_SOURCE = cmptest.h aead_xchacha20poly1305.c
aead_xchacha20poly1305_LDADD = $(TESTS_LDADD)
auth_SOURCE = cmptest.h auth.c
auth_LDADD = $(TESTS_LDADD)
auth2_SOURCE = cmptest.h auth2.c
auth2_LDADD = $(TESTS_LDADD)
auth3_SOURCE = cmptest.h auth3.c
auth3_LDADD = $(TESTS_LDADD)
auth5_SOURCE = cmptest.h auth5.c quirks.h
auth5_LDADD = $(TESTS_LDADD)
auth6_SOURCE = cmptest.h auth6.c quirks.h
auth6_LDADD = $(TESTS_LDADD)
auth7_SOURCE = cmptest.h auth7.c quirks.h
auth7_LDADD = $(TESTS_LDADD)
box_SOURCE = cmptest.h box.c
box_LDADD = $(TESTS_LDADD)
box2_SOURCE = cmptest.h box2.c
box2_LDADD = $(TESTS_LDADD)
box7_SOURCE = cmptest.h box7.c
box7_LDADD = $(TESTS_LDADD)
box8_SOURCE = cmptest.h box8.c
box8_LDADD = $(TESTS_LDADD)
box_easy_SOURCE = cmptest.h box_easy.c
box_easy_LDADD = $(TESTS_LDADD)
box_easy2_SOURCE = cmptest.h box_easy2.c
box_easy2_LDADD = $(TESTS_LDADD)
box_seal_SOURCE = cmptest.h box_seal.c
box_seal_LDADD = $(TESTS_LDADD)
box_seed_SOURCE = cmptest.h box_seed.c
box_seed_LDADD = $(TESTS_LDADD)
chacha20_SOURCE = cmptest.h chacha20.c
chacha20_LDADD = $(TESTS_LDADD)
codecs_SOURCE = cmptest.h codecs.c
codecs_LDADD = $(TESTS_LDADD)
core_ed25519_SOURCE = cmptest.h core_ed25519.c
core_ed25519_LDADD = $(TESTS_LDADD)
core_ristretto255_SOURCE = cmptest.h core_ristretto255.c
core_ristretto255_LDADD = $(TESTS_LDADD)
core1_SOURCE = cmptest.h core1.c
core1_LDADD = $(TESTS_LDADD)
core2_SOURCE = cmptest.h core2.c
core2_LDADD = $(TESTS_LDADD)
core3_SOURCE = cmptest.h core3.c
core3_LDADD = $(TESTS_LDADD)
core4_SOURCE = cmptest.h core4.c
core4_LDADD = $(TESTS_LDADD)
core5_SOURCE = cmptest.h core5.c
core5_LDADD = $(TESTS_LDADD)
core6_SOURCE = cmptest.h core6.c
core6_LDADD = $(TESTS_LDADD)
ed25519_convert_SOURCE = cmptest.h ed25519_convert.c
ed25519_convert_LDADD = $(TESTS_LDADD)
generichash_SOURCE = cmptest.h generichash.c
generichash_LDADD = $(TESTS_LDADD)
generichash2_SOURCE = cmptest.h generichash2.c
generichash2_LDADD = $(TESTS_LDADD)
generichash3_SOURCE = cmptest.h generichash3.c
generichash3_LDADD = $(TESTS_LDADD)
hash_SOURCE = cmptest.h hash.c
hash_LDADD = $(TESTS_LDADD)
hash3_SOURCE = cmptest.h hash3.c
hash3_LDADD = $(TESTS_LDADD)
kdf_SOURCE = cmptest.h kdf.c
kdf_LDADD = $(TESTS_LDADD)
keygen_SOURCE = cmptest.h keygen.c
keygen_LDADD = $(TESTS_LDADD)
kx_SOURCE = cmptest.h kx.c
kx_LDADD = $(TESTS_LDADD)
metamorphic_SOURCE = cmptest.h metamorphic.c
metamorphic_LDADD = $(TESTS_LDADD)
misuse_SOURCE = cmptest.h misuse.c
misuse_LDADD = $(TESTS_LDADD)
onetimeauth_SOURCE = cmptest.h onetimeauth.c
onetimeauth_LDADD = $(TESTS_LDADD)
onetimeauth2_SOURCE = cmptest.h onetimeauth2.c
onetimeauth2_LDADD = $(TESTS_LDADD)
onetimeauth7_SOURCE = cmptest.h onetimeauth7.c
onetimeauth7_LDADD = $(TESTS_LDADD)
pwhash_argon2i_SOURCE = cmptest.h pwhash_argon2i.c
pwhash_argon2i_LDADD = $(TESTS_LDADD)
pwhash_argon2id_SOURCE = cmptest.h pwhash_argon2id.c
pwhash_argon2id_LDADD = $(TESTS_LDADD)
pwhash_scrypt_SOURCE = cmptest.h pwhash_scrypt.c
pwhash_scrypt_LDADD = $(TESTS_LDADD)
pwhash_scrypt_ll_SOURCE = cmptest.h pwhash_scrypt_ll.c
pwhash_scrypt_ll_LDADD = $(TESTS_LDADD)
randombytes_SOURCE = cmptest.h randombytes.c
randombytes_LDADD = $(TESTS_LDADD)
scalarmult_SOURCE = cmptest.h scalarmult.c
scalarmult_LDADD = $(TESTS_LDADD)
scalarmult_ed25519_SOURCE = cmptest.h scalarmult_ed25519.c
scalarmult_ed25519_LDADD = $(TESTS_LDADD)
scalarmult_ristretto255_SOURCE = cmptest.h scalarmult_ristretto255.c
scalarmult_ristretto255_LDADD = $(TESTS_LDADD)
scalarmult2_SOURCE = cmptest.h scalarmult2.c
scalarmult2_LDADD = $(TESTS_LDADD)
scalarmult5_SOURCE = cmptest.h scalarmult5.c
scalarmult5_LDADD = $(TESTS_LDADD)
scalarmult6_SOURCE = cmptest.h scalarmult6.c
scalarmult6_LDADD = $(TESTS_LDADD)
scalarmult7_SOURCE = cmptest.h scalarmult7.c
scalarmult7_LDADD = $(TESTS_LDADD)
scalarmult8_SOURCE = cmptest.h scalarmult8.c
scalarmult8_LDADD = $(TESTS_LDADD)
secretbox_SOURCE = cmptest.h secretbox.c
secretbox_LDADD = $(TESTS_LDADD)
secretbox2_SOURCE = cmptest.h secretbox2.c
secretbox2_LDADD = $(TESTS_LDADD)
secretbox7_SOURCE = cmptest.h secretbox7.c
secretbox7_LDADD = $(TESTS_LDADD)
secretbox8_SOURCE = cmptest.h secretbox8.c
secretbox8_LDADD = $(TESTS_LDADD)
secretbox_easy_SOURCE = cmptest.h secretbox_easy.c
secretbox_easy_LDADD = $(TESTS_LDADD)
secretbox_easy2_SOURCE = cmptest.h secretbox_easy2.c
secretbox_easy2_LDADD = $(TESTS_LDADD)
secretstream_SOURCE = cmptest.h secretstream.c
secretstream_LDADD = $(TESTS_LDADD)
shorthash_SOURCE = cmptest.h shorthash.c
shorthash_LDADD = $(TESTS_LDADD)
sign_SOURCE = cmptest.h sign.c
sign_LDADD = $(TESTS_LDADD)
siphashx24_SOURCE = cmptest.h siphashx24.c
siphashx24_LDADD = $(TESTS_LDADD)
sodium_core_SOURCE = cmptest.h sodium_core.c
sodium_core_LDADD = $(TESTS_LDADD)
sodium_utils_SOURCE = cmptest.h sodium_utils.c
sodium_utils_LDADD = $(TESTS_LDADD)
sodium_utils2_SOURCE = cmptest.h sodium_utils2.c
sodium_utils2_LDADD = $(TESTS_LDADD)
sodium_utils3_SOURCE = cmptest.h sodium_utils3.c
sodium_utils3_LDADD = $(TESTS_LDADD)
sodium_version_SOURCE = cmptest.h sodium_version.c
sodium_version_LDADD = $(TESTS_LDADD)
stream_SOURCE = cmptest.h stream.c
stream_LDADD = $(TESTS_LDADD)
stream2_SOURCE = cmptest.h stream2.c
stream2_LDADD = $(TESTS_LDADD)
stream3_SOURCE = cmptest.h stream3.c
stream3_LDADD = $(TESTS_LDADD)
stream4_SOURCE = cmptest.h stream4.c
stream4_LDADD = $(TESTS_LDADD)
verify1_SOURCE = cmptest.h verify1.c
verify1_LDADD = $(TESTS_LDADD)
xchacha20_SOURCE = cmptest.h xchacha20.c
xchacha20_LDADD = $(TESTS_LDADD)
if !MINIMAL
TESTS_TARGETS += \
core_ed25519 \
core_ristretto255 \
pwhash_scrypt \
pwhash_scrypt_ll \
scalarmult_ed25519 \
scalarmult_ristretto255 \
siphashx24 \
xchacha20
endif
if WASI
LOG_COMPILER = ./wasi-test-wrapper.sh
endif
verify: check
@VALGRIND_CHECK_RULES@

2783
deps/libsodium/test/default/Makefile.in vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1,276 @@
#define TEST_NAME "aead_aes256gcm2"
#include "cmptest.h"
static struct {
const char *key_hex;
const char nonce_hex[crypto_aead_aes256gcm_NPUBBYTES * 2 + 1];
const char *ad_hex;
const char *message_hex;
const char *detached_ciphertext_hex;
const char mac_hex[crypto_aead_aes256gcm_ABYTES * 2 + 1];
const char *outcome;
} tests[] = {
{ "92ace3e348cd821092cd921aa3546374299ab46209691bc28b8752d17f123c20",
"00112233445566778899aabb", "00000000ffffffff", "00010203040506070809",
"e27abdd2d2a53d2f136b", "9a4a2579529301bcfb71c78d4060f52c", "valid" },
{ "29d3a44f8723dc640239100c365423a312934ac80239212ac3df3421a2098123",
"00112233445566778899aabb", "aabbccddeeff", "", "",
"2a7d77fa526b8250cb296078926b5020", "valid" },
{ "cc56b680552eb75008f5484b4cb803fa5063ebd6eab91f6ab6aef4916a766273",
"99e23ec48985bccdeeab60f1", "", "2a", "06",
"633c1e9703ef744ffffb40edf9d14355", "valid" },
{ "51e4bf2bad92b7aff1a4bc05550ba81df4b96fabf41c12c7b00e60e48db7e152",
"4f07afedfdc3b6c2361823d3", "", "be3308f72a2c6aed", "cf332a12fdee800b",
"602e8d7c4799d62c140c9bb834876b09", "valid" },
{ "67119627bd988eda906219e08c0d0d779a07d208ce8a4fe0709af755eeec6dcb",
"68ab7fdbf61901dad461d23c", "", "51f8c1f731ea14acdb210a6d973e07",
"43fc101bff4b32bfadd3daf57a590e", "ec04aacb7148a8b8be44cb7eaf4efa69",
"valid" },
{ "59d4eafb4de0cfc7d3db99a8f54b15d7b39f0acc8da69763b019c1699f87674a",
"2fcb1b38a99e71b84740ad9b", "", "549b365af913f3b081131ccb6b825588",
"f58c16690122d75356907fd96b570fca", "28752c20153092818faba2a334640d6e",
"valid" },
{ "3b2458d8176e1621c0cc24c0c0e24c1e80d72f7ee9149a4b166176629616d011",
"45aaa3e5d16d2d42dc03445d", "", "3ff1514b1c503915918f0c0c31094a6e1f",
"73a6b6f45f6ccc5131e07f2caa1f2e2f56", "2d7379ec1db5952d4e95d30c340b1b1d",
"valid" },
{ "0212a8de5007ed87b33f1a7090b6114f9e08cefd9607f2c276bdcfdbc5ce9cd7",
"e6b1adf2fd58a8762c65f31b", "",
"10f1ecf9c60584665d9ae5efe279e7f7377eea6916d2b111",
"0843fff52d934fc7a071ea62c0bd351ce85678cde3ea2c9e",
"7355fde599006715053813ce696237a8", "valid" },
{ "b279f57e19c8f53f2f963f5f2519fdb7c1779be2ca2b3ae8e1128b7d6c627fc4",
"98bc2c7438d5cd7665d76f6e", "c0",
"fcc515b294408c8645c9183e3f4ecee5127846d1",
"eb5500e3825952866d911253f8de860c00831c81",
"ecb660e1fb0541ec41e8d68a64141b3a", "valid" },
{ "cdccfe3f46d782ef47df4e72f0c02d9c7f774def970d23486f11a57f54247f17",
"376187894605a8d45e30de51", "956846a209e087ed",
"e28e0e9f9d22463ac0e42639b530f42102fded75",
"feca44952447015b5df1f456df8ca4bb4eee2ce2",
"082e91924deeb77880e1b1c84f9b8d30", "valid" },
{ "f32364b1d339d82e4f132d8f4a0ec1ff7e746517fa07ef1a7f422f4e25a48194",
"5a86a50a0e8a179c734b996d", "ab2ac7c44c60bdf8228c7884adb20184",
"43891bccb522b1e72a6b53cf31c074e9d6c2df8e",
"43dda832e942e286da314daa99bef5071d9d2c78",
"c3922583476ced575404ddb85dd8cd44", "valid" },
{ "ff0089ee870a4a39f645b0a5da774f7a5911e9696fc9cad646452c2aa8595a12",
"bc2a7757d0ce2d8b1f14ccd9",
"972ab4e06390caae8f99dd6e2187be6c7ff2c08a24be16ef",
"748b28031621d95ee61812b4b4f47d04c6fc2ff3",
"a929ee7e67c7a2f91bbcec6389a3caf43ab49305",
"ebec6774b955e789591c822dab739e12", "valid" },
{ "00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f",
"000000000000000000000000", "", "561008fa07a68f5c61285cd013464eaf",
"23293e9b07ca7d1b0cae7cc489a973b3", "ffffffffffffffffffffffffffffffff",
"valid" },
{ "00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f",
"ffffffffffffffffffffffff", "", "c6152244cea1978d3e0bc274cf8c0b3b",
"7cb6fc7c6abc009efe9551a99f36a421", "00000000000000000000000000000000",
"valid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9de8fef6d8ab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ee8fef6d8ab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "1ce8fef6d8ab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce9fef6d8ab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fe76d8ab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d9ab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6daab1bf1bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1b71bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1be887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf13f887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bfa87232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887332eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887232ebb590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887232e8b590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf8872326ab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887232eab590dc",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887232eab590df",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887232eab5909d",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1bf1bf887232eab5905d",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9de8fef6d8ab1bf1be887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fe76d8ab1b71bf887232eab590dd",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9ce8fef6d8ab1b71bf887232eab5905d",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "631701092754e40e40778dcd154a6f22",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "00000000000000000000000000000000",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "ffffffffffffffffffffffffffffffff",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "1c687e76582b9b713f08f2b26a35105d",
"invalid" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"505152535455565758595a5b", "", "202122232425262728292a2b2c2d2e2f",
"b2061457c0759fc1749f174ee1ccadfa", "9de9fff7d9aa1af0be897333ebb491dc",
"invalid" }
};
static int
tv(void)
{
unsigned char *ad;
unsigned char *decrypted;
unsigned char *detached_ciphertext;
unsigned char *key;
unsigned char *message;
unsigned char *mac;
unsigned char *nonce;
size_t ad_len;
size_t detached_ciphertext_len;
size_t message_len;
unsigned int i;
key = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_KEYBYTES);
nonce = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_NPUBBYTES);
mac = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_ABYTES);
for (i = 0U; i < (sizeof tests) / (sizeof tests[0]); i++) {
assert(strlen(tests[i].key_hex) == 2 * crypto_aead_aes256gcm_KEYBYTES);
sodium_hex2bin(key, crypto_aead_aes256gcm_KEYBYTES, tests[i].key_hex,
strlen(tests[i].key_hex), NULL, NULL, NULL);
assert(strlen(tests[i].nonce_hex) ==
2 * crypto_aead_aes256gcm_NPUBBYTES);
sodium_hex2bin(nonce, crypto_aead_aes256gcm_NPUBBYTES,
tests[i].nonce_hex, strlen(tests[i].nonce_hex), NULL,
NULL, NULL);
message_len = strlen(tests[i].message_hex) / 2;
message = (unsigned char *) sodium_malloc(message_len);
sodium_hex2bin(message, message_len, tests[i].message_hex,
strlen(tests[i].message_hex), NULL, NULL, NULL);
ad_len = strlen(tests[i].ad_hex) / 2;
ad = (unsigned char *) sodium_malloc(ad_len);
sodium_hex2bin(ad, ad_len, tests[i].ad_hex, strlen(tests[i].ad_hex),
NULL, NULL, NULL);
detached_ciphertext_len = message_len;
assert(strlen(tests[i].detached_ciphertext_hex) == 2 * message_len);
assert(strlen(tests[i].mac_hex) == 2 * crypto_aead_aes256gcm_ABYTES);
sodium_hex2bin(mac, crypto_aead_aes256gcm_ABYTES, tests[i].mac_hex,
strlen(tests[i].mac_hex), NULL, NULL, NULL);
detached_ciphertext =
(unsigned char *) sodium_malloc(detached_ciphertext_len);
sodium_hex2bin(detached_ciphertext, detached_ciphertext_len,
tests[i].detached_ciphertext_hex,
strlen(tests[i].detached_ciphertext_hex), NULL, NULL,
NULL);
decrypted = (unsigned char *) sodium_malloc(message_len);
if (crypto_aead_aes256gcm_decrypt_detached(
decrypted, NULL, detached_ciphertext, detached_ciphertext_len,
mac, ad, ad_len, nonce, key) == 0) {
if (strcmp(tests[i].outcome, "valid") != 0) {
printf("*** test case %u succeeded, was supposed to be %s\n", i,
tests[i].outcome);
}
if (memcmp(decrypted, message, message_len) != 0) {
printf("Incorrect decryption of test vector #%u\n",
(unsigned int) i);
}
} else {
if (strcmp(tests[i].outcome, "invalid") != 0) {
printf("*** test case %u failed, was supposed to be %s\n", i,
tests[i].outcome);
}
}
sodium_free(message);
sodium_free(ad);
sodium_free(decrypted);
sodium_free(detached_ciphertext);
}
sodium_free(key);
sodium_free(mac);
sodium_free(nonce);
return 0;
}
int
main(void)
{
if (crypto_aead_aes256gcm_is_available()) {
tv();
}
printf("OK\n");
return 0;
}

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1,372 @@
#define TEST_NAME "aead_chacha20poly1305"
#include "cmptest.h"
static int
tv(void)
{
#undef MLEN
#define MLEN 10U
#undef ADLEN
#define ADLEN 10U
#undef CLEN
#define CLEN (MLEN + crypto_aead_chacha20poly1305_ABYTES)
static const unsigned char firstkey[crypto_aead_chacha20poly1305_KEYBYTES]
= { 0x42, 0x90, 0xbc, 0xb1, 0x54, 0x17, 0x35, 0x31, 0xf3, 0x14, 0xaf,
0x57, 0xf3, 0xbe, 0x3b, 0x50, 0x06, 0xda, 0x37, 0x1e, 0xce, 0x27,
0x2a, 0xfa, 0x1b, 0x5d, 0xbd, 0xd1, 0x10, 0x0a, 0x10, 0x07 };
static const unsigned char m[MLEN]
= { 0x86, 0xd0, 0x99, 0x74, 0x84, 0x0b, 0xde, 0xd2, 0xa5, 0xca };
static const unsigned char nonce[crypto_aead_chacha20poly1305_NPUBBYTES]
= { 0xcd, 0x7c, 0xf6, 0x7b, 0xe3, 0x9c, 0x79, 0x4a };
static const unsigned char ad[ADLEN]
= { 0x87, 0xe2, 0x29, 0xd4, 0x50, 0x08, 0x45, 0xa0, 0x79, 0xc0 };
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_chacha20poly1305_ABYTES);
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
unsigned long long found_clen;
unsigned long long found_maclen;
unsigned long long m2len;
size_t i;
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("found_clen is not properly set\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
crypto_aead_chacha20poly1305_encrypt_detached(detached_c,
mac, &found_maclen,
m, MLEN, ad, ADLEN,
NULL, nonce, firstkey);
if (found_maclen != crypto_aead_chacha20poly1305_abytes()) {
printf("found_maclen is not properly set\n");
}
if (memcmp(detached_c, c, MLEN) != 0) {
printf("detached ciphertext is bogus\n");
}
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, CLEN,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2\n");
}
memset(m2, 0, m2len);
assert(crypto_aead_chacha20poly1305_decrypt_detached(NULL, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) == 0);
if (crypto_aead_chacha20poly1305_decrypt_detached(m2, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt_detached() failed\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("detached m != m2\n");
}
for (i = 0U; i < CLEN; i++) {
c[i] ^= (i + 1U);
if (crypto_aead_chacha20poly1305_decrypt(m2, NULL, NULL, c, CLEN,
ad, ADLEN, nonce, firstkey)
== 0 || memcmp(m, m2, MLEN) == 0) {
printf("message can be forged\n");
}
c[i] ^= (i + 1U);
}
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, m, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("found_clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2 (adlen=0)\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_decrypt(
m2, &m2len, NULL, guard_page,
randombytes_uniform(crypto_aead_chacha20poly1305_ABYTES),
NULL, 0U, nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_decrypt() worked with a short "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_decrypt() worked with an empty "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
memcpy(c, m, MLEN);
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, c, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("found_clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_decrypt(c, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, c, MLEN) != 0) {
printf("m != c (adlen=0)\n");
}
sodium_free(c);
sodium_free(detached_c);
sodium_free(mac);
sodium_free(m2);
assert(crypto_aead_chacha20poly1305_keybytes() > 0U);
assert(crypto_aead_chacha20poly1305_npubbytes() > 0U);
assert(crypto_aead_chacha20poly1305_nsecbytes() == 0U);
assert(crypto_aead_chacha20poly1305_messagebytes_max() > 0U);
assert(crypto_aead_chacha20poly1305_messagebytes_max() == crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX);
assert(crypto_aead_chacha20poly1305_keybytes() == crypto_aead_chacha20poly1305_KEYBYTES);
assert(crypto_aead_chacha20poly1305_nsecbytes() == crypto_aead_chacha20poly1305_NSECBYTES);
assert(crypto_aead_chacha20poly1305_npubbytes() == crypto_aead_chacha20poly1305_NPUBBYTES);
assert(crypto_aead_chacha20poly1305_abytes() == crypto_aead_chacha20poly1305_ABYTES);
return 0;
}
static int
tv_ietf(void)
{
#undef MLEN
#define MLEN 114U
#undef ADLEN
#define ADLEN 12U
#undef CLEN
#define CLEN (MLEN + crypto_aead_chacha20poly1305_ietf_ABYTES)
static const unsigned char firstkey[crypto_aead_chacha20poly1305_ietf_KEYBYTES]
= {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
};
#undef MESSAGE
#define MESSAGE "Ladies and Gentlemen of the class of '99: If I could offer you " \
"only one tip for the future, sunscreen would be it."
unsigned char *m = (unsigned char *) sodium_malloc(MLEN);
static const unsigned char nonce[crypto_aead_chacha20poly1305_ietf_NPUBBYTES]
= { 0x07, 0x00, 0x00, 0x00,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 };
static const unsigned char ad[ADLEN]
= { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 };
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_chacha20poly1305_ietf_ABYTES);
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
unsigned long long found_clen;
unsigned long long found_maclen;
unsigned long long m2len;
size_t i;
assert(sizeof MESSAGE - 1U == MLEN);
memcpy(m, MESSAGE, MLEN);
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_clen != MLEN + crypto_aead_chacha20poly1305_ietf_abytes()) {
printf("found_clen is not properly set\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
crypto_aead_chacha20poly1305_ietf_encrypt_detached(detached_c,
mac, &found_maclen,
m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_maclen != crypto_aead_chacha20poly1305_ietf_abytes()) {
printf("found_maclen is not properly set\n");
}
if (memcmp(detached_c, c, MLEN) != 0) {
printf("detached ciphertext is bogus\n");
}
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN, ad,
ADLEN, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2\n");
}
memset(m2, 0, m2len);
assert(crypto_aead_chacha20poly1305_ietf_decrypt_detached(NULL, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) == 0);
if (crypto_aead_chacha20poly1305_ietf_decrypt_detached(m2, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt_detached() failed\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("detached m != m2\n");
}
for (i = 0U; i < CLEN; i++) {
c[i] ^= (i + 1U);
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, NULL, NULL, c, CLEN,
ad, ADLEN, nonce, firstkey)
== 0 || memcmp(m, m2, MLEN) == 0) {
printf("message can be forged\n");
}
c[i] ^= (i + 1U);
}
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2 (adlen=0)\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_ietf_decrypt(
m2, &m2len, NULL, guard_page,
randombytes_uniform(crypto_aead_chacha20poly1305_ietf_ABYTES),
NULL, 0U, nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with a short "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
m2len = 1;
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
nonce, firstkey) != -1) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with an empty "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
memcpy(c, m, MLEN);
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, c, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_chacha20poly1305_ietf_decrypt(c, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, c, MLEN) != 0) {
printf("m != c (adlen=0)\n");
}
sodium_free(c);
sodium_free(detached_c);
sodium_free(mac);
sodium_free(m2);
sodium_free(m);
assert(crypto_aead_chacha20poly1305_ietf_keybytes() > 0U);
assert(crypto_aead_chacha20poly1305_ietf_keybytes() == crypto_aead_chacha20poly1305_keybytes());
assert(crypto_aead_chacha20poly1305_ietf_npubbytes() > 0U);
assert(crypto_aead_chacha20poly1305_ietf_npubbytes() > crypto_aead_chacha20poly1305_npubbytes());
assert(crypto_aead_chacha20poly1305_ietf_nsecbytes() == 0U);
assert(crypto_aead_chacha20poly1305_ietf_nsecbytes() == crypto_aead_chacha20poly1305_nsecbytes());
assert(crypto_aead_chacha20poly1305_ietf_messagebytes_max() == crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX);
assert(crypto_aead_chacha20poly1305_IETF_KEYBYTES == crypto_aead_chacha20poly1305_ietf_KEYBYTES);
assert(crypto_aead_chacha20poly1305_IETF_NSECBYTES == crypto_aead_chacha20poly1305_ietf_NSECBYTES);
assert(crypto_aead_chacha20poly1305_IETF_NPUBBYTES == crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
assert(crypto_aead_chacha20poly1305_IETF_ABYTES == crypto_aead_chacha20poly1305_ietf_ABYTES);
assert(crypto_aead_chacha20poly1305_IETF_MESSAGEBYTES_MAX == crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX);
return 0;
}
int
main(void)
{
tv();
tv_ietf();
return 0;
}

View File

@ -0,0 +1,63 @@
,0xe3,0xe4,0x46,0xf7,0xed,0xe9,0xa1,0x9b
,0x62,0xa4,0x67,0x7d,0xab,0xf4,0xe3,0xd2
,0x4b,0x87,0x6b,0xb2,0x84,0x75,0x38,0x96
,0xe1,0xd6
,0xe3,0xe4,0x46,0xf7,0xed,0xe9,0xa1,0x9b
,0x62,0xa4,0x69,0xe7,0x78,0x9b,0xcd,0x95
,0x4e,0x65,0x8e,0xd3,0x84,0x23,0xe2,0x31
,0x61,0xdc
,0xe3,0xe4,0x46,0xf7,0xed,0xe9,0xa1,0x9b
,0x62,0xa4,0x69,0xe7,0x78,0x9b,0xcd,0x95
,0x4e,0x65,0x8e,0xd3,0x84,0x23,0xe2,0x31
,0x61,0xdc
,0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb
,0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2
,0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe
,0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6
,0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12
,0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b
,0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29
,0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36
,0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c
,0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58
,0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94
,0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc
,0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d
,0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b
,0x61,0x16,0x1a,0xe1,0x0b,0x59,0x4f,0x09
,0xe2,0x6a,0x7e,0x90,0x2e,0xcb,0xd0,0x60
,0x06,0x91
,0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb
,0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2
,0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe
,0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6
,0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12
,0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b
,0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29
,0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36
,0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c
,0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58
,0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94
,0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc
,0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d
,0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b
,0x61,0x16,0x6a,0x23,0xa4,0x68,0x1f,0xd5
,0x94,0x56,0xae,0xa1,0xd2,0x9f,0x82,0x47
,0x72,0x16
,0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb
,0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2
,0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe
,0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6
,0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12
,0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b
,0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29
,0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36
,0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c
,0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58
,0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94
,0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc
,0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d
,0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b
,0x61,0x16,0x6a,0x23,0xa4,0x68,0x1f,0xd5
,0x94,0x56,0xae,0xa1,0xd2,0x9f,0x82,0x47
,0x72,0x16

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1,203 @@
#define TEST_NAME "aead_xchacha20poly1305"
#include "cmptest.h"
static int
tv(void)
{
#undef MLEN
#define MLEN 114U
#undef ADLEN
#define ADLEN 12U
#undef CLEN
#define CLEN (MLEN + crypto_aead_xchacha20poly1305_ietf_ABYTES)
static const unsigned char firstkey[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]
= {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
};
#undef MESSAGE
#define MESSAGE "Ladies and Gentlemen of the class of '99: If I could offer you " \
"only one tip for the future, sunscreen would be it."
unsigned char *m = (unsigned char *) sodium_malloc(MLEN);
static const unsigned char nonce[crypto_aead_xchacha20poly1305_ietf_NPUBBYTES]
= { 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53 };
static const unsigned char ad[ADLEN]
= { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 };
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
unsigned char *key2 = (unsigned char *) sodium_malloc(crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_xchacha20poly1305_ietf_ABYTES);
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
unsigned long long found_clen;
unsigned long long found_maclen;
unsigned long long m2len;
size_t i;
assert(sizeof MESSAGE - 1U == MLEN);
memcpy(m, MESSAGE, MLEN);
crypto_aead_xchacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_clen != MLEN + crypto_aead_xchacha20poly1305_ietf_abytes()) {
printf("found_clen is not properly set\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
crypto_aead_xchacha20poly1305_ietf_encrypt_detached(detached_c,
mac, &found_maclen,
m, MLEN,
ad, ADLEN,
NULL, nonce, firstkey);
if (found_maclen != crypto_aead_xchacha20poly1305_ietf_abytes()) {
printf("found_maclen is not properly set\n");
}
if (memcmp(detached_c, c, MLEN) != 0) {
printf("detached ciphertext is bogus\n");
}
if (crypto_aead_xchacha20poly1305_ietf_decrypt(NULL, 0, NULL, c, CLEN, ad,
ADLEN, nonce, firstkey) != 0) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() tag-only verification failed\n");
}
if (crypto_aead_xchacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN, ad,
ADLEN, nonce, firstkey) != 0) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() failed\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2\n");
}
memset(m2, 0, m2len);
if (crypto_aead_xchacha20poly1305_ietf_decrypt_detached(m2, NULL,
c, MLEN, mac,
ad, ADLEN,
nonce, firstkey) != 0) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt_detached() failed\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("detached m != m2\n");
}
for (i = 0U; i < CLEN; i++) {
c[i] ^= (i + 1U);
if (crypto_aead_xchacha20poly1305_ietf_decrypt(m2, NULL, NULL, c, CLEN,
ad, ADLEN, nonce, firstkey)
== 0 || memcmp(m, m2, MLEN) == 0) {
printf("message can be forged\n");
}
c[i] ^= (i + 1U);
}
crypto_aead_xchacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_xchacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, m2, MLEN) != 0) {
printf("m != m2 (adlen=0)\n");
}
m2len = 1;
if (crypto_aead_xchacha20poly1305_ietf_decrypt(
m2, &m2len, NULL, guard_page,
randombytes_uniform(crypto_aead_xchacha20poly1305_ietf_ABYTES),
NULL, 0U, nonce, firstkey) != -1) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() worked with a short "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
m2len = 1;
if (crypto_aead_xchacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
nonce, firstkey) != -1) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() worked with an empty "
"ciphertext\n");
}
if (m2len != 0) {
printf("Message length should have been set to zero after a failure\n");
}
memcpy(c, m, MLEN);
crypto_aead_xchacha20poly1305_ietf_encrypt(c, &found_clen, c, MLEN,
NULL, 0U, NULL, nonce, firstkey);
if (found_clen != CLEN) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < CLEN; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7) {
printf("\n");
}
}
printf("\n");
if (crypto_aead_xchacha20poly1305_ietf_decrypt(c, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
}
if (m2len != MLEN) {
printf("m2len is not properly set (adlen=0)\n");
}
if (memcmp(m, c, MLEN) != 0) {
printf("m != c (adlen=0)\n");
}
crypto_aead_xchacha20poly1305_ietf_keygen(key2);
if (crypto_aead_xchacha20poly1305_ietf_decrypt(c, &m2len, NULL, c, CLEN,
NULL, 0U, nonce, key2) == 0) {
printf("crypto_aead_xchacha20poly1305_ietf_decrypt() with a wrong key should have failed\n");
}
sodium_free(c);
sodium_free(detached_c);
sodium_free(key2);
sodium_free(mac);
sodium_free(m2);
sodium_free(m);
assert(crypto_aead_xchacha20poly1305_ietf_abytes() == crypto_aead_xchacha20poly1305_ietf_ABYTES);
assert(crypto_aead_xchacha20poly1305_ietf_keybytes() == crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
assert(crypto_aead_xchacha20poly1305_ietf_npubbytes() == crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
assert(crypto_aead_xchacha20poly1305_ietf_nsecbytes() == 0U);
assert(crypto_aead_xchacha20poly1305_ietf_nsecbytes() == crypto_aead_xchacha20poly1305_ietf_NSECBYTES);
assert(crypto_aead_xchacha20poly1305_ietf_messagebytes_max() == crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX);
assert(crypto_aead_xchacha20poly1305_IETF_KEYBYTES == crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
assert(crypto_aead_xchacha20poly1305_IETF_NSECBYTES == crypto_aead_xchacha20poly1305_ietf_NSECBYTES);
assert(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES == crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
assert(crypto_aead_xchacha20poly1305_IETF_ABYTES == crypto_aead_xchacha20poly1305_ietf_ABYTES);
assert(crypto_aead_xchacha20poly1305_IETF_MESSAGEBYTES_MAX == crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX);
return 0;
}
int
main(void)
{
tv();
return 0;
}

View File

@ -0,0 +1,51 @@
,0xf8,0xeb,0xea,0x48,0x75,0x04,0x40,0x66
,0xfc,0x16,0x2a,0x06,0x04,0xe1,0x71,0xfe
,0xec,0xfb,0x3d,0x20,0x42,0x52,0x48,0x56
,0x3b,0xcf,0xd5,0xa1,0x55,0xdc,0xc4,0x7b
,0xbd,0xa7,0x0b,0x86,0xe5,0xab,0x9b,0x55
,0x00,0x2b,0xd1,0x27,0x4c,0x02,0xdb,0x35
,0x32,0x1a,0xcd,0x7a,0xf8,0xb2,0xe2,0xd2
,0x50,0x15,0xe1,0x36,0xb7,0x67,0x94,0x58
,0xe9,0xf4,0x32,0x43,0xbf,0x71,0x9d,0x63
,0x9b,0xad,0xb5,0xfe,0xac,0x03,0xf8,0x0a
,0x19,0xa9,0x6e,0xf1,0x0c,0xb1,0xd1,0x53
,0x33,0xa8,0x37,0xb9,0x09,0x46,0xba,0x38
,0x54,0xee,0x74,0xda,0x3f,0x25,0x85,0xef
,0xc7,0xe1,0xe1,0x70,0xe1,0x7e,0x15,0xe5
,0x63,0xe7,0x76,0x01,0xf4,0xf8,0x5c,0xaf
,0xa8,0xe5,0x87,0x76,0x14,0xe1,0x43,0xe6
,0x84,0x20
,0xf8,0xeb,0xea,0x48,0x75,0x04,0x40,0x66
,0xfc,0x16,0x2a,0x06,0x04,0xe1,0x71,0xfe
,0xec,0xfb,0x3d,0x20,0x42,0x52,0x48,0x56
,0x3b,0xcf,0xd5,0xa1,0x55,0xdc,0xc4,0x7b
,0xbd,0xa7,0x0b,0x86,0xe5,0xab,0x9b,0x55
,0x00,0x2b,0xd1,0x27,0x4c,0x02,0xdb,0x35
,0x32,0x1a,0xcd,0x7a,0xf8,0xb2,0xe2,0xd2
,0x50,0x15,0xe1,0x36,0xb7,0x67,0x94,0x58
,0xe9,0xf4,0x32,0x43,0xbf,0x71,0x9d,0x63
,0x9b,0xad,0xb5,0xfe,0xac,0x03,0xf8,0x0a
,0x19,0xa9,0x6e,0xf1,0x0c,0xb1,0xd1,0x53
,0x33,0xa8,0x37,0xb9,0x09,0x46,0xba,0x38
,0x54,0xee,0x74,0xda,0x3f,0x25,0x85,0xef
,0xc7,0xe1,0xe1,0x70,0xe1,0x7e,0x15,0xe5
,0x63,0xe7,0xe0,0x96,0xe0,0x33,0xd9,0x1b
,0x63,0xf7,0xac,0x92,0xe9,0x97,0x2e,0x0d
,0x43,0xe5
,0xf8,0xeb,0xea,0x48,0x75,0x04,0x40,0x66
,0xfc,0x16,0x2a,0x06,0x04,0xe1,0x71,0xfe
,0xec,0xfb,0x3d,0x20,0x42,0x52,0x48,0x56
,0x3b,0xcf,0xd5,0xa1,0x55,0xdc,0xc4,0x7b
,0xbd,0xa7,0x0b,0x86,0xe5,0xab,0x9b,0x55
,0x00,0x2b,0xd1,0x27,0x4c,0x02,0xdb,0x35
,0x32,0x1a,0xcd,0x7a,0xf8,0xb2,0xe2,0xd2
,0x50,0x15,0xe1,0x36,0xb7,0x67,0x94,0x58
,0xe9,0xf4,0x32,0x43,0xbf,0x71,0x9d,0x63
,0x9b,0xad,0xb5,0xfe,0xac,0x03,0xf8,0x0a
,0x19,0xa9,0x6e,0xf1,0x0c,0xb1,0xd1,0x53
,0x33,0xa8,0x37,0xb9,0x09,0x46,0xba,0x38
,0x54,0xee,0x74,0xda,0x3f,0x25,0x85,0xef
,0xc7,0xe1,0xe1,0x70,0xe1,0x7e,0x15,0xe5
,0x63,0xe7,0xe0,0x96,0xe0,0x33,0xd9,0x1b
,0x63,0xf7,0xac,0x92,0xe9,0x97,0x2e,0x0d
,0x43,0xe5

141
deps/libsodium/test/default/auth.c vendored Normal file
View File

@ -0,0 +1,141 @@
#define TEST_NAME "auth"
#include "cmptest.h"
/* "Test Case 2" from RFC 4231 */
static unsigned char key[32] = "Jefe";
static unsigned char c[] = "what do ya want for nothing?";
/* Hacker manifesto */
static unsigned char key2[] =
"Another one got caught today, it's all over the papers. \"Teenager "
"Arrested in Computer Crime Scandal\", \"Hacker Arrested after Bank "
"Tampering\"... Damn kids. They're all alike.";
static unsigned char a[crypto_auth_BYTES];
static unsigned char a2[crypto_auth_hmacsha512_BYTES];
static unsigned char a3[crypto_auth_hmacsha512_BYTES];
int
main(void)
{
crypto_auth_hmacsha512_state st;
crypto_auth_hmacsha256_state st256;
crypto_auth_hmacsha512256_state st512_256;
size_t i;
assert(crypto_auth_hmacsha512_statebytes() ==
sizeof(crypto_auth_hmacsha512_state));
crypto_auth(a, c, sizeof c - 1U, key);
for (i = 0; i < sizeof a; ++i) {
printf(",0x%02x", (unsigned int) a[i]);
if (i % 8 == 7)
printf("\n");
}
printf("\n");
crypto_auth_hmacsha512_init(&st, key, sizeof key);
crypto_auth_hmacsha512_update(&st, c, 1U);
crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
crypto_auth_hmacsha512_final(&st, a2);
for (i = 0; i < sizeof a2; ++i) {
printf(",0x%02x", (unsigned int) a2[i]);
if (i % 8 == 7)
printf("\n");
}
printf("\n");
crypto_auth_hmacsha512_init(&st, key2, sizeof key2);
crypto_auth_hmacsha512_update(&st, c, 1U);
crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
crypto_auth_hmacsha512_final(&st, a2);
for (i = 0; i < sizeof a2; ++i) {
printf(",0x%02x", (unsigned int) a2[i]);
if (i % 8 == 7)
printf("\n");
}
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha256_init(&st256, key2, sizeof key2);
crypto_auth_hmacsha256_update(&st256, guard_page, 0U);
crypto_auth_hmacsha256_update(&st256, c, 1U);
crypto_auth_hmacsha256_update(&st256, c, sizeof c - 2U);
crypto_auth_hmacsha256_final(&st256, a2);
for (i = 0; i < sizeof a2; ++i) {
printf(",0x%02x", (unsigned int) a2[i]);
if (i % 8 == 7)
printf("\n");
}
/* Empty message tests: HMAC-SHA512 */
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha512_init(&st, key, sizeof key);
crypto_auth_hmacsha512_final(&st, a2);
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha512_init(&st, key, sizeof key);
crypto_auth_hmacsha512_update(&st, a2, 0U);
crypto_auth_hmacsha512_final(&st, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha512_init(&st, key, sizeof key);
crypto_auth_hmacsha512_update(&st, guard_page, 0U);
crypto_auth_hmacsha512_final(&st, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
/* Empty message tests: HMAC-SHA512-256 */
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key);
crypto_auth_hmacsha512256_final(&st512_256, a2);
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key);
crypto_auth_hmacsha512256_update(&st512_256, a2, 0U);
crypto_auth_hmacsha512256_final(&st512_256, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key);
crypto_auth_hmacsha512256_update(&st512_256, guard_page, 0U);
crypto_auth_hmacsha512256_final(&st512_256, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
/* Empty message tests: HMAC-SHA256 */
memset(a2, 0, sizeof a2);
crypto_auth_hmacsha256_init(&st256, key, sizeof key);
crypto_auth_hmacsha256_final(&st256, a2);
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha256_init(&st256, key, sizeof key);
crypto_auth_hmacsha256_update(&st256, a2, 0U);
crypto_auth_hmacsha256_final(&st256, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
memset(a3, 0, sizeof a3);
crypto_auth_hmacsha256_init(&st256, key, sizeof key);
crypto_auth_hmacsha256_update(&st256, guard_page, 0U);
crypto_auth_hmacsha256_final(&st256, a3);
assert(sodium_memcmp(a2, a3, sizeof a2) == 0);
/* --- */
assert(crypto_auth_bytes() > 0U);
assert(crypto_auth_keybytes() > 0U);
assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0);
assert(crypto_auth_hmacsha256_bytes() > 0U);
assert(crypto_auth_hmacsha256_keybytes() > 0U);
assert(crypto_auth_hmacsha512_bytes() > 0U);
assert(crypto_auth_hmacsha512_keybytes() > 0U);
assert(crypto_auth_hmacsha512256_bytes() == crypto_auth_bytes());
assert(crypto_auth_hmacsha512256_keybytes() == crypto_auth_keybytes());
assert(crypto_auth_hmacsha512256_statebytes() >=
crypto_auth_hmacsha512256_keybytes());
assert(crypto_auth_hmacsha256_statebytes() ==
sizeof(crypto_auth_hmacsha256_state));
assert(crypto_auth_hmacsha512_statebytes() ==
sizeof(crypto_auth_hmacsha512_state));
return 0;
}

30
deps/libsodium/test/default/auth.exp vendored Normal file
View File

@ -0,0 +1,30 @@
,0x16,0x4b,0x7a,0x7b,0xfc,0xf8,0x19,0xe2
,0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3
,0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6
,0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54
,0x7b,0x9d,0x83,0x38,0xeb,0x1e,0x3d,0xdd
,0xba,0x8a,0x9a,0x35,0x08,0xd0,0x34,0xa1
,0xec,0xbe,0x75,0x11,0x37,0xfa,0x1b,0xcb
,0xa0,0xf9,0x2a,0x3e,0x6d,0xfc,0x79,0x80
,0xb8,0x81,0xa8,0x64,0x5f,0x92,0x67,0x22
,0x74,0x37,0x96,0x4b,0xf3,0x07,0x0b,0xe2
,0xb3,0x36,0xb3,0xa3,0x20,0xf8,0x25,0xce
,0xc9,0x87,0x2d,0xb2,0x50,0x4b,0xf3,0x6d
,0x73,0xe0,0x0d,0xcb,0xf4,0xf8,0xa3,0x33
,0x30,0xac,0x52,0xed,0x2c,0xc9,0xd1,0xb2
,0xef,0xb1,0x77,0x13,0xd3,0xec,0xe3,0x96
,0x14,0x9f,0x37,0x65,0x3c,0xfe,0x70,0xe7
,0x1f,0x2c,0x6f,0x9a,0x62,0xc3,0xc5,0x3a
,0x31,0x8a,0x9a,0x0b,0x3b,0x78,0x60,0xa4
,0x31,0x6f,0x72,0x9b,0x8d,0x30,0x0f,0x15
,0x9b,0x2f,0x60,0x93,0xa8,0x60,0xc1,0xed
,0x62,0x27,0xe4,0xce,0x7c,0x7f,0xe7,0xa4
,0xba,0x9e,0x2a,0xc3,0x42,0xc3,0x5d,0x24
,0x03,0x3e,0x38,0x8c,0x9b,0xdc,0x29,0x9b
,0x4a,0x50,0x50,0xf6,0x71,0x70,0xf4,0x83
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

34
deps/libsodium/test/default/auth2.c vendored Normal file
View File

@ -0,0 +1,34 @@
/* "Test Case AUTH256-4" from RFC 4868 */
#define TEST_NAME "auth2"
#include "cmptest.h"
static unsigned char key[32] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20
};
static unsigned char c[50] = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd };
static unsigned char a[32];
int
main(void)
{
int i;
crypto_auth_hmacsha256(a, c, sizeof c, key);
for (i = 0; i < 32; ++i) {
printf(",0x%02x", (unsigned int) a[i]);
if (i % 8 == 7)
printf("\n");
}
return 0;
}

4
deps/libsodium/test/default/auth2.exp vendored Normal file
View File

@ -0,0 +1,4 @@
,0x37,0x2e,0xfc,0xf9,0xb4,0x0b,0x35,0xc2
,0x11,0x5b,0x13,0x46,0x90,0x3d,0x2e,0xf4
,0x2f,0xce,0xd4,0x6f,0x08,0x46,0xe7,0x25
,0x7b,0xb1,0x56,0xd3,0xd7,0xb3,0x0d,0x3f

36
deps/libsodium/test/default/auth3.c vendored Normal file
View File

@ -0,0 +1,36 @@
/* "Test Case AUTH256-4" from RFC 4868 */
#define TEST_NAME "auth3"
#include "cmptest.h"
static unsigned char key[32] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20
};
static unsigned char c[50] = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd };
static unsigned char a[32] = { 0x37, 0x2e, 0xfc, 0xf9, 0xb4, 0x0b, 0x35, 0xc2,
0x11, 0x5b, 0x13, 0x46, 0x90, 0x3d, 0x2e, 0xf4,
0x2f, 0xce, 0xd4, 0x6f, 0x08, 0x46, 0xe7, 0x25,
0x7b, 0xb1, 0x56, 0xd3, 0xd7, 0xb3, 0x0d, 0x3f };
int
main(void)
{
static unsigned char a2[crypto_auth_hmacsha256_BYTES];
printf("%d\n", crypto_auth_hmacsha256_verify(a, c, sizeof c, key));
crypto_auth_hmacsha256(a2, guard_page, 0U, key);
assert(crypto_auth_hmacsha256_verify(a2, guard_page, 0U, key) == 0);
return 0;
}

1
deps/libsodium/test/default/auth3.exp vendored Normal file
View File

@ -0,0 +1 @@
0

41
deps/libsodium/test/default/auth5.c vendored Normal file
View File

@ -0,0 +1,41 @@
#define TEST_NAME "auth5"
#include "cmptest.h"
static unsigned char key[32];
static unsigned char c[1000];
static unsigned char a[32];
int
main(void)
{
size_t clen;
for (clen = 0; clen < 1000; ++clen) {
crypto_auth_keygen(key);
randombytes_buf(c, clen);
crypto_auth(a, c, clen, key);
if (crypto_auth_verify(a, c, clen, key) != 0) {
printf("fail %u\n", (unsigned int) clen);
return 100;
}
if (clen > 0) {
c[rand() % clen] += 1 + (rand() % 255);
if (crypto_auth_verify(a, c, clen, key) == 0) {
printf("forgery %u\n", (unsigned int) clen);
return 100;
}
a[rand() % sizeof a] += 1 + (rand() % 255);
if (crypto_auth_verify(a, c, clen, key) == 0) {
printf("forgery %u\n", (unsigned int) clen);
return 100;
}
}
}
crypto_auth_keygen(key);
crypto_auth(a, guard_page, 0U, key);
assert(crypto_auth_verify(a, guard_page, 0U, key) == 0);
return 0;
}

0
deps/libsodium/test/default/auth5.exp vendored Normal file
View File

23
deps/libsodium/test/default/auth6.c vendored Normal file
View File

@ -0,0 +1,23 @@
#define TEST_NAME "auth6"
#include "cmptest.h"
/* "Test Case 2" from RFC 4231 */
static unsigned char key[32] = "Jefe";
static unsigned char c[] = "what do ya want for nothing?";
static unsigned char a[64];
int
main(void)
{
int i;
crypto_auth_hmacsha512(a, c, sizeof c - 1U, key);
for (i = 0; i < 64; ++i) {
printf(",0x%02x", (unsigned int) a[i]);
if (i % 8 == 7)
printf("\n");
}
return 0;
}

8
deps/libsodium/test/default/auth6.exp vendored Normal file
View File

@ -0,0 +1,8 @@
,0x16,0x4b,0x7a,0x7b,0xfc,0xf8,0x19,0xe2
,0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3
,0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6
,0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54
,0x97,0x58,0xbf,0x75,0xc0,0x5a,0x99,0x4a
,0x6d,0x03,0x4f,0x65,0xf8,0xf0,0xe6,0xfd
,0xca,0xea,0xb1,0xa3,0x4d,0x4a,0x6b,0x4b
,0x63,0x6e,0x07,0x0a,0x38,0xbc,0xe7,0x37

41
deps/libsodium/test/default/auth7.c vendored Normal file
View File

@ -0,0 +1,41 @@
#define TEST_NAME "auth7"
#include "cmptest.h"
static unsigned char key[32];
static unsigned char c[600];
static unsigned char a[64];
int
main(void)
{
size_t clen;
for (clen = 0; clen < sizeof c; ++clen) {
crypto_auth_keygen(key);
randombytes_buf(c, clen);
crypto_auth_hmacsha512(a, c, clen, key);
if (crypto_auth_hmacsha512_verify(a, c, clen, key) != 0) {
printf("fail %u\n", (unsigned int) clen);
return 100;
}
if (clen > 0) {
c[(size_t) rand() % clen] += 1 + (rand() % 255);
if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
printf("forgery %u\n", (unsigned int) clen);
return 100;
}
a[rand() % sizeof a] += 1 + (rand() % 255);
if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
printf("forgery %u\n", (unsigned int) clen);
return 100;
}
}
}
crypto_auth_keygen(key);
crypto_auth_hmacsha512(a, guard_page, 0U, key);
assert(crypto_auth_hmacsha512_verify(a, guard_page, 0U, key) == 0);
return 0;
}

0
deps/libsodium/test/default/auth7.exp vendored Normal file
View File

112
deps/libsodium/test/default/box.c vendored Normal file
View File

@ -0,0 +1,112 @@
#define TEST_NAME "box"
#include "cmptest.h"
static const unsigned char alicesk[32] = {
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1,
0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0,
0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
};
static const unsigned char bobpk[32] = {
0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 0xd3, 0x5b, 0x61,
0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78,
0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
};
static const unsigned char small_order_p[crypto_box_PUBLICKEYBYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00
};
static const unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6,
0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8,
0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19,
0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
/* API requires first 32 bytes to be 0 */
static const unsigned char m[163] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0xbe, 0x07, 0x5f, 0xc5,
0x3c, 0x81, 0xf2, 0xd5, 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b,
0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, 0x4b, 0x66, 0x84, 0x9b,
0x64, 0x24, 0x4f, 0xfc, 0xe5, 0xec, 0xba, 0xaf, 0x33, 0xbd, 0x75, 0x1a,
0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29, 0x6c, 0xdc, 0x3c, 0x01,
0x23, 0x35, 0x61, 0xf4, 0x1d, 0xb6, 0x6c, 0xce, 0x31, 0x4a, 0xdb, 0x31,
0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d, 0xce, 0xea, 0x3a, 0x7f,
0xa1, 0x34, 0x80, 0x57, 0xe2, 0xf6, 0x55, 0x6a, 0xd6, 0xb1, 0x31, 0x8a,
0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde, 0x04, 0x89, 0x77, 0xeb,
0x48, 0xf5, 0x9f, 0xfd, 0x49, 0x24, 0xca, 0x1c, 0x60, 0x90, 0x2e, 0x52,
0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40, 0xe0, 0x82, 0xf9, 0x37,
0x76, 0x38, 0x48, 0x64, 0x5e, 0x07, 0x05
};
static unsigned char c[163];
int
main(void)
{
unsigned char k[crypto_box_BEFORENMBYTES];
int i;
int ret;
ret = crypto_box(c, m, 163, nonce, bobpk, alicesk);
assert(ret == 0);
for (i = 16; i < 163; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7)
printf("\n");
}
printf("\n");
ret = crypto_box(c, m, 163, nonce, small_order_p, alicesk);
assert(ret == -1);
memset(c, 0, sizeof c);
ret = crypto_box_beforenm(k, bobpk, alicesk);
assert(ret == 0);
crypto_box_afternm(c, m, 163, nonce, k);
for (i = 16; i < 163; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
if (i % 8 == 7)
printf("\n");
}
printf("\n");
ret = crypto_box_beforenm(k, small_order_p, alicesk);
assert(ret == -1);
assert(crypto_box_seedbytes() > 0U);
assert(crypto_box_publickeybytes() > 0U);
assert(crypto_box_secretkeybytes() > 0U);
assert(crypto_box_beforenmbytes() > 0U);
assert(crypto_box_noncebytes() > 0U);
assert(crypto_box_zerobytes() > 0U);
assert(crypto_box_boxzerobytes() > 0U);
assert(crypto_box_macbytes() > 0U);
assert(crypto_box_messagebytes_max() > 0U);
assert(strcmp(crypto_box_primitive(), "curve25519xsalsa20poly1305") == 0);
assert(crypto_box_curve25519xsalsa20poly1305_seedbytes() ==
crypto_box_seedbytes());
assert(crypto_box_curve25519xsalsa20poly1305_publickeybytes() ==
crypto_box_publickeybytes());
assert(crypto_box_curve25519xsalsa20poly1305_secretkeybytes() ==
crypto_box_secretkeybytes());
assert(crypto_box_curve25519xsalsa20poly1305_beforenmbytes() ==
crypto_box_beforenmbytes());
assert(crypto_box_curve25519xsalsa20poly1305_noncebytes() ==
crypto_box_noncebytes());
assert(crypto_box_curve25519xsalsa20poly1305_zerobytes() ==
crypto_box_zerobytes());
assert(crypto_box_curve25519xsalsa20poly1305_boxzerobytes() ==
crypto_box_boxzerobytes());
assert(crypto_box_curve25519xsalsa20poly1305_macbytes() ==
crypto_box_macbytes());
assert(crypto_box_curve25519xsalsa20poly1305_messagebytes_max() ==
crypto_box_messagebytes_max());
return 0;
}

38
deps/libsodium/test/default/box.exp vendored Normal file
View File

@ -0,0 +1,38 @@
,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73
,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce
,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4
,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a
,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b
,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72
,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2
,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38
,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a
,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae
,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea
,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda
,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde
,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3
,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6
,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74
,0xe3,0x55,0xa5
,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73
,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce
,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4
,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a
,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b
,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72
,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2
,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38
,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a
,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae
,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea
,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda
,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde
,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3
,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6
,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74
,0xe3,0x55,0xa5

80
deps/libsodium/test/default/box2.c vendored Normal file
View File

@ -0,0 +1,80 @@
#define TEST_NAME "box2"
#include "cmptest.h"
static unsigned char bobsk[32] = { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a,
0x4b, 0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80,
0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26,
0x18, 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27,
0xff, 0x88, 0xe0, 0xeb };
static unsigned char alicepk[32] = { 0x85, 0x20, 0xf0, 0x09, 0x89, 0x30, 0xa7,
0x54, 0x74, 0x8b, 0x7d, 0xdc, 0xb4, 0x3e,
0xf7, 0x5a, 0x0d, 0xbf, 0x3a, 0x0d, 0x26,
0x38, 0x1a, 0xf4, 0xeb, 0xa4, 0xa9, 0x8e,
0xaa, 0x9b, 0x4e, 0x6a };
static const unsigned char small_order_p[crypto_box_PUBLICKEYBYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00
};
static unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6,
0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8,
0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19,
0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
/* API requires first 16 bytes to be 0 */
static unsigned char c[163] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, 0x8e, 0x99, 0x3b, 0x9f,
0x48, 0x68, 0x12, 0x73, 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce,
0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, 0x47, 0x6f, 0xb8, 0xc5,
0x31, 0xa1, 0x18, 0x6a, 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b,
0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, 0x71, 0xd2, 0xc2, 0x0f,
0x9b, 0x92, 0x8f, 0xe2, 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38,
0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a, 0xb9, 0x32, 0x16, 0x45,
0x48, 0xe5, 0x26, 0xae, 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea,
0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda, 0x99, 0x83, 0x2b, 0x61,
0xca, 0x01, 0xb6, 0xde, 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3,
0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6, 0x59, 0x9b, 0x1f, 0x65,
0x4c, 0xb4, 0x5a, 0x74, 0xe3, 0x55, 0xa5
};
static unsigned char m[163];
int
main(void)
{
unsigned char k[crypto_box_BEFORENMBYTES];
int i;
int ret;
if (crypto_box_open(m, c, 163, nonce, alicepk, bobsk) == 0) {
for (i = 32; i < 163; ++i) {
printf(",0x%02x", (unsigned int) m[i]);
if (i % 8 == 7)
printf("\n");
}
printf("\n");
}
ret = crypto_box_open(m, c, 163, nonce, small_order_p, bobsk);
assert(ret == -1);
memset(m, 0, sizeof m);
ret = crypto_box_beforenm(k, small_order_p, bobsk);
assert(ret == -1);
ret = crypto_box_beforenm(k, alicepk, bobsk);
assert(ret == 0);
if (crypto_box_open_afternm(m, c, 163, nonce, k) == 0) {
for (i = 32; i < 163; ++i) {
printf(",0x%02x", (unsigned int) m[i]);
if (i % 8 == 7)
printf("\n");
}
printf("\n");
}
return 0;
}

34
deps/libsodium/test/default/box2.exp vendored Normal file
View File

@ -0,0 +1,34 @@
,0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5
,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b
,0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4
,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc
,0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a
,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29
,0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4
,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31
,0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d
,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57
,0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a
,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde
,0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd
,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52
,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
,0x5e,0x07,0x05
,0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5
,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b
,0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4
,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc
,0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a
,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29
,0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4
,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31
,0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d
,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57
,0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a
,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde
,0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd
,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52
,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
,0x5e,0x07,0x05

50
deps/libsodium/test/default/box7.c vendored Normal file
View File

@ -0,0 +1,50 @@
#define TEST_NAME "box7"
#include "cmptest.h"
static unsigned char alicesk[crypto_box_SECRETKEYBYTES];
static unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
static unsigned char bobsk[crypto_box_SECRETKEYBYTES];
static unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
static unsigned char n[crypto_box_NONCEBYTES];
int
main(void)
{
unsigned char *m;
unsigned char *c;
unsigned char *m2;
size_t mlen;
size_t mlen_max = 1000;
size_t i;
int ret;
m = (unsigned char *) sodium_malloc(mlen_max);
c = (unsigned char *) sodium_malloc(mlen_max);
m2 = (unsigned char *) sodium_malloc(mlen_max);
memset(m, 0, crypto_box_ZEROBYTES);
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
for (mlen = 0; mlen + crypto_box_ZEROBYTES <= mlen_max; mlen++) {
randombytes_buf(n, crypto_box_NONCEBYTES);
randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
ret = crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
assert(ret == 0);
if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
bobsk) == 0) {
for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
if (m2[i] != m[i]) {
printf("bad decryption\n");
break;
}
}
} else {
printf("ciphertext fails verification\n");
}
}
sodium_free(m);
sodium_free(c);
sodium_free(m2);
return 0;
}

0
deps/libsodium/test/default/box7.exp vendored Normal file
View File

58
deps/libsodium/test/default/box8.c vendored Normal file
View File

@ -0,0 +1,58 @@
#define TEST_NAME "box8"
#include "cmptest.h"
static unsigned char alicesk[crypto_box_SECRETKEYBYTES];
static unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
static unsigned char bobsk[crypto_box_SECRETKEYBYTES];
static unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
static unsigned char n[crypto_box_NONCEBYTES];
int
main(void)
{
unsigned char *m;
unsigned char *c;
unsigned char *m2;
size_t mlen;
size_t mlen_max = 1000;
size_t i;
int faults;
int ret;
m = (unsigned char *) sodium_malloc(mlen_max);
c = (unsigned char *) sodium_malloc(mlen_max);
m2 = (unsigned char *) sodium_malloc(mlen_max);
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
for (mlen = 0; mlen + crypto_box_ZEROBYTES <= mlen_max; mlen++) {
randombytes_buf(n, crypto_box_NONCEBYTES);
randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
ret = crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
assert(ret == 0);
#ifdef BROWSER_TESTS
faults = 1;
#else
faults = 5;
#endif
while (faults > 0) {
c[rand() % (mlen + crypto_box_ZEROBYTES)] = rand();
if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
bobsk) == 0) {
for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
if (m2[i] != m[i]) {
printf("forgery\n");
return 100;
}
}
} else {
faults--;
}
}
}
sodium_free(m);
sodium_free(c);
sodium_free(m2);
return 0;
}

0
deps/libsodium/test/default/box8.exp vendored Normal file
View File

72
deps/libsodium/test/default/box_easy.c vendored Normal file
View File

@ -0,0 +1,72 @@
#define TEST_NAME "box_easy"
#include "cmptest.h"
static unsigned char alicesk[32] = { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5,
0x7d, 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2,
0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb,
0xc0, 0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5,
0x1d, 0xb9, 0x2c, 0x2a };
static unsigned char bobpk[32] = { 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1,
0xb4, 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4,
0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b,
0x78, 0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14,
0x6f, 0x88, 0x2b, 0x4f };
static unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6,
0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8,
0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19,
0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
static unsigned char m[131] = {
0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, 0xcf, 0x14, 0x13, 0x16,
0xeb, 0xeb, 0x0c, 0x7b, 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4,
0x4b, 0x66, 0x84, 0x9b, 0x64, 0x24, 0x4f, 0xfc, 0xe5, 0xec, 0xba, 0xaf,
0x33, 0xbd, 0x75, 0x1a, 0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29,
0x6c, 0xdc, 0x3c, 0x01, 0x23, 0x35, 0x61, 0xf4, 0x1d, 0xb6, 0x6c, 0xce,
0x31, 0x4a, 0xdb, 0x31, 0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d,
0xce, 0xea, 0x3a, 0x7f, 0xa1, 0x34, 0x80, 0x57, 0xe2, 0xf6, 0x55, 0x6a,
0xd6, 0xb1, 0x31, 0x8a, 0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde,
0x04, 0x89, 0x77, 0xeb, 0x48, 0xf5, 0x9f, 0xfd, 0x49, 0x24, 0xca, 0x1c,
0x60, 0x90, 0x2e, 0x52, 0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40,
0xe0, 0x82, 0xf9, 0x37, 0x76, 0x38, 0x48, 0x64, 0x5e, 0x07, 0x05
};
static unsigned char c[147 + crypto_box_MACBYTES];
int
main(void)
{
size_t i;
int ret;
ret = crypto_box_easy(c, m, 131, nonce, bobpk, alicesk);
assert(ret == 0);
for (i = 0; i < 131 + crypto_box_MACBYTES; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
}
printf("\n");
/* Null message */
ret = crypto_box_easy(c, guard_page, 0, nonce, bobpk, alicesk);
assert(ret == 0);
for (i = 0; i < 1 + crypto_box_MACBYTES; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
}
printf("\n");
ret =
crypto_box_open_easy(c, c, crypto_box_MACBYTES, nonce, bobpk, alicesk);
assert(ret == 0);
for (i = 0; i < 1 + crypto_box_MACBYTES; ++i) {
printf(",0x%02x", (unsigned int) c[i]);
}
printf("\n");
c[randombytes_uniform(crypto_box_MACBYTES)]++;
ret = crypto_box_open_easy(c, c, crypto_box_MACBYTES, nonce, bobpk, alicesk);
assert(ret == -1);
return 0;
}

View File

@ -0,0 +1,3 @@
,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74,0xe3,0x55,0xa5
,0x25,0x39,0x12,0x1d,0x8e,0x23,0x4e,0x65,0x2d,0x65,0x1f,0xa4,0xc8,0xcf,0xf8,0x80,0x8e
,0x25,0x39,0x12,0x1d,0x8e,0x23,0x4e,0x65,0x2d,0x65,0x1f,0xa4,0xc8,0xcf,0xf8,0x80,0x8e

149
deps/libsodium/test/default/box_easy2.c vendored Normal file
View File

@ -0,0 +1,149 @@
#define TEST_NAME "box_easy2"
#include "cmptest.h"
static const unsigned char small_order_p[crypto_box_PUBLICKEYBYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00
};
int
main(void)
{
unsigned char *alicepk;
unsigned char *alicesk;
unsigned char *bobpk;
unsigned char *bobsk;
unsigned char *mac;
unsigned char *nonce;
unsigned char *k1;
unsigned char *k2;
unsigned char *m;
unsigned char *m2;
unsigned char *c;
size_t mlen;
size_t i;
size_t m_size;
size_t m2_size;
size_t c_size;
int ret;
m2_size = m_size = 7U + randombytes_uniform(1000);
c_size = crypto_box_MACBYTES + m_size;
m = (unsigned char *) sodium_malloc(m_size);
m2 = (unsigned char *) sodium_malloc(m2_size);
c = (unsigned char *) sodium_malloc(c_size);
alicepk = (unsigned char *) sodium_malloc(crypto_box_PUBLICKEYBYTES);
alicesk = (unsigned char *) sodium_malloc(crypto_box_SECRETKEYBYTES);
bobpk = (unsigned char *) sodium_malloc(crypto_box_PUBLICKEYBYTES);
bobsk = (unsigned char *) sodium_malloc(crypto_box_SECRETKEYBYTES);
mac = (unsigned char *) sodium_malloc(crypto_box_MACBYTES);
nonce = (unsigned char *) sodium_malloc(crypto_box_NONCEBYTES);
k1 = (unsigned char *) sodium_malloc(crypto_box_BEFORENMBYTES);
k2 = (unsigned char *) sodium_malloc(crypto_box_BEFORENMBYTES);
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
mlen = (size_t) randombytes_uniform((uint32_t) m_size) + 1U;
randombytes_buf(m, mlen);
randombytes_buf(nonce, crypto_box_NONCEBYTES);
ret = crypto_box_easy(c, m, mlen, nonce, bobpk, alicesk);
assert(ret == 0);
if (crypto_box_open_easy(m2, c,
(unsigned long long) mlen + crypto_box_MACBYTES,
nonce, alicepk, bobsk) != 0) {
printf("open() failed");
return 1;
}
printf("%d\n", memcmp(m, m2, mlen));
for (i = 0; i < mlen + crypto_box_MACBYTES - 1; i++) {
if (crypto_box_open_easy(m2, c, (unsigned long long) i, nonce, alicepk,
bobsk) == 0) {
printf("short open() should have failed");
return 1;
}
}
memcpy(c, m, mlen);
ret =
crypto_box_easy(c, c, (unsigned long long) mlen, nonce, bobpk, alicesk);
assert(ret == 0);
printf("%d\n", memcmp(m, c, mlen) == 0);
printf("%d\n", memcmp(m, c + crypto_box_MACBYTES, mlen) == 0);
if (crypto_box_open_easy(c, c,
(unsigned long long) mlen + crypto_box_MACBYTES,
nonce, alicepk, bobsk) != 0) {
printf("crypto_box_open_easy() failed\n");
}
ret = crypto_box_beforenm(k1, small_order_p, bobsk);
assert(ret == -1);
ret = crypto_box_beforenm(k2, small_order_p, alicesk);
assert(ret == -1);
ret = crypto_box_beforenm(k1, alicepk, bobsk);
assert(ret == 0);
ret = crypto_box_beforenm(k2, bobpk, alicesk);
assert(ret == 0);
memset(m2, 0, m2_size);
if (crypto_box_easy_afternm(c, m, 0, nonce, k1) != 0) {
printf(
"crypto_box_easy_afternm() with a null ciphertext should have "
"worked\n");
}
crypto_box_easy_afternm(c, m, (unsigned long long) mlen, nonce, k1);
if (crypto_box_open_easy_afternm(
m2, c, (unsigned long long) mlen + crypto_box_MACBYTES, nonce,
k2) != 0) {
printf("crypto_box_open_easy_afternm() failed\n");
}
printf("%d\n", memcmp(m, m2, mlen));
if (crypto_box_open_easy_afternm(m2, c, crypto_box_MACBYTES - 1U, nonce,
k2) == 0) {
printf(
"crypto_box_open_easy_afternm() with a huge ciphertext should have "
"failed\n");
}
memset(m2, 0, m2_size);
ret = crypto_box_detached(c, mac, m, (unsigned long long) mlen, nonce,
small_order_p, bobsk);
assert(ret == -1);
ret = crypto_box_detached(c, mac, m, (unsigned long long) mlen, nonce,
alicepk, bobsk);
assert(ret == 0);
if (crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen, nonce,
small_order_p, alicesk) != -1) {
printf("crypto_box_open_detached() with a weak key passed\n");
}
if (crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen, nonce,
bobpk, alicesk) != 0) {
printf("crypto_box_open_detached() failed\n");
}
printf("%d\n", memcmp(m, m2, mlen));
memset(m2, 0, m2_size);
crypto_box_detached_afternm(c, mac, m, (unsigned long long) mlen, nonce,
k1);
if (crypto_box_open_detached_afternm(m2, c, mac, (unsigned long long) mlen,
nonce, k2) != 0) {
printf("crypto_box_open_detached_afternm() failed\n");
}
printf("%d\n", memcmp(m, m2, mlen));
sodium_free(alicepk);
sodium_free(alicesk);
sodium_free(bobpk);
sodium_free(bobsk);
sodium_free(mac);
sodium_free(nonce);
sodium_free(k1);
sodium_free(k2);
sodium_free(m);
sodium_free(m2);
sodium_free(c);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1,7 @@
0
0
0
0
0
0
OK

165
deps/libsodium/test/default/box_seal.c vendored Normal file
View File

@ -0,0 +1,165 @@
#define TEST_NAME "box_seal"
#include "cmptest.h"
static
void tv1(void)
{
unsigned char pk[crypto_box_PUBLICKEYBYTES];
unsigned char sk[crypto_box_SECRETKEYBYTES];
unsigned char *c;
unsigned char *m;
unsigned char *m2;
size_t m_len;
size_t c_len;
crypto_box_keypair(pk, sk);
m_len = (size_t) randombytes_uniform(1000);
c_len = crypto_box_SEALBYTES + m_len;
m = (unsigned char *) sodium_malloc(m_len);
m2 = (unsigned char *) sodium_malloc(m_len);
c = (unsigned char *) sodium_malloc(c_len);
randombytes_buf(m, m_len);
if (crypto_box_seal(c, m, m_len, pk) != 0) {
printf("crypto_box_seal() failure\n");
return;
}
if (crypto_box_seal_open(m2, c, c_len, pk, sk) != 0) {
printf("crypto_box_seal_open() failure\n");
return;
}
printf("%d\n", memcmp(m, m2, m_len));
printf("%d\n", crypto_box_seal_open(m, c, 0U, pk, sk));
printf("%d\n", crypto_box_seal_open(m, c, c_len - 1U, pk, sk));
printf("%d\n", crypto_box_seal_open(m, c, c_len, sk, pk));
sodium_free(c);
sodium_free(m);
sodium_free(m2);
assert(crypto_box_sealbytes() == crypto_box_SEALBYTES);
}
static
void tv2(void)
{
unsigned char pk[crypto_box_PUBLICKEYBYTES];
unsigned char sk[crypto_box_SECRETKEYBYTES];
unsigned char *cm;
unsigned char *m2;
size_t m_len;
size_t cm_len;
crypto_box_keypair(pk, sk);
m_len = (size_t) randombytes_uniform(1000);
cm_len = crypto_box_SEALBYTES + m_len;
m2 = (unsigned char *) sodium_malloc(m_len);
cm = (unsigned char *) sodium_malloc(cm_len);
randombytes_buf(cm, m_len);
if (crypto_box_seal(cm, cm, m_len, pk) != 0) {
printf("crypto_box_seal() failure\n");
return;
}
if (crypto_box_seal_open(m2, cm, cm_len, pk, sk) != 0) {
printf("crypto_box_seal_open() failure\n");
return;
}
assert(m_len == 0 || memcmp(cm, m2, m_len) != 0);
sodium_free(cm);
sodium_free(m2);
}
#ifndef SODIUM_LIBRARY_MINIMAL
static
void tv3(void)
{
unsigned char pk[crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES];
unsigned char sk[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES];
unsigned char *c;
unsigned char *m;
unsigned char *m2;
size_t m_len;
size_t c_len;
crypto_box_curve25519xchacha20poly1305_keypair(pk, sk);
m_len = (size_t) randombytes_uniform(1000);
c_len = crypto_box_curve25519xchacha20poly1305_SEALBYTES + m_len;
m = (unsigned char *) sodium_malloc(m_len);
m2 = (unsigned char *) sodium_malloc(m_len);
c = (unsigned char *) sodium_malloc(c_len);
randombytes_buf(m, m_len);
if (crypto_box_curve25519xchacha20poly1305_seal(c, m, m_len, pk) != 0) {
printf("crypto_box_curve25519xchacha20poly1305_seal() failure\n");
return;
}
if (crypto_box_curve25519xchacha20poly1305_seal_open(m2, c, c_len, pk, sk) != 0) {
printf("crypto_box_curve25519xchacha20poly1305_seal_open() failure\n");
return;
}
printf("%d\n", memcmp(m, m2, m_len));
printf("%d\n", crypto_box_curve25519xchacha20poly1305_seal_open(m, c, 0U, pk, sk));
printf("%d\n", crypto_box_curve25519xchacha20poly1305_seal_open(m, c, c_len - 1U, pk, sk));
printf("%d\n", crypto_box_curve25519xchacha20poly1305_seal_open(m, c, c_len, sk, pk));
sodium_free(c);
sodium_free(m);
sodium_free(m2);
assert(crypto_box_curve25519xchacha20poly1305_sealbytes() ==
crypto_box_curve25519xchacha20poly1305_SEALBYTES);
}
static
void tv4(void)
{
unsigned char pk[crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES];
unsigned char sk[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES];
unsigned char *cm;
unsigned char *m2;
size_t m_len;
size_t cm_len;
crypto_box_curve25519xchacha20poly1305_keypair(pk, sk);
m_len = (size_t) randombytes_uniform(1000);
cm_len = crypto_box_curve25519xchacha20poly1305_SEALBYTES + m_len;
m2 = (unsigned char *) sodium_malloc(m_len);
cm = (unsigned char *) sodium_malloc(cm_len);
randombytes_buf(cm, m_len);
if (crypto_box_curve25519xchacha20poly1305_seal(cm, cm, m_len, pk) != 0) {
printf("crypto_box_curve25519xchacha20poly1305_seal() failure\n");
return;
}
if (crypto_box_curve25519xchacha20poly1305_seal_open(m2, cm, cm_len, pk, sk) != 0) {
printf("crypto_box_curve25519xchacha20poly1305_seal_open() failure\n");
return;
}
assert(m_len == 0 || memcmp(cm, m2, m_len) != 0);
sodium_free(cm);
sodium_free(m2);
}
#else
static
void tv3(void)
{
printf("0\n-1\n-1\n-1\n");
}
static
void tv4(void)
{ }
#endif
int
main(void)
{
tv1();
tv2();
tv3();
tv4();
return 0;
}

View File

@ -0,0 +1,8 @@
0
-1
-1
-1
0
-1
-1
-1

30
deps/libsodium/test/default/box_seed.c vendored Normal file
View File

@ -0,0 +1,30 @@
#define TEST_NAME "box_seed"
#include "cmptest.h"
static unsigned char seed[32] = { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5,
0x7d, 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2,
0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb,
0xc0, 0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5,
0x1d, 0xb9, 0x2c, 0x2a };
int
main(void)
{
int i;
unsigned char sk[32];
unsigned char pk[32];
crypto_box_seed_keypair(pk, sk, seed);
for (i = 0; i < 32; ++i) {
printf(",0x%02x", (unsigned int) pk[i]);
if (i % 8 == 7)
printf("\n");
}
for (i = 0; i < 32; ++i) {
printf(",0x%02x", (unsigned int) sk[i]);
if (i % 8 == 7)
printf("\n");
}
return 0;
}

View File

@ -0,0 +1,8 @@
,0xed,0x77,0x49,0xb4,0xd9,0x89,0xf6,0x95
,0x7f,0x3b,0xfd,0xe6,0xc5,0x67,0x67,0xe9
,0x88,0xe2,0x1c,0x9f,0x87,0x84,0xd9,0x1d
,0x61,0x00,0x11,0xcd,0x55,0x3f,0x9b,0x06
,0xac,0xcd,0x44,0xeb,0x8e,0x93,0x31,0x9c
,0x05,0x70,0xbc,0x11,0x00,0x5c,0x0e,0x01
,0x89,0xd3,0x4f,0xf0,0x2f,0x6c,0x17,0x77
,0x34,0x11,0xad,0x19,0x12,0x93,0xc9,0x8f

186
deps/libsodium/test/default/chacha20.c vendored Normal file
View File

@ -0,0 +1,186 @@
#define TEST_NAME "chacha20"
#include "cmptest.h"
static
void tv(void)
{
static struct {
const char *key_hex;
const char *nonce_hex;
} tests[]
= { { "0000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000" },
{ "0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000" },
{ "0000000000000000000000000000000000000000000000000000000000000000",
"0000000000000001" },
{ "0000000000000000000000000000000000000000000000000000000000000000",
"0100000000000000" },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"0001020304050607" } };
unsigned char key[crypto_stream_chacha20_KEYBYTES];
unsigned char nonce[crypto_stream_chacha20_NONCEBYTES];
unsigned char *part;
unsigned char out[160];
unsigned char zero[160];
char out_hex[160 * 2 + 1];
size_t i = 0U;
size_t plen;
memset(zero, 0, sizeof zero);
do {
sodium_hex2bin((unsigned char *)key, sizeof key, tests[i].key_hex,
strlen(tests[i].key_hex), NULL, NULL, NULL);
sodium_hex2bin(nonce, sizeof nonce, tests[i].nonce_hex,
strlen(tests[i].nonce_hex), NULL, NULL, NULL);
crypto_stream_chacha20(out, sizeof out, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
for (plen = 1U; plen < sizeof out; plen++) {
part = (unsigned char *) sodium_malloc(plen);
crypto_stream_chacha20_xor(part, out, plen, nonce, key);
if (memcmp(part, zero, plen) != 0) {
printf("Failed with length %lu\n", (unsigned long) plen);
}
sodium_free(part);
}
} while (++i < (sizeof tests) / (sizeof tests[0]));
assert(66 <= sizeof out);
for (plen = 1U; plen < 66; plen += 3) {
memset(out, (int) (plen & 0xff), sizeof out);
crypto_stream_chacha20(out, plen, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
}
randombytes_buf(out, sizeof out);
crypto_stream_chacha20(out, sizeof out, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
assert(crypto_stream_chacha20(out, 0U, nonce, key) == 0);
assert(crypto_stream_chacha20_xor(out, out, 0U, nonce, key) == 0);
assert(crypto_stream_chacha20_xor(out, out, 0U, nonce, key) == 0);
assert(crypto_stream_chacha20_xor_ic(out, out, 0U, nonce, 1U, key) == 0);
memset(out, 0x42, sizeof out);
crypto_stream_chacha20_xor(out, out, sizeof out, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
crypto_stream_chacha20_xor_ic(out, out, sizeof out, nonce, 0U, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
crypto_stream_chacha20_xor_ic(out, out, sizeof out, nonce, 1U, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
}
static
void tv_ietf(void)
{
static struct {
const char *key_hex;
const char *nonce_hex;
uint32_t ic;
} tests[]
= { { "0000000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000",
0U },
{ "0000000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000",
1U },
{ "0000000000000000000000000000000000000000000000000000000000000001",
"000000000000000000000000",
1U },
{ "00ff000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000",
2U },
{ "0000000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000002",
0U },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"000000090000004a00000000",
1U },
{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
"000000090000004a00000000",
0xfeffffff }};
unsigned char key[crypto_stream_chacha20_KEYBYTES];
unsigned char nonce[crypto_stream_chacha20_IETF_NONCEBYTES];
unsigned char *part;
unsigned char out[160];
unsigned char zero[160];
char out_hex[160 * 2 + 1];
size_t i = 0U;
size_t plen;
memset(zero, 0, sizeof zero);
do {
sodium_hex2bin((unsigned char *)key, sizeof key, tests[i].key_hex,
strlen(tests[i].key_hex), ": ", NULL, NULL);
sodium_hex2bin(nonce, sizeof nonce, tests[i].nonce_hex,
strlen(tests[i].nonce_hex), ": ", NULL, NULL);
memset(out, 0, sizeof out);
crypto_stream_chacha20_ietf_xor_ic(out, out, sizeof out, nonce, tests[i].ic, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
for (plen = 1U; plen < sizeof out; plen++) {
part = (unsigned char *) sodium_malloc(plen);
crypto_stream_chacha20_ietf_xor_ic(part, out, plen, nonce, tests[i].ic, key);
if (memcmp(part, zero, plen) != 0) {
printf("Failed with length %lu\n", (unsigned long) plen);
}
sodium_free(part);
}
} while (++i < (sizeof tests) / (sizeof tests[0]));
assert(66 <= sizeof out);
for (plen = 1U; plen < 66; plen += 3) {
memset(out, (int) (plen & 0xff), sizeof out);
crypto_stream_chacha20_ietf(out, plen, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
}
randombytes_buf(out, sizeof out);
crypto_stream_chacha20_ietf(out, sizeof out, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
assert(crypto_stream_chacha20_ietf(out, 0U, nonce, key) == 0);
assert(crypto_stream_chacha20_ietf_xor(out, out, 0U, nonce, key) == 0);
assert(crypto_stream_chacha20_ietf_xor(out, out, 0U, nonce, key) == 0);
assert(crypto_stream_chacha20_ietf_xor_ic(out, out, 0U, nonce, 1U, key) == 0);
memset(out, 0x42, sizeof out);
crypto_stream_chacha20_ietf_xor(out, out, sizeof out, nonce, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
crypto_stream_chacha20_ietf_xor_ic(out, out, sizeof out, nonce, 0U, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
crypto_stream_chacha20_ietf_xor_ic(out, out, sizeof out, nonce, 1U, key);
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
printf("[%s]\n", out_hex);
}
int
main(void)
{
tv();
tv_ietf();
assert(crypto_stream_chacha20_keybytes() > 0U);
assert(crypto_stream_chacha20_keybytes() == crypto_stream_chacha20_KEYBYTES);
assert(crypto_stream_chacha20_noncebytes() > 0U);
assert(crypto_stream_chacha20_noncebytes() == crypto_stream_chacha20_NONCEBYTES);
assert(crypto_stream_chacha20_messagebytes_max() == crypto_stream_chacha20_MESSAGEBYTES_MAX);
assert(crypto_stream_chacha20_ietf_keybytes() > 0U);
assert(crypto_stream_chacha20_ietf_keybytes() == crypto_stream_chacha20_ietf_KEYBYTES);
assert(crypto_stream_chacha20_ietf_noncebytes() > 0U);
assert(crypto_stream_chacha20_ietf_noncebytes() == crypto_stream_chacha20_ietf_NONCEBYTES);
assert(crypto_stream_chacha20_ietf_messagebytes_max() == crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX);
return 0;
}

View File

@ -0,0 +1,64 @@
[76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee65869f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29b721769ce64e43d57133b074d839d531ed1f28510afb45ace10a1f4b794d6f2d09a0e663266ce1ae7ed1081968a0758e718e997bd362c6b0c34634a9a0b35d]
[4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea817e9ad275ae5469633aeb5224ecf849929b9d828db1ced4dd832025e8018b8160b82284f3c949aa5a8eca00bbb4a73bdad192b5c42f73f2fd4e273644c8b36125a64addeb006c13a096d68b9ff7b57e7090f880392effd5b297a83bbaf2fbe8cf5d4618965e3dc776]
[de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df137821031e85a050278a7084527214f73efc7fa5b5277062eb7a0433e445f41e31afab757283547e3d3d30ee0371c1e6025ff4c91b794a291cf7568d48ff84b37329e2730b12738a072a2b2c7169e326fe4893a7b2421bb910b79599a7ce4fbaee86be427c5ee0e8225eb6f48231fd504939d59eac8bd106cc138779b893c54da8758f62a]
[ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd138e50d32111e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d6bbdb0041b2f586b5305e5e44aff19b235936144675efbe4409eb7e8e5f1430f5f5836aeb49bb5328b017c4b9dc11f8a03863fa803dc71d5726b2b6b31aa32708afe5af1d6b690584d58792b271e5fdb92c486051c48b79a4d48a109bb2d0477956e74c25e93c3c2]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5a97a5f576fe064025]
[f7010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101]
[f798a189040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404]
[f798a189f195e6070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707]
[f798a189f195e66982100a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a]
[f798a189f195e66982105ffb640d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d]
[f798a189f195e66982105ffb640bb775101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010]
[f798a189f195e66982105ffb640bb7757f579d131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313]
[f798a189f195e66982105ffb640bb7757f579da31602161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac561c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac31f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b73252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b4641282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c92b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c94400492e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f159163a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2b3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040]
[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5a97a5f576fe064025]
[b5dae3cbb3d7a42bc0521db92649f5373d15dfe15440bed1ae43ee14ba18818376e616393179040372008b06420b552b4791fc1ba85e11b31b54571e69aa66587a42c9d864fe77d65c6606553ec89c24cb9cd7640bc49b1acbb922aa046b8bffd818895e835afc147cfbf1e6e630ba6c4be5a53a0b69146cb5514cca9da27385dffb96b585eadb5759d8051270f47d81c7661da216a19f18d5e7b734bc440267]
[42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242]
[7a42c9d864fe77d65c6606553ec89c24cb9cd7640bc49b1acbb922aa046b8bffd818895e835afc147cfbf1e6e630ba6c4be5a53a0b69146cb5514cca9da27385dffb96b585eadb5759d8051270f47d81c7661da216a19f18d5e7b734bc440267918c466e1428f08745f37a99c77c7f2b1b244bd4162e8b86e4a8bf85358202954ced04b52fef7b3ba787744e715554285ecb0ed6e133c528d69d346abc0ce8b0]
[76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee65869f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29b721769ce64e43d57133b074d839d531ed1f28510afb45ace10a1f4b794d6f2d09a0e663266ce1ae7ed1081968a0758e718e997bd362c6b0c34634a9a0b35d]
[9f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29b721769ce64e43d57133b074d839d531ed1f28510afb45ace10a1f4b794d6f2d09a0e663266ce1ae7ed1081968a0758e718e997bd362c6b0c34634a9a0b35d012737681f7b5d0f281e3afde458bc1e73d2d313c9cf94c05ff3716240a248f21320a058d7b3566bd520daaa3ed2bf0ac5b8b120fb852773c3639734b45c91a4]
[3aeb5224ecf849929b9d828db1ced4dd832025e8018b8160b82284f3c949aa5a8eca00bbb4a73bdad192b5c42f73f2fd4e273644c8b36125a64addeb006c13a096d68b9ff7b57e7090f880392effd5b297a83bbaf2fbe8cf5d4618965e3dc776cd430d9b4e7eda8a767fb0e860319aadb5fd96a855de1fbfc92cb0489190cfdd87da6dbf1f736a2d499941ca097e5170bd685578611323120cebf296181ed4f5]
[72d54dfbf12ec44b362692df94137f328fea8da73990265ec1bbbea1ae9af0ca13b25aa26cb4a648cb9b9d1be65b2c0924a66c54d545ec1b7374f4872e99f096bf74dbd52cc4fc95ceb6097fe5e65358c9dbc0a5ecbf7894a132a9a54ae3e951f2e9f209aa9c3d9a877ac9dab62433d2961a17d103e455dfb7337c90f6857aad233065955a212b5c7a8eab4dc8a629e5b6b8ba914afd06de7177054b33d21c96]
[c2c64d378cd536374ae204b9ef933fcd1a8b2288b3dfa49672ab765b54ee27c78a970e0e955c14f3a88e741b97c286f75f8fc299e8148362fa198a39531bed6d1a91288c874ec254f322c2a197340c55bb3e9b3998f7de2309486a0bb494abd20c9c5ef99c1370d61e77f408ac5514f49202bcc6828d45409d2d1416f8ae106b06ebd2541256264fa415bd54cb12e1d4449ed85299a1b7a249b75ff6c89b2e3f]
[10f1e7e4d13b5915500fdd1fa32071c4c7d1f4c733c068030422aa9ac3d46c4ed2826446079faa0914c2d705d98b02a2b5129cd1de164eb9cbd083e8a2503c4e0a88837739d7bf4ef8ccacb0ea2bb9d69d56c394aa351dfda5bf459f0a2e9fe8e721f89255f9c486bf21679c683d4f9c5cf2fa27865526005b06ca374c86af3bdcbfbdcb83be65862ed5c20eae5a43241d6a92da6dca9a156be25297f51c2718]
[75924bad7831b25662dbac54b46827990b6168ae990e7bd7e1fd2ad282bf23ef052c7d1a0a6c1ef862070943a0d4da24705fbc006dfb85e2af18c0a264d772a44c70fbedac9d6a6867ff6be0a32826507f2c784101583211c9e2453d4cc8b283d5e86682bd4bf511271b91dbd351415f5a009d1f78b64085a9a4341be7d42e2679d57e2747097f0129950e2c9e9ca1356022d45da252af71ac37f351a2e77911]
[8a010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101]
[8adc91fd040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404]
[8adc91fd9ff4f0070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707]
[8adc91fd9ff4f0f51b0f0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a]
[8adc91fd9ff4f0f51b0fad50ff0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d]
[8adc91fd9ff4f0f51b0fad50ff15d637101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efd131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a742001c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c151f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd98222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d5282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f492e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69c313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69ca34c1f343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434343434]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69ca34c1ff9e939373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69ca34c1ff9e939a755843a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69ca34c1ff9e939a75584c52d693d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69ca34c1ff9e939a75584c52d690a35d4404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040]
[8adc91fd9ff4f0f51b0fad50ff15d637e40efda206cc52c783a74200503c1582cd9833367d0a54d57d3c9e998f490ee69ca34c1ff9e939a75584c52d690a35d410f1e7e4d13b5915500fdd1fa32071c4c7d1f4c733c068030422aa9ac3d46c4ed2826446079faa0914c2d705d98b02a2b5129cd1de164eb9cbd083e8a2503c4e0a88837739d7bf4ef8ccacb0ea2bb9d69d56c394aa351dfda5bf459f0a2e9fe8]
[c89ed3bfddb6b2b7594def12bd579475a64cbfe0448e1085c1e50042127e57c08fda71743f4816973f7edcdbcd0b4ca4dee10e5dbbab7be517c6876f2b48779652b3a5a693791b57124d9f5de16233868593b68571822a414660e8d881962e0c90c0260445dde84b568095479bc940e0f750de939c540cfb8992c1aae0127e0c48cac1357b95fd0cba8eeef2a869fb94df1481d6e8775fbfe7fd07dd486cddaa]
[42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242]
[52b3a5a693791b57124d9f5de16233868593b68571822a414660e8d881962e0c90c0260445dde84b568095479bc940e0f750de939c540cfb8992c1aae0127e0c48cac1357b95fd0cba8eeef2a869fb94df1481d6e8775fbfe7fd07dd486cddaaa563bad017bb86c4fd6325de2a7f0dde1eb0b865c4176442194488750ec4ed799efdff89c1fc27c46c97804cec1801665f28d0982f88d85729a010d5b75e655a]

231
deps/libsodium/test/default/cmptest.h vendored Normal file
View File

@ -0,0 +1,231 @@
#ifndef __CMPTEST_H__
#define __CMPTEST_H__
#ifdef NDEBUG
#/**/undef/**/ NDEBUG
#endif
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "sodium.h"
#include "quirks.h"
#ifdef __EMSCRIPTEN__
# undef TEST_SRCDIR
# define TEST_SRCDIR "/test-data"
#endif
#ifndef TEST_SRCDIR
# define TEST_SRCDIR "."
#endif
#define TEST_NAME_RES TEST_NAME ".res"
#define TEST_NAME_OUT TEST_SRCDIR "/" TEST_NAME ".exp"
#ifdef HAVE_ARC4RANDOM
# undef rand
# define rand(X) arc4random(X)
#endif
int xmain(void);
static unsigned char *guard_page;
#ifdef BENCHMARKS
# include <sys/time.h>
# ifndef ITERATIONS
# define ITERATIONS 128
# endif
struct {
void *pnt;
size_t size;
} mempool[1024];
static size_t mempool_idx;
static __attribute__((malloc)) void *mempool_alloc(size_t size)
{
size_t i;
if (size >= (size_t) 0x80000000 - (size_t) 0x00000fff) {
return NULL;
}
size = (size + (size_t) 0x00000fff) & ~ (size_t) 0x00000fff;
for (i = 0U; i < mempool_idx; i++) {
if (mempool[i].size >= (size | (size_t) 0x80000000)) {
mempool[i].size &= ~ (size_t) 0x80000000;
return mempool[i].pnt;
}
}
if (mempool_idx >= sizeof mempool / sizeof mempool[0]) {
return NULL;
}
mempool[mempool_idx].size = size;
return (mempool[mempool_idx++].pnt = (void *) malloc(size));
}
static void mempool_free(void *pnt)
{
size_t i;
for (i = 0U; i < mempool_idx; i++) {
if (mempool[i].pnt == pnt) {
if ((mempool[i].size & (size_t) 0x80000000) != (size_t) 0x0) {
break;
}
mempool[i].size |= (size_t) 0x80000000;
return;
}
}
abort();
}
static __attribute__((malloc)) void *mempool_allocarray(size_t count, size_t size)
{
if (count > (size_t) 0U && size >= (size_t) SIZE_MAX / count) {
return NULL;
}
return mempool_alloc(count * size);
}
static int mempool_free_all(void)
{
size_t i;
int ret = 0;
for (i = 0U; i < mempool_idx; i++) {
if ((mempool[i].size & (size_t) 0x80000000) == (size_t) 0x0) {
ret = -1;
}
free(mempool[i].pnt);
mempool[i].pnt = NULL;
}
mempool_idx = (size_t) 0U;
return ret;
}
#define sodium_malloc(X) mempool_alloc(X)
#define sodium_free(X) mempool_free(X)
#define sodium_allocarray(X, Y) mempool_allocarray((X), (Y))
static unsigned long long now(void)
{
struct timeval tp;
unsigned long long now;
if (gettimeofday(&tp, NULL) != 0) {
abort();
}
now = ((unsigned long long) tp.tv_sec * 1000000ULL) +
(unsigned long long) tp.tv_usec;
return now;
}
int main(void)
{
unsigned long long ts_start;
unsigned long long ts_end;
unsigned int i;
if (sodium_init() != 0) {
return 99;
}
#ifndef __EMSCRIPTEN__
randombytes_set_implementation(&randombytes_salsa20_implementation);
#endif
ts_start = now();
for (i = 0; i < ITERATIONS; i++) {
if (xmain() != 0) {
abort();
}
}
ts_end = now();
printf("%llu\n", 1000000ULL * (ts_end - ts_start) / ITERATIONS);
if (mempool_free_all() != 0) {
fprintf(stderr, "** memory leaks detected **\n");
return 99;
}
return 0;
}
#undef printf
#define printf(...) do { } while(0)
#elif !defined(BROWSER_TESTS)
static FILE *fp_res;
int main(void)
{
FILE *fp_out;
unsigned char *_guard_page;
int c;
if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) {
perror("fopen(" TEST_NAME_RES ")");
return 99;
}
if (sodium_init() != 0) {
return 99;
}
# if defined(__EMSCRIPTEN__) || defined(__SANITIZE_ADDRESS__)
guard_page = _guard_page = NULL;
#else
if ((_guard_page = (unsigned char *) sodium_malloc(0)) == NULL) {
perror("sodium_malloc()");
return 99;
}
guard_page = _guard_page + 1;
#endif
if (xmain() != 0) {
return 99;
}
fflush(fp_res);
rewind(fp_res);
if ((fp_out = fopen(TEST_NAME_OUT, "r")) == NULL) {
perror("fopen(" TEST_NAME_OUT ")");
return 99;
}
do {
if ((c = fgetc(fp_res)) != fgetc(fp_out)) {
return 99;
}
} while (c != EOF);
sodium_free(_guard_page);
return 0;
}
#undef printf
#define printf(...) fprintf(fp_res, __VA_ARGS__)
#else
int main(void)
{
if (sodium_init() != 0) {
return 99;
}
if (xmain() != 0) {
return 99;
}
printf("--- SUCCESS ---\n");
return 0;
}
#endif
#define main xmain
#endif

251
deps/libsodium/test/default/codecs.c vendored Normal file
View File

@ -0,0 +1,251 @@
#define TEST_NAME "codecs"
#include "cmptest.h"
int
main(void)
{
unsigned char buf1[1000];
char buf3[33];
unsigned char buf4[4];
const char *b64;
char *b64_;
const char *b64_end;
unsigned char *bin;
const char *hex;
const char *hex_end;
size_t b64_len;
size_t bin_len;
unsigned int i;
printf("%s\n",
sodium_bin2hex(buf3, 33U, (const unsigned char *) "0123456789ABCDEF",
16U));
printf("bin2hex(..., guard_page, 0):%s\n",
sodium_bin2hex(buf3, sizeof buf3, guard_page, 0U));
printf("bin2hex(..., \"\", 0):%s\n",
sodium_bin2hex(buf3, sizeof buf3, (const unsigned char *) "", 0U));
hex = "Cafe : 6942";
sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len,
&hex_end);
printf("%lu:%02x%02x%02x%02x\n", (unsigned long) bin_len,
buf4[0], buf4[1], buf4[2], buf4[3]);
printf("dt1: %ld\n", (long) (hex_end - hex));
hex = "Cafe : 6942";
sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len, NULL);
printf("%lu:%02x%02x%02x%02x\n", (unsigned long) bin_len,
buf4[0], buf4[1], buf4[2], buf4[3]);
hex = "deadbeef";
if (sodium_hex2bin(buf1, 1U, hex, 8U, NULL, &bin_len, &hex_end) != -1) {
printf("sodium_hex2bin() overflow not detected\n");
}
printf("dt2: %ld\n", (long) (hex_end - hex));
hex = "de:ad:be:eff";
if (sodium_hex2bin(buf1, 4U, hex, 12U, ":", &bin_len, &hex_end) != -1) {
printf(
"sodium_hex2bin() with an odd input length and a short output "
"buffer\n");
}
printf("dt3: %ld\n", (long) (hex_end - hex));
hex = "de:ad:be:eff";
if (sodium_hex2bin(buf1, sizeof buf1, hex, 12U, ":",
&bin_len, &hex_end) != -1) {
printf("sodium_hex2bin() with an odd input length\n");
}
printf("dt4: %ld\n", (long) (hex_end - hex));
hex = "de:ad:be:eff";
if (sodium_hex2bin(buf1, sizeof buf1, hex, 13U, ":",
&bin_len, &hex_end) != -1) {
printf("sodium_hex2bin() with an odd input length (2)\n");
}
printf("dt5: %ld\n", (long) (hex_end - hex));
hex = "de:ad:be:eff";
if (sodium_hex2bin(buf1, sizeof buf1, hex, 12U, ":",
&bin_len, NULL) != -1) {
printf("sodium_hex2bin() with an odd input length and no end pointer\n");
}
hex = "de:ad:be:ef*";
if (sodium_hex2bin(buf1, sizeof buf1, hex, 12U, ":",
&bin_len, &hex_end) != 0) {
printf("sodium_hex2bin() with an extra character and an end pointer\n");
}
printf("dt6: %ld\n", (long) (hex_end - hex));
hex = "de:ad:be:ef*";
if (sodium_hex2bin(buf1, sizeof buf1, hex, 12U, ":",
&bin_len, NULL) != -1) {
printf("sodium_hex2bin() with an extra character and no end pointer\n");
}
assert(sodium_hex2bin(buf4, sizeof buf4, (const char *) guard_page, 0U,
NULL, &bin_len, NULL) == 0);
assert(bin_len == 0);
assert(sodium_hex2bin(buf4, sizeof buf4, "", 0U, NULL, &bin_len, NULL) == 0);
assert(bin_len == 0);
printf("%s\n",
sodium_bin2base64(buf3, 31U, (const unsigned char *) "\xfb\xf0\xf1" "0123456789ABCDEFab",
21U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 33U, (const unsigned char *) "\xfb\xf0\xf1" "0123456789ABCDEFabc",
22U, sodium_base64_VARIANT_ORIGINAL_NO_PADDING));
printf("%s\n",
sodium_bin2base64(buf3, 31U, (const unsigned char *) "\xfb\xf0\xf1" "0123456789ABCDEFab",
21U, sodium_base64_VARIANT_URLSAFE));
printf("%s\n",
sodium_bin2base64(buf3, 33U, (const unsigned char *) "\xfb\xf0\xf1" "0123456789ABCDEFabc",
22U, sodium_base64_VARIANT_URLSAFE_NO_PADDING));
printf("%s\n",
sodium_bin2base64(buf3, 1U, guard_page,
0U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 5U, (const unsigned char *) "a",
1U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 5U, (const unsigned char *) "ab",
2U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 5U, (const unsigned char *) "abc",
3U, sodium_base64_VARIANT_ORIGINAL));
printf("%s\n",
sodium_bin2base64(buf3, 1U, guard_page,
0U, sodium_base64_VARIANT_ORIGINAL_NO_PADDING));
printf("%s\n",
sodium_bin2base64(buf3, 3U, (const unsigned char *) "a",
1U, sodium_base64_VARIANT_ORIGINAL_NO_PADDING));
printf("%s\n",
sodium_bin2base64(buf3, 4U, (const unsigned char *) "ab",
2U, sodium_base64_VARIANT_ORIGINAL_NO_PADDING));
printf("%s\n",
sodium_bin2base64(buf3, 5U, (const unsigned char *) "abc",
3U, sodium_base64_VARIANT_ORIGINAL_NO_PADDING));
b64 = "VGhpcyBpcyBhIGpvdXJu" "\n" "ZXkgaW50by" " " "Bzb3VuZA==";
memset(buf4, '*', sizeof buf4);
assert(sodium_base642bin(buf4, sizeof buf4, b64, strlen(b64), "\n\r ", &bin_len,
&b64_end, sodium_base64_VARIANT_ORIGINAL) == -1);
buf4[bin_len] = 0;
printf("[%s]\n", (const char *) buf4);
printf("[%s]\n", b64_end);
memset(buf1, '*', sizeof buf1);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), "\n\r ", &bin_len,
&b64_end, sodium_base64_VARIANT_ORIGINAL) == 0);
buf1[bin_len] = 0;
printf("[%s]\n", (const char *) buf1);
assert(*b64_end == 0);
memset(buf1, '*', sizeof buf1);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, &bin_len,
&b64_end, sodium_base64_VARIANT_ORIGINAL) == 0);
buf1[bin_len] = 0;
printf("[%s]\n", (const char *) buf1);
printf("[%s]\n", b64_end);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, NULL,
&b64_end, sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, NULL,
&b64_end, sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), " \r\n", NULL,
&b64_end, sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, NULL,
&b64_end, sodium_base64_VARIANT_URLSAFE_NO_PADDING) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), " \r\n", NULL,
&b64_end, sodium_base64_VARIANT_URLSAFE_NO_PADDING) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, NULL,
NULL, sodium_base64_VARIANT_ORIGINAL) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, NULL,
NULL, sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), " \r\n", NULL,
NULL, sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), NULL, NULL,
NULL, sodium_base64_VARIANT_URLSAFE_NO_PADDING) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, b64, strlen(b64), " \r\n", NULL,
NULL, sodium_base64_VARIANT_URLSAFE_NO_PADDING) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=", (size_t) 2U, NULL, NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a*", (size_t) 2U, NULL, NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a*", (size_t) 2U, "~", NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a*", (size_t) 2U, "*", NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a==", (size_t) 3U, NULL, NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=*", (size_t) 3U, NULL, NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=*", (size_t) 3U, "~", NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(guard_page, (size_t) 10U, "a=*", (size_t) 3U, "*", NULL, NULL,
sodium_base64_VARIANT_URLSAFE) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "O1R", (size_t) 3U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "O1Q", (size_t) 3U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "O1", (size_t) 2U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "Ow", (size_t) 2U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "O", (size_t) 1U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "", (size_t) 0U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "A", (size_t) 1U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "AA", (size_t) 2U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "kaw", (size_t) 3U, NULL, NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "kQ*", (size_t) 3U, "@", NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "kQ*", (size_t) 3U, "*", NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == -1);
assert(sodium_base642bin(buf1, sizeof buf1, "kaw=**", (size_t) 6U, "*", NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "kaw*=*", (size_t) 6U, "~*", NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "ka*w*=*", (size_t) 7U, "*~", NULL, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(sodium_base642bin(buf1, sizeof buf1, (const char *) guard_page, 0U,
NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) == 0);
assert(bin_len == 0);
assert(sodium_base642bin(buf1, sizeof buf1, "", 0U, NULL, &bin_len, NULL,
sodium_base64_VARIANT_ORIGINAL) == 0);
assert(bin_len == 0);
for (i = 0; i < 1000; i++) {
assert(sizeof buf1 >= 100);
bin_len = (size_t) randombytes_uniform(100);
bin = (unsigned char *) sodium_malloc(bin_len);
b64_len = (bin_len + 2U) / 3U * 4U + 1U;
assert(b64_len == sodium_base64_encoded_len(bin_len, sodium_base64_VARIANT_URLSAFE));
b64_ = (char *) sodium_malloc(b64_len);
randombytes_buf(bin, bin_len);
memcpy(buf1, bin, bin_len);
b64 = sodium_bin2base64(b64_, b64_len, bin, bin_len,
sodium_base64_VARIANT_URLSAFE);
assert(b64 != NULL);
assert(sodium_base642bin(bin, bin_len + 10, b64, b64_len,
NULL, NULL, &b64_end,
sodium_base64_VARIANT_URLSAFE) == 0);
assert(b64_end == &b64[b64_len - 1]);
assert(memcmp(bin, buf1, bin_len) == 0);
sodium_free(bin);
sodium_free(b64_);
}
return 0;
}

30
deps/libsodium/test/default/codecs.exp vendored Normal file
View File

@ -0,0 +1,30 @@
30313233343536373839414243444546
bin2hex(..., guard_page, 0):
bin2hex(..., "", 0):
4:cafe6942
dt1: 11
4:cafe6942
dt2: 2
dt3: 11
dt4: 11
dt5: 11
dt6: 11
+/DxMDEyMzQ1Njc4OUFCQ0RFRmFi
+/DxMDEyMzQ1Njc4OUFCQ0RFRmFiYw
-_DxMDEyMzQ1Njc4OUFCQ0RFRmFi
-_DxMDEyMzQ1Njc4OUFCQ0RFRmFiYw
YQ==
YWI=
YWJj
YQ
YWI
YWJj
[]
[BpcyBhIGpvdXJu
ZXkgaW50by Bzb3VuZA==]
[This is a journey into sound]
[This is a journ]
[
ZXkgaW50by Bzb3VuZA==]

41
deps/libsodium/test/default/core1.c vendored Normal file
View File

@ -0,0 +1,41 @@
#define TEST_NAME "core1"
#include "cmptest.h"
static unsigned char shared[32] = { 0x4a, 0x5d, 0x9d, 0x5b, 0xa4, 0xce, 0x2d,
0xe1, 0x72, 0x8e, 0x3b, 0xf4, 0x80, 0x35,
0x0f, 0x25, 0xe0, 0x7e, 0x21, 0xc9, 0x47,
0xd1, 0x9e, 0x33, 0x76, 0xf0, 0x9b, 0x3c,
0x1e, 0x16, 0x17, 0x42 };
static unsigned char zero[32];
static unsigned char c[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
static unsigned char firstkey[32];
int
main(void)
{
int i;
crypto_core_hsalsa20(firstkey, zero, shared, c);
for (i = 0; i < 32; ++i) {
if (i > 0) {
printf(",");
} else {
printf(" ");
}
printf("0x%02x", (unsigned int) firstkey[i]);
if (i % 8 == 7) {
printf("\n");
}
}
assert(crypto_core_hsalsa20_outputbytes() > 0U);
assert(crypto_core_hsalsa20_inputbytes() > 0U);
assert(crypto_core_hsalsa20_keybytes() > 0U);
assert(crypto_core_hsalsa20_constbytes() > 0U);
return 0;
}

4
deps/libsodium/test/default/core1.exp vendored Normal file
View File

@ -0,0 +1,4 @@
0x1b,0x27,0x55,0x64,0x73,0xe9,0x85,0xd4
,0x62,0xcd,0x51,0x19,0x7a,0x9a,0x46,0xc7
,0x60,0x09,0x54,0x9e,0xac,0x64,0x74,0xf2
,0x06,0xc4,0xee,0x08,0x44,0xf6,0x83,0x89

38
deps/libsodium/test/default/core2.c vendored Normal file
View File

@ -0,0 +1,38 @@
#define TEST_NAME "core2"
#include "cmptest.h"
static unsigned char firstkey[32] = { 0x1b, 0x27, 0x55, 0x64, 0x73, 0xe9, 0x85,
0xd4, 0x62, 0xcd, 0x51, 0x19, 0x7a, 0x9a,
0x46, 0xc7, 0x60, 0x09, 0x54, 0x9e, 0xac,
0x64, 0x74, 0xf2, 0x06, 0xc4, 0xee, 0x08,
0x44, 0xf6, 0x83, 0x89 };
static unsigned char nonceprefix[16] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6,
0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8,
0x75, 0xfc, 0x73, 0xd6 };
static unsigned char c[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
static unsigned char secondkey[32];
int
main(void)
{
int i;
crypto_core_hsalsa20(secondkey, nonceprefix, firstkey, c);
for (i = 0; i < 32; ++i) {
if (i > 0) {
printf(",");
} else {
printf(" ");
}
printf("0x%02x", (unsigned int) secondkey[i]);
if (i % 8 == 7) {
printf("\n");
}
}
return 0;
}

4
deps/libsodium/test/default/core2.exp vendored Normal file
View File

@ -0,0 +1,4 @@
0xdc,0x90,0x8d,0xda,0x0b,0x93,0x44,0xa9
,0x53,0x62,0x9b,0x73,0x38,0x20,0x77,0x88
,0x80,0xf3,0xce,0xb4,0x21,0xbb,0x61,0xb9
,0x1c,0xbd,0x4c,0x3e,0x66,0x25,0x6c,0xe4

115
deps/libsodium/test/default/core3.c vendored Normal file
View File

@ -0,0 +1,115 @@
#define TEST_NAME "core3"
#include "cmptest.h"
static unsigned char SECONDKEY[32] = { 0xdc, 0x90, 0x8d, 0xda, 0x0b, 0x93, 0x44,
0xa9, 0x53, 0x62, 0x9b, 0x73, 0x38, 0x20,
0x77, 0x88, 0x80, 0xf3, 0xce, 0xb4, 0x21,
0xbb, 0x61, 0xb9, 0x1c, 0xbd, 0x4c, 0x3e,
0x66, 0x25, 0x6c, 0xe4 };
static unsigned char NONCESUFFIX[8] = { 0x82, 0x19, 0xe0, 0x03,
0x6b, 0x7a, 0x0b, 0x37 };
static unsigned char C[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
int
main(void)
{
unsigned char *secondkey;
unsigned char *c;
unsigned char *noncesuffix;
unsigned char *in;
unsigned char *output;
unsigned char *h;
size_t output_len = 64 * 256 * 256;
size_t pos = 0;
int i;
pos = 0;
secondkey = (unsigned char *) sodium_malloc(32);
memcpy(secondkey, SECONDKEY, 32);
noncesuffix = (unsigned char *) sodium_malloc(8);
memcpy(noncesuffix, NONCESUFFIX, 8);
c = (unsigned char *) sodium_malloc(16);
memcpy(c, C, 16);
in = (unsigned char *) sodium_malloc(16);
output = (unsigned char *) sodium_malloc(output_len);
h = (unsigned char *) sodium_malloc(32);
for (i = 0; i < 8; i++) {
in[i] = noncesuffix[i];
}
for (; i < 16; i++) {
in[i] = 0;
}
do {
do {
crypto_core_salsa20(output + pos, in, secondkey, c);
pos += 64;
in[8]++;
} while (in[8] != 0);
in[9]++;
} while (in[9] != 0);
crypto_hash_sha256(h, output, output_len);
for (i = 0; i < 32; ++i) {
printf("%02x", h[i]);
}
printf("\n");
#ifndef SODIUM_LIBRARY_MINIMAL
pos = 0;
do {
do {
crypto_core_salsa2012(output + pos, in, secondkey, c);
pos += 64;
in[8]++;
} while (in[8] != 0);
in[9]++;
} while (in[9] != 0);
crypto_hash_sha256(h, output, output_len);
for (i = 0; i < 32; ++i) {
printf("%02x", h[i]);
}
printf("\n");
pos = 0;
do {
do {
crypto_core_salsa208(output + pos, in, secondkey, c);
pos += 64;
in[8]++;
} while (in[8] != 0);
in[9]++;
} while (in[9] != 0);
crypto_hash_sha256(h, output, output_len);
for (i = 0; i < 32; ++i) {
printf("%02x", h[i]);
}
printf("\n");
#else
printf("a4e3147dddd2ba7775939b50208a22eb3277d4e4bad8a1cfbc999c6bd392b638\n"
"017421baa9959cbe894bd003ec87938254f47c1e757eb66cf89c353d0c2b68de\n");
#endif
sodium_free(h);
sodium_free(output);
sodium_free(in);
sodium_free(c);
sodium_free(noncesuffix);
sodium_free(secondkey);
assert(crypto_core_salsa20_outputbytes() == crypto_core_salsa20_OUTPUTBYTES);
assert(crypto_core_salsa20_inputbytes() == crypto_core_salsa20_INPUTBYTES);
assert(crypto_core_salsa20_keybytes() == crypto_core_salsa20_KEYBYTES);
assert(crypto_core_salsa20_constbytes() == crypto_core_salsa20_CONSTBYTES);
return 0;
}

3
deps/libsodium/test/default/core3.exp vendored Normal file
View File

@ -0,0 +1,3 @@
662b9d0e3463029156069b12f918691a98f7dfb2ca0393c96bbfc6b1fbd630a2
a4e3147dddd2ba7775939b50208a22eb3277d4e4bad8a1cfbc999c6bd392b638
017421baa9959cbe894bd003ec87938254f47c1e757eb66cf89c353d0c2b68de

36
deps/libsodium/test/default/core4.c vendored Normal file
View File

@ -0,0 +1,36 @@
#define TEST_NAME "core4"
#include "cmptest.h"
static unsigned char k[32] = { 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213, 214, 215, 216 };
static unsigned char in[16] = { 101, 102, 103, 104, 105, 106, 107, 108,
109, 110, 111, 112, 113, 114, 115, 116 };
static unsigned char c[16] = { 101, 120, 112, 97, 110, 100, 32, 51,
50, 45, 98, 121, 116, 101, 32, 107 };
static unsigned char out[64];
int
main(void)
{
int i;
crypto_core_salsa20(out, in, k, c);
for (i = 0; i < 64; ++i) {
if (i > 0) {
printf(",");
} else {
printf(" ");
}
printf("%3u", (unsigned int) out[i]);
if (i % 8 == 7) {
printf("\n");
}
}
return 0;
}

8
deps/libsodium/test/default/core4.exp vendored Normal file
View File

@ -0,0 +1,8 @@
69, 37, 68, 39, 41, 15,107,193
,255,139,122, 6,170,233,217, 98
, 89,144,182,106, 21, 51,200, 65
,239, 49,222, 34,215,114, 40,126
,104,197, 7,225,197,153, 31, 2
,102, 78, 76,176, 84,245,246,184
,177,160,133,130, 6, 72,149,119
,192,195,132,236,234,103,246, 74

33
deps/libsodium/test/default/core5.c vendored Normal file
View File

@ -0,0 +1,33 @@
#define TEST_NAME "core5"
#include "cmptest.h"
static unsigned char k[32] = { 0xee, 0x30, 0x4f, 0xca, 0x27, 0x00, 0x8d, 0x8c,
0x12, 0x6f, 0x90, 0x02, 0x79, 0x01, 0xd8, 0x0f,
0x7f, 0x1d, 0x8b, 0x8d, 0xc9, 0x36, 0xcf, 0x3b,
0x9f, 0x81, 0x96, 0x92, 0x82, 0x7e, 0x57, 0x77 };
static unsigned char in[16] = {
0x81, 0x91, 0x8e, 0xf2, 0xa5, 0xe0, 0xda, 0x9b,
0x3e, 0x90, 0x60, 0x52, 0x1e, 0x4b, 0xb3, 0x52
};
static unsigned char c[16] = { 101, 120, 112, 97, 110, 100, 32, 51,
50, 45, 98, 121, 116, 101, 32, 107 };
unsigned char out[32];
int
main(void)
{
int i;
crypto_core_hsalsa20(out, in, k, c);
for (i = 0; i < 32; ++i) {
printf(",0x%02x", (unsigned int) out[i]);
if (i % 8 == 7) {
printf("\n");
}
}
return 0;
}

4
deps/libsodium/test/default/core5.exp vendored Normal file
View File

@ -0,0 +1,4 @@
,0xbc,0x1b,0x30,0xfc,0x07,0x2c,0xc1,0x40
,0x75,0xe4,0xba,0xa7,0x31,0xb5,0xa8,0x45
,0xea,0x9b,0x11,0xe9,0xa5,0x19,0x1f,0x94
,0xe1,0x8c,0xba,0x8f,0xd8,0x21,0xa7,0xcd

52
deps/libsodium/test/default/core6.c vendored Normal file
View File

@ -0,0 +1,52 @@
#define TEST_NAME "core6"
#include "cmptest.h"
static unsigned char k[32] = { 0xee, 0x30, 0x4f, 0xca, 0x27, 0x00, 0x8d, 0x8c,
0x12, 0x6f, 0x90, 0x02, 0x79, 0x01, 0xd8, 0x0f,
0x7f, 0x1d, 0x8b, 0x8d, 0xc9, 0x36, 0xcf, 0x3b,
0x9f, 0x81, 0x96, 0x92, 0x82, 0x7e, 0x57, 0x77 };
static unsigned char in[16] = {
0x81, 0x91, 0x8e, 0xf2, 0xa5, 0xe0, 0xda, 0x9b,
0x3e, 0x90, 0x60, 0x52, 0x1e, 0x4b, 0xb3, 0x52
};
static unsigned char c[16] = { 101, 120, 112, 97, 110, 100, 32, 51,
50, 45, 98, 121, 116, 101, 32, 107 };
static unsigned char out[64];
static void
print(unsigned char *x, unsigned char *y)
{
int i;
unsigned int borrow = 0;
for (i = 0; i < 4; ++i) {
unsigned int xi = x[i];
unsigned int yi = y[i];
printf(",0x%02x", 255 & (xi - yi - borrow));
borrow = (xi < yi + borrow);
}
}
int
main(void)
{
crypto_core_salsa20(out, in, k, c);
print(out, c);
print(out + 20, c + 4);
printf("\n");
print(out + 40, c + 8);
print(out + 60, c + 12);
printf("\n");
print(out + 24, in);
print(out + 28, in + 4);
printf("\n");
print(out + 32, in + 8);
print(out + 36, in + 12);
printf("\n");
return 0;
}

4
deps/libsodium/test/default/core6.exp vendored Normal file
View File

@ -0,0 +1,4 @@
,0xbc,0x1b,0x30,0xfc,0x07,0x2c,0xc1,0x40
,0x75,0xe4,0xba,0xa7,0x31,0xb5,0xa8,0x45
,0xea,0x9b,0x11,0xe9,0xa5,0x19,0x1f,0x94
,0xe1,0x8c,0xba,0x8f,0xd8,0x21,0xa7,0xcd

View File

@ -0,0 +1,529 @@
#define TEST_NAME "core_ed25519"
#include "cmptest.h"
static const unsigned char non_canonical_p[32] = {
0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
};
static const unsigned char non_canonical_invalid_p[32] = {
0xf5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
};
static const unsigned char max_canonical_p[32] = {
0xe4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
};
static const unsigned char L_p1[32] = {
0xee, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
};
static const unsigned char L[32] = {
0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
};
static const unsigned char L_1[32] = {
0xec, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
};
static const unsigned char sc_8[32] = {
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char sc_highbit[32] = {
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
};
static void
add_P(unsigned char * const S)
{
static const unsigned char P[32] = {
0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
};
sodium_add(S, P, sizeof P);
}
static void
add_l64(unsigned char * const S)
{
static const unsigned char l[crypto_core_ed25519_NONREDUCEDSCALARBYTES] =
{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
sodium_add(S, l, sizeof l);
}
int
main(void)
{
unsigned char *r;
unsigned char *p, *p2, *p3;
unsigned char *sc, *sc2, *sc3;
unsigned char *sc64;
char *hex;
unsigned int i, j;
r = (unsigned char *) sodium_malloc(crypto_core_ed25519_UNIFORMBYTES);
p = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
for (i = 0; i < 500; i++) {
randombytes_buf(r, crypto_core_ed25519_UNIFORMBYTES);
if (crypto_core_ed25519_from_uniform(p, r) != 0) {
printf("crypto_core_ed25519_from_uniform() failed\n");
}
if (crypto_core_ed25519_is_valid_point(p) == 0) {
printf("crypto_core_ed25519_from_uniform() 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");
}
}
p2 = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
p3 = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
crypto_core_ed25519_random(p2);
j = 1 + (unsigned int) randombytes_uniform(100);
memcpy(p3, p, crypto_core_ed25519_BYTES);
for (i = 0; i < j; i++) {
crypto_core_ed25519_add(p, p, p2);
if (crypto_core_ed25519_is_valid_point(p) != 1) {
printf("crypto_core_add() returned an invalid point\n");
}
}
if (memcmp(p, p3, crypto_core_ed25519_BYTES) == 0) {
printf("crypto_core_add() failed\n");
}
for (i = 0; i < j; i++) {
crypto_core_ed25519_sub(p, p, p2);
}
if (memcmp(p, p3, crypto_core_ed25519_BYTES) != 0) {
printf("crypto_core_add() or crypto_core_sub() failed\n");
}
sc = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_SCALARBYTES);
memset(sc, 0, crypto_scalarmult_ed25519_SCALARBYTES);
sc[0] = 8;
memcpy(p2, p, crypto_core_ed25519_BYTES);
memcpy(p3, p, crypto_core_ed25519_BYTES);
for (i = 0; i < 254; i++) {
crypto_core_ed25519_add(p2, p2, p2);
}
for (i = 0; i < 8; i++) {
crypto_core_ed25519_add(p2, p2, p);
}
if (crypto_scalarmult_ed25519(p3, sc, p) != 0) {
printf("crypto_scalarmult_ed25519() failed\n");
}
if (memcmp(p2, p3, crypto_core_ed25519_BYTES) != 0) {
printf("crypto_scalarmult_ed25519() is inconsistent with crypto_core_ed25519_add()\n");
}
assert(crypto_core_ed25519_is_valid_point(p) == 1);
memset(p, 0, crypto_core_ed25519_BYTES);
assert(crypto_core_ed25519_is_valid_point(p) == 0);
p[0] = 1;
assert(crypto_core_ed25519_is_valid_point(p) == 0);
p[0] = 2;
assert(crypto_core_ed25519_is_valid_point(p) == 0);
p[0] = 9;
assert(crypto_core_ed25519_is_valid_point(p) == 1);
assert(crypto_core_ed25519_is_valid_point(max_canonical_p) == 1);
assert(crypto_core_ed25519_is_valid_point(non_canonical_invalid_p) == 0);
assert(crypto_core_ed25519_is_valid_point(non_canonical_p) == 0);
memcpy(p2, p, crypto_core_ed25519_BYTES);
add_P(p2);
crypto_core_ed25519_add(p3, p2, p2);
crypto_core_ed25519_sub(p3, p3, p2);
assert(memcmp(p2, p, crypto_core_ed25519_BYTES) != 0);
assert(memcmp(p3, p, crypto_core_ed25519_BYTES) == 0);
p[0] = 2;
assert(crypto_core_ed25519_add(p3, p2, p) == -1);
assert(crypto_core_ed25519_add(p3, p2, non_canonical_p) == 0);
assert(crypto_core_ed25519_add(p3, p2, non_canonical_invalid_p) == -1);
assert(crypto_core_ed25519_add(p3, p, p3) == -1);
assert(crypto_core_ed25519_add(p3, non_canonical_p, p3) == 0);
assert(crypto_core_ed25519_add(p3, non_canonical_invalid_p, p3) == -1);
assert(crypto_core_ed25519_sub(p3, p2, p) == -1);
assert(crypto_core_ed25519_sub(p3, p2, non_canonical_p) == 0);
assert(crypto_core_ed25519_sub(p3, p2, non_canonical_invalid_p) == -1);
assert(crypto_core_ed25519_sub(p3, p, p3) == -1);
assert(crypto_core_ed25519_sub(p3, non_canonical_p, p3) == 0);
assert(crypto_core_ed25519_sub(p3, non_canonical_invalid_p, p3) == -1);
for (i = 0; i < 1000; i++) {
crypto_core_ed25519_random(p);
do {
crypto_core_ed25519_scalar_random(sc);
} while (sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
if (crypto_scalarmult_ed25519_noclamp(p2, sc, p) != 0) {
printf("crypto_scalarmult_ed25519_noclamp() failed\n");
}
assert(crypto_core_ed25519_is_valid_point(p2));
if (crypto_core_ed25519_scalar_invert(sc, sc) != 0) {
printf("crypto_core_ed25519_scalar_invert() failed\n");
}
if (crypto_scalarmult_ed25519_noclamp(p3, sc, p2) != 0) {
printf("crypto_scalarmult_ed25519_noclamp() failed\n");
}
assert(memcmp(p3, p, crypto_core_ed25519_BYTES) == 0);
}
sc64 = (unsigned char *) sodium_malloc(64);
crypto_core_ed25519_scalar_random(sc);
memcpy(sc64, sc, crypto_core_ed25519_BYTES);
memset(sc64 + crypto_core_ed25519_BYTES, 0,
64 - crypto_core_ed25519_BYTES);
i = (unsigned int) randombytes_uniform(100);
do {
add_l64(sc64);
} while (i-- > 0);
crypto_core_ed25519_scalar_reduce(sc64, sc64);
if (memcmp(sc64, sc, crypto_core_ed25519_BYTES) != 0) {
printf("crypto_core_ed25519_scalar_reduce() failed\n");
}
randombytes_buf(r, crypto_core_ed25519_UNIFORMBYTES);
crypto_core_ed25519_from_uniform(p, r);
memcpy(p2, p, crypto_core_ed25519_BYTES);
crypto_core_ed25519_scalar_random(sc);
if (crypto_scalarmult_ed25519_noclamp(p, sc, p) != 0) {
printf("crypto_scalarmult_ed25519_noclamp() failed (1)\n");
}
crypto_core_ed25519_scalar_complement(sc, sc);
if (crypto_scalarmult_ed25519_noclamp(p2, sc, p2) != 0) {
printf("crypto_scalarmult_ed25519_noclamp() failed (2)\n");
}
crypto_core_ed25519_add(p3, p, p2);
crypto_core_ed25519_from_uniform(p, r);
crypto_core_ed25519_sub(p, p, p3);
assert(p[0] == 0x01);
for (i = 1; i < crypto_core_ed25519_BYTES; i++) {
assert(p[i] == 0);
}
crypto_core_ed25519_random(p);
memcpy(p2, p, crypto_core_ed25519_BYTES);
crypto_core_ed25519_scalar_random(sc);
if (crypto_scalarmult_ed25519_noclamp(p, sc, p) != 0) {
printf("crypto_scalarmult_ed25519_noclamp() failed (3)\n");
}
crypto_core_ed25519_scalar_negate(sc, sc);
if (crypto_scalarmult_ed25519_noclamp(p2, sc, p2) != 0) {
printf("crypto_scalarmult_ed25519_noclamp() failed (4)\n");
}
crypto_core_ed25519_add(p, p, p2);
assert(p[0] == 0x01);
for (i = 1; i < crypto_core_ed25519_BYTES; i++) {
assert(p[i] == 0);
}
hex = (char *) sodium_malloc(crypto_core_ed25519_SCALARBYTES * 2 + 1);
for (i = 0; i < crypto_core_ed25519_SCALARBYTES; i++) {
sc[i] = 255 - i;
}
if (crypto_core_ed25519_scalar_invert(sc, sc) != 0) {
printf("crypto_core_ed25519_scalar_invert() failed\n");
}
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("inv1: %s\n", hex);
if (crypto_core_ed25519_scalar_invert(sc, sc) != 0) {
printf("crypto_core_ed25519_scalar_invert() failed\n");
}
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("inv2: %s\n", hex);
for (i = 0; i < crypto_core_ed25519_SCALARBYTES; i++) {
sc[i] = 32 - i;
}
if (crypto_core_ed25519_scalar_invert(sc, sc) != 0) {
printf("crypto_core_ed25519_scalar_invert() failed\n");
}
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("inv3: %s\n", hex);
if (crypto_core_ed25519_scalar_invert(sc, sc) != 0) {
printf("crypto_core_ed25519_scalar_invert() failed\n");
}
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("inv4: %s\n", hex);
for (i = 0; i < crypto_core_ed25519_SCALARBYTES; i++) {
sc[i] = 255 - i;
}
crypto_core_ed25519_scalar_negate(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("neg1: %s\n", hex);
crypto_core_ed25519_scalar_negate(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("neg2: %s\n", hex);
for (i = 0; i < crypto_core_ed25519_SCALARBYTES; i++) {
sc[i] = 32 - i;
}
crypto_core_ed25519_scalar_negate(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("neg3: %s\n", hex);
crypto_core_ed25519_scalar_negate(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("neg4: %s\n", hex);
for (i = 0; i < crypto_core_ed25519_SCALARBYTES; i++) {
sc[i] = 255 - i;
}
crypto_core_ed25519_scalar_complement(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("comp1: %s\n", hex);
crypto_core_ed25519_scalar_complement(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("comp2: %s\n", hex);
for (i = 0; i < crypto_core_ed25519_SCALARBYTES; i++) {
sc[i] = 32 - i;
}
crypto_core_ed25519_scalar_complement(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("comp3: %s\n", hex);
crypto_core_ed25519_scalar_complement(sc, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("comp4: %s\n", hex);
sc2 = (unsigned char *) sodium_malloc(crypto_core_ed25519_SCALARBYTES);
sc3 = (unsigned char *) sodium_malloc(crypto_core_ed25519_SCALARBYTES);
for (i = 0; i < 1000; i++) {
randombytes_buf(sc, crypto_core_ed25519_SCALARBYTES);
randombytes_buf(sc2, crypto_core_ed25519_SCALARBYTES);
sc[crypto_core_ed25519_SCALARBYTES - 1] &= 0x7f;
sc2[crypto_core_ed25519_SCALARBYTES - 1] &= 0x7f;
crypto_core_ed25519_scalar_add(sc3, sc, sc2);
assert(!sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_sub(sc3, sc3, sc2);
assert(!sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_sub(sc3, sc3, sc);
assert(sodium_is_zero(sc3, crypto_core_ed25519_SCALARBYTES));
}
memset(sc, 0x69, crypto_core_ed25519_SCALARBYTES);
memset(sc2, 0x42, crypto_core_ed25519_SCALARBYTES);
crypto_core_ed25519_scalar_add(sc, sc, sc2);
crypto_core_ed25519_scalar_add(sc, sc2, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("add1: %s\n", hex);
crypto_core_ed25519_scalar_sub(sc, sc2, sc);
crypto_core_ed25519_scalar_sub(sc, sc, sc2);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("sub1: %s\n", hex);
memset(sc, 0xcd, crypto_core_ed25519_SCALARBYTES);
memset(sc2, 0x42, crypto_core_ed25519_SCALARBYTES);
crypto_core_ed25519_scalar_add(sc, sc, sc2);
crypto_core_ed25519_scalar_add(sc, sc2, sc);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("add2: %s\n", hex);
crypto_core_ed25519_scalar_sub(sc, sc2, sc);
crypto_core_ed25519_scalar_sub(sc, sc, sc2);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("sub2: %s\n", hex);
memset(sc, 0x69, crypto_core_ed25519_SCALARBYTES);
memset(sc2, 0x42, crypto_core_ed25519_SCALARBYTES);
for (i = 0; i < 100; i++) {
crypto_core_ed25519_scalar_mul(sc, sc, sc2);
crypto_core_ed25519_scalar_mul(sc2, sc, sc2);
}
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc2, crypto_core_ed25519_SCALARBYTES);
printf("mul: %s\n", hex);
for (i = 0; i < 1000; i++) {
crypto_core_ed25519_scalar_random(sc);
memset(sc2, 0, crypto_core_ed25519_SCALARBYTES);
crypto_core_ed25519_scalar_mul(sc3, sc, sc2);
assert(sodium_is_zero(sc3, crypto_core_ed25519_SCALARBYTES));
sc2[0]++;
crypto_core_ed25519_scalar_mul(sc3, sc, sc2);
assert(memcmp(sc3, sc, crypto_core_ed25519_SCALARBYTES) == 0);
sc2[0]++;
crypto_core_ed25519_scalar_mul(sc3, sc, sc2);
crypto_core_ed25519_scalar_sub(sc3, sc3, sc);
crypto_core_ed25519_scalar_sub(sc3, sc3, sc);
assert(sodium_is_zero(sc3, crypto_core_ed25519_SCALARBYTES));
do {
crypto_core_ed25519_scalar_random(sc2);
} while (sodium_is_zero(sc2, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_mul(sc3, sc, sc2);
crypto_core_ed25519_scalar_invert(sc2, sc2);
crypto_core_ed25519_scalar_mul(sc3, sc3, sc2);
assert(memcmp(sc3, sc, crypto_core_ed25519_SCALARBYTES) == 0);
sc[31] |= 0x11;
memset(sc2, 0, crypto_core_ed25519_SCALARBYTES);
sc2[0] = 1;
crypto_core_ed25519_scalar_mul(sc3, sc, sc2);
assert(memcmp(sc3, sc, crypto_core_ed25519_SCALARBYTES) != 0);
}
crypto_core_ed25519_scalar_mul(sc, L_1, sc_8);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L-1)*8: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, sc_8, L_1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("8(L-1): %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, L_1, L_1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L-1)^2: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, L, sc_8);
crypto_core_ed25519_scalar_mul(sc, L_p1, sc_8);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L+1)*8: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, sc_8, L_p1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("8(L+1): %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, L_p1, L_p1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L+1)^2: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, L_1, sc_highbit);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L-1)h: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, sc_highbit, L_1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("h(L-1): %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, L_p1, sc_highbit);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L+1)h: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, sc_highbit, L_p1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("h(L+1): %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, sc_highbit, sc_highbit);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("h^2: %s\n", hex);
crypto_core_ed25519_scalar_mul(sc, L, sc_8);
assert(sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_mul(sc, sc_8, L);
assert(sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_mul(sc, L, L);
assert(sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_mul(sc, L, L_1);
assert(sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_mul(sc, L_1, L);
assert(sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_add(sc, L_1, sc_8);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L-1)+8: %s\n", hex);
crypto_core_ed25519_scalar_add(sc, sc_8, L_1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("8+(L-1): %s\n", hex);
crypto_core_ed25519_scalar_add(sc, L_1, L_1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L-1)*2: %s\n", hex);
crypto_core_ed25519_scalar_add(sc, L, sc_8);
crypto_core_ed25519_scalar_add(sc, L_p1, sc_8);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L+1)+8: %s\n", hex);
crypto_core_ed25519_scalar_add(sc, sc_8, L_p1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("8+(L+1): %s\n", hex);
crypto_core_ed25519_scalar_add(sc, L_p1, L_p1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L+1)*2: %s\n", hex);
crypto_core_ed25519_scalar_add(sc, L_1, sc_highbit);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L-1)+h: %s\n", hex);
crypto_core_ed25519_scalar_add(sc, sc_highbit, L_1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("h+(L-1): %s\n", hex);
crypto_core_ed25519_scalar_add(sc, L_p1, sc_highbit);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("(L+1)+h: %s\n", hex);
crypto_core_ed25519_scalar_add(sc, sc_highbit, L_p1);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("h+(L+1): %s\n", hex);
crypto_core_ed25519_scalar_add(sc, sc_highbit, sc_highbit);
sodium_bin2hex(hex, crypto_core_ed25519_SCALARBYTES * 2 + 1,
sc, crypto_core_ed25519_SCALARBYTES);
printf("h*2: %s\n", hex);
sodium_free(hex);
sodium_free(sc64);
sodium_free(sc3);
sodium_free(sc2);
sodium_free(sc);
sodium_free(p3);
sodium_free(p2);
sodium_free(p);
sodium_free(r);
assert(crypto_core_ed25519_BYTES == crypto_core_ed25519_bytes());
assert(crypto_core_ed25519_SCALARBYTES == crypto_core_ed25519_scalarbytes());
assert(crypto_core_ed25519_NONREDUCEDSCALARBYTES == crypto_core_ed25519_nonreducedscalarbytes());
assert(crypto_core_ed25519_NONREDUCEDSCALARBYTES >= crypto_core_ed25519_SCALARBYTES);
assert(crypto_core_ed25519_UNIFORMBYTES == crypto_core_ed25519_uniformbytes());
assert(crypto_core_ed25519_UNIFORMBYTES >= crypto_core_ed25519_BYTES);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1,40 @@
inv1: 5858cdec40a044b1548b3bb08f8ce0d71103d1f887df84ebc502643dac4df40b
inv2: 09688ce78a8ff8273f636b0bc748c0cceeeeedecebeae9e8e7e6e5e4e3e2e100
inv3: f70b4f272b47bd6a1015a511fb3c9fc1b9c21ca4ca2e17d5a225b4c410b9b60d
inv4: 201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201
neg1: e46b69758fd3193097398c9717b11e48111112131415161718191a1b1c1d1e0f
neg2: 09688ce78a8ff8273f636b0bc748c0cceeeeedecebeae9e8e7e6e5e4e3e2e100
neg3: cdb4d73ffe47f83ebe85e18dcae6cc03f0f0f1f2f3f4f5f6f7f8f9fafbfcfd0e
neg4: 201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201
comp1: e56b69758fd3193097398c9717b11e48111112131415161718191a1b1c1d1e0f
comp2: 09688ce78a8ff8273f636b0bc748c0cceeeeedecebeae9e8e7e6e5e4e3e2e100
comp3: ceb4d73ffe47f83ebe85e18dcae6cc03f0f0f1f2f3f4f5f6f7f8f9fafbfcfd0e
comp4: 201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201
add1: f7567cd87c82ec1c355a6304c143bcc9ecedededededededededededededed0d
sub1: f67c79849de0253ba142949e1db6224b13121212121212121212121212121202
add2: b02e8581ce62f69922427c23f970f7e951525252525252525252525252525202
sub2: 3da570db4b001cbeb35a7b7fe588e72aaeadadadadadadadadadadadadadad0d
mul: 4453ef38408c06677c1b810e4bf8b1991f01c88716fbfa2f075a518b77da400b
(L-1)*8: e5d3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010
8(L-1): e5d3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010
(L-1)^2: 0100000000000000000000000000000000000000000000000000000000000000
(L+1)*8: 0800000000000000000000000000000000000000000000000000000000000000
8(L+1): 0800000000000000000000000000000000000000000000000000000000000000
(L+1)^2: 0100000000000000000000000000000000000000000000000000000000000000
(L-1)h: 609faee7d21893c0b2e6bc17f5cef7a600000000000000000000000000000000
h(L-1): 609faee7d21893c0b2e6bc17f5cef7a600000000000000000000000000000000
(L+1)h: 8d344775474a7f9723b63a8be92ae76dffffffffffffffffffffffffffffff0f
h(L+1): 8d344775474a7f9723b63a8be92ae76dffffffffffffffffffffffffffffff0f
h^2: 726cf51b9ec1dda146af8c58ffd22d148f6ffd85f41cbb738f260cdf4650e60c
(L-1)+8: 0700000000000000000000000000000000000000000000000000000000000000
8+(L-1): 0700000000000000000000000000000000000000000000000000000000000000
(L-1)*2: ebd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010
(L+1)+8: 0900000000000000000000000000000000000000000000000000000000000000
8+(L+1): 0900000000000000000000000000000000000000000000000000000000000000
(L+1)*2: 0200000000000000000000000000000000000000000000000000000000000000
(L-1)+h: 8c344775474a7f9723b63a8be92ae76dffffffffffffffffffffffffffffff0f
h+(L-1): 8c344775474a7f9723b63a8be92ae76dffffffffffffffffffffffffffffff0f
(L+1)+h: 8e344775474a7f9723b63a8be92ae76dffffffffffffffffffffffffffffff0f
h+(L+1): 8e344775474a7f9723b63a8be92ae76dffffffffffffffffffffffffffffff0f
h*2: 1000000000000000000000000000000000000000000000000000000000000000
OK

View File

@ -0,0 +1,271 @@
#define TEST_NAME "core_ristretto255"
#include "cmptest.h"
static void
tv1(void)
{
static const char *bad_encodings_hex[] = {
/* Non-canonical field encodings */
"00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
"f3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
"edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
"0100000000000000000000000000000000000000000000000000000000000080",
/* Negative field elements */
"0100000000000000000000000000000000000000000000000000000000000000",
"01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
"ed57ffd8c914fb201471d1c3d245ce3c746fcbe63a3679d51b6a516ebebe0e20",
"c34c4e1826e5d403b78e246e88aa051c36ccf0aafebffe137d148a2bf9104562",
"c940e5a4404157cfb1628b108db051a8d439e1a421394ec4ebccb9ec92a8ac78",
"47cfc5497c53dc8e61c91d17fd626ffb1c49e2bca94eed052281b510b1117a24",
"f1c6165d33367351b0da8f6e4511010c68174a03b6581212c71c0e1d026c3c72",
"87260f7a2f12495118360f02c26a470f450dadf34a413d21042b43b9d93e1309",
/* Non-square x^2 */
"26948d35ca62e643e26a83177332e6b6afeb9d08e4268b650f1f5bbd8d81d371",
"4eac077a713c57b4f4397629a4145982c661f48044dd3f96427d40b147d9742f",
"de6a7b00deadc788eb6b6c8d20c0ae96c2f2019078fa604fee5b87d6e989ad7b",
"bcab477be20861e01e4a0e295284146a510150d9817763caf1a6f4b422d67042",
"2a292df7e32cababbd9de088d1d1abec9fc0440f637ed2fba145094dc14bea08",
"f4a9e534fc0d216c44b218fa0c42d99635a0127ee2e53c712f70609649fdff22",
"8268436f8c4126196cf64b3c7ddbda90746a378625f9813dd9b8457077256731",
"2810e5cbc2cc4d4eece54f61c6f69758e289aa7ab440b3cbeaa21995c2f4232b",
/* Negative xy value */
"3eb858e78f5a7254d8c9731174a94f76755fd3941c0ac93735c07ba14579630e",
"a45fdc55c76448c049a1ab33f17023edfb2be3581e9c7aade8a6125215e04220",
"d483fe813c6ba647ebbfd3ec41adca1c6130c2beeee9d9bf065c8d151c5f396e",
"8a2e1d30050198c65a54483123960ccc38aef6848e1ec8f5f780e8523769ba32",
"32888462f8b486c68ad7dd9610be5192bbeaf3b443951ac1a8118419d9fa097b",
"227142501b9d4355ccba290404bde41575b037693cef1f438c47f8fbf35d1165",
"5c37cc491da847cfeb9281d407efc41e15144c876e0170b499a96a22ed31e01e",
"445425117cb8c90edcbc7c1cc0e74f747f2c1efa5630a967c64f287792a48a4b",
/* s = -1, which causes y = 0 */
"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"
};
unsigned char *s;
size_t i;
s = (unsigned char *) sodium_malloc(crypto_core_ristretto255_BYTES);
for (i = 0; i < sizeof bad_encodings_hex / sizeof bad_encodings_hex[0]; i++) {
sodium_hex2bin(s, crypto_core_ristretto255_BYTES, bad_encodings_hex[i],
crypto_core_ristretto255_BYTES * 2 + 1,
NULL, NULL, NULL);
if (crypto_core_ristretto255_is_valid_point(s)) {
printf("[%s] was not rejected\n", bad_encodings_hex[i]);
}
}
sodium_free(s);
};
static void
tv2(void)
{
static const char *hash_hex[] = {
"5d1be09e3d0c82fc538112490e35701979d99e06ca3e2b5b54bffe8b4dc772c1"
"4d98b696a1bbfb5ca32c436cc61c16563790306c79eaca7705668b47dffe5bb6",
"f116b34b8f17ceb56e8732a60d913dd10cce47a6d53bee9204be8b44f6678b27"
"0102a56902e2488c46120e9276cfe54638286b9e4b3cdb470b542d46c2068d38",
"8422e1bbdaab52938b81fd602effb6f89110e1e57208ad12d9ad767e2e25510c"
"27140775f9337088b982d83d7fcf0b2fa1edffe51952cbe7365e95c86eaf325c",
"ac22415129b61427bf464e17baee8db65940c233b98afce8d17c57beeb7876c2"
"150d15af1cb1fb824bbd14955f2b57d08d388aab431a391cfc33d5bafb5dbbaf",
"165d697a1ef3d5cf3c38565beefcf88c0f282b8e7dbd28544c483432f1cec767"
"5debea8ebb4e5fe7d6f6e5db15f15587ac4d4d4a1de7191e0c1ca6664abcc413",
"a836e6c9a9ca9f1e8d486273ad56a78c70cf18f0ce10abb1c7172ddd605d7fd2"
"979854f47ae1ccf204a33102095b4200e5befc0465accc263175485f0e17ea5c",
"2cdc11eaeb95daf01189417cdddbf95952993aa9cb9c640eb5058d09702c7462"
"2c9965a697a3b345ec24ee56335b556e677b30e6f90ac77d781064f866a3c982"
};
unsigned char *s;
unsigned char *u;
char *hex;
size_t i;
s = (unsigned char *) sodium_malloc(crypto_core_ristretto255_BYTES);
u = (unsigned char *) sodium_malloc(crypto_core_ristretto255_HASHBYTES);
hex = (char *) sodium_malloc(crypto_core_ristretto255_BYTES * 2 + 1);
for (i = 0; i < sizeof hash_hex / sizeof hash_hex[0]; i++) {
sodium_hex2bin(u, crypto_core_ristretto255_HASHBYTES, hash_hex[i],
crypto_core_ristretto255_HASHBYTES * 2 + 1,
NULL, NULL, NULL);
crypto_core_ristretto255_from_hash(s, u);
sodium_bin2hex(hex, crypto_core_ristretto255_BYTES * 2 + 1,
s, crypto_core_ristretto255_BYTES);
printf("%s\n", hex);
}
sodium_free(hex);
sodium_free(u);
sodium_free(s);
}
static void
tv3(void)
{
static const unsigned char l[crypto_core_ed25519_BYTES] =
{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
unsigned char *r =
(unsigned char *) sodium_malloc(crypto_core_ristretto255_SCALARBYTES);
unsigned char *r_inv =
(unsigned char *) sodium_malloc(crypto_core_ristretto255_SCALARBYTES);
unsigned char *ru =
(unsigned char *) sodium_malloc(crypto_core_ristretto255_HASHBYTES);
unsigned char *s =
(unsigned char *) sodium_malloc(crypto_core_ristretto255_BYTES);
unsigned char *s_ =
(unsigned char *) sodium_malloc(crypto_core_ristretto255_BYTES);
unsigned char *s2 =
(unsigned char *) sodium_malloc(crypto_core_ristretto255_BYTES);
int i;
for (i = 0; i < 1000; i++) {
crypto_core_ristretto255_scalar_random(r);
if (crypto_scalarmult_ristretto255_base(s, r) != 0 ||
crypto_core_ristretto255_is_valid_point(s) != 1) {
printf("crypto_scalarmult_ristretto255_base() failed\n");
}
crypto_core_ristretto255_random(s);
if (crypto_core_ristretto255_is_valid_point(s) != 1) {
printf("crypto_core_ristretto255_random() failed\n");
}
if (crypto_scalarmult_ristretto255(s, l, s) == 0) {
printf("s*l != inf (1)\n");
}
randombytes_buf(ru, crypto_core_ristretto255_HASHBYTES);
if (crypto_core_ristretto255_from_hash(s, ru) != 0 ||
crypto_core_ristretto255_is_valid_point(s) != 1) {
printf("crypto_core_ristretto255_from_hash() failed\n");
}
if (crypto_scalarmult_ristretto255(s2, l, s) == 0) {
printf("s*l != inf (2)\n");
}
if (crypto_scalarmult_ristretto255(s2, r, s) != 0 ||
crypto_core_ristretto255_is_valid_point(s2) != 1) {
printf("crypto_scalarmult_ristretto255() failed\n");
}
if (crypto_core_ristretto255_scalar_invert(r_inv, r) != 0) {
printf("crypto_core_ristretto255_scalar_invert() failed\n");
}
if (crypto_scalarmult_ristretto255(s_, r_inv, s2) != 0 ||
crypto_core_ristretto255_is_valid_point(s_) != 1) {
printf("crypto_scalarmult_ristretto255() failed\n");
}
if (memcmp(s, s_, crypto_core_ristretto255_BYTES) != 0) {
printf("inversion failed\n");
}
if (crypto_scalarmult_ristretto255(s2, l, s2) == 0) {
printf("s*l != inf (3)\n");
}
if (crypto_core_ristretto255_add(s2, s, s_) != 0) {
printf("addition failed");
}
if (crypto_core_ristretto255_sub(s2, s2, s_) != 0) {
printf("subtraction failed");
}
if (crypto_core_ristretto255_is_valid_point(s2) == 0) {
printf("invalid point");
}
if (memcmp(s, s2, crypto_core_ristretto255_BYTES) != 0) {
printf("s2 + s - s_ != s\n");
}
if (crypto_core_ristretto255_sub(s2, s2, s) != 0) {
printf("subtraction failed");
}
if (crypto_core_ristretto255_is_valid_point(s2) == -1) {
printf("s + s' - s - s' != 0");
}
}
crypto_core_ristretto255_random(s);
memset(s_, 0xfe, crypto_core_ristretto255_BYTES);
assert(crypto_core_ristretto255_add(s2, s_, s) == -1);
assert(crypto_core_ristretto255_add(s2, s, s_) == -1);
assert(crypto_core_ristretto255_add(s2, s_, s_) == -1);
assert(crypto_core_ristretto255_add(s2, s, s) == 0);
assert(crypto_core_ristretto255_sub(s2, s_, s) == -1);
assert(crypto_core_ristretto255_sub(s2, s, s_) == -1);
assert(crypto_core_ristretto255_sub(s2, s_, s_) == -1);
assert(crypto_core_ristretto255_sub(s2, s, s) == 0);
sodium_free(s2);
sodium_free(s_);
sodium_free(s);
sodium_free(ru);
sodium_free(r_inv);
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
main(void)
{
tv1();
tv2();
tv3();
tv4();
assert(crypto_core_ristretto255_BYTES == crypto_core_ristretto255_bytes());
assert(crypto_core_ristretto255_SCALARBYTES == crypto_core_ristretto255_scalarbytes());
assert(crypto_core_ristretto255_NONREDUCEDSCALARBYTES == crypto_core_ristretto255_nonreducedscalarbytes());
assert(crypto_core_ristretto255_NONREDUCEDSCALARBYTES >= crypto_core_ristretto255_SCALARBYTES);
assert(crypto_core_ristretto255_HASHBYTES == crypto_core_ristretto255_hashbytes());
assert(crypto_core_ristretto255_HASHBYTES >= crypto_core_ristretto255_BYTES);
assert(crypto_core_ristretto255_BYTES == crypto_core_ed25519_BYTES);
assert(crypto_core_ristretto255_SCALARBYTES == crypto_core_ed25519_SCALARBYTES);
assert(crypto_core_ristretto255_NONREDUCEDSCALARBYTES == crypto_core_ed25519_NONREDUCEDSCALARBYTES);
assert(crypto_core_ristretto255_HASHBYTES >= 2 * crypto_core_ed25519_UNIFORMBYTES);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1,8 @@
3066f82a1a747d45120d1740f14358531a8f04bbffe6a819f86dfe50f44a0a46
f26e5b6f7d362d2d2a94c5d0e7602cb4773c95a2e5c31a64f133189fa76ed61b
006ccd2a9e6867e6a2c5cea83d3302cc9de128dd2a9a57dd8ee7b9d7ffe02826
f8f0c87cf237953c5890aec3998169005dae3eca1fbb04548c635953c817f92a
ae81e7dedf20a497e10c304a765c1767a42d6e06029758d2d7e8ef7cc4c41179
e2705652ff9f5e44d3e841bf1c251cf7dddb77d140870d1ab2ed64f1a9ce8628
80bd07262511cdde4863f8a7434cef696750681cb9510eea557088f76d9e5065
OK

View File

@ -0,0 +1,70 @@
#define TEST_NAME "ed25519_convert"
#include "cmptest.h"
static const unsigned char keypair_seed[crypto_sign_ed25519_SEEDBYTES] = {
0x42, 0x11, 0x51, 0xa4, 0x59, 0xfa, 0xea, 0xde, 0x3d, 0x24, 0x71,
0x15, 0xf9, 0x4a, 0xed, 0xae, 0x42, 0x31, 0x81, 0x24, 0x09, 0x5a,
0xfa, 0xbe, 0x4d, 0x14, 0x51, 0xa5, 0x59, 0xfa, 0xed, 0xee
};
int
main(void)
{
unsigned char ed25519_pk[crypto_sign_ed25519_PUBLICKEYBYTES];
unsigned char ed25519_skpk[crypto_sign_ed25519_SECRETKEYBYTES];
unsigned char curve25519_pk[crypto_scalarmult_curve25519_BYTES];
unsigned char curve25519_pk2[crypto_scalarmult_curve25519_BYTES];
unsigned char curve25519_sk[crypto_scalarmult_curve25519_BYTES];
char curve25519_pk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
char curve25519_sk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
unsigned int i;
assert(crypto_sign_ed25519_SEEDBYTES <= crypto_hash_sha512_BYTES);
crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, keypair_seed);
if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) != 0) {
printf("conversion failed\n");
}
crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk);
sodium_bin2hex(curve25519_pk_hex, sizeof curve25519_pk_hex, curve25519_pk,
sizeof curve25519_pk);
sodium_bin2hex(curve25519_sk_hex, sizeof curve25519_sk_hex, curve25519_sk,
sizeof curve25519_sk);
printf("curve25519 pk: [%s]\n", curve25519_pk_hex);
printf("curve25519 sk: [%s]\n", curve25519_sk_hex);
for (i = 0U; i < 500U; i++) {
crypto_sign_ed25519_keypair(ed25519_pk, ed25519_skpk);
if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) !=
0) {
printf("conversion failed\n");
}
crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk);
crypto_scalarmult_curve25519_base(curve25519_pk2, curve25519_sk);
if (memcmp(curve25519_pk, curve25519_pk2, sizeof curve25519_pk) != 0) {
printf("conversion failed\n");
}
}
sodium_hex2bin(ed25519_pk, crypto_sign_ed25519_PUBLICKEYBYTES,
"0000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000",
64, NULL, NULL, NULL);
assert(crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) == -1);
sodium_hex2bin(ed25519_pk, crypto_sign_ed25519_PUBLICKEYBYTES,
"0200000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000",
64, NULL, NULL, NULL);
assert(crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) == -1);
sodium_hex2bin(ed25519_pk, crypto_sign_ed25519_PUBLICKEYBYTES,
"0500000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000",
64, NULL, NULL, NULL);
assert(crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) == -1);
printf("ok\n");
return 0;
}

View File

@ -0,0 +1,3 @@
curve25519 pk: [f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50]
curve25519 sk: [8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166]
ok

1406
deps/libsodium/test/default/generichash.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,65 @@
05
5d8c
22221b
d4974470
be8492fb36
edc178279907
26848f2ae0c2e6
045cf1235112b9f6
5110bad569356dfa6c
1339d95145bc8a33d3aa
3dbb39b4d57c5566808a88
22378260939cee01022686a2
e18b37abcead6cc520e6504dac
3cbb356604cf862e62ad2f534323
44c41ba227b191961b475ec5875057
0c7c9c3922d41a7b2b3b20f92685d560
8508c01d19709bdd881866aa1f8c63ca06
f6b2dddfbece6d7d52e114c7e5a97772e18d
d36b5af9591d0cd3747254e26bc6e1de5b6081
f7f7ce69149418d7ec33327bd86e14bcca4b8ed7
2c9aba9a56de21165753c4f3cee9310a9c8fe546b9
ee5e08cee5fbbcb51900341bb30db6695920faecda6a
fe9ffb56dc5716b91bc7d77ce7b05e7cc39c31683bec91
c500ae0f5bff0f1106ce104ae9c291add7207e0d8ebcb1ed
68e23d12000b387158afd6458d3bcef9c26936ca68b5c0f3d6
220efa2c09f67dbb02aa623bbc0cb92107a30f53b633e78d4b44
54df984b47e4bcd489d9c045c488743fac91c9b3e0cbcc37495fac
b4852cf66c6ce164c002bbb62ded0faeb4a39c39fdffb372ff14dd31
d79cafb5565e7775616e1c9b09100d61fb71efaf25affcf2d480d2c980
ae557883145e374adef583ba0550429d5cdd86b254c33bf52d02e070efda
9f53d28c0df7b327c2eb4c8a12c742829225b7f30fda7baf64135098fdb01b
a9f51bb7f6a3e9cdb96ce652c07d177962a348a9cced1b92f948187e59b44463
f2960cf5fd57fc92f549cd5a2803147964f60e7703e1b8897c088cded74c7bd39f
89981acbb690eb03ed2a67510d1d85a1b4f9d496fdfe134550ae14146bb05fd5fedd
6d8245383fd7c418b46511339e711b9d4a0d1f5fdf6de45fdd3d0664164b7bf878a124
1f0b6b083d524e0741710ddef499ce88f51083bb3ad80a1815cc57acf006436e9b6ad72b
fc35bfe34c915020bb8b44fa0a19933774eaaf61919780fd55564e085bc31646dfc1d426e9
117d58f1f8cb2c036102686035975be90550795e5a0e3469a8f7a2cba9bc88961852b18c8ae3
c679c950818729c799bb7f39cef2d89fa80a147817f379a073ef1ccafea5d369815c70373bf5be
d487ad2143024ee8c645a066c035b74abe3a11f1c9fcd738b154b8ca37134d74fb78c40d1a2274cf
2d3ee00828b0ccea6812b40f214fab6d4f23f7e74ae228115bcb208ced2d5e1cb9cdff41de912af7a8
a697b26d4c4475e312288b98ae2ec4954d3c74c8e144c0ab518616ff9f52918a946fd765af75e761178c
f647bcba2a711f431d6d453aa7d75dcf5bb9ab6f8b83f89117230f633e7580f27c71c4f4c211cadd04f587
1fc1d6a4db753e2f4fd1456b2b709dd70ad58547eeda9d5a55762b5cd4097a7a1bd73cc633ec27168ee65631
1cfe0f63ab155379b4a1b5bf694a33635097b8e4b6dbd3b983d62454d36d7bf4550bece301abdd27b2dd76ca9f
73dee8a0a558e7b6f6eefe411280e253b05ef006d499849fea5d6a95f9141ee160322fff3a3f70e10c84025e02ce
edf9e706f4acae4f4bed72404f14458ba075d2b9d9a4a1ed46d1f1c5e23113a74cce9f7735432a922a3d8097f22c7a
95d5cd54c6722ac4335fa0ab38d388c9fd0baea48a9078605e400534ef38f13abb1d770da84b90b0256e1c1b64f54ba9
fe6b85ee8b5eb7da035264ed46e6dcd948571018d1f6976de4102fcb4bb5f1422e7df1b5aaa5b6b56c5961966db29ead6e
499ab83c01e4bf74ea5036392f9f810eae8a066fff49e316e4288baccb2001efa24f64cef7bfae70c90f139b198e53ad87f1
eac6c9d97264241a8adba22ee925438ed9787a547018608a10676a7594bc51c60294bd9159fbcada9022b44880a37c5b07c1b4
0771e3ae24bbfe424800d4bae776fef3da1607990019e7c4b30bc8140061ebf0b64aad7b018a878d579caa67154b98a04402735e
d569e5f5fe197387451441911a2be2effa606dad39820af44cea056bd9d1499dde41fa1c6c3a0459d5866c944bec2ac83328953726
68e523ded865c4d8318d61c312189a59597bbc3995e312e85137611af761a5f73508ac79e359edf729d4508830fc642b432f09185914
601af664ae596166707244adbb4f704593b355c6a659c844d853c6647fb265cdbcea26ed43657251dec37f2d6453fa0ace55f22d303cb0
703d8e552236b2090143444545f0a61a809d8ef9843bcf6883f61671fb31c8d6ac9fd373e7f9f79a0c72fa6a37dc655ba1fb01a5f41e36d1
03896f594afd1bf97acb862106eb05a1d8b54ec08d184812a79f4dc7b287a7486e60927b6c23e5f51fcbc94798648b28fd13438300567bec95
cc66a891768e95a2717b040c111996f14942f10f2475c33aa5f1c97476e6f8386733d6b21c16102d01ff1f715475f01099e1f19aa763238a38a9
007aac8eae29e5bf2be1b54857f5fe80c324424a3273b46e55482fbc4ae1033df4a97016b60c81a5344abd6366f56d8cee2c2e94619418293990de
50c81e92605a6111ea4c7c602acfb3945d4c2631c8c08fa4b594134577f5c2ffcca90d48604162cfdb2a0bb40416ff9134a275461b829ff1b875f995
661b7a1c70170aa7559aa82639fa65c1bdcfb5e336cb23b40a9edf5b4f6eeca1a176a9844da705cafb990dd94b9dc6194eb6b2de3eca9dbd255bb267a1
9ff11c233aaf5e0242b0dbe6e110a42e58b86141ad0ef130fd2bb895700019782de66d435bf0a8d6f5eda5d7d1105e7a6f3ef17a9da8f9c16fc21075431a
bdd3d0fafe8ba2b29d1ac0b79aa46e249cc9d3a82d0f772d690637bbdd353722356658d00436ff5dd5239ab747979329345eb8c7ed11b7331456ae87350fcf
bd965bf31e87d70327536f2a341cebc4768eca275fa05ef98f7f1b71a0351298de006fba73fe6733ed01d75801b4a928e54231b38e38c562b2e33ea1284992fa
2fc6e69fa26a89a5ed269092cb9b2a449a4409a7a44011eecad13d7c4b0456602d402fa5844f1a7a758136ce3d5d8d0e8b86921ffff4f692dd95bdc8e5ff0052

View File

@ -0,0 +1,62 @@
#define TEST_NAME "generichash2"
#include "cmptest.h"
int
main(void)
{
#define MAXLEN 64
crypto_generichash_state *st;
unsigned char in[MAXLEN];
unsigned char out[crypto_generichash_BYTES_MAX];
unsigned char k[crypto_generichash_KEYBYTES_MAX];
size_t h, i, j;
assert(crypto_generichash_statebytes() >= sizeof *st);
st = (crypto_generichash_state *)
sodium_malloc(crypto_generichash_statebytes());
for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h) {
k[h] = (unsigned char) h;
}
for (i = 0; i < MAXLEN; ++i) {
in[i] = (unsigned char) i;
if (crypto_generichash_init(st, k,
1 + i % crypto_generichash_KEYBYTES_MAX,
1 + i % crypto_generichash_BYTES_MAX) != 0) {
printf("crypto_generichash_init()\n");
return 1;
}
crypto_generichash_update(st, in, i);
crypto_generichash_update(st, in, i);
crypto_generichash_update(st, in, i);
if (crypto_generichash_final(st, out,
1 + i % crypto_generichash_BYTES_MAX) != 0) {
printf("crypto_generichash_final() should have returned 0\n");
}
for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
if (crypto_generichash_final(st, out,
1 + i % crypto_generichash_BYTES_MAX) != -1) {
printf("crypto_generichash_final() should have returned -1\n");
}
}
assert(crypto_generichash_init(st, k, sizeof k, 0U) == -1);
assert(crypto_generichash_init(st, k, sizeof k,
crypto_generichash_BYTES_MAX + 1U) == -1);
assert(crypto_generichash_init(st, k, crypto_generichash_KEYBYTES_MAX + 1U,
sizeof out) == -1);
assert(crypto_generichash_init(st, k, 0U, sizeof out) == 0);
assert(crypto_generichash_init(st, k, 1U, sizeof out) == 0);
assert(crypto_generichash_init(st, NULL, 1U, 0U) == -1);
assert(crypto_generichash_init(st, NULL, crypto_generichash_KEYBYTES,
1U) == 0);
assert(crypto_generichash_init(st, NULL, crypto_generichash_KEYBYTES,
0U) == -1);
sodium_free(st);
return 0;
}

View File

@ -0,0 +1,64 @@
05
22a8
287a9d
d8eeab1c
d4ce34973f
584f7ac46f0c
32c848bb67545b
8438e21361bca125
27a6faae998b4fabb4
508c05a4f2daee150bad
68c886c97dce370e8c72fa
d41e90824ace31ba7bf512ac
6e0d7a1e2b92a68e45ea867895
1fc5ee8715312db38da9066152a5
3138504ba58fcd56c62752bc98a6d2
b689ecd5357cb5276007627fbdf4082e
afe251881beb8b9dfa3d4f76aafc7b2995
980eaa215cb0911027c5564db809bb8ac0a1
56048436883efdfc8feaa239d960fa5ce24d42
fce905b6d57fd841f58899a77887a4988e6aa2d1
6f7afd81d24ccf4d98188b71bdbb7e6c637620879b
50406b4c37b48621505942b35dff30a75f7d2868146b
32c21792e18e7a79a4a20ef291721d7eab4e4cf99fbe79
4b9d9ac5dbfb825acd87588667e6683e0fde4cdcd0a532f9
2b55a3ebb461623e5de4fbacfb8b26819cfa8adeb094c8c13b
4c7d261780b25a864a008352ad64d1ae7fc21d608317813cf63f
f0ca06b8e12c48f1511d0991ba562f06dbe6ba6d5e18280224cc6a
838a5f7056bfbca65a245796dd3510cb07ff1614b44989d91ac650b2
a58a8da276577160441f8b9e9c52a041b7caf7cd316acc506f620ab0e1
e03940a7231049ff2b86c47a28e4951f105d2a3aa3421190fe0ed6aa4ad6
a7af977c0b34294b1a03d0cc2dcf6eb72f9a32721c3f70128384aeb1f56047
0e5625d74ada70b8a3b23ca76894e9a0f9dee88f5e3e370e27ad25061ea9dd6f
775fd9257b265997a16557a445985091798af60e68d06e3ae8e2e886d23ed12f6e
852e8d4208166a990e215ed06b86c708f491e014584ac9b08f97f24d9f08a84c8e83
fbdca0db9a933fcffcce2ae694d7e16e7571b100564fcb3d69cec82ea42f254a493a32
50530ae5eb9780f3fafc5d179f7b363a0d69314a8545d68588b5fec28c8e8d1a011857f6
5eb71553ff1ac4aba3f84faeb70281c738e3428aae68edc9842ebf55ffd7184a015e323445
39b279c6d9cca89f8052f953abf71041faf3491b2b965cef503d715e8bf339e02a58fd0e0fba
e315bef5f4918e881dc8d39d3c6b3948c2ea8e21ac00ee7c7ab875a53e194add0c3d9b8bcba5b2
4e950f0e1da3111d054136fbdf10b4b88b20de6ad0c6bd5024a5e0a8b4cd7059685c0b663a00cbfa
b1ed8d99fd62a4f504ecdd58a01759a85932a7783f88f314cdca5019e05063dcc1fcb3c39b8c07758e
e4d78e734b0cb5bbd83e22bc67f97bbc8a3644f789f6c26a3ec2fe72c75b4d48a3bc000e6f2f2f0726fe
162e01beb796433a2771eab54611fc93677ed12c73a93ea4d75e148bec7ab14b3e31ab7f395456fb2b47ab
759c30631fd52e80a22f0614125dcd136287db65079908b75fb5b03be1cdf6dd0a1c9de0cc759cdd82c33758
af2992acdaf0908f03a2025854de6446123c919b1e24db711df6cb070091343b4e6f5b2716c20c2547f50f1fde
b833064955778a611fe41a9f1a2de730a16fb4e61a7e2fb67425ce199101d4e71dd7b0c731ea4188e9cc30e9bc52
e546ee327168d9b4e0d73d9a043f9ef03f880bc8aee91b0923704eb7361ac916b00f5c71c872e2f911a77ef76704b5
83d86f056729fa1a6e1d3fe8c3d2ebe42b327025747f2e6ba923d2b7b893e31571839937222852033844e585b17d462f
5d70402524fbef569552a3ff6854087e090ff9ac9ea03aba92cf9f33a28845fa6a1631090dca10e05cdd3341b391a15fcf
64f4d3ebf0717900f7c04512d1e18f9985975991d4254d76c4e2ee02c0edd6f912f715991984731b808b8370be1f201e53bf
7d45eae6626dfc9ec3591764b8c39c72ca67e6c1893ab590963a75922719937d1d0ff188a510ffbdf9c777a4d565b3683cbf38
68e007db5067874548c0d12a9ca709221f9bd352e3eb9847fde6c5de4a8550f4b85b67fe4e5aad70626ebb27d71e5b528effb2e6
b0dc4dc0bd0d41a8ccfa45a127542079bc4e6f63a63863a9ce21f44481d23eff1060ea03851759b9317209405d5b7cc4387cc2759b
adf6a9df484e93eb3a6113c3fd68a49b2166878fc652833c9cbef3fd8dd281d385ad0374bc25bc865b216ca395e21c30b9eda1d58a8d
f1df9bc169323da338daa8a94867db96a1a2a6feb26569198fb4591ae602ba6f766a879e745d71e93b6cb8886b914f2bf4aa55d4c48045
0c7446078a5077f33bba1ebfad60bbf1b1df47aab2eb3f3f3274ce56ead7800cf095af8208b6d570c4c832fe33227bbbc0842a13e1e82ad9
accd0b4682e56698ecc55a60a8db8b3f950b6bffc5a1d160daf6ca25e13e3b4983ced5903df0bdc21f70c2ec5adb1a2ec9617df645cdd17ac9
b787bae190ff2608eb383e0299cc10d6b7232de67ab74285e7bfa933d79f91226066537d74a9d40140d7b1683c2d42cd1935f6430cc554db2b69
d09b717a0c80f581c07b8813e0ae79cec2188f77122f7477954610655a20420f13eb1b68cacde8c1fdf7a9a398efa72f40c85f0122812eaa33aba0
87fff156d9895917468e92848fdcfacc134ca3bfc7fce484bd6db41c682ee2ee47151df0fa863d5641633d908c0328e6cbe080e80d8293530ffd2c4f
1b17b2c0e7afcd224ec9bbe9ce9a13a00bd0a336b863f1b4d5304043778244323bd23fb6154a2e1e94aa48f6ff0e12787a50ca09e9e72ece9e038f6218
23ac1ccd5e7df51b65b284650158d662e7ef51ebae01b879f39cec484b688c792f8e854bd8ca31ffe8796d28f10e49ab402dab47878a21cb95556dc32b0a
f8f5323ebcc28bf927e72d342b5b70d80ba67794afb4c28debad21b0dae24c7a9252e862eb4b83bea6d9c0bb7c108983c987f13d73f250c7f14483f0454a24
55b97ca594d68ccf69a0a93fe7fa4004c7e2947a8cac4ca4a44e17ac6876f472e3f221b341a28004cd35a79cfad7fabb9378ce5af03e4c0445ebbe9540943bbd

View File

@ -0,0 +1,176 @@
#define TEST_NAME "generichash3"
#include "cmptest.h"
int
main(void)
{
#define MAXLEN 64
crypto_generichash_blake2b_state st;
unsigned char salt[crypto_generichash_blake2b_SALTBYTES]
= { '5', 'b', '6', 'b', '4', '1', 'e', 'd',
'9', 'b', '3', '4', '3', 'f', 'e', '0' };
unsigned char personal[crypto_generichash_blake2b_PERSONALBYTES]
= { '5', '1', '2', '6', 'f', 'b', '2', 'a',
'3', '7', '4', '0', '0', 'd', '2', 'a' };
unsigned char in[MAXLEN];
unsigned char out[crypto_generichash_blake2b_BYTES_MAX];
unsigned char k[crypto_generichash_blake2b_KEYBYTES_MAX];
size_t h;
size_t i;
size_t j;
assert(crypto_generichash_blake2b_statebytes() >= sizeof st);
for (h = 0; h < crypto_generichash_blake2b_KEYBYTES_MAX; ++h) {
k[h] = (unsigned char) h;
}
for (i = 0; i < MAXLEN; ++i) {
in[i] = (unsigned char) i;
crypto_generichash_blake2b_init_salt_personal(
&st, k, 1 + i % crypto_generichash_blake2b_KEYBYTES_MAX,
1 + i % crypto_generichash_blake2b_BYTES_MAX, salt, personal);
crypto_generichash_blake2b_update(&st, in, (unsigned long long) i);
crypto_generichash_blake2b_final(
&st, out, 1 + i % crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < 1 + i % crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
}
memset(out, 0, sizeof out);
crypto_generichash_blake2b_init_salt_personal(
&st, k, 0U, crypto_generichash_blake2b_BYTES_MAX, salt, personal);
crypto_generichash_blake2b_update(&st, in, MAXLEN);
crypto_generichash_blake2b_final(&st, out,
crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_init_salt_personal(
&st, NULL, 1U, crypto_generichash_blake2b_BYTES_MAX, salt, personal);
crypto_generichash_blake2b_update(&st, in, MAXLEN);
crypto_generichash_blake2b_final(&st, out,
crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_init_salt_personal(
&st, k, crypto_generichash_blake2b_KEYBYTES_MAX,
crypto_generichash_blake2b_BYTES_MAX, NULL, personal);
crypto_generichash_blake2b_update(&st, in, MAXLEN);
crypto_generichash_blake2b_final(&st, out,
crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_init_salt_personal(
&st, k, crypto_generichash_blake2b_KEYBYTES_MAX,
crypto_generichash_blake2b_BYTES_MAX, salt, NULL);
crypto_generichash_blake2b_update(&st, in, MAXLEN);
crypto_generichash_blake2b_final(
&st, out, crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_salt_personal(
out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
k, 0U, salt, personal);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_salt_personal(
out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
NULL, 0U, salt, personal);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_salt_personal(
out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
k, crypto_generichash_blake2b_KEYBYTES_MAX, salt, personal);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_salt_personal(
out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
k, crypto_generichash_blake2b_KEYBYTES_MAX, NULL, personal);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
memset(out, 0, sizeof out);
crypto_generichash_blake2b_salt_personal(
out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
k, crypto_generichash_blake2b_KEYBYTES_MAX, salt, NULL);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
assert(crypto_generichash_blake2b_salt_personal
(guard_page, 0,
in, (unsigned long long) sizeof in,
k, sizeof k, NULL, NULL) == -1);
assert(crypto_generichash_blake2b_salt_personal
(guard_page, crypto_generichash_BYTES_MAX + 1,
in, (unsigned long long) sizeof in,
k, sizeof k, NULL, NULL) == -1);
assert(crypto_generichash_blake2b_salt_personal
(guard_page, (unsigned long long) sizeof in,
in, (unsigned long long) sizeof in,
k, crypto_generichash_KEYBYTES_MAX + 1, NULL, NULL) == -1);
crypto_generichash_blake2b_init_salt_personal(&st, NULL, 0U, crypto_generichash_BYTES,
NULL, personal);
crypto_generichash_blake2b_update(&st, in, MAXLEN);
crypto_generichash_blake2b_final(&st, out, crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
crypto_generichash_blake2b_init_salt_personal(&st, NULL, 0U, crypto_generichash_BYTES,
salt, NULL);
crypto_generichash_blake2b_update(&st, in, MAXLEN);
crypto_generichash_blake2b_final(&st, out, crypto_generichash_blake2b_BYTES_MAX);
for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
printf("%02x", (unsigned int) out[j]);
}
printf("\n");
assert(crypto_generichash_blake2b_init_salt_personal
(&st, k, sizeof k, 0, NULL, NULL) == -1);
assert(crypto_generichash_blake2b_init_salt_personal
(&st, k, sizeof k, crypto_generichash_blake2b_BYTES_MAX + 1, NULL, NULL) == -1);
assert(crypto_generichash_blake2b_init_salt_personal
(&st, k, crypto_generichash_blake2b_KEYBYTES_MAX + 1, sizeof out, NULL, NULL) == -1);
assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, crypto_generichash_BYTES,
NULL, personal) == 0);
assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, crypto_generichash_BYTES,
salt, NULL) == 0);
return 0;
}

View File

@ -0,0 +1,75 @@
ba
6139
3a1666
5797e9d0
834a26efe6
d7e9e862bbce
40d8b84c374750
276789189244cf04
16f73ffe0673cc9992
b3835bfaf6eb71d94078
8c624e844d34f4a59f34cc
e0a394962413ad09975df3cf
47f043c3aacb501f97e0458ae3
b4a11f2fb72a7e6f96fdacf98d49
f434079e9adeb244047cb6855f9854
5fbe885c4b2d4e0d78dc5905622a277a
e262ba3e2ab76efdf83513108e3b987d1b
add93dde78d32e77bc039c34a49043f19d26
093842ac10e2eb1237ddc9ca9e7990cf397772
09e7f6a0e2ea4888f1dbf6562effd1561c65029c
bd33a9ec914f5b81864a49184338e4062d6c6b2b2e
8dc46295235d94f5881d429a5ad47f9db9e35cf8c6b3
ba5df554dca7ac1cba4889fa88adf3070fbf4ab5d187b5
1ff84715e71c66214d271d421395fb6166db97b1d47ed697
75a0d227c70549f5b0c933b7b21f151355bd47e04b6085c91f
a32a5c9439a0fa771dcbe7f338b5dcef62a754edc4952614d6f0
53a87de519cdcc7f64730d58bce6baaf7b44c5c428a4611a208ad4
5e5ad8f0c4f083f9b7a5154d9c0dfd0f3d2fce94cf54fc215450314a
9c76b9e63c77e6564b1e5111c2fb140046e1e5a4f900a7cfc2bac3fcfa
bb919251ca310eb9b994e5d7883bc9fa2144b59b8d5d940677b7130ac777
faa492a66f08ef0c7adb868fcb7b523aedd35b8ff1414bd1d554794f144474
9b273ebe335540b87be899abe169389ed61ed262c3a0a16e4998bbf752f0bee3
1e0070b92429c151b33bdd1bb4430a0e650a3dfc94d404054e93c8568330ecc505
e3b64149f1b76231686d592d1d4af984ce2826ba03c2224a92f95f9526130ce4eb40
5f8e378120b73db9eefa65ddcdcdcb4acd8046c31a5e47f298caa400937d5623f1394b
74c757a4165a1782c933e587353a9fd8f6d7bf26b7f51b52c542747030bfb3d560c2e5c2
2d5ee85cc238b923806dd98db18919d1924f2340ec88917d4ce1799cbfd5f2cb9df99db2e1
c93ff727e6f9822efec0a77eed0025c0eff19127bf8746b7c71c2a098f57cef02febb86a1e6c
adfb6d7ba13779a5dd1bbf268e400f4156f0f5c9d5b670ff539e1d9c1a63373416f3001f338407
3a6900e58a448887d77c5911e4bdde620e64f25b2d71723fa60f7cb3efa7c320b6153bdbc3287949
413eb0fd379b32dd88e82242a87cc58ce3e64c72352387a4c70f92ee5c8d23fa7ecd86f6df170a32d2
92d0d3cacc3e25628caf6f2c4cd50d25d154ac45098f531d690230b859f37cfe089eb169f76bba72a3ff
92f6ccc11a9a3bee520b17e0cddc4550c0e9cf47ddd9a6161284259ffb161c1d0675b505cb1066872768e8
a3cd675804e6be7f120138a9eaadcd56bb7763d1c046e87fe0d358c8276b0d24621f46c60b46e397933b75b4
304a1af53cbdd6486b8419d1ebd5e9528c540d8dc46a10be49067f46a0617229577015d776783f702b2954df43
d8a6358970446453ac0c82c758644ab68989b5b4f06f9768807ce0c5f2a0dbac1e8450f4e3a02deecf7b54b6a45d
1264b8dee9ac4aa8de69a43ada95cc95f20230f33836d4a1db8c2466ab38361686e5ac282025ccc2e0f6a1cd98a4dd
7eed787abaa7f4e8b8aa3090f0676201cfbaaf350899661cdd5216ac0b5cd874443f5c0688ffd7ca1ccbfe1ca7e1a3f5
8907f0218585167962a8e8213559a643dd03c2bf1a7a5ad3e3bc5f88c0ff1532ee8cd29880e7e0e68da22a5798aef27cc5
12dea17b0733e5060751b1115e10c3d4b2f4583bcd009d9f1f42ec23d4a6a0df1185d3abbdbe86de08569e70583d6de1c1fe
8ff75e91f1de547dc3a25472db2f51f5910a290c449603da54207b5e39bd735d240ec913b52df90709b5d29357971d6c341452
4a3b16b12400f38e74778efc3a4caa52ec6fdf6b0180a5bfac9189e52e162c10e8911a54ab33e2b389ee1949e58edaa119e2b2b9
c9943e7186fdc9bbfa1d7087fa7086babe6fcf95a6196d1772187854071304e2f1fff39e6e6f48f76addb16d5c00249e0523aac91f
0297f16fdd34add9cc87b4adf816525b590ba08ac733c43f8d225d194df4f9c83b4dce617be51e25b5f6c80dff249f27c707de20e422
576bb891eab9930998e2e73b5d0498e3c5f040f8dec9397a8c7a622c17de01fee7cc936e3bd4de1f7fd8b31dea9e70c65462bbb5dc7b50
9416a57ae7c8c51c6e008f940fe06d8ebc02c350c19a2f71583a6d260b085670d73a95248fef0f4cae5292ba7db1189a7cd9c51122ba7913
ea644b9051cca5eee8868a553e3f0f4e14739e1555474151156e10578256b288a233870dd43a380765400ea446df7f452c1e03a9e5b6731256
f99cc1603de221abc1ecb1a7eb4bbf06e99561d1cc5541d8d601bae2b1dd3cbe448ac276667f26de5e269183a09f7deaf35d33174b3cc8ad4aa2
ee2be1ec57fdac23f89402a534177eca0f4b982a4ed2c2e900b6a79e1f47a2d023eff2e647baf4f4c0da3a28d08a44bc780516974074e2523e6651
9cda001868949a2bad96c5b3950a8315e6e5214d0b54dcd596280565d351806ef22cf3053f63623da72fcad9afa3896641658632334c9ec4f644c984
c6d6722a916651a8671383d8260873347d9c248696b4cb3dac4dea9ba57ed971127cb18e44211d7e14177ace248b3c6e0785356ee261ebdc6ef0faf143
5dd258a3e7505bc6b9776b0df25676a1c19e2c8258c7b5f2e361423523d96299eb6827bc7c27e7bca2d2b59d717c2ebcb05e6dcaa32289d96fae9a4077ef
19c14de35fe19c92cc0e624280e4136355d4cfa9a0a98b090c4b06f5665021920725852ff1f566b0c8c37157b25fb9f947a2e70b40577a17860a0732c170ac
5fcdcc02be7714a0dbc77df498bf999ea9225d564adca1c121c9af03af92cac8177b9b4a86bcc47c79aa32aac58a3fef967b2132e9352d4613fe890beed2571b
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
5789f474edd5206ededaccfc35e7dd3ed730748125b5395abf802b2601126b19b109a1db67556945bc79bb25e1ab59610599d155070e0e04354f11a6a5d6f3ac
e78efc663a5547c089f2b3b08973c974c4bfd365eac18b80c68bdb3b1ba4554b54d6b8465a68a3b9aa0bc020621f16efd5b8dd8c7c01ed9ee3ec5544aae465ff
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
fb4e2ad6b7fe6afd2ba06d5c1d79379c5bf10e336a35c89a1aaf408a805171716e0635a5b1d18190131e15b6888510bcb3e3752b050f892a09dbbde60b051495
5789f474edd5206ededaccfc35e7dd3ed730748125b5395abf802b2601126b19b109a1db67556945bc79bb25e1ab59610599d155070e0e04354f11a6a5d6f3ac
e78efc663a5547c089f2b3b08973c974c4bfd365eac18b80c68bdb3b1ba4554b54d6b8465a68a3b9aa0bc020621f16efd5b8dd8c7c01ed9ee3ec5544aae465ff
4f9875a42ba0da8ae3448d2d62b1ff51be672eb1b8a1b0fa5bcd5334c861eff06b5903d672d318fd04e0ef94ddd37eca6d4ad2051a36a0236dc4cc09a5a44358
ec9f272db92d1fa99324115f34cda8b4690ad029c1df36986cf9e1f844d8fdeca8e8e8311620ad24cbbfa12eccb676b979565405c8e2e20a2e4f18fb27c93d76

47
deps/libsodium/test/default/hash.c vendored Normal file
View File

@ -0,0 +1,47 @@
#define TEST_NAME "hash"
#include "cmptest.h"
static unsigned char x[] = "testing\n";
static unsigned char x2[] =
"The Conscience of a Hacker is a small essay written January 8, 1986 by a "
"computer security hacker who went by the handle of The Mentor, who "
"belonged to the 2nd generation of Legion of Doom.";
static unsigned char h[crypto_hash_BYTES];
int
main(void)
{
size_t i;
crypto_hash(h, x, sizeof x - 1U);
for (i = 0; i < crypto_hash_BYTES; ++i) {
printf("%02x", (unsigned int) h[i]);
}
printf("\n");
crypto_hash(h, x2, sizeof x2 - 1U);
for (i = 0; i < crypto_hash_BYTES; ++i) {
printf("%02x", (unsigned int) h[i]);
}
printf("\n");
crypto_hash_sha256(h, x, sizeof x - 1U);
for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
printf("%02x", (unsigned int) h[i]);
}
printf("\n");
crypto_hash_sha256(h, x2, sizeof x2 - 1U);
for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
printf("%02x", (unsigned int) h[i]);
}
printf("\n");
assert(crypto_hash_bytes() > 0U);
assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
assert(crypto_hash_sha256_bytes() > 0U);
assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
assert(crypto_hash_sha256_statebytes() == sizeof(crypto_hash_sha256_state));
assert(crypto_hash_sha512_statebytes() == sizeof(crypto_hash_sha512_state));
return 0;
}

4
deps/libsodium/test/default/hash.exp vendored Normal file
View File

@ -0,0 +1,4 @@
24f950aac7b9ea9b3cb728228a0c82b67c39e96b4b344798870d5daee93e3ae5931baae8c7cacfea4b629452c38026a81d138bc7aad1af3ef7bfd5ec646d6c28
a77abe1ccf8f5497e228fbc0acd73a521ededb21b89726684a6ebbc3baa32361aca5a244daa84f24bf19c68baf78e6907625a659b15479eb7bd426fc62aafa73
12a61f4e173fb3a11c05d6471f74728f76231b4a5fcd9667cef3af87a3ae4dc2
71cc8123fef8c236e451d3c3ddf1adae9aa6cd9521e7041769d737024900a03a

20
deps/libsodium/test/default/hash3.c vendored Normal file
View File

@ -0,0 +1,20 @@
#define TEST_NAME "hash3"
#include "cmptest.h"
static unsigned char x[] = "testing\n";
static unsigned char h[crypto_hash_BYTES];
int
main(void)
{
size_t i;
crypto_hash(h, x, sizeof x - 1U);
for (i = 0; i < crypto_hash_BYTES; ++i) {
printf("%02x", (unsigned int) h[i]);
}
printf("\n");
return 0;
}

1
deps/libsodium/test/default/hash3.exp vendored Normal file
View File

@ -0,0 +1 @@
24f950aac7b9ea9b3cb728228a0c82b67c39e96b4b344798870d5daee93e3ae5931baae8c7cacfea4b629452c38026a81d138bc7aad1af3ef7bfd5ec646d6c28

View File

@ -0,0 +1,98 @@
<!doctype html>
<html>
<head>
<meta name="google" content="notranslate" />
<style>
body {
background: white;
color: black;
}
.test p {
margin: 1px;
}
.test {
font-family: monospace;
white-space: pre;
}
.err {
background: red;
color: white;
}
.passed {
background: green;
color: white;
}
</style>
</head>
<body>
<h1></h1>
<section class="test" id="test-res"></section>
<script>
var performance;
if (typeof performance !== 'object') {
performance = {
mark: function(s) { this[s] = new Date() },
measure: function(_t, s1, s2) { this.t = this[s2] - this[s1] },
getEntriesByName: function() { return [ { duration: this.t } ] }
};
}
var Module = { preRun: function() { performance.mark('bench_start') } };
function runTest(tname) {
var xhr, expected, hn, idx = 0, passed = true;
function outputReceived(e) {
var found = e.data;
var p = document.createElement('p');
if (found !== expected[idx++]) {
p.className = 'err';
passed = false;
}
p.appendChild(document.createTextNode(found));
document.getElementById('test-res').appendChild(p);
if (idx >= expected.length) {
if (passed) {
performance.mark('bench_end')
performance.measure('bench', 'bench_start', 'bench_end');
var duration = Math.round(performance.getEntriesByName('bench')[0].duration);
hn.appendChild(document.createTextNode(' - PASSED (time: ' + duration + ' ms)'));
hn.className = 'passed';
} else {
hn.appendChild(document.createTextNode(' - FAILED'));
hn.className = 'err';
}
}
}
hn = document.getElementsByTagName('h1')[0];
hn.appendChild(document.createTextNode('Test: ' + tname));
try {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {
xhr = new XMLHttpRequest();
}
xhr.open('GET', tname + '.exp');
xhr.onreadystatechange = function() {
if (xhr.readyState != 4 ||
(xhr.status != 200 && xhr.status != 302 && xhr.status != 0)) {
return;
}
expected = xhr.responseText.split('\n');
if (expected.length > 0 && expected[expected.length - 1] === '') {
expected.pop();
}
expected.push('--- SUCCESS ---');
window.addEventListener('test-output', outputReceived, false);
var s = document.getElementsByTagName('script')[0];
var st = document.createElement('script');
st.src = tname + '.js';
s.parentNode.insertBefore(st, s);
}
xhr.send(null);
}
runTest('{{tname}}');
</script>
</body>
</html>

71
deps/libsodium/test/default/kdf.c vendored Normal file
View File

@ -0,0 +1,71 @@
#define TEST_NAME "kdf"
#include "cmptest.h"
static void
tv_kdf(void)
{
unsigned char *master_key;
unsigned char *subkey;
char *context;
char hex[crypto_kdf_BYTES_MAX * 2 + 1];
uint64_t i;
int ret;
context = (char *) sodium_malloc(crypto_kdf_CONTEXTBYTES);
master_key = (unsigned char *) sodium_malloc(crypto_kdf_KEYBYTES);
memcpy(context, "KDF test", sizeof "KDF test" -1U);
for (i = 0; i < crypto_kdf_KEYBYTES; i++) {
master_key[i] = i;
}
subkey = (unsigned char *) sodium_malloc(crypto_kdf_BYTES_MAX);
for (i = 0; i < 10; i++) {
ret = crypto_kdf_derive_from_key(subkey, crypto_kdf_BYTES_MAX,
i, context, master_key);
assert(ret == 0);
sodium_bin2hex(hex, sizeof hex, subkey, crypto_kdf_BYTES_MAX);
printf("%s\n", hex);
}
sodium_free(subkey);
for (i = 0; i < crypto_kdf_BYTES_MAX + 2; i++) {
subkey = (unsigned char *) sodium_malloc(crypto_kdf_BYTES_MAX);
if (crypto_kdf_derive_from_key(subkey, (size_t) i,
i, context, master_key) == 0) {
sodium_bin2hex(hex, sizeof hex, subkey, (size_t) i);
printf("%s\n", hex);
} else {
printf("Failure -- probably expected for output length=%u\n",
(unsigned int) i);
}
sodium_free(subkey);
}
sodium_free(master_key);
sodium_free(context);
assert(strcmp(crypto_kdf_primitive(), crypto_kdf_PRIMITIVE) == 0);
assert(crypto_kdf_BYTES_MAX > 0);
assert(crypto_kdf_BYTES_MIN <= crypto_kdf_BYTES_MAX);
assert(crypto_kdf_bytes_min() == crypto_kdf_BYTES_MIN);
assert(crypto_kdf_bytes_max() == crypto_kdf_BYTES_MAX);
assert(crypto_kdf_CONTEXTBYTES > 0);
assert(crypto_kdf_contextbytes() == crypto_kdf_CONTEXTBYTES);
assert(crypto_kdf_KEYBYTES >= 16);
assert(crypto_kdf_keybytes() == crypto_kdf_KEYBYTES);
assert(crypto_kdf_bytes_min() == crypto_kdf_blake2b_bytes_min());
assert(crypto_kdf_bytes_max() == crypto_kdf_blake2b_bytes_max());
assert(crypto_kdf_contextbytes() == crypto_kdf_blake2b_contextbytes());
assert(crypto_kdf_keybytes() == crypto_kdf_blake2b_keybytes());
printf("tv_kdf: ok\n");
}
int
main(void)
{
tv_kdf();
return 0;
}

77
deps/libsodium/test/default/kdf.exp vendored Normal file
View File

@ -0,0 +1,77 @@
a0c724404728c8bb95e5433eb6a9716171144d61efb23e74b873fcbeda51d8071b5d70aae12066dfc94ce943f145aa176c055040c3dd73b0a15e36254d450614
02507f144fa9bf19010bf7c70b235b4c2663cc00e074f929602a5e2c10a780757d2a3993d06debc378a90efdac196dd841817b977d67b786804f6d3cd585bab5
1944da61ff18dc2028c3578ac85be904931b83860896598f62468f1cb5471c6a344c945dbc62c9aaf70feb62472d17775ea5db6ed5494c68b7a9a59761f39614
131c0ca1633ed074986215b264f6e0474f362c52b029effc7b0f75977ee89cc95d85c3db87f7e399197a25411592beeeb7e5128a74646a460ecd6deb4994b71e
a7023a0bf9be245d078aed26bcde0465ff0cc0961196a5482a0ff4ff8b4015971e13611f50529cb408f5776b14a90e7c3dd9160a22211db64ff4b5c0b9953680
50f49313f3a05b2e565c13feedb44daa675cafd42c2b2cf9edbce9c949fbfc3f175dcb738671509ae2ea66fb85e552394d479afa7fa3affe8791744796b94176
13b58d6d69780089293862cd59a1a8a4ef79bb850e3f3ba41fb22446a7dd1dc4da4667d37b33bf1225dcf8173c4c349a5d911c5bd2db9c5905ed70c11e809e3b
15d44b4b44ffa006eeceeb508c98a970aaa573d65905687b9e15854dec6d49c612757e149f78268f727660dedf9abce22a9691feb20a01b0525f4b47a3cf19db
9aebba11c5428ae8225716369e30a48943be39159a899f804e9963ef78822e186c21fe95bb0b85e60ef03a6f58d0b9d06e91f79d0ab998450b8810c73ca935b4
70f9b83e463fb441e7a4c43275125cd5b19d8e2e4a5d179a39f5db10bbce745a199104563d308cf8d4c6b27bbb759ded232f5bdb7c367dd632a9677320dfe416
Failure -- probably expected for output length=0
Failure -- probably expected for output length=1
Failure -- probably expected for output length=2
Failure -- probably expected for output length=3
Failure -- probably expected for output length=4
Failure -- probably expected for output length=5
Failure -- probably expected for output length=6
Failure -- probably expected for output length=7
Failure -- probably expected for output length=8
Failure -- probably expected for output length=9
Failure -- probably expected for output length=10
Failure -- probably expected for output length=11
Failure -- probably expected for output length=12
Failure -- probably expected for output length=13
Failure -- probably expected for output length=14
Failure -- probably expected for output length=15
a529216624ef9161e4cf117272aafff2
068bd6940b80c6cc2530a68c31d9f4e323
0acf4f6c74a590c8a1c0997ec9a1a3f48b2a
ac17a37ce74c0efece75f9337de20795dbadcc
268214dc9477a2e3c1022829f934ab992a5a3d84
33b76197b4531665e494760909eda1cc570e7da9bb
3d4efbc569ca7f858ad4f49c56b820986a406e6eebbc
983fea27520f507c40231f9557908f07c095bdf4a4ce5d
94d678717625e011995c7355f2092267dee47bf0722dd380
198901896c4f51e74ffa8b2805415c6eaba5accfc85a6e6b34
4ffabb81d49021f85ef5d2a713ab02ae86bc2e7d1522f5e077fe
eebc3d55b3f4fc8b64d2474063254da7db98e7398dfdd510e28075
22c134b9d664e1bdb14dc309a936bf1512b19e4f5175642efb1a0df7
4b179762bfc8e27a9e575113faa76247b9c046d6f22d5a02e2910a299b
abc45eb2b031307b8822c7e59a43f4108850c34a7445936bc848422251c4
d6565bd3265b6373f4f6a6b6458e981006da5e9d532ce94ca4737e188995e9
154b291f11196737f8b7f491e4ca11764e0227d34f94295408a869f007aa8618
e9dd395570e09ebb523ffc6ba098a38b17bc4944f14bd3725bdd7edbd8bcff54fb
7248294d37159e85bacde68c7762a673794c91b811e05f4e3b9e3ecc82bfcf63a2cd
d060ee4d93f8de6d9ae60fca9596413455183a1f83c7a2381227cec8f7a217e4072f85
20790290347b9b0f413a954f40e52e270b3b45417e96c8733161672188701c08dd76cc3d
7674188112a1ab8d3926d468be8e51d788ce4144bb20ff842034e4d1ddab3929a4f1a13a74
a2ab1f980a47472d8a539f20410cc9bf143d941331ab2259ea73684c0608939c5b23e9cbcb3d
f4cfbe3050f15ebbaf8d2f3bf3a678c01fc21ee1f4be07d0744c7fbf4835ea9d9472a3d785c24c
66efa5dfe3efd4cc8ca25f2d622c97a20a192d7add965f26b002b7eb81aae4203c0e5f07fd945845
ad5d8031055c96dc9db10285206d7edc38d3af85736df8a3b5fdd30a318e80c28d9b26c95a60fa3e68
9107c8a57a2c9ca40158f33ca0bfb64c095d2f21ca98bb7138477599330a36cdfc2ae5751e370d0e024e
b0c190177358b955ebebc5e0b86ec91dde3b6f1982ea4d68ec5ec3bdd6527c362e5275600b263601c98452
31bfaaad4adde0f87d87372e398c42cb7befe065ab2957ebb91ef9dc534b410783899b2e1e84221286f3bab4
2258dd1f3e516cb8e3d1f6c45808573c365192f073698939721af8961a02a8bdd002a31fd239b9498663a01f27
7c7a88016610493bb44a9432a88b50f97e2e94383972ff95da826692d96c52d82f86899b3561ec9c95a8b1bf3213
3929dc7473be4c633be9e08801a8abd284dc0c6154c5c81a4c18259699dd86753c5e14fbd723be46ebb04f4ab3058c
30b720220015fa60daa69c83f9754d772b1b2dd12ab6baaa2f4edab458d4d251c1cddb8c4a554f3eb13969316b890fbd
33fa2412a5c3294d49e964419e96d043a2099a72b3351e3bed0f07e12255c95b509ea9bf2963a4c0fe9cc2314dbc44f673
ca891d2c82a6a8f833dc1a05f190bab6de221307eab1dd2c88341d4d2537a2fc0056b0d04d8104fd3fe89e1ea20877893e81
fd78ac89a64d03672ad99d663f2613d15277cda1636e334a1706b7211ff1f3a3b3d2e671e391c75e3d242c482ce7e1b8b427ed
36a6072743d3aafd3ee89344b9ef92cb58a2853ae92b20283520439fcb55afffd3d4b5e4e8c92a85d3cf74497bdcf68bbf1fcf93
a90afcfaffec1105ad05fdaa9473fb5daf1bf8fb376b7326db46ef4c120c553188c69131933371d409eb56d66d5adca618e1dac65b
9b990d1fcddbdb5e5c7a48a6a2a666e02e7d4d4a814ece40660d99e1c02d5f023c56ae82526fc6dc8c933d0add92fc376efcddd55a42
ec545dcf456d1b0907c07418a42bf2b3d668b4797ba6874bf0d563f5f429a820f02177dd4d05e639a06807c9619fee54ffe07712493543
b0106957626894586682a275f69ed4533e2f94334cc0430394b68d82679aca00dd579e712bdd2d7f5bbce9a050269739bd8427b75b06027f
05751bfeebb480c9bca0d25d8197e2673845f405d7fb9793e29169ac19956c525f6e637f3d5ea50597b04342afed4ca16f988b4f21a34f1902
7b4e4294d3f64085b5c09be73548f1f5cb5c6f04e57ce6cdd3077e2fb37640bf1ca0c6393b87d48a6b7e3e42628bd30fca132ded03ce51f71d9d
082d248862cbfd71a634769a4b1cf52a4af47ace5b9ea4d583ca52207efc7234a6d321788130cbdec122579ad03afe00bc68c9fb3f68dd0532a96f
a2b39b4428d981013e8a9c0e41b3eed504983fc18dc4b60332b1ab28b9705228147bdb95cc17889d5f0f9cfb7fd16f9d414b1a829346a8922e945b40
efbf0f8bda1b9ef24fe389f1cf0c0c8a08bca03fc95badabb79a487d8ce1351683f59183aa6229f880d69ad60114ac128f69b2be250109972ab1f3fc3b
dfe0ba2a6de25fa06b47375e9d9cf6c6fa1493a8a2a81c28d6e09bc161057b445659db76e92e349ff44f34a2a9e3bcaa6b84b21bae56f1499c170ab81af0
02f9cbdb10759314515b01379c474ad74a1b575137bd3949776dbcfc3e18060cb13ee1f6dcf86035768fc7be63e01de321cacbfade209900dd94273fd8e176
06ae14308eeeda62a00cb6d5edf18d1707029515db98f472bbf0617419301b1d4f4f2ab65849446be46f87e1d31c6c74283897b9976f70d8a16253ac927e0d9f
Failure -- probably expected for output length=65
tv_kdf: ok

67
deps/libsodium/test/default/keygen.c vendored Normal file
View File

@ -0,0 +1,67 @@
#define TEST_NAME "keygen"
#include "cmptest.h"
typedef struct KeygenTV_ {
void (*fn)(unsigned char *k);
size_t key_len;
} KeygenTV;
static void
tv_keygen(void)
{
static const KeygenTV tvs[] = {
{ crypto_auth_keygen, crypto_auth_KEYBYTES },
{ crypto_auth_hmacsha256_keygen, crypto_auth_hmacsha256_KEYBYTES },
{ crypto_aead_aes256gcm_keygen, crypto_aead_aes256gcm_KEYBYTES },
{ crypto_auth_hmacsha512_keygen, crypto_auth_hmacsha512_KEYBYTES },
{ crypto_auth_hmacsha512256_keygen, crypto_auth_hmacsha512256_KEYBYTES },
{ crypto_generichash_keygen, crypto_generichash_KEYBYTES },
{ crypto_generichash_blake2b_keygen, crypto_generichash_blake2b_KEYBYTES },
{ crypto_kdf_keygen, crypto_kdf_KEYBYTES },
{ crypto_onetimeauth_keygen, crypto_onetimeauth_KEYBYTES },
{ crypto_onetimeauth_poly1305_keygen, crypto_onetimeauth_poly1305_KEYBYTES },
{ crypto_aead_chacha20poly1305_ietf_keygen, crypto_aead_chacha20poly1305_ietf_KEYBYTES },
{ crypto_aead_chacha20poly1305_keygen, crypto_aead_chacha20poly1305_KEYBYTES },
{ crypto_aead_chacha20poly1305_ietf_keygen, crypto_aead_chacha20poly1305_ietf_KEYBYTES },
{ crypto_aead_xchacha20poly1305_ietf_keygen, crypto_aead_xchacha20poly1305_ietf_KEYBYTES },
{ crypto_secretbox_xsalsa20poly1305_keygen, crypto_secretbox_xsalsa20poly1305_KEYBYTES },
{ crypto_secretbox_keygen, crypto_secretbox_KEYBYTES },
{ crypto_secretstream_xchacha20poly1305_keygen, crypto_secretstream_xchacha20poly1305_KEYBYTES },
{ crypto_shorthash_keygen, crypto_shorthash_KEYBYTES },
{ crypto_stream_keygen, crypto_stream_KEYBYTES },
{ crypto_stream_chacha20_keygen, crypto_stream_chacha20_KEYBYTES },
{ crypto_stream_chacha20_ietf_keygen, crypto_stream_chacha20_ietf_KEYBYTES },
{ crypto_stream_salsa20_keygen, crypto_stream_salsa20_KEYBYTES },
{ crypto_stream_xsalsa20_keygen, crypto_stream_xsalsa20_KEYBYTES }
};
const KeygenTV *tv;
unsigned char *key;
size_t i;
int j;
for (i = 0; i < (sizeof tvs) / (sizeof tvs[0]); i++) {
tv = &tvs[i];
key = (unsigned char *) sodium_malloc(tv->key_len);
key[tv->key_len - 1U] = 0;
for (j = 0; j < 10000; j++) {
tv->fn(key);
if (key[tv->key_len - 1U] != 0) {
break;
}
}
sodium_free(key);
if (j >= 10000) {
printf("Buffer underflow with test vector %u\n", (unsigned int) i);
}
}
printf("tv_keygen: ok\n");
}
int
main(void)
{
tv_keygen();
return 0;
}

View File

@ -0,0 +1 @@
tv_keygen: ok

149
deps/libsodium/test/default/kx.c vendored Normal file
View File

@ -0,0 +1,149 @@
#define TEST_NAME "kx"
#include "cmptest.h"
static const unsigned char small_order_p[crypto_scalarmult_BYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00
};
static void
tv_kx(void)
{
unsigned char *seed;
unsigned char *client_pk, *client_sk;
unsigned char *client_rx, *client_tx;
unsigned char *server_pk, *server_sk;
unsigned char *server_rx, *server_tx;
char hex[65];
int i;
seed = (unsigned char *) sodium_malloc(crypto_kx_SEEDBYTES);
for (i = 0; i < crypto_kx_SEEDBYTES; i++) {
seed[i] = (unsigned char) i;
}
client_pk = (unsigned char *) sodium_malloc(crypto_kx_PUBLICKEYBYTES);
client_sk = (unsigned char *) sodium_malloc(crypto_kx_SECRETKEYBYTES);
crypto_kx_seed_keypair(client_pk, client_sk, seed);
sodium_bin2hex(hex, sizeof hex, client_pk, crypto_kx_PUBLICKEYBYTES);
printf("client_pk: [%s]\n", hex);
sodium_bin2hex(hex, sizeof hex, client_sk, crypto_kx_SECRETKEYBYTES);
printf("client_sk: [%s]\n", hex);
server_pk = (unsigned char *) sodium_malloc(crypto_kx_PUBLICKEYBYTES);
server_sk = (unsigned char *) sodium_malloc(crypto_kx_SECRETKEYBYTES);
crypto_kx_keypair(server_pk, server_sk);
client_rx = (unsigned char *) sodium_malloc(crypto_kx_SESSIONKEYBYTES);
client_tx = (unsigned char *) sodium_malloc(crypto_kx_SESSIONKEYBYTES);
assert(crypto_kx_client_session_keys(client_rx, client_tx,
client_pk, client_sk,
small_order_p) == -1);
if (crypto_kx_client_session_keys(client_rx, client_tx,
client_pk, client_sk, server_pk) != 0) {
printf("crypto_kx_client_session_keys() failed\n");
}
server_rx = (unsigned char *) sodium_malloc(crypto_kx_SESSIONKEYBYTES);
server_tx = (unsigned char *) sodium_malloc(crypto_kx_SESSIONKEYBYTES);
assert(crypto_kx_server_session_keys(server_rx, server_tx,
server_pk, server_sk,
small_order_p) == -1);
if (crypto_kx_server_session_keys(server_rx, server_tx,
server_pk, server_sk, client_pk) != 0) {
printf("crypto_kx_server_session_keys() failed\n");
}
if (memcmp(server_rx, client_tx, crypto_kx_SESSIONKEYBYTES) != 0 ||
memcmp(server_tx, client_rx, crypto_kx_SESSIONKEYBYTES) != 0) {
printf("client session keys != server session keys\n");
}
sodium_increment(client_pk, crypto_kx_PUBLICKEYBYTES);
if (crypto_kx_server_session_keys(server_rx, server_tx,
server_pk, server_sk, client_pk) != 0) {
printf("crypto_kx_server_session_keys() failed\n");
}
if (memcmp(server_rx, client_tx, crypto_kx_SESSIONKEYBYTES) == 0 &&
memcmp(server_tx, client_rx, crypto_kx_SESSIONKEYBYTES) == 0) {
printf("peer's public key is ignored\n");
}
crypto_kx_keypair(client_pk, client_sk);
if (crypto_kx_server_session_keys(server_rx, server_tx,
server_pk, server_sk, client_pk) != 0) {
printf("crypto_kx_server_session_keys() failed\n");
}
if (memcmp(server_rx, client_tx, crypto_kx_SESSIONKEYBYTES) == 0 ||
memcmp(server_tx, client_rx, crypto_kx_SESSIONKEYBYTES) == 0) {
printf("session keys are constant\n");
}
crypto_kx_seed_keypair(client_pk, client_sk, seed);
sodium_increment(seed, crypto_kx_SEEDBYTES);
crypto_kx_seed_keypair(server_pk, server_sk, seed);
if (crypto_kx_server_session_keys(server_rx, server_tx,
server_pk, server_sk, client_pk) != 0) {
printf("crypto_kx_server_session_keys() failed\n");
}
sodium_bin2hex(hex, sizeof hex, server_rx, crypto_kx_SESSIONKEYBYTES);
printf("server_rx: [%s]\n", hex);
sodium_bin2hex(hex, sizeof hex, server_tx, crypto_kx_SESSIONKEYBYTES);
printf("server_tx: [%s]\n", hex);
if (crypto_kx_client_session_keys(client_rx, client_tx,
client_pk, client_sk, server_pk) != 0) {
printf("crypto_kx_client_session_keys() failed\n");
}
sodium_bin2hex(hex, sizeof hex, client_rx, crypto_kx_SESSIONKEYBYTES);
printf("client_rx: [%s]\n", hex);
sodium_bin2hex(hex, sizeof hex, client_tx, crypto_kx_SESSIONKEYBYTES);
printf("client_tx: [%s]\n", hex);
randombytes_buf(client_rx, crypto_kx_SESSIONKEYBYTES);
randombytes_buf(client_tx, crypto_kx_SESSIONKEYBYTES);
randombytes_buf(server_rx, crypto_kx_SESSIONKEYBYTES);
randombytes_buf(server_tx, crypto_kx_SESSIONKEYBYTES);
if (crypto_kx_client_session_keys(client_rx, NULL,
client_pk, client_sk, server_pk) != 0 ||
crypto_kx_client_session_keys(NULL, client_tx,
client_pk, client_sk, server_pk) != 0 ||
crypto_kx_server_session_keys(server_rx, NULL,
server_pk, server_sk, client_pk) != 0 ||
crypto_kx_server_session_keys(NULL, server_tx,
server_pk, server_sk, client_pk) != 0) {
printf("failure when one of the pointers happens to be NULL");
}
assert(memcmp(client_rx, client_tx, crypto_kx_SESSIONKEYBYTES) == 0);
assert(memcmp(client_tx, server_rx, crypto_kx_SESSIONKEYBYTES) == 0);
assert(memcmp(server_rx, server_tx, crypto_kx_SESSIONKEYBYTES) == 0);
sodium_free(client_rx);
sodium_free(client_tx);
sodium_free(server_rx);
sodium_free(server_tx);
sodium_free(server_sk);
sodium_free(server_pk);
sodium_free(client_sk);
sodium_free(client_pk);
sodium_free(seed);
assert(strcmp(crypto_kx_primitive(), crypto_kx_PRIMITIVE) == 0);
assert(crypto_kx_publickeybytes() == crypto_kx_PUBLICKEYBYTES);
assert(crypto_kx_secretkeybytes() == crypto_kx_SECRETKEYBYTES);
assert(crypto_kx_seedbytes() == crypto_kx_SEEDBYTES);
assert(crypto_kx_sessionkeybytes() == crypto_kx_SESSIONKEYBYTES);
printf("tv_kx: ok\n");
}
int
main(void)
{
tv_kx();
return 0;
}

7
deps/libsodium/test/default/kx.exp vendored Normal file
View File

@ -0,0 +1,7 @@
client_pk: [0e0216223f147143d32615a91189c288c1728cba3cc5f9f621b1026e03d83129]
client_sk: [cb2f5160fc1f7e05a55ef49d340b48da2e5a78099d53393351cd579dd42503d6]
server_rx: [62c8f4fa81800abd0577d99918d129b65deb789af8c8351f391feb0cbf238604]
server_tx: [749519c68059bce69f7cfcc7b387a3de1a1e8237d110991323bf62870115731a]
client_rx: [749519c68059bce69f7cfcc7b387a3de1a1e8237d110991323bf62870115731a]
client_tx: [62c8f4fa81800abd0577d99918d129b65deb789af8c8351f391feb0cbf238604]
tv_kx: ok

View File

@ -0,0 +1,187 @@
#define TEST_NAME "metamorphic"
#include "cmptest.h"
#define MAXLEN 512
#define MAX_ITER 1000
static void
mm_generichash(void)
{
crypto_generichash_state st;
unsigned char *h, *h2;
unsigned char *k;
unsigned char *m;
size_t hlen;
size_t klen;
size_t mlen;
size_t l1, l2;
int i;
for (i = 0; i < MAX_ITER; i++) {
mlen = randombytes_uniform(MAXLEN);
m = (unsigned char *) sodium_malloc(mlen);
klen = randombytes_uniform(crypto_generichash_KEYBYTES_MAX -
crypto_generichash_KEYBYTES_MIN + 1U)
+ crypto_generichash_KEYBYTES_MIN;
k = (unsigned char *) sodium_malloc(klen);
hlen = randombytes_uniform(crypto_generichash_BYTES_MAX -
crypto_generichash_BYTES_MIN + 1U)
+ crypto_generichash_BYTES_MIN;
h = (unsigned char *) sodium_malloc(hlen);
h2 = (unsigned char *) sodium_malloc(hlen);
randombytes_buf(k, klen);
randombytes_buf(m, mlen);
crypto_generichash_init(&st, k, klen, hlen);
l1 = randombytes_uniform((uint32_t) mlen);
l2 = randombytes_uniform((uint32_t) (mlen - l1));
crypto_generichash_update(&st, m, l1);
crypto_generichash_update(&st, m + l1, l2);
crypto_generichash_update(&st, m + l1 + l2, mlen - l1 - l2);
crypto_generichash_final(&st, h, hlen);
crypto_generichash(h2, hlen, m, mlen, k, klen);
assert(memcmp(h, h2, hlen) == 0);
sodium_free(h2);
sodium_free(h);
sodium_free(k);
sodium_free(m);
}
}
static void
mm_onetimeauth(void)
{
crypto_onetimeauth_state st;
unsigned char *h, *h2;
unsigned char *k;
unsigned char *m;
size_t mlen;
size_t l1, l2;
int i;
for (i = 0; i < MAX_ITER; i++) {
mlen = randombytes_uniform(MAXLEN);
m = (unsigned char *) sodium_malloc(mlen);
k = (unsigned char *) sodium_malloc(crypto_onetimeauth_KEYBYTES);
h = (unsigned char *) sodium_malloc(crypto_onetimeauth_BYTES);
h2 = (unsigned char *) sodium_malloc(crypto_onetimeauth_BYTES);
crypto_onetimeauth_keygen(k);
randombytes_buf(m, mlen);
crypto_onetimeauth_init(&st, k);
l1 = randombytes_uniform((uint32_t) mlen);
l2 = randombytes_uniform((uint32_t) (mlen - l1));
crypto_onetimeauth_update(&st, m, l1);
crypto_onetimeauth_update(&st, m + l1, l2);
crypto_onetimeauth_update(&st, m + l1 + l2, mlen - l1 - l2);
crypto_onetimeauth_final(&st, h);
crypto_onetimeauth(h2, m, mlen, k);
assert(memcmp(h, h2, crypto_onetimeauth_BYTES) == 0);
sodium_free(h2);
sodium_free(h);
sodium_free(k);
sodium_free(m);
}
}
static void
mm_hmacsha256(void)
{
crypto_auth_hmacsha256_state st;
unsigned char *h, *h2;
unsigned char *k;
unsigned char *m;
size_t mlen;
size_t l1, l2;
int i;
for (i = 0; i < MAX_ITER; i++) {
mlen = randombytes_uniform(MAXLEN);
m = (unsigned char *) sodium_malloc(mlen);
k = (unsigned char *) sodium_malloc(crypto_auth_hmacsha256_KEYBYTES);
h = (unsigned char *) sodium_malloc(crypto_auth_hmacsha256_BYTES);
h2 = (unsigned char *) sodium_malloc(crypto_auth_hmacsha256_BYTES);
crypto_auth_hmacsha256_keygen(k);
randombytes_buf(m, mlen);
crypto_auth_hmacsha256_init(&st, k, crypto_auth_hmacsha256_KEYBYTES);
l1 = randombytes_uniform((uint32_t) mlen);
l2 = randombytes_uniform((uint32_t) (mlen - l1));
crypto_auth_hmacsha256_update(&st, m, l1);
crypto_auth_hmacsha256_update(&st, m + l1, l2);
crypto_auth_hmacsha256_update(&st, m + l1 + l2, mlen - l1 - l2);
crypto_auth_hmacsha256_final(&st, h);
crypto_auth_hmacsha256(h2, m, mlen, k);
assert(memcmp(h, h2, crypto_auth_hmacsha256_BYTES) == 0);
sodium_free(h2);
sodium_free(h);
sodium_free(k);
sodium_free(m);
}
}
static void
mm_hmacsha512(void)
{
crypto_auth_hmacsha512_state st;
unsigned char *h, *h2;
unsigned char *k;
unsigned char *m;
size_t mlen;
size_t l1, l2;
int i;
for (i = 0; i < MAX_ITER; i++) {
mlen = randombytes_uniform(MAXLEN);
m = (unsigned char *) sodium_malloc(mlen);
k = (unsigned char *) sodium_malloc(crypto_auth_hmacsha512_KEYBYTES);
h = (unsigned char *) sodium_malloc(crypto_auth_hmacsha512_BYTES);
h2 = (unsigned char *) sodium_malloc(crypto_auth_hmacsha512_BYTES);
crypto_auth_hmacsha512_keygen(k);
randombytes_buf(m, mlen);
crypto_auth_hmacsha512_init(&st, k, crypto_auth_hmacsha512_KEYBYTES);
l1 = randombytes_uniform((uint32_t) mlen);
l2 = randombytes_uniform((uint32_t) (mlen - l1));
crypto_auth_hmacsha512_update(&st, m, l1);
crypto_auth_hmacsha512_update(&st, m + l1, l2);
crypto_auth_hmacsha512_update(&st, m + l1 + l2, mlen - l1 - l2);
crypto_auth_hmacsha512_final(&st, h);
crypto_auth_hmacsha512(h2, m, mlen, k);
assert(memcmp(h, h2, crypto_auth_hmacsha512_BYTES) == 0);
sodium_free(h2);
sodium_free(h);
sodium_free(k);
sodium_free(m);
}
}
int
main(void)
{
mm_generichash();
mm_onetimeauth();
mm_hmacsha256();
mm_hmacsha512();
printf("OK\n");
return 0;
}

View File

@ -0,0 +1 @@
OK

184
deps/libsodium/test/default/misuse.c vendored Normal file
View File

@ -0,0 +1,184 @@
#define TEST_NAME "misuse"
#include "cmptest.h"
#ifdef HAVE_CATCHABLE_ABRT
# include <signal.h>
static void
sigabrt_handler_15(int sig)
{
(void) sig;
exit(0);
}
# ifndef SODIUM_LIBRARY_MINIMAL
static void
sigabrt_handler_14(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_15);
assert(crypto_box_curve25519xchacha20poly1305_easy
(guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
guard_page, guard_page, guard_page) == -1);
exit(1);
}
static void
sigabrt_handler_13(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_14);
assert(crypto_box_curve25519xchacha20poly1305_easy_afternm
(guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
guard_page, guard_page) == -1);
exit(1);
}
# endif
static void
sigabrt_handler_12(int sig)
{
(void) sig;
# ifdef SODIUM_LIBRARY_MINIMAL
signal(SIGABRT, sigabrt_handler_15);
# else
signal(SIGABRT, sigabrt_handler_13);
# endif
assert(crypto_pwhash_str_alg((char *) guard_page,
"", 0U, 1U, 1U, -1) == -1);
exit(1);
}
static void
sigabrt_handler_11(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_12);
assert(crypto_box_easy(guard_page, guard_page,
crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
guard_page, guard_page, guard_page) == -1);
exit(1);
}
static void
sigabrt_handler_10(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_11);
assert(crypto_box_easy_afternm(guard_page, guard_page,
crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
guard_page, guard_page) == -1);
exit(1);
}
static void
sigabrt_handler_9(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_10);
assert(sodium_base642bin(guard_page, 1, (const char *) guard_page, 1,
NULL, NULL, NULL, -1) == -1);
exit(1);
}
static void
sigabrt_handler_8(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_9);
assert(sodium_bin2base64((char *) guard_page, 1, guard_page, 1,
sodium_base64_VARIANT_ORIGINAL) == NULL);
exit(1);
}
static void
sigabrt_handler_7(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_8);
assert(sodium_bin2base64((char *) guard_page, 1,
guard_page, 1, -1) == NULL);
exit(1);
}
static void
sigabrt_handler_6(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_7);
assert(sodium_pad(NULL, guard_page, SIZE_MAX, 16, 1) == -1);
exit(1);
}
static void
sigabrt_handler_5(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_6);
assert(crypto_aead_xchacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
NULL, 0, NULL,
guard_page, guard_page) == -1);
exit(1);
}
static void
sigabrt_handler_4(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_5);
assert(crypto_aead_chacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
NULL, 0, NULL,
guard_page, guard_page) == -1);
exit(1);
}
static void
sigabrt_handler_3(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_4);
assert(crypto_aead_chacha20poly1305_encrypt(guard_page, NULL, NULL, UINT64_MAX,
NULL, 0, NULL,
guard_page, guard_page) == -1);
exit(1);
}
static void
sigabrt_handler_2(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_3);
#if SIZE_MAX > 0x4000000000ULL
randombytes_buf_deterministic(guard_page, 0x4000000001ULL, guard_page);
#else
abort();
#endif
exit(1);
}
static void
sigabrt_handler_1(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_2);
assert(crypto_kx_server_session_keys(NULL, NULL, guard_page, guard_page,
guard_page) == -1);
exit(1);
}
int
main(void)
{
signal(SIGABRT, sigabrt_handler_1);
assert(crypto_kx_client_session_keys(NULL, NULL, guard_page, guard_page,
guard_page) == -1);
return 1;
}
#else
int
main(void)
{
return 0;
}
#endif

View File

View File

@ -0,0 +1,63 @@
#define TEST_NAME "onetimeauth"
#include "cmptest.h"
static unsigned char rs[32] = {
0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, 0x6d, 0x11, 0xc2,
0xcb, 0x21, 0x4d, 0x3c, 0x25, 0x25, 0x39, 0x12, 0x1d, 0x8e, 0x23,
0x4e, 0x65, 0x2d, 0x65, 0x1f, 0xa4, 0xc8, 0xcf, 0xf8, 0x80
};
static unsigned char c[131] = {
0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, 0xc2, 0x96, 0x50, 0xba,
0x32, 0xfc, 0x76, 0xce, 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4,
0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a, 0xc0, 0xdf, 0xc1, 0x7c,
0x98, 0xdc, 0xe8, 0x7b, 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72,
0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2, 0x27, 0x0d, 0x6f, 0xb8,
0x63, 0xd5, 0x17, 0x38, 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a,
0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae, 0x90, 0x22, 0x43, 0x68,
0x51, 0x7a, 0xcf, 0xea, 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda,
0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde, 0x56, 0x24, 0x4a, 0x9e,
0x88, 0xd5, 0xf9, 0xb3, 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6,
0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74, 0xe3, 0x55, 0xa5
};
static unsigned char a[16];
int
main(void)
{
crypto_onetimeauth_state st;
int i;
assert(crypto_onetimeauth_statebytes() == sizeof st);
crypto_onetimeauth(a, c, 131, rs);
for (i = 0; i < 16; ++i) {
printf(",0x%02x", (unsigned int) a[i]);
if (i % 8 == 7)
printf("\n");
}
memset(a, 0, sizeof a);
crypto_onetimeauth_init(&st, rs);
crypto_onetimeauth_update(&st, c, 100);
crypto_onetimeauth_update(&st, c, 0);
crypto_onetimeauth_update(&st, c + 100, 31);
crypto_onetimeauth_final(&st, a);
for (i = 0; i < 16; ++i) {
printf(",0x%02x", (unsigned int) a[i]);
if (i % 8 == 7)
printf("\n");
}
assert(crypto_onetimeauth_bytes() > 0U);
assert(crypto_onetimeauth_keybytes() > 0U);
assert(strcmp(crypto_onetimeauth_primitive(), "poly1305") == 0);
assert(crypto_onetimeauth_poly1305_bytes() == crypto_onetimeauth_bytes());
assert(crypto_onetimeauth_poly1305_keybytes() ==
crypto_onetimeauth_keybytes());
assert(crypto_onetimeauth_statebytes() > 0);
assert(crypto_onetimeauth_statebytes() == crypto_onetimeauth_poly1305_statebytes());
return 0;
}

View File

@ -0,0 +1,4 @@
,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9

View File

@ -0,0 +1,33 @@
#define TEST_NAME "onetimeauth2"
#include "cmptest.h"
static unsigned char rs[32] = {
0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, 0x6d, 0x11, 0xc2,
0xcb, 0x21, 0x4d, 0x3c, 0x25, 0x25, 0x39, 0x12, 0x1d, 0x8e, 0x23,
0x4e, 0x65, 0x2d, 0x65, 0x1f, 0xa4, 0xc8, 0xcf, 0xf8, 0x80
};
static unsigned char c[131] = {
0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, 0xc2, 0x96, 0x50, 0xba,
0x32, 0xfc, 0x76, 0xce, 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4,
0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a, 0xc0, 0xdf, 0xc1, 0x7c,
0x98, 0xdc, 0xe8, 0x7b, 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72,
0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2, 0x27, 0x0d, 0x6f, 0xb8,
0x63, 0xd5, 0x17, 0x38, 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a,
0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae, 0x90, 0x22, 0x43, 0x68,
0x51, 0x7a, 0xcf, 0xea, 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda,
0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde, 0x56, 0x24, 0x4a, 0x9e,
0x88, 0xd5, 0xf9, 0xb3, 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6,
0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74, 0xe3, 0x55, 0xa5
};
static unsigned char a[16] = { 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9 };
int
main(void)
{
printf("%d\n", crypto_onetimeauth_verify(a, c, 131, rs));
return 0;
}

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,36 @@
#define TEST_NAME "onetimeauth7"
#include "cmptest.h"
static unsigned char key[32];
static unsigned char c[1000];
static unsigned char a[16];
int
main(void)
{
int clen;
for (clen = 0; clen < 1000; ++clen) {
crypto_onetimeauth_keygen(key);
randombytes_buf(c, clen);
crypto_onetimeauth(a, c, clen, key);
if (crypto_onetimeauth_verify(a, c, clen, key) != 0) {
printf("fail %d\n", clen);
return 100;
}
if (clen > 0) {
c[rand() % clen] += 1 + (rand() % 255);
if (crypto_onetimeauth_verify(a, c, clen, key) == 0) {
printf("forgery %d\n", clen);
return 100;
}
a[rand() % sizeof a] += 1 + (rand() % 255);
if (crypto_onetimeauth_verify(a, c, clen, key) == 0) {
printf("forgery %d\n", clen);
return 100;
}
}
}
return 0;
}

View File

22
deps/libsodium/test/default/pre.js.inc vendored Executable file
View File

@ -0,0 +1,22 @@
try {
this['Module'] = Module;
Module.test;
} catch(e) {
this['Module'] = Module = {};
}
if (typeof process === 'object') {
if (typeof(FS) === 'object') {
Module['preRun'] = Module['preRun'] || [];
Module['preRun'].push(function() {
FS.init();
FS.mkdir('/test-data');
FS.mount(NODEFS, { root: '.' }, '/test-data');
});
}
} else {
Module['print'] = function(x) {
var event = new Event('test-output');
event.data = x;
window.dispatchEvent(event);
};
}

View File

@ -0,0 +1,453 @@
#define TEST_NAME "pwhash_argon2i"
#include "cmptest.h"
#define OUT_LEN 128
#define OPSLIMIT 3
#define MEMLIMIT 5000000
static void
tv(void)
{
static struct {
const char * passwd_hex;
size_t passwd_len;
const char * salt_hex;
size_t outlen;
unsigned long long opslimit;
size_t memlimit;
unsigned int lanes;
} tests[] = {
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 5, 7256678, 1 },
{ "e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed"
"9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e0"
"0cc2890277f0fd3c622115772f7048adaebed86e",
86,
"f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d",
250, 4, 7849083, 1 },
{ "92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3"
"b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392"
"be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0"
"441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f491"
"5d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746"
"711f58c8c392016b2fdfc09c64f0f6b6ab7b",
183,
"3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194",
249, 3, 7994791, 1 },
{ "027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3"
"b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b64"
"51a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53"
"f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce6"
"9bb078ed1f0d31e7f9b8062409f37f19f8550aae",
152,
"eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5", 5,
4, 1397645, 1 },
{ "4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82"
"ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d"
"43ced68642bfb8bbbdd0f50b30118f5e",
82,
"39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258",
190, 3, 1432947, 1 },
{ "c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba"
"9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e82"
"61cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe"
"02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e"
"089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f",
156,
"039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6",
178, 3, 4886999, 1 },
{ "b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f1"
"7b",
34,
"44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb",
231, 1, 1631659, 1 },
{ "a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f"
"7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63"
"d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c"
"496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb6"
"76a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b30"
"1560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d"
"55a3b4169f22cccb0745a2689407ea1901a0a766eb99",
220,
"3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf",
167, 3, 1784128, 1 },
};
char passwd[256];
unsigned char salt[crypto_pwhash_SALTBYTES];
unsigned char out[256];
char out_hex[256 * 2 + 1];
size_t i = 0U;
do {
sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen, passwd,
tests[i].passwd_len, (const unsigned char *) salt,
tests[i].opslimit, tests[i].memlimit,
crypto_pwhash_alg_argon2i13()) != 0) {
printf("[tv] pwhash failure (maybe intentional): [%u]\n",
(unsigned int) i);
continue;
}
sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
printf("%s\n", out_hex);
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
tv2(void)
{
static struct {
const char * passwd_hex;
size_t passwd_len;
const char * salt_hex;
size_t outlen;
unsigned long long opslimit;
size_t memlimit;
unsigned int lanes;
} tests[] = {
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 4, 397645, 1 },
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 3, 397645, 1 },
};
char passwd[256];
unsigned char salt[crypto_pwhash_SALTBYTES];
unsigned char out[256];
char out_hex[256 * 2 + 1];
size_t i = 0U;
do {
sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen, passwd,
tests[i].passwd_len, (const unsigned char *) salt,
tests[i].opslimit, tests[i].memlimit,
crypto_pwhash_alg_argon2i13()) != 0) {
printf("[tv2] pwhash failure: [%u]\n", (unsigned int) i);
continue;
}
sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
printf("%s\n", out_hex);
} while (++i < (sizeof tests) / (sizeof tests[0]));
if (crypto_pwhash(out, sizeof out, "password", strlen("password"), salt, 3,
1ULL << 12, 0) != -1) {
printf("[tv2] pwhash should have failed (0)\n");
}
if (crypto_pwhash_argon2i(out, sizeof out, "password", strlen("password"), salt, 3,
1ULL << 12, 0) != -1) {
printf("[tv2] pwhash should have failed (0')\n");
}
if (crypto_pwhash(out, sizeof out, "password", strlen("password"), salt, 3,
1, crypto_pwhash_alg_argon2i13()) != -1) {
printf("[tv2] pwhash should have failed (1)\n");
}
if (crypto_pwhash(out, sizeof out, "password", strlen("password"), salt, 3,
1ULL << 12, crypto_pwhash_alg_argon2i13()) != -1) {
printf("[tv2] pwhash should have failed (2)\n");
}
if (crypto_pwhash(out, sizeof out, "password", strlen("password"), salt, 2,
1ULL << 12, crypto_pwhash_alg_argon2i13()) != -1) {
printf("[tv2] pwhash should have failed (3)\n");
}
if (crypto_pwhash(out, 15, "password", strlen("password"), salt, 3,
1ULL << 12, crypto_pwhash_alg_argon2i13()) != -1) {
printf("[tv2] pwhash with a short output length should have failed\n");
}
if (crypto_pwhash(out, sizeof out, "password", 0x100000000ULL, salt, 3,
1ULL << 12, crypto_pwhash_alg_argon2i13()) != -1) {
printf("[tv2] pwhash with a long password length should have failed\n");
}
assert(crypto_pwhash_argon2i(out, sizeof out, "password", strlen("password"), salt,
OPSLIMIT, MEMLIMIT, crypto_pwhash_alg_argon2id13()) == -1);
}
static void
tv3(void)
{
static struct {
const char *passwd;
const char *out;
} tests[] = {
{ "",
"$argon2i$v=19$m=4096,t=1,p=1$X1NhbHQAAAAAAAAAAAAAAA$bWh++"
"MKN1OiFHKgIWTLvIi1iHicmHH7+Fv3K88ifFfI" },
{ "",
"$argon2i$v=19$m=2048,t=4,p=1$SWkxaUhpY21ISDcrRnYzSw$Mbg/"
"Eck1kpZir5T9io7C64cpffdTBaORgyriLQFgQj8" },
{ "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg ",
"$argon2i$v=19$m=4096,t=3,p=2$X1NhbHQAAAAAAAAAAAAAAA$z/QMiU4lQxGsYNc/"
"+K/bizwsA1P11UG2dj/7+aILJ4I" },
{ "K3S=KyH#)36_?]LxeR8QNKw6X=gFbxai$C%29V*",
"$argon2i$v=19$m=4096,t=3,p=1$X1NhbHQAAAAAAAAAAAAAAA$fu2Wsecyt+"
"yPnBvSvYN16oP5ozRmkp0ixJ1YL19V3Uo" }
};
char *out;
char *passwd;
size_t i = 0U;
int ret;
do {
out = (char *) sodium_malloc(strlen(tests[i].out) + 1U);
assert(out != NULL);
memcpy(out, tests[i].out, strlen(tests[i].out) + 1U);
passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
assert(passwd != NULL);
memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U);
ret = crypto_pwhash_str_verify(out, passwd, strlen(passwd));
sodium_free(out);
sodium_free(passwd);
if (ret != 0) {
printf("[tv3] pwhash_str failure (maybe intentional): [%u]\n",
(unsigned int) i);
}
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
str_tests(void)
{
char *str_out;
char *str_out2;
char *salt;
const char *passwd = "Correct Horse Battery Staple";
salt = (char *) sodium_malloc(crypto_pwhash_SALTBYTES);
str_out = (char *) sodium_malloc(crypto_pwhash_STRBYTES);
str_out2 = (char *) sodium_malloc(crypto_pwhash_STRBYTES);
memcpy(salt, ">A 16-bytes salt", crypto_pwhash_SALTBYTES);
if (crypto_pwhash_argon2i_str(str_out, passwd, strlen(passwd), OPSLIMIT,
MEMLIMIT) != 0) {
printf("pwhash_argon2i_str failure\n");
}
if (crypto_pwhash_argon2i_str(str_out2, passwd, strlen(passwd), OPSLIMIT,
MEMLIMIT) != 0) {
printf("pwhash_argon2i_str(2) failure\n");
}
if (strcmp(str_out, str_out2) == 0) {
printf("pwhash_argon2i_str() doesn't generate different salts\n");
}
if (crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT) != 0) {
printf("needs_rehash() false positive\n");
}
if (crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != 1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT / 2, MEMLIMIT) != 1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT * 2) != 1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT * 2, MEMLIMIT) != 1) {
printf("needs_rehash() false negative\n");
}
if (crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != 1) {
printf("pwhash_str_needs_rehash() didn't handle argon2i\n");
}
if (crypto_pwhash_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
printf("needs_rehash() didn't fail with an invalid hash string\n");
}
if (sodium_is_zero((const unsigned char *) str_out + strlen(str_out),
crypto_pwhash_STRBYTES - strlen(str_out)) != 1 ||
sodium_is_zero((const unsigned char *) str_out2 + strlen(str_out2),
crypto_pwhash_STRBYTES - strlen(str_out2)) != 1) {
printf("pwhash_str() doesn't properly pad with zeros\n");
}
if (crypto_pwhash_argon2i_str_verify(str_out, passwd, strlen(passwd)) != 0) {
printf("pwhash_str_verify(1) failure\n");
}
str_out[14]++;
if (crypto_pwhash_argon2i_str_verify(str_out, passwd, strlen(passwd)) != -1) {
printf("pwhash_str_verify(2) failure\n");
}
str_out[14]--;
assert(str_out[crypto_pwhash_STRBYTES - 1U] == 0);
if (crypto_pwhash_argon2i_str(str_out2, passwd, 0x100000000ULL, OPSLIMIT,
MEMLIMIT) != -1) {
printf("pwhash_str() with a large password should have failed\n");
}
if (crypto_pwhash_argon2i_str(str_out2, passwd, strlen(passwd), 1, MEMLIMIT) !=
-1) {
printf("pwhash_str() with a small opslimit should have failed\n");
}
if (crypto_pwhash_argon2i_str_verify("$argon2i$m=65536,t=2,p=1c29tZXNhbHQ"
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
"password", 0x100000000ULL) != -1) {
printf("pwhash_str_verify(invalid(0)) failure\n");
}
if (crypto_pwhash_argon2i_str_verify("$argon2i$m=65536,t=2,p=1c29tZXNhbHQ"
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(1)) failure %d\n", errno);
}
if (crypto_pwhash_argon2i_str_verify("$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ"
"9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(2)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ"
"$b2G3seW+uPzerwQQC+/E1K50CLLO7YXy0JRcaTuswRo",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(3)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2i$v=19$m=65536,t=2,p=1c29tZXNhbHQ"
"$wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(4)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
"wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(5)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
"$8iIuixkI73Js3G1uMbezQXD0b8LG4SXGsOwoQkdAQIM",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(6)) failure\n");
}
if (crypto_pwhash_str_verify(
"$argon2i$v=19$m=4096,t=3,p=2$b2RpZHVlamRpc29kaXNrdw"
"$TNnWIwlu1061JHrnCqIAmjs3huSxYIU+0jWipu7Kc9M",
"password", strlen("password")) != 0) {
printf("pwhash_str_verify(valid(7)) failure\n");
}
if (crypto_pwhash_str_verify(
"$argon2i$v=19$m=4096,t=3,p=2$b2RpZHVlamRpc29kaXNrdw"
"$TNnWIwlu1061JHrnCqIAmjs3huSxYIU+0jWipu7Kc9M",
"passwore", strlen("passwore")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(7)) failure\n");
}
if (crypto_pwhash_str_verify(
"$Argon2i$v=19$m=4096,t=3,p=2$b2RpZHVlamRpc29kaXNrdw"
"$TNnWIwlu1061JHrnCqIAmjs3huSxYIU+0jWipu7Kc9M",
"password", strlen("password")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(8)) failure\n");
}
if (crypto_pwhash_str_verify(
"$argon2i$v=1$m=4096,t=3,p=2$b2RpZHVlamRpc29kaXNrdw"
"$TNnWIwlu1061JHrnCqIAmjs3huSxYIU+0jWipu7Kc9M",
"password", strlen("password")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(9)) failure\n");
}
if (crypto_pwhash_str_verify(
"$argon2i$v=1$m=4096,t=3,p=2$b2RpZHVla~=mRpc29kaXNrdw"
"$TNnWIwlu1061JHrnCqIAmjs3huSxYIU+0jWipu7Kc9M",
"password", strlen("password")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(10)) failure\n");
}
if (crypto_pwhash_str_verify(
"$argon2i$v=1$m=4096,t=3,p=2$b2RpZHVlamRpc29kaXNrdw"
"$TNnWIwlu1061JHrnCqIAmjs3huSxYI~=U+0jWipu7Kc9M",
"password", strlen("password")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(11)) failure\n");
}
assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT,
crypto_pwhash_ALG_ARGON2I13) == 0);
assert(crypto_pwhash_argon2i_str_verify(str_out, "test", 4) == 0);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT) == 0);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out,
OPSLIMIT / 2, MEMLIMIT) == 1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT / 2) == 1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out, 0, 0) == 1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out + 1,
OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_argon2id_str_needs_rehash("", OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT,
crypto_pwhash_ALG_ARGON2ID13) == 0);
assert(crypto_pwhash_argon2id_str_verify(str_out, "test", 4) == 0);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT) == 0);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out,
OPSLIMIT / 2, MEMLIMIT) == 1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT / 2) == 1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out, 0, 0) == 1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_argon2id_str_needs_rehash("", OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out + 1,
OPSLIMIT, MEMLIMIT) == -1);
sodium_free(salt);
sodium_free(str_out);
sodium_free(str_out2);
}
int
main(void)
{
tv();
tv2();
tv3();
str_tests();
assert(crypto_pwhash_argon2i_bytes_min() > 0U);
assert(crypto_pwhash_argon2i_bytes_max() > crypto_pwhash_argon2i_bytes_min());
assert(crypto_pwhash_argon2i_passwd_max() > crypto_pwhash_argon2i_passwd_min());
assert(crypto_pwhash_argon2i_saltbytes() > 0U);
assert(crypto_pwhash_argon2i_strbytes() > 1U);
assert(crypto_pwhash_argon2i_strbytes() > strlen(crypto_pwhash_argon2i_strprefix()));
assert(crypto_pwhash_argon2i_opslimit_min() > 0U);
assert(crypto_pwhash_argon2i_opslimit_max() > 0U);
assert(crypto_pwhash_argon2i_memlimit_min() > 0U);
assert(crypto_pwhash_argon2i_memlimit_max() > 0U);
assert(crypto_pwhash_argon2i_opslimit_interactive() > 0U);
assert(crypto_pwhash_argon2i_memlimit_interactive() > 0U);
assert(crypto_pwhash_argon2i_opslimit_moderate() > 0U);
assert(crypto_pwhash_argon2i_memlimit_moderate() > 0U);
assert(crypto_pwhash_argon2i_opslimit_sensitive() > 0U);
assert(crypto_pwhash_argon2i_memlimit_sensitive() > 0U);
assert(crypto_pwhash_argon2i_bytes_min() == crypto_pwhash_argon2i_BYTES_MIN);
assert(crypto_pwhash_argon2i_bytes_max() == crypto_pwhash_argon2i_BYTES_MAX);
assert(crypto_pwhash_argon2i_passwd_min() == crypto_pwhash_argon2i_PASSWD_MIN);
assert(crypto_pwhash_argon2i_passwd_max() == crypto_pwhash_argon2i_PASSWD_MAX);
assert(crypto_pwhash_argon2i_saltbytes() == crypto_pwhash_argon2i_SALTBYTES);
assert(crypto_pwhash_argon2i_strbytes() == crypto_pwhash_argon2i_STRBYTES);
assert(crypto_pwhash_argon2i_opslimit_min() == crypto_pwhash_argon2i_OPSLIMIT_MIN);
assert(crypto_pwhash_argon2i_opslimit_max() == crypto_pwhash_argon2i_OPSLIMIT_MAX);
assert(crypto_pwhash_argon2i_memlimit_min() == crypto_pwhash_argon2i_MEMLIMIT_MIN);
assert(crypto_pwhash_argon2i_memlimit_max() == crypto_pwhash_argon2i_MEMLIMIT_MAX);
assert(crypto_pwhash_argon2i_opslimit_interactive() ==
crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE);
assert(crypto_pwhash_argon2i_memlimit_interactive() ==
crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE);
assert(crypto_pwhash_argon2i_opslimit_moderate() ==
crypto_pwhash_argon2i_OPSLIMIT_MODERATE);
assert(crypto_pwhash_argon2i_memlimit_moderate() ==
crypto_pwhash_argon2i_MEMLIMIT_MODERATE);
assert(crypto_pwhash_argon2i_opslimit_sensitive() ==
crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE);
assert(crypto_pwhash_argon2i_memlimit_sensitive() ==
crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE);
assert(crypto_pwhash_argon2i_alg_argon2i13() == crypto_pwhash_argon2i_ALG_ARGON2I13);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1,11 @@
23b803c84eaa25f4b44634cc1e5e37792c53fcd9b1eb20f865329c68e09cbfa9f1968757901b383fce221afe27713f97914a041395bbe1fb70e079e5bed2c7145b1f6154046f5958e9b1b29055454e264d1f2231c316f26be2e3738e83a80315e9a0951ce4b137b52e7d5ee7b37f7d936dcee51362bcf792595e3c896ad5042734fc90c92cae572ce63ff659a2f7974a3bd730d04d525d253ccc38
0bb3769b064b9c43a9460476ab38c4a9a2470d55d4c992c6e723af895e4c07c09af41f22f90eab583a0c362d177f4677f212482fd145bfb9ac6211635e48461122bb49097b5fb0739d2cd22a39bf03d268e7495d4fd8d710aa156202f0a06e932ff513e6e7c76a4e98b6df5cf922f124791b1076ad904e6897271f5d7d24c5929e2a3b836d0f2f2697c2d758ee79bf1264f3fae65f3744e0f6d7d07ef6e8b35b70c0f88e9036325bfb24ac7f550351486da87aef10d6b0cb77d1cf6e31cf98399c6f241c605c6530dffb4764784f6c0b0bf601d4e4431e8b18dabdc3079c6e264302ade79f61cbd5497c95486340bb891a737223100be0429650
e9aa073b0b872f15c083d1d7ce52c09f493b827ca78f13a06c1721b45b1e17b24c04e19fe869333135360197a7eb55994fee3e8d9680aedfdf7674f3ad7b84d59d7eab03579ffc10c7093093bc48ec84252aa1b30f40f5e838f1443e15e2772a39f4e774eb052097e8881e94f15457b779fa2af2bbc9a993687657c7704ac8a37c25c1df4289eb4c70da45f2fd46bc0f78259767d3dd478a7c369cf866758bc36d9bd8e2e3c9fb0cf7fd6073ebf630c1f67fa7d303c07da40b36749d157ea37965fef810f2ea05ae6fc7d96a8f3470d73e15b22b42e8d6986dbfe5303256b2b3560372c4452ffb2a04fb7c6691489f70cb46831be0679117f7
[tv] pwhash failure (maybe intentional): [3]
c121209f0ba70aed93d49200e5dc82cce013cef25ea31e160bf8db3cf448a59d1a56f6c19259e18ea020553cb75781761d112b2d949a297584c65e60df95ad89c4109825a3171dc6f20b1fd6b0cdfd194861bc2b414295bee5c6c52619e544abce7d520659c3d51de2c60e89948d830695ab38dcb75dd7ab06a4770dd4bc7c8f335519e04b038416b1a7dbd25c026786a8105c5ffe7a0931364f0376ae5772be39b51d91d3281464e0f3a128e7155a68e87cf79626ffca0b2a3022fc8420
91c337ce8918a5805a59b00bd1819d3eb4356807cbd2a80b271c4b482dce03f5b02ae4eb831ff668cbb327b93c300b41da4852e5547bea8342d518dd9311aaeb5f90eccf66d548f9275631f0b1fd4b299cec5d2e86a59e55dc7b3afab6204447b21d1ef1da824abaf31a25a0d6135c4fe81d34a06816c8a6eab19141f5687108500f3719a862af8c5fee36e130c69921e11ce83dfc72c5ec3b862c1bccc5fd63ad57f432fbcca6f9e18d5a59015950cdf053
[tv] pwhash failure (maybe intentional): [6]
e942951dfbc2d508294b10f9e97b47d0cd04e668a043cb95679cc1139df7c27cd54367688725be9d069f5704c12223e7e4ca181fbd0bed18bb4634795e545a6c04a7306933a41a794baedbb628d41bc285e0b9084055ae136f6b63624c874f5a1e1d8be7b0b7227a171d2d7ed578d88bfdcf18323198962d0dcad4126fd3f21adeb1e11d66252ea0c58c91696e91031bfdcc2a9dc0e028d17b9705ba2d7bcdcd1e3ba75b4b1fea
fd329873387429cb79faaec4f65c35649f65de0aabc1f092ca9dee20029d8ae6c3a97e9940763e1703a7fef5a20eb7f210123fc8c6d3f1745d19d5e3c1eb392ab4a6070c8a6b9ecbeabae0711326e81530099541a882d4bd7733c4a7477ae72b6928c46cd07264172a9d2cfb7d649594f877f8b447d9c01b17996b85db5a71f733f8cc5fd0436540a5b7a1d79de09e20c3abe6515501b3156cd51e
bbbc4c7963593601d4d685ed9d89682374f8e6b3ce92ce8ccc702728ec8bf839fd7cb8e37ddb09be8c18c7e0ed099949665227a00fb33e1f63ca830dbeb13b29d987b445b3e081cd8428bdb2f9e003e12bea98230fd30842fa193af9169171b550322072c88330ea464cbe02b6ee044374d3f3d174c23617b707159a11926c56601123dcc30508ec84fdb0797b7ab23a77eeefb2a0be2ef45e903c
OK

View File

@ -0,0 +1,503 @@
#define TEST_NAME "pwhash_argon2id"
#include "cmptest.h"
#define OUT_LEN 128
#define OPSLIMIT 3
#define MEMLIMIT 5000000
static void
tv(void)
{
static struct {
const char * passwd_hex;
size_t passwd_len;
const char * salt_hex;
size_t outlen;
unsigned long long opslimit;
size_t memlimit;
unsigned int lanes;
} tests[] = {
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 5, 7256678, 1 },
{ "e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed"
"9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e0"
"0cc2890277f0fd3c622115772f7048adaebed86e",
86,
"f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d",
250, 4, 7849083, 1 },
{ "92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3"
"b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392"
"be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0"
"441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f491"
"5d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746"
"711f58c8c392016b2fdfc09c64f0f6b6ab7b",
183,
"3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194",
249, 3, 7994791, 1 },
{ "027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3"
"b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b64"
"51a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53"
"f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce6"
"9bb078ed1f0d31e7f9b8062409f37f19f8550aae",
152,
"eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5", 5,
4, 1397645, 1 },
{ "4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82"
"ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d"
"43ced68642bfb8bbbdd0f50b30118f5e",
82,
"39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258",
190, 3, 1432947, 1 },
{ "c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba"
"9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e82"
"61cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe"
"02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e"
"089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f",
156,
"039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6",
178, 3, 4886999, 1 },
{ "b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f1"
"7b",
34,
"44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb",
231, 1, 1631659, 1 },
{ "a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f"
"7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63"
"d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c"
"496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb6"
"76a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b30"
"1560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d"
"55a3b4169f22cccb0745a2689407ea1901a0a766eb99",
220,
"3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf",
167, 3, 1784128, 1 },
};
char passwd[256];
unsigned char salt[crypto_pwhash_SALTBYTES];
unsigned char out[256];
char out_hex[256 * 2 + 1];
size_t i = 0U;
do {
sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen, passwd,
tests[i].passwd_len, (const unsigned char *) salt,
tests[i].opslimit, tests[i].memlimit,
crypto_pwhash_alg_default()) != 0) {
printf("[tv] pwhash failure (maybe intentional): [%u]\n",
(unsigned int) i);
continue;
}
sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
printf("%s\n", out_hex);
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
tv2(void)
{
static struct {
const char * passwd_hex;
size_t passwd_len;
const char * salt_hex;
size_t outlen;
unsigned long long opslimit;
size_t memlimit;
unsigned int lanes;
} tests[] = {
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 4, 397645, 1 },
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 3, 397645, 1 },
};
char passwd[256];
unsigned char salt[crypto_pwhash_SALTBYTES];
unsigned char out[256];
char out_hex[256 * 2 + 1];
size_t i = 0U;
do {
sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen, passwd,
tests[i].passwd_len, (const unsigned char *) salt,
tests[i].opslimit, tests[i].memlimit,
crypto_pwhash_alg_default()) != 0) {
printf("[tv2] pwhash failure: [%u]\n", (unsigned int) i);
continue;
}
sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
printf("%s\n", out_hex);
} while (++i < (sizeof tests) / (sizeof tests[0]));
if (crypto_pwhash_argon2id(out, sizeof out, "password", strlen("password"), salt, 3,
1ULL << 12, 0) != -1) {
printf("[tv2] pwhash should have failed (0)\n");
}
if (crypto_pwhash_argon2id(out, sizeof out, "password", strlen("password"), salt, 3,
1, crypto_pwhash_argon2id_alg_argon2id13()) != -1) {
printf("[tv2] pwhash should have failed (1)\n");
}
if (crypto_pwhash_argon2id(out, sizeof out, "password", strlen("password"), salt, 3,
1ULL << 12, crypto_pwhash_argon2id_alg_argon2id13()) != -1) {
printf("[tv2] pwhash should have failed (2)\n");
}
if (crypto_pwhash_argon2id(out, sizeof out, "password", strlen("password"), salt, 2,
1ULL << 12, crypto_pwhash_argon2id_alg_argon2id13()) != -1) {
printf("[tv2] pwhash should have failed (3)\n");
}
if (crypto_pwhash_argon2id(out, 15, "password", strlen("password"), salt, 3,
1ULL << 12, crypto_pwhash_argon2id_alg_argon2id13()) != -1) {
printf("[tv2] pwhash with a short output length should have failed\n");
}
if (crypto_pwhash_argon2id(out, sizeof out, "password", 0x100000000ULL, salt, 3,
1ULL << 12, crypto_pwhash_argon2id_alg_argon2id13()) != -1) {
printf("[tv2] pwhash with a long password length should have failed\n");
}
assert(crypto_pwhash_argon2id(out, sizeof out, "password", strlen("password"), salt,
OPSLIMIT, MEMLIMIT, crypto_pwhash_alg_argon2i13()) == -1);
}
static void
tv3(void)
{
static struct {
const char *passwd;
const char *out;
} tests[] = {
{ "",
"$argon2id$v=19$m=4096,t=0,p=1$X1NhbHQAAAAAAAAAAAAAAA$bWh++MKN1OiFHKgIWTLvIi1iHicmHH7+Fv3K88ifFfI" },
{ "",
"$argon2id$v=19$m=2048,t=4,p=1$SWkxaUhpY21ISDcrRnYzSw$Mbg/Eck1kpZir5T9io7C64cpffdTBaORgyriLQFgQj8" },
{ "",
"$argon2id$v=19$m=4882,t=2,p=1$bA81arsiXysd3WbTRzmEOw$Nm8QBM+7RH1DXo9rvp5cwKEOOOfD2g6JuxlXihoNcpE" },
{ "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg ",
"$argon2id$v=19$m=4096,t=0,p=1$PkEgMTYtYnl0ZXMgc2FsdA$ltB/ue1kPtBMBGfsysMpPigE6hiNEKZ9vs8vLNVDQGA" },
{ "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg ",
"$argon2id$v=19$m=4096,t=19,p=1$PkEgMTYtYnl0ZXMgc2FsdA$ltB/ue1kPtBMBGfsysMpPigE6hiNEKZ9vs8vLNVDQGA" },
{ "K3S=KyH#)36_?]LxeR8QNKw6X=gFbxai$C%29V*",
"$argon2id$v=19$m=4096,t=1,p=3$PkEgcHJldHR5IGxvbmcgc2FsdA$HUqx5Z1b/ZypnUrvvJ5UC2Q+T6Q1WwASK/Kr9dRbGA0" }
};
char *out;
char *passwd;
size_t i = 0U;
int ret;
do {
out = (char *) sodium_malloc(strlen(tests[i].out) + 1U);
assert(out != NULL);
memcpy(out, tests[i].out, strlen(tests[i].out) + 1U);
passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
assert(passwd != NULL);
memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U);
ret = crypto_pwhash_str_verify(out, passwd, strlen(passwd));
sodium_free(out);
sodium_free(passwd);
if (ret != 0) {
printf("[tv3] pwhash_argon2id_str failure (maybe intentional): [%u]\n",
(unsigned int) i);
}
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
str_tests(void)
{
char *str_out;
char *str_out2;
char *salt;
const char *passwd = "Correct Horse Battery Staple";
salt = (char *) sodium_malloc(crypto_pwhash_argon2id_SALTBYTES);
str_out = (char *) sodium_malloc(crypto_pwhash_argon2id_STRBYTES);
str_out2 = (char *) sodium_malloc(crypto_pwhash_argon2id_STRBYTES);
memcpy(salt, ">A 16-bytes salt", crypto_pwhash_argon2id_SALTBYTES);
if (crypto_pwhash_str(str_out, passwd, strlen(passwd), OPSLIMIT,
MEMLIMIT) != 0) {
printf("pwhash_str failure\n");
}
if (crypto_pwhash_str(str_out2, passwd, strlen(passwd), OPSLIMIT,
MEMLIMIT) != 0) {
printf("pwhash_str(2) failure\n");
}
if (strcmp(str_out, str_out2) == 0) {
printf("pwhash_str() doesn't generate different salts\n");
}
if (crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT) != 0 ||
crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT) != 0) {
printf("needs_rehash() false positive\n");
}
if (crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != 1 ||
crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT - 1, MEMLIMIT) != 1 ||
crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT * 2) != 1 ||
crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT + 1, MEMLIMIT) != 1) {
printf("needs_rehash() false negative (0)\n");
}
if (crypto_pwhash_argon2id_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != 1 ||
crypto_pwhash_argon2id_str_needs_rehash(str_out, OPSLIMIT - 1, MEMLIMIT) != 1 ||
crypto_pwhash_argon2id_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT * 2) != 1 ||
crypto_pwhash_argon2id_str_needs_rehash(str_out, OPSLIMIT + 1, MEMLIMIT) != 1) {
printf("needs_rehash() false negative (1)\n");
}
if (crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != -1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT - 1, MEMLIMIT) != -1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT * 2) != -1 ||
crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT + 1, MEMLIMIT) != -1) {
printf("needs_rehash() false negative (2)\n");
}
if (crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != 1) {
printf("pwhash_str_needs_rehash() didn't handle argon2id\n");
}
if (crypto_pwhash_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1 ||
crypto_pwhash_argon2id_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
printf("needs_rehash() didn't fail with an invalid hash string\n");
}
if (sodium_is_zero((const unsigned char *) str_out + strlen(str_out),
crypto_pwhash_STRBYTES - strlen(str_out)) != 1 ||
sodium_is_zero((const unsigned char *) str_out2 + strlen(str_out2),
crypto_pwhash_STRBYTES - strlen(str_out2)) != 1) {
printf("pwhash_argon2id_str() doesn't properly pad with zeros\n");
}
if (crypto_pwhash_argon2id_str_verify(str_out, passwd, strlen(passwd)) != 0) {
printf("pwhash_argon2id_str_verify(1) failure\n");
}
if (crypto_pwhash_str_verify(str_out, passwd, strlen(passwd)) != 0) {
printf("pwhash_str_verify(1') failure\n");
}
str_out[14]++;
if (crypto_pwhash_str_verify(str_out, passwd, strlen(passwd)) != -1) {
printf("pwhash_argon2id_str_verify(2) failure\n");
}
str_out[14]--;
assert(str_out[crypto_pwhash_argon2id_STRBYTES - 1U] == 0);
if (crypto_pwhash_str(str_out2, passwd, 0x100000000ULL, OPSLIMIT,
MEMLIMIT) != -1) {
printf("pwhash_str() with a large password should have failed\n");
}
if (crypto_pwhash_str(str_out2, passwd, strlen(passwd), 1, MEMLIMIT) != 0) {
printf("pwhash_str() with a small opslimit should not have failed\n");
}
if (crypto_pwhash_str(str_out2, passwd, strlen(passwd), 0, MEMLIMIT) != -1) {
printf("pwhash_argon2id_str() with a null opslimit should have failed\n");
}
if (crypto_pwhash_str_verify("$argon2id$m=65536,t=2,p=1c29tZXNhbHQ"
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
"password", 0x100000000ULL) != -1) {
printf("pwhash_str_verify(invalid(0)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$m=65536,t=2,p=1c29tZXNhbHQ"
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(1)) failure %d\n", errno);
}
if (crypto_pwhash_str_verify("$argon2id$m=65536,t=2,p=1$c29tZXNhbHQ"
"9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(2)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$m=65536,t=2,p=1$c29tZXNhbHQ"
"$b2G3seW+uPzerwQQC+/E1K50CLLO7YXy0JRcaTuswRo",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(3)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$v=19$m=65536,t=2,p=1c29tZXNhbHQ"
"$wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(4)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
"wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(5)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
"$8iIuixkI73Js3G1uMbezQXD0b8LG4SXGsOwoQkdAQIM",
"password", strlen("password")) != -1) {
printf("pwhash_str_verify(invalid(6)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$v=19$m=256,t=3,p=1$MDEyMzQ1Njc"
"$G5ajKFCoUzaXRLdz7UJb5wGkb2Xt+X5/GQjUYtS2+TE",
"password", strlen("password")) != 0) {
printf("pwhash_str_verify(valid(7)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$v=19$m=256,t=3,p=1$MDEyMzQ1Njc"
"$G5ajKFCoUzaXRLdz7UJb5wGkb2Xt+X5/GQjUYtS2+TE",
"passwore", strlen("passwore")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(7)) failure\n");
}
if (crypto_pwhash_str_verify("$Argon2id$v=19$m=256,t=3,p=1$MDEyMzQ1Njc"
"$G5ajKFCoUzaXRLdz7UJb5wGkb2Xt+X5/GQjUYtS2+TE",
"password", strlen("password")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(8)) failure\n");
}
if (crypto_pwhash_str_verify("$argon2id$v=19$m=256,t=3,p=2$MDEyMzQ1Njc"
"$G5ajKFCoUzaXRLdz7UJb5wGkb2Xt+X5/GQjUYtS2+TE",
"password", strlen("password")) != -1 || errno != EINVAL) {
printf("pwhash_str_verify(invalid(9)) failure\n");
}
assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT,
crypto_pwhash_ALG_ARGON2ID13) == 0);
assert(crypto_pwhash_argon2id_str_verify(str_out, "test", 4) == 0);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT) == 0);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out,
OPSLIMIT / 2, MEMLIMIT) == 1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT / 2) == 1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out, 0, 0) == 1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out + 1,
OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_argon2i_str_needs_rehash("", OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT,
crypto_pwhash_ALG_ARGON2I13) == 0);
assert(crypto_pwhash_argon2i_str_verify(str_out, "test", 4) == 0);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT) == 0);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out,
OPSLIMIT / 2, MEMLIMIT) == 1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out,
OPSLIMIT, MEMLIMIT / 2) == 1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out, 0, 0) == 1);
assert(crypto_pwhash_argon2id_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_argon2i_str_needs_rehash("", OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_argon2i_str_needs_rehash(str_out + 1,
OPSLIMIT, MEMLIMIT) == -1);
sodium_free(salt);
sodium_free(str_out);
sodium_free(str_out2);
}
int
main(void)
{
tv();
tv2();
tv3();
str_tests();
assert(crypto_pwhash_bytes_min() > 0U);
assert(crypto_pwhash_bytes_max() > crypto_pwhash_bytes_min());
assert(crypto_pwhash_passwd_max() > crypto_pwhash_passwd_min());
assert(crypto_pwhash_saltbytes() > 0U);
assert(crypto_pwhash_strbytes() > 1U);
assert(crypto_pwhash_strbytes() > strlen(crypto_pwhash_strprefix()));
assert(crypto_pwhash_opslimit_min() > 0U);
assert(crypto_pwhash_opslimit_max() > 0U);
assert(crypto_pwhash_memlimit_min() > 0U);
assert(crypto_pwhash_memlimit_max() > 0U);
assert(crypto_pwhash_opslimit_interactive() > 0U);
assert(crypto_pwhash_memlimit_interactive() > 0U);
assert(crypto_pwhash_opslimit_moderate() > 0U);
assert(crypto_pwhash_memlimit_moderate() > 0U);
assert(crypto_pwhash_opslimit_sensitive() > 0U);
assert(crypto_pwhash_memlimit_sensitive() > 0U);
assert(strcmp(crypto_pwhash_primitive(), "argon2i") == 0);
assert(crypto_pwhash_bytes_min() == crypto_pwhash_BYTES_MIN);
assert(crypto_pwhash_bytes_max() == crypto_pwhash_BYTES_MAX);
assert(crypto_pwhash_passwd_min() == crypto_pwhash_PASSWD_MIN);
assert(crypto_pwhash_passwd_max() == crypto_pwhash_PASSWD_MAX);
assert(crypto_pwhash_saltbytes() == crypto_pwhash_SALTBYTES);
assert(crypto_pwhash_strbytes() == crypto_pwhash_STRBYTES);
assert(crypto_pwhash_opslimit_min() == crypto_pwhash_OPSLIMIT_MIN);
assert(crypto_pwhash_opslimit_max() == crypto_pwhash_OPSLIMIT_MAX);
assert(crypto_pwhash_memlimit_min() == crypto_pwhash_MEMLIMIT_MIN);
assert(crypto_pwhash_memlimit_max() == crypto_pwhash_MEMLIMIT_MAX);
assert(crypto_pwhash_opslimit_interactive() ==
crypto_pwhash_OPSLIMIT_INTERACTIVE);
assert(crypto_pwhash_memlimit_interactive() ==
crypto_pwhash_MEMLIMIT_INTERACTIVE);
assert(crypto_pwhash_opslimit_moderate() ==
crypto_pwhash_OPSLIMIT_MODERATE);
assert(crypto_pwhash_memlimit_moderate() ==
crypto_pwhash_MEMLIMIT_MODERATE);
assert(crypto_pwhash_opslimit_sensitive() ==
crypto_pwhash_OPSLIMIT_SENSITIVE);
assert(crypto_pwhash_memlimit_sensitive() ==
crypto_pwhash_MEMLIMIT_SENSITIVE);
assert(crypto_pwhash_argon2id_bytes_min() == crypto_pwhash_bytes_min());
assert(crypto_pwhash_argon2id_bytes_max() == crypto_pwhash_bytes_max());
assert(crypto_pwhash_argon2id_passwd_min() == crypto_pwhash_passwd_min());
assert(crypto_pwhash_argon2id_passwd_max() == crypto_pwhash_passwd_max());
assert(crypto_pwhash_argon2id_saltbytes() == crypto_pwhash_saltbytes());
assert(crypto_pwhash_argon2id_strbytes() == crypto_pwhash_strbytes());
assert(strcmp(crypto_pwhash_argon2id_strprefix(),
crypto_pwhash_strprefix()) == 0);
assert(crypto_pwhash_argon2id_opslimit_min() ==
crypto_pwhash_opslimit_min());
assert(crypto_pwhash_argon2id_opslimit_max() ==
crypto_pwhash_opslimit_max());
assert(crypto_pwhash_argon2id_memlimit_min() ==
crypto_pwhash_memlimit_min());
assert(crypto_pwhash_argon2id_memlimit_max() ==
crypto_pwhash_memlimit_max());
assert(crypto_pwhash_argon2id_opslimit_interactive() ==
crypto_pwhash_opslimit_interactive());
assert(crypto_pwhash_argon2id_opslimit_moderate() ==
crypto_pwhash_opslimit_moderate());
assert(crypto_pwhash_argon2id_opslimit_sensitive() ==
crypto_pwhash_opslimit_sensitive());
assert(crypto_pwhash_argon2id_memlimit_interactive() ==
crypto_pwhash_memlimit_interactive());
assert(crypto_pwhash_argon2id_memlimit_moderate() ==
crypto_pwhash_memlimit_moderate());
assert(crypto_pwhash_argon2id_memlimit_sensitive() ==
crypto_pwhash_memlimit_sensitive());
assert(crypto_pwhash_alg_argon2id13() ==
crypto_pwhash_argon2id_alg_argon2id13());
assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_ALG_ARGON2I13);
assert(crypto_pwhash_alg_argon2i13() != crypto_pwhash_alg_default());
assert(crypto_pwhash_alg_argon2id13() == crypto_pwhash_ALG_ARGON2ID13);
assert(crypto_pwhash_alg_argon2id13() != crypto_pwhash_alg_argon2i13());
assert(crypto_pwhash_alg_argon2id13() == crypto_pwhash_alg_default());
assert(crypto_pwhash_argon2id(guard_page, 0, (const char *) guard_page, 0, guard_page,
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
0) == -1);
assert(crypto_pwhash_argon2id(guard_page, 0, (const char *) guard_page, 0, guard_page,
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
crypto_pwhash_ALG_ARGON2I13) == -1);
assert(crypto_pwhash_argon2i(guard_page, 0, (const char *) guard_page, 0, guard_page,
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
0) == -1);
assert(crypto_pwhash_argon2i(guard_page, 0, (const char *) guard_page, 0, guard_page,
crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
crypto_pwhash_ALG_ARGON2ID13) == -1);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1,14 @@
18acec5d6507739f203d1f5d9f1d862f7c2cdac4f19d2bdff64487e60d969e3ced615337b9eec6ac4461c6ca07f0939741e57c24d0005c7ea171a0ee1e7348249d135b38f222e4dad7b9a033ed83f5ca27277393e316582033c74affe2566a2bea47f91f0fd9fe49ece7e1f79f3ad6e9b23e0277c8ecc4b313225748dd2a80f5679534a0700e246a79a49b3f74eb89ec6205fe1eeb941c73b1fcf1
26bab5f101560e48c711da4f05e81f5a3802b7a93d5155b9cab153069cc42b8e9f910bfead747652a0708d70e4de0bada37218bd203a1201c36b42f9a269b675b1f30cfc36f35a3030e9c7f57dfba0d341a974c1886f708c3e8297efbfe411bb9d51375264bd7c70d57a8a56fc9de2c1c97c08776803ec2cd0140bba8e61dc0f4ad3d3d1a89b4b710af81bfe35a0eea193e18a6da0f5ec05542c9eefc4584458e1da715611ba09617384748bd43b9bf1f3a6df4ecd091d0875e08d6e2fd8a5c7ce08904b5160cd38167b76ec76ef2d310049055a564da23d4ebd2b87e421cc33c401e12d5cd8d936c9baf75ebdfb557d342d2858fc781da31860
6eb45e668582d63788ca8f6e930ca60b045a795fca987344f9a7a135aa3b5132b50a34a3864c26581f1f56dd0bcbfafbfa92cd9bff6b24a734cfe88f854aef4bda0a7983120f44936e8ff31d29728ac08ccce6f3f916b3c63962755c23a1fa9bb4e8823fc867bfd18f28980d94bc5874423ab7f96cc0ab78d8fa21fbd00cd3a1d96a73fa439ccc3fc4eab1590677b06cc78b0f674dfb680f23022fb902022dd8620803229c6ddf79a8156ccfce48bbd76c05ab670634f206e5b2e896230baa74a856964dbd8511acb71d75a1506766a125d8ce037f1db72086ebc3bccaefbd8cd9380167c2530386544ebfbeadbe237784d102bb92a10fd242
[tv] pwhash failure (maybe intentional): [3]
08d8cd330c57e1b4643241d05bb468ba4ee4e932cd0858816be9ef15360b27bbd06a87130ee92222be267a29b81f5ae8fe8613324cfc4832dc49387fd0602f1c57b4d0f3855db94fb7e12eb05f9a484aed4a4307abf586cd3d55c809bc081541e00b682772fb2066504ff935b8ebc551a2083882f874bc0fae68e56848ae34c91097c3bf0cca8e75c0797eef3efde3f75e005815018db3cf7c109a812264c4de69dcb22322dbbcfa447f5b00ecd1b04a7be1569c8e556adb7bba48adf81d
d6e9d6cabd42fb9ba7162fe9b8e41d59d3c7034756cb460c9affe393308bd0225ce0371f2e6c3ca32aca2002bf2d3909c6b6e7dfc4a00e850ff4f570f8f749d4bb6f0091e554be67a9095ae1eefaa1a933316cbec3c2fd4a14a5b6941bda9b7eabd821d79abde2475a53af1a8571c7ee46460be415882e0b393f48c12f740a6a72cba9773000602e13b40d3dfa6ac1d4ec43a838b7e3e165fecad4b2498389e60a3ff9f0f8f4b9fca1126e64f49501e38690
7fb72409b0987f8190c3729710e98c3f80c5a8727d425fdcde7f3644d467fe973f5b5fee683bd3fce812cb9ae5e9921a2d06c2f1905e4e839692f2b934b682f11a2fe2b90482ea5dd234863516dba6f52dc0702d324ec77d860c2e181f84472bd7104fedce071ffa93c5309494ad51623d214447a7b2b1462dc7d5d55a1f6fd5b54ce024118d86f0c6489d16545aaa87b6689dad9f2fb47fda9894f8e12b87d978b483ccd4cc5fd9595cdc7a818452f915ce2f7df95ec12b1c72e3788d473441d884f9748eb14703c21b45d82fd667b85f5b2d98c13303b3fe76285531a826b6fc0fe8e3dddecf
4e702bc5f891df884c6ddaa243aa846ce3c087fe930fef0f36b3c2be34164ccc295db509254743f18f947159c813bcd5dd8d94a3aec93bbe57605d1fad1aef1112687c3d4ef1cb329d21f1632f626818d766915d886e8d819e4b0b9c9307f4b6afc081e13b0cf31db382ff1bf05a16aac7af696336d75e99f82163e0f371e1d25c4add808e215697ad3f779a51a462f8bf52610af21fc69dba6b072606f2dabca7d4ae1d91d919
20e7ba6faa2c0a4b07f3ff38e15e252a069c2c62bac3f2785d311764d73e67fd713be342ee938e6df4de6af1a89a44b8589838864457bcfe3cf0f2d329b800ab9f5810b6325588eb4e0c56f99192b2cc76dc8194dc1097fe5ed12ac4214481c03c3597131ba164a56e7187e2da565a8cd529668e9a37faa58a1701c49a14edf7a50dec4143b456cba6d14c957bb655e99ce96bc506961216ef887a
8fb6ed1862cdd2a399e10956c60dc9b2670338ea59c3414d0443216925ba24c6e89a17f3e56c12893dcbc9bc498e8308aea9627d9c9e47912d6342b631008719edfa2db364b97e60cf47a97ad9aa3b7f139d80ddda44f1ef2af881ce027a15644218cac6cc74751469ae56be0469fbc760825882b3e8abca55daaae5753575106cf867cd69932602c63ec880ad8811d9aa4870a9e0b39fef47c92e
[tv3] pwhash_argon2id_str failure (maybe intentional): [0]
[tv3] pwhash_argon2id_str failure (maybe intentional): [1]
[tv3] pwhash_argon2id_str failure (maybe intentional): [3]
OK

View File

@ -0,0 +1,393 @@
#define TEST_NAME "pwhash_scrypt"
#include "cmptest.h"
#define OUT_LEN 128
#define OPSLIMIT 1000000
#define MEMLIMIT 10000000
static void
tv(void)
{
static struct {
const char *passwd_hex;
size_t passwdlen;
const char *salt_hex;
size_t outlen;
unsigned long long opslimit;
size_t memlimit;
} tests[] = {
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 481326, 7256678 },
{ "e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed"
"9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e0"
"0cc2890277f0fd3c622115772f7048adaebed86e",
86,
"f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d",
250, 535778, 7849083 },
{ "92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3"
"b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392"
"be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0"
"441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f491"
"5d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746"
"711f58c8c392016b2fdfc09c64f0f6b6ab7b",
183,
"3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194",
249, 311757, 7994791 },
{ "027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3"
"b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b64"
"51a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53"
"f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce6"
"9bb078ed1f0d31e7f9b8062409f37f19f8550aae",
152,
"eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5", 5,
643464, 1397645 },
{ "4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82"
"ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d"
"43ced68642bfb8bbbdd0f50b30118f5e",
82,
"39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258",
190, 758010, 5432947 },
{ "1845e375479537e9dd4f4486d5c91ac72775d66605eeb11a787b78a7745f1fd005"
"2d526c67235dbae1b2a4d575a74cb551c8e9096c593a497aee74ba3047d911358e"
"de57bc27c9ea1829824348daaab606217cc931dcb6627787bd6e4e5854f0e8",
97,
"3ee91a805aa62cfbe8dce29a2d9a44373a5006f4a4ce24022aca9cecb29d1473",
212, 233177, 13101817 },
{ "c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba"
"9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e82"
"61cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe"
"02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e"
"089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f",
156,
"039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6",
178, 234753, 4886999 },
{ "8f3a06e2fd8711350a517bb12e31f3d3423e8dc0bb14aac8240fca0995938d59bb"
"37bd0a7dfc9c9cc0705684b46612e8c8b1d6655fb0f9887562bb9899791a0250d1"
"320f945eda48cdc20c233f40a5bb0a7e3ac5ad7250ce684f68fc0b8c9633bfd75a"
"ad116525af7bdcdbbdb4e00ab163fd4df08f243f12557e",
122,
"90631f686a8c3dbc0703ffa353bc1fdf35774568ac62406f98a13ed8f47595fd",
55, 695191, 15738350 },
{ "b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f1"
"7b",
34,
"44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb",
231, 78652, 6631659 },
{ "a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f"
"7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63"
"d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c"
"496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb6"
"76a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b30"
"1560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d"
"55a3b4169f22cccb0745a2689407ea1901a0a766eb99",
220,
"3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf",
167, 717248, 10784179 },
};
char passwd[256];
unsigned char salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
unsigned char out[256];
char out_hex[256 * 2 + 1];
size_t i = 0U;
do {
sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash_scryptsalsa208sha256(
out, (unsigned long long) tests[i].outlen, passwd,
tests[i].passwdlen, (const unsigned char *) salt,
tests[i].opslimit, tests[i].memlimit) != 0) {
printf("pwhash failure\n");
}
sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
printf("%s\n", out_hex);
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
tv2(void)
{
static struct {
const char *passwd_hex;
size_t passwdlen;
const char *salt_hex;
size_t outlen;
unsigned long long opslimit;
size_t memlimit;
} tests[] = {
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 64, 1397645 },
{ "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
"65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
"a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
"8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
127,
"5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
155, 32768, 1397645 },
};
char passwd[256];
unsigned char salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
unsigned char out[256];
char out_hex[256 * 2 + 1];
size_t i = 0U;
do {
sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash_scryptsalsa208sha256(
out, (unsigned long long) tests[i].outlen, passwd,
tests[i].passwdlen, (const unsigned char *) salt,
tests[i].opslimit, tests[i].memlimit) != 0) {
printf("pwhash failure\n");
}
sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
printf("%s\n", out_hex);
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
tv3(void)
{
static struct {
const char *passwd;
const char *out;
} tests[] = {
{ "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg "
"nrDFal+Jxl3,2`#^tFSu%v_+7iYse8-cCkNf!tD=KrW)",
"$7$B6....1....75gBMAGwfFWZqBdyF3WdTQnWdUsuTiWjG1fF9c1jiSD$tc8RoB3."
"Em3/zNgMLWo2u00oGIoTyJv4fl3Fl8Tix72" },
{ "bl72h6#y<':MFRZ>B IA1=NRkCKS%W8`1I.2uQxJN0g)N N aTt^4K!Iw5r "
"H6;crDsv^a55j9tsk'/GqweZn;cdk6+F_St6:#*=?ZCD_lw>.",
"$7$A6....3....Iahc6qM0.UQJHVgE4h9oa1/"
"4OWlWLm9CCtfguvz6bQD$QnXCo3M7nIqtry2WKsUZ5gQ.mY0wAlJu."
"WUhtE8vF66" },
{ "Py "
">e.5b+tLo@rL`dC2k@eJ&4eVl!W=JJ4+k&mAt@gt',FS1JjqKW3aq21:]^kna`"
"mde7kVkN5NrpKUptu)@4*b&?BE_sJMG1=&@`3GBCV]Wg7xwgo7x3El",
"$7$96..../....f6bEusKt79kK4wdYN0ki2nw4bJQ7P3rN6k3BSigsK/"
"D$Dsvuw7vXj5xijmrb/NOhdgoyK/OiSIYv88cEtl9Cik7" },
{ "2vj;Um]FKOL27oam(:Uo8+UmSTvb1FD*h?jk_,S=;RDgF-$Fjk?]9yvfxe@fN^!NN("
"Cuml?+2Raa",
"$7$86....I....7XwIxLtCx4VphmFeUa6OGuGJrFaIaYzDiLNu/"
"tyUPhD$U3q5GCEqCWxMwh.YQHDJrlg7FIZgViv9pcXE3h1vg61" },
{ "CT=[9uUoGav,J`kU+348tA50ue#sL:ABZ3QgF+r[#vh:tTOiL>s8tv%,Jeo]jH/"
"_4^i(*jD-_ku[9Ko[=86 06V",
"$7$A6....2....R3.bjH6YS9wz9z8Jsj.3weGQ3J80ZZElGw2oVux1TP6$"
"i5u6lFzXDHaIgYEICinLD6WNaovbiXP8SnLrDRdKgA9" },
{ "J#wNn`hDgOpTHNI.w^1a70%f,.9V_m038H_JIJQln`vdWnn/"
"rmILR?9H5g(+`;@H(2VosN9Fgk[WEjaBr'yB9Q19-imNa04[Mk5kvGcSn-TV",
"$7$B6....1....Dj1y.4mF1J9XmT/6IDskYdCLaPFJTq9xcCwXQ1DpT92$92/"
"hYfZLRq1nTLyIz.uc/dC6wLqwnsoqpkadrCXusm6" },
{ "j4BS38Asa;p)[K+9TY!3YDj<LK-`nLVXQw9%*QfM",
"$7$B6....1....5Ods8mojVwXJq4AywF/uI9BdMSiJ/zT8hQP/"
"4cB68VC$nk4ExHNXJ802froj51/1wJTrSZvTIyyK7PecOxRRaz0" },
{ "M.R>Qw+!qJb]>pP :_.9`dxM9k [eR7Y!yL-3)sNs[R,j_/^ "
"TH=5ny'15>6UXWcQW^6D%XCsO[vN[%ReA-`tV1vW(Nt*0KVK#]45P_A",
"$7$B6....1....D/"
"eyk8N5y6Z8YVQEsw521cTx.9zzLuK7YDs1KMMh.o4$alfW8ZbsUWnXc."
"vqon2zoljVk24Tt1.IsCuo2KurvS2" },
{ "K3S=KyH#)36_?]LxeR8QNKw6X=gFb'ai$C%29V* "
"tyh^Wo$TN-#Q4qkmtTCf0LLb.^E$0uykkP",
"$7$B6....1....CuBuU97xgAage8whp/"
"JNKobo0TFbsORGVbfcQIefyP8$aqalP."
"XofGViB8EPLONqHma8vs1xc9uTIMYh9CgE.S8" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
/* Invalid pwhash strings */
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....1....$TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$.6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A.....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6.........TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i44269$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AH" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx54269" },
{ "Y0!?iQa9M%5ekffW(`",
"$7^A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$!6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A!....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....!....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "",
"$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7fA6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4#"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$AX....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....1!...TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
"a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
{ "Y0!?iQa9M%5ekffW(`", "$7$A6....1" },
{ "Y0!?iQa9M%5ekffW(`", "$7$" },
{ "Y0!?iQa9M%5ekffW(`", "" },
{ "Y0!?iQa9M%5ekffW(`",
"$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$" },
{ "test",
"$7$.6..../.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
{ "test",
"$7$z6..../.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
{ "test",
"$7$8zzzzzzzzzz.lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
{ "test",
"$7$8.....zzzzz.lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
{ "test",
"$7$86..../..../lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." }
};
char * out;
char * passwd;
size_t i = 0U;
do {
out = (char *) sodium_malloc(strlen(tests[i].out) + 1U);
assert(out != NULL);
memcpy(out, tests[i].out, strlen(tests[i].out) + 1U);
passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
assert(passwd != NULL);
memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U);
if (crypto_pwhash_scryptsalsa208sha256_str_verify(
out, passwd, strlen(passwd)) != 0) {
printf("pwhash_str failure: [%u]\n", (unsigned int) i);
}
sodium_free(out);
sodium_free(passwd);
} while (++i < (sizeof tests) / (sizeof tests[0]));
}
static void
str_tests(void)
{
char *str_out;
char *str_out2;
const char *passwd = "Correct Horse Battery Staple";
str_out =
(char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
str_out2 =
(char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
if (crypto_pwhash_scryptsalsa208sha256_str(str_out, passwd, strlen(passwd),
OPSLIMIT, MEMLIMIT) != 0) {
printf("pwhash_str failure\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str(str_out2, passwd, strlen(passwd),
OPSLIMIT, MEMLIMIT) != 0) {
printf("pwhash_str(2) failure\n");
}
if (strcmp(str_out, str_out2) == 0) {
printf("pwhash_str doesn't generate different salts\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out, OPSLIMIT, MEMLIMIT) != 0) {
printf("needs_rehash() false positive\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out, OPSLIMIT, MEMLIMIT / 2) != 1 ||
crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out, OPSLIMIT / 2, MEMLIMIT) != 1 ||
crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out, OPSLIMIT, MEMLIMIT * 2) != 1 ||
crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out, OPSLIMIT * 2, MEMLIMIT) != 1) {
printf("needs_rehash() false negative\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
printf("needs_rehash() didn't fail with an invalid hash string\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
strlen(passwd)) != 0) {
printf("pwhash_str_verify failure\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
strlen(passwd)) != 0) {
printf("pwhash_str_verify failure\n");
}
str_out[14]++;
if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
strlen(passwd)) == 0) {
printf("pwhash_str_verify(2) failure\n");
}
str_out[14]--;
assert(str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U] == 0);
assert(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
(str_out, 0, 0) == 1);
assert(crypto_pwhash_str_needs_rehash(str_out, 0, 0) == -1);
assert(crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT) == -1);
assert(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
("", OPSLIMIT, MEMLIMIT) == -1);
sodium_free(str_out);
sodium_free(str_out2);
}
int
main(void)
{
tv();
tv2();
tv3();
str_tests();
assert(crypto_pwhash_scryptsalsa208sha256_bytes_min() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_bytes_max() >
crypto_pwhash_scryptsalsa208sha256_bytes_min());
assert(crypto_pwhash_scryptsalsa208sha256_passwd_max() >
crypto_pwhash_scryptsalsa208sha256_passwd_min());
assert(crypto_pwhash_scryptsalsa208sha256_saltbytes() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_strbytes() > 1U);
assert(crypto_pwhash_scryptsalsa208sha256_strbytes() >
strlen(crypto_pwhash_scryptsalsa208sha256_strprefix()));
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_min() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_max() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_min() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_max() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_interactive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() > 0U);
printf("OK\n");
return 0;
}

View File

@ -0,0 +1,37 @@
8d40f5f8c6a1791204f03e19a98cd74f918b6e331b39cfc2415e5014d7738b7bb0a83551fb14a035e07fdd4dc0c60c1a6822ac253918979f6324ff0c87cba75d3b91f88f41ca5414a0f152bdc4d636f42ab2250afd058c19ec31a3374d1bd7133289bf21513ff67cbf8482e626aee9864c58fd05f9ea02e508a10182b7d838157119866f072004987ef6c56683ed207705923921af9d76444a331a
d985d4c278343a46d82af0c4268b7ae6b6d1d2dd289675ef45bfb6d0648bffe5bab8c91228f3a31b091154a9c1142670a07b92e70a298333066de07db9300e046fd7cacc99780804683df7babdfc9d019047178400b2875bde0a1ad824dda7a422d9ed48475af9a3876378dd3a2f206e34984e223afb82c0c1e4644c9a458f4666379fdd3e2d9206d87e3c32c3977f35826a27590baaa1ec1a3bd7d15a92bc84c95dcfc56c14fca7c4c9810162dfdf9dc08a191e79fe40250b7e07d3a9317d9a5cb56e1062c419a6cd6a9b73128e8ad79ab7efffbb3cc52c1f49f86d2ebb46e6e4846aecdb14c2d046f5380517ff8cc794e4a772a58b93083dad
ee7e9e1369267ec555981f0ea088ff6f93953abfcb767d88ec3c46393d24cfbaba5e4e26e0f35b5d5259647748476d65cd8881c96f8cda049d9c877b2d33d932e67f4c0df2cb434b4b4900e0c49c3f8ba9663795420577e65d0b456201ad9162fbc485c7b44f2b34e6673aa3692c123021ee3b624c3bb22b808b89613d8ecc7b87da47f57152eb3f7b10ad206f6b09cb6935b347b5e42bc3b8c9c9bcd8d7b7c44929b367fc279dec48ea78e6ee3e2620d7459700bd0aedb1c9aa5a323ca94403927f5e5c2b73bda7c5c3287b62fe51874cfeb1dc3151cd886b26d83ece68833229d2d432798c602d85b0505947207d8430febbe901164b12ce
pwhash failure
0000000000
bcc5c2fd785e4781d1201ed43d84925537e2a540d3de55f5812f29e9dd0a4a00451a5c8ddbb4862c03d45c75bf91b7fb49265feb667ad5c899fdbf2ca19eac67aa5e48595d5b02f8183ab07f71b1ce0d76e5df54919f63810ad0893ded7d1ca18fc956ec06ffd4c3d1f77a00ed53608947b25eea5df6bea02272be15815f974c321a2a9208674fdf59d1d798c2a12f1889df68b0c222b37ee9ef0d6391fc160b0281ec53073cb3a3706ce1d71c3af2f5237a1b3d8545d99012eecc0b4abb
82765c040c58c1810f8c053ef5c248556299385476bde44bdd91a0d9a239f24e9b1717fd8b23209ffa45b7aa7937296c601b79e77da99e8d2fda0ea4459be2d0900f5bc5a269b5488d873d4632d1baf75965e509ee24b12501a9ce3bbbd8b7d759987d545a1c221a363195e5802d768b3b9e00ebe5ac0ed8ad2362c1c4157b910a40f94adf2561a2b0d3e65dbb06f244e5ac44d362103df54c9b9175777b3db1cdadb03e977ab8a79baf1e1e18ec9f5d0f25c487ddc53d7e81910f83576b44e9caeece26e2eb376569ad3a8cdccbde8bc355210e
ca9216d4127e2e4a6ee3584b49be106217bb61cc807016d46d0cfbb1fd722e2bbac33541386bdfeac41a299ead22790993fcaa8e1d23bd1c8426afa5ff4c08e731dc476ef834f142c32dfb2c1be12b9978802e63b2cd6f226b1a8df59f0c79154d7ef4296a68ec654538d987104f9a11aca1b7c83ab2ed8fd69da6b88f0bcbd27d3fea01329cecf10c57ec3ba163d57b38801bd6c3b31ce527b33717bb56a46f78fb96be9f2424a21b3284232388cbba6a74
2732a7566023c8db90a5fdd08dbe6c1b5e70c046d50c5735c8d86a589ba177f69db12d6cc3596319fa27c9e063ed05b8a31970a07dc905
d7b1ef464be03ce9050b5108e25f0b8e821299986fe0ff89e17fbae65ba9fad167fbd265866ac03efc86ab0b50d46d6740a59adf5949b44f7f9f3ac3f3d4cc9f128966db9099deb1b6b78505242b2401a193820408eb0780b27162ebafb7c505b0e7c32ce66c6efc0be487008c1201454680498a2fc06e00b454e0b20933906bbb0e43b399b9ee46d882f107df1ebdd1e7cd867c9cdba6015b7e80064ae8b3417d969524bec046e782a13b125f058cd36b5d1ae65886ae7caab45a6d98651ada435b8ee11d5c1224232f5f515df974138dd6cf347b730481d4b073af8ff0394fe9f0b8cdfd99f5
1839be14287053bfcd4ea60db82777fad1a6e9535c388b770743e61235449e668717199defd516c438b3ebd79b3529eb32482ef414525292ea1bbec09da10790a2330a4399f2fe6dd63d80954e3c547a5f1c619db5a30bde495b23f2214b4fa7572851d75246f2817775f0b521acc6efbc7832c9a76de7465e3c65cade88e86c973f85a882bb54f92b983977c6e937c88f083ba68c70fb49497065b158e2e789809b1d4cc9ec2d
d54916748076b9d9f72198c8fbef563462dc8c706e1ad38abd1fac570016721acd0a7659ab49a47299a996b43597690c0c947143069f35d83e606273dbf2d622321393949b8ed5a68315362c4f84804384d05e0e0e86bc00e3641233f9f975ab46b60ba185c5e5fe47f78efd207e69fd8f6390730828b93b9b3763ea1283caa03bc36726763715de811915681dd214524f5ad4dd386608cac6c7f2
d54916748076b9d9f72198c8fbef563462dc8c706e1ad38abd1fac570016721acd0a7659ab49a47299a996b43597690c0c947143069f35d83e606273dbf2d622321393949b8ed5a68315362c4f84804384d05e0e0e86bc00e3641233f9f975ab46b60ba185c5e5fe47f78efd207e69fd8f6390730828b93b9b3763ea1283caa03bc36726763715de811915681dd214524f5ad4dd386608cac6c7f2
pwhash_str failure: [10]
pwhash_str failure: [11]
pwhash_str failure: [12]
pwhash_str failure: [13]
pwhash_str failure: [14]
pwhash_str failure: [15]
pwhash_str failure: [16]
pwhash_str failure: [17]
pwhash_str failure: [18]
pwhash_str failure: [19]
pwhash_str failure: [20]
pwhash_str failure: [21]
pwhash_str failure: [22]
pwhash_str failure: [23]
pwhash_str failure: [24]
pwhash_str failure: [25]
pwhash_str failure: [26]
pwhash_str failure: [27]
pwhash_str failure: [28]
pwhash_str failure: [29]
pwhash_str failure: [30]
pwhash_str failure: [31]
pwhash_str failure: [32]
OK

View File

@ -0,0 +1,59 @@
#define TEST_NAME "pwhash_scrypt_ll"
#include "cmptest.h"
static const char * passwd1 = "";
static const char * salt1 = "";
static const uint64_t N1 = 16U;
static const uint32_t r1 = 1U;
static const uint32_t p1 = 1U;
static const char * passwd2 = "password";
static const char * salt2 = "NaCl";
static const uint64_t N2 = 1024U;
static const uint32_t r2 = 8U;
static const uint32_t p2 = 16U;
static const char * passwd3 = "pleaseletmein";
static const char * salt3 = "SodiumChloride";
static const uint64_t N3 = 16384U;
static const uint32_t r3 = 8U;
static const uint32_t p3 = 1U;
static void
tv(const char *passwd, const char *salt, uint64_t N, uint32_t r, uint32_t p)
{
uint8_t data[64];
size_t i;
size_t olen = (sizeof data / sizeof data[0]);
size_t passwd_len = strlen(passwd);
size_t salt_len = strlen(salt);
int line_items = 0;
if (crypto_pwhash_scryptsalsa208sha256_ll(
(const uint8_t *) passwd, passwd_len, (const uint8_t *) salt,
salt_len, N, r, p, data, olen) != 0) {
printf("pwhash_scryptsalsa208sha256_ll([%s],[%s]) failure\n", passwd,
salt);
return;
}
printf("scrypt('%s', '%s', %lu, %lu, %lu, %lu) =\n", passwd, salt,
(unsigned long) N, (unsigned long) r, (unsigned long) p,
(unsigned long) olen);
for (i = 0; i < olen; i++) {
printf("%02x%c", data[i], line_items < 15 ? ' ' : '\n');
line_items = line_items < 15 ? line_items + 1 : 0;
}
}
int
main(void)
{
tv(passwd1, salt1, N1, r1, p1);
tv(passwd2, salt2, N2, r2, p2);
tv(passwd3, salt3, N3, r3, p3);
return 0;
}

View File

@ -0,0 +1,15 @@
scrypt('', '', 16, 1, 1, 64) =
77 d6 57 62 38 65 7b 20 3b 19 ca 42 c1 8a 04 97
f1 6b 48 44 e3 07 4a e8 df df fa 3f ed e2 14 42
fc d0 06 9d ed 09 48 f8 32 6a 75 3a 0f c8 1f 17
e8 d3 e0 fb 2e 0d 36 28 cf 35 e2 0c 38 d1 89 06
scrypt('password', 'NaCl', 1024, 8, 16, 64) =
fd ba be 1c 9d 34 72 00 78 56 e7 19 0d 01 e9 fe
7c 6a d7 cb c8 23 78 30 e7 73 76 63 4b 37 31 62
2e af 30 d9 2e 22 a3 88 6f f1 09 27 9d 98 30 da
c7 27 af b9 4a 83 ee 6d 83 60 cb df a2 cc 06 40
scrypt('pleaseletmein', 'SodiumChloride', 16384, 8, 1, 64) =
70 23 bd cb 3a fd 73 48 46 1c 06 cd 81 fd 38 eb
fd a8 fb ba 90 4f 8e 3e a9 b5 43 f6 54 5d a1 f2
d5 43 29 55 61 3f 0f cf 62 d4 97 05 24 2a 9a f9
e6 1e 85 dc 0d 65 1e 40 df cf 01 7b 45 57 58 87

View File

@ -0,0 +1,164 @@
#define TEST_NAME "randombytes"
#include "cmptest.h"
static unsigned char x[65536];
static unsigned long long freq[256];
static int
compat_tests(void)
{
size_t i;
memset(x, 0, sizeof x);
randombytes(x, sizeof x);
for (i = 0; i < 256; ++i) {
freq[i] = 0;
}
for (i = 0; i < sizeof x; ++i) {
++freq[255 & (int) x[i]];
}
for (i = 0; i < 256; ++i) {
if (!freq[i]) {
printf("nacl_tests failed\n");
}
}
return 0;
}
static int
randombytes_tests(void)
{
static const unsigned char seed[randombytes_SEEDBYTES] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
};
unsigned char out[100];
unsigned int f = 0U;
unsigned int i;
uint32_t n;
#ifndef BENCHMARKS
# ifdef __EMSCRIPTEN__
assert(strcmp(randombytes_implementation_name(), "js") == 0);
# else
assert(strcmp(randombytes_implementation_name(), "sysrandom") == 0);
# endif
#endif
randombytes(x, 1U);
do {
n = randombytes_random();
f |= ((n >> 24) > 1);
f |= ((n >> 16) > 1) << 1;
f |= ((n >> 8) > 1) << 2;
f |= ((n) > 1) << 3;
f |= (n > 0x7fffffff) << 4;
} while (f != 0x1f);
randombytes_close();
for (i = 0; i < 256; ++i) {
freq[i] = 0;
}
for (i = 0; i < 65536; ++i) {
++freq[randombytes_uniform(256)];
}
for (i = 0; i < 256; ++i) {
if (!freq[i]) {
printf("randombytes_uniform() test failed\n");
}
}
assert(randombytes_uniform(1U) == 0U);
randombytes_close();
#ifndef __EMSCRIPTEN__
assert(&randombytes_internal_implementation == &randombytes_salsa20_implementation);
randombytes_set_implementation(&randombytes_internal_implementation);
assert(strcmp(randombytes_implementation_name(), "internal") == 0);
#endif
randombytes_stir();
for (i = 0; i < 256; ++i) {
freq[i] = 0;
}
for (i = 0; i < 65536; ++i) {
++freq[randombytes_uniform(256)];
}
for (i = 0; i < 256; ++i) {
if (!freq[i]) {
printf("randombytes_uniform() test failed\n");
}
}
memset(x, 0, sizeof x);
randombytes_buf(x, sizeof x);
for (i = 0; i < 256; ++i) {
freq[i] = 0;
}
for (i = 0; i < sizeof x; ++i) {
++freq[255 & (int) x[i]];
}
for (i = 0; i < 256; ++i) {
if (!freq[i]) {
printf("randombytes_buf() test failed\n");
}
}
assert(randombytes_uniform(1U) == 0U);
randombytes_buf_deterministic(out, sizeof out, seed);
for (i = 0; i < sizeof out; ++i) {
printf("%02x", out[i]);
}
printf(" (deterministic)\n");
randombytes_close();
randombytes(x, 1U);
randombytes_close();
assert(randombytes_SEEDBYTES > 0);
assert(randombytes_seedbytes() == randombytes_SEEDBYTES);
return 0;
}
static uint32_t
randombytes_uniform_impl(const uint32_t upper_bound)
{
return upper_bound;
}
static int
impl_tests(void)
{
randombytes_implementation impl = randombytes_sysrandom_implementation;
uint32_t v = randombytes_random();
impl.uniform = randombytes_uniform_impl;
randombytes_close();
randombytes_set_implementation(&impl);
assert(randombytes_uniform(1) == 1);
assert(randombytes_uniform(v) == v);
assert(randombytes_uniform(v) == v);
assert(randombytes_uniform(v) == v);
assert(randombytes_uniform(v) == v);
randombytes_close();
impl.close = NULL;
randombytes_close();
return 0;
}
int
main(void)
{
compat_tests();
randombytes_tests();
#ifndef __EMSCRIPTEN__
impl_tests();
#endif
printf("OK\n");
#ifndef __EMSCRIPTEN__
randombytes_set_implementation(&randombytes_salsa20_implementation);
#endif
return 0;
}

Some files were not shown because too many files have changed in this diff Show More