003 File Manager
Current Path:
/usr/src/sys/contrib/libsodium/test/default
usr
/
src
/
sys
/
contrib
/
libsodium
/
test
/
default
/
📁
..
📄
Makefile.am
(13.38 KB)
📄
aead_aes256gcm.c
(145.82 KB)
📄
aead_aes256gcm.exp
(3 B)
📄
aead_chacha20poly1305.c
(14.76 KB)
📄
aead_chacha20poly1305.exp
(2.35 KB)
📄
aead_xchacha20poly1305.c
(8.09 KB)
📄
aead_xchacha20poly1305.exp
(1.95 KB)
📄
auth.c
(2.88 KB)
📄
auth.exp
(1.12 KB)
📄
auth2.c
(1.08 KB)
📄
auth2.exp
(164 B)
📄
auth3.c
(1.25 KB)
📄
auth3.exp
(2 B)
📄
auth5.c
(954 B)
📄
auth6.c
(449 B)
📄
auth6.exp
(328 B)
📄
auth7.c
(1010 B)
📄
box.c
(4.42 KB)
📄
box.exp
(1.47 KB)
📄
box2.c
(3.31 KB)
📄
box2.exp
(1.31 KB)
📄
box7.c
(1.53 KB)
📄
box8.c
(1.7 KB)
📄
box_easy.c
(2.83 KB)
📄
box_easy.exp
(908 B)
📄
box_easy2.c
(5.42 KB)
📄
box_easy2.exp
(15 B)
📄
box_seal.c
(1.2 KB)
📄
box_seal.exp
(11 B)
📄
box_seed.c
(839 B)
📄
box_seed.exp
(328 B)
📄
chacha20.c
(7.63 KB)
📄
chacha20.exp
(20.19 KB)
📄
cmptest.h
(4.22 KB)
📄
codecs.c
(11.08 KB)
📄
codecs.exp
(367 B)
📄
core1.c
(1.18 KB)
📄
core1.exp
(164 B)
📄
core2.c
(1.19 KB)
📄
core2.exp
(164 B)
📄
core3.c
(3.19 KB)
📄
core3.exp
(195 B)
📄
core4.c
(981 B)
📄
core4.exp
(264 B)
📄
core5.c
(908 B)
📄
core5.exp
(164 B)
📄
core6.c
(1.31 KB)
📄
core6.exp
(164 B)
📄
core_ed25519.c
(5.44 KB)
📄
core_ed25519.exp
(3 B)
📄
ed25519_convert.c
(3.4 KB)
📄
ed25519_convert.exp
(167 B)
📄
generichash.c
(144.45 KB)
📄
generichash.exp
(4.25 KB)
📄
generichash2.c
(2.41 KB)
📄
generichash2.exp
(4.13 KB)
📄
generichash3.c
(7.17 KB)
📄
generichash3.exp
(5.51 KB)
📄
hash.c
(1.47 KB)
📄
hash.exp
(388 B)
📄
hash2.exp
(129 B)
📄
hash3.c
(335 B)
📄
hash3.exp
(129 B)
📄
index.html.tpl
(2.67 KB)
📄
kdf.c
(2.31 KB)
📄
kdf.exp
(5.97 KB)
📄
keygen.c
(2.62 KB)
📄
keygen.exp
(14 B)
📄
kx.c
(6.21 KB)
📄
kx.exp
(478 B)
📄
metamorphic.c
(5.48 KB)
📄
metamorphic.exp
(3 B)
📄
misuse.c
(3.67 KB)
📄
nacl-test-wrapper.sh
(771 B)
📄
onetimeauth.c
(2.32 KB)
📄
onetimeauth.exp
(164 B)
📄
onetimeauth2.c
(1.38 KB)
📄
onetimeauth2.exp
(2 B)
📄
onetimeauth7.c
(948 B)
📄
pre.js.inc
(563 B)
📄
pwhash_argon2i.c
(21.74 KB)
📄
pwhash_argon2i.exp
(3.03 KB)
📄
pwhash_argon2id.c
(25.18 KB)
📄
pwhash_argon2id.exp
(3.61 KB)
📄
pwhash_scrypt.c
(18.31 KB)
📄
pwhash_scrypt.exp
(4.53 KB)
📄
pwhash_scrypt_ll.c
(1.68 KB)
📄
pwhash_scrypt_ll.exp
(714 B)
📄
randombytes.c
(4 KB)
📄
randombytes.exp
(220 B)
📄
scalarmult.c
(2.42 KB)
📄
scalarmult.exp
(260 B)
📄
scalarmult2.c
(794 B)
📄
scalarmult2.exp
(164 B)
📄
scalarmult5.c
(1.18 KB)
📄
scalarmult5.exp
(164 B)
📄
scalarmult6.c
(1.51 KB)
📄
scalarmult6.exp
(164 B)
📄
scalarmult7.c
(909 B)
📄
scalarmult7.exp
(2 B)
📄
scalarmult_ed25519.c
(3.4 KB)
📄
scalarmult_ed25519.exp
(3 B)
📄
secretbox.c
(3.5 KB)
📄
secretbox.exp
(1.47 KB)
📄
secretbox2.c
(2.37 KB)
📄
secretbox2.exp
(672 B)
📄
secretbox7.c
(1.05 KB)
📄
secretbox8.c
(1.2 KB)
📄
secretbox_easy.c
(4.44 KB)
📄
secretbox_easy.exp
(4.02 KB)
📄
secretbox_easy2.c
(2.54 KB)
📄
secretbox_easy2.exp
(10 B)
📄
secretstream.c
(11.43 KB)
📄
secretstream.exp
(3 B)
📄
shorthash.c
(968 B)
📄
shorthash.exp
(1.06 KB)
📄
sign.c
(2.65 MB)
📄
sign.exp
(512 B)
📄
siphashx24.c
(1.02 KB)
📄
siphashx24.exp
(2.06 KB)
📄
sodium_core.c
(936 B)
📄
sodium_core.exp
(17 B)
📄
sodium_utils.c
(6.41 KB)
📄
sodium_utils.exp
(550 B)
📄
sodium_utils2.c
(2.22 KB)
📄
sodium_utils2.exp
(46 B)
📄
sodium_utils3.c
(1.35 KB)
📄
sodium_utils3.exp
(43 B)
📄
sodium_version.c
(387 B)
📄
sodium_version.exp
(6 B)
📄
stream.c
(2.33 KB)
📄
stream.exp
(8.57 KB)
📄
stream2.c
(1.48 KB)
📄
stream2.exp
(130 B)
📄
stream3.c
(979 B)
📄
stream3.exp
(164 B)
📄
stream4.c
(2.02 KB)
📄
stream4.exp
(672 B)
📄
verify1.c
(2.05 KB)
📄
verify1.exp
(6 B)
📄
wintest.bat
(1.34 KB)
📄
xchacha20.c
(25.49 KB)
📄
xchacha20.exp
(482 B)
Editing: secretstream.c
#define TEST_NAME "secretstream" #include "cmptest.h" int main(void) { crypto_secretstream_xchacha20poly1305_state *state, *statesave; crypto_secretstream_xchacha20poly1305_state state_copy; unsigned char *ad; unsigned char *header; unsigned char *k; unsigned char *c1, *c2, *c3, *csave; unsigned char *m1, *m2, *m3; unsigned char *m1_, *m2_, *m3_; unsigned long long res_len; size_t ad_len; size_t m1_len, m2_len, m3_len; int ret; unsigned char tag; state = (crypto_secretstream_xchacha20poly1305_state *) sodium_malloc(crypto_secretstream_xchacha20poly1305_statebytes()); statesave = (crypto_secretstream_xchacha20poly1305_state *) sodium_malloc(crypto_secretstream_xchacha20poly1305_statebytes()); header = (unsigned char *) sodium_malloc(crypto_secretstream_xchacha20poly1305_HEADERBYTES); ad_len = randombytes_uniform(100); m1_len = randombytes_uniform(1000); m2_len = randombytes_uniform(1000); m3_len = randombytes_uniform(1000); c1 = (unsigned char *) sodium_malloc(m1_len + crypto_secretstream_xchacha20poly1305_ABYTES); c2 = (unsigned char *) sodium_malloc(m2_len + crypto_secretstream_xchacha20poly1305_ABYTES); c3 = (unsigned char *) sodium_malloc(m3_len + crypto_secretstream_xchacha20poly1305_ABYTES); csave = (unsigned char *) sodium_malloc((m1_len | m2_len | m3_len) + crypto_secretstream_xchacha20poly1305_ABYTES); ad = (unsigned char *) sodium_malloc(ad_len); m1 = (unsigned char *) sodium_malloc(m1_len); m2 = (unsigned char *) sodium_malloc(m2_len); m3 = (unsigned char *) sodium_malloc(m3_len); m1_ = (unsigned char *) sodium_malloc(m1_len); m2_ = (unsigned char *) sodium_malloc(m2_len); m3_ = (unsigned char *) sodium_malloc(m3_len); randombytes_buf(ad, ad_len); randombytes_buf(m1, m1_len); memcpy(m1_, m1, m1_len); randombytes_buf(m2, m2_len); memcpy(m2_, m2, m2_len); randombytes_buf(m3, m3_len); memcpy(m3_, m3, m3_len); k = (unsigned char *) sodium_malloc(crypto_secretstream_xchacha20poly1305_KEYBYTES); crypto_secretstream_xchacha20poly1305_keygen(k); /* push */ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c1, &res_len, m1, m1_len, NULL, 0, 0); assert(ret == 0); assert(res_len == m1_len + crypto_secretstream_xchacha20poly1305_ABYTES); ret = crypto_secretstream_xchacha20poly1305_push (state, c2, NULL, m2, m2_len, ad, 0, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c3, NULL, m3, m3_len, ad, ad_len, crypto_secretstream_xchacha20poly1305_TAG_FINAL); assert(ret == 0); /* pull */ ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m1, &res_len, &tag, c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); assert(tag == 0); assert(memcmp(m1, m1_, m1_len) == 0); assert(res_len == m1_len); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); assert(tag == 0); assert(memcmp(m2, m2_, m2_len) == 0); if (ad_len > 0) { ret = crypto_secretstream_xchacha20poly1305_pull (state, m3, NULL, &tag, c3, m3_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == -1); } ret = crypto_secretstream_xchacha20poly1305_pull (state, m3, NULL, &tag, c3, m3_len + crypto_secretstream_xchacha20poly1305_ABYTES, ad, ad_len); assert(ret == 0); assert(tag == crypto_secretstream_xchacha20poly1305_TAG_FINAL); assert(memcmp(m3, m3_, m3_len) == 0); /* previous with FINAL tag */ ret = crypto_secretstream_xchacha20poly1305_pull (state, m3, NULL, &tag, c3, m3_len + crypto_secretstream_xchacha20poly1305_ABYTES, ad, ad_len); assert(ret == -1); /* previous without a tag */ ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == -1); /* short ciphertext */ ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, randombytes_uniform(crypto_secretstream_xchacha20poly1305_ABYTES), NULL, 0); assert(ret == -1); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, 0, NULL, 0); assert(ret == -1); /* empty ciphertext */ ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == -1); /* without explicit rekeying */ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c1, NULL, m1, m1_len, NULL, 0, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c2, NULL, m2, m2_len, NULL, 0, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m1, NULL, &tag, c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); /* with explicit rekeying */ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c1, NULL, m1, m1_len, NULL, 0, 0); assert(ret == 0); crypto_secretstream_xchacha20poly1305_rekey(state); ret = crypto_secretstream_xchacha20poly1305_push (state, c2, NULL, m2, m2_len, NULL, 0, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m1, NULL, &tag, c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == -1); crypto_secretstream_xchacha20poly1305_rekey(state); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); /* with explicit rekeying using TAG_REKEY */ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k); assert(ret == 0); memcpy(statesave, state, sizeof *state); ret = crypto_secretstream_xchacha20poly1305_push (state, c1, NULL, m1, m1_len, NULL, 0, crypto_secretstream_xchacha20poly1305_TAG_REKEY); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c2, NULL, m2, m2_len, NULL, 0, 0); assert(ret == 0); memcpy(csave, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES); ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m1, NULL, &tag, c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, &tag, 0); assert(ret == 0); assert(tag == crypto_secretstream_xchacha20poly1305_TAG_REKEY); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, &tag, 0); assert(ret == 0); assert(tag == 0); memcpy(state, statesave, sizeof *state); ret = crypto_secretstream_xchacha20poly1305_push (state, c1, NULL, m1, m1_len, NULL, 0, 0); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c2, NULL, m2, m2_len, NULL, 0, 0); assert(ret == 0); assert(memcmp(csave, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES) != 0); /* New stream */ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_push (state, c1, &res_len, m1, m1_len, NULL, 0, crypto_secretstream_xchacha20poly1305_TAG_PUSH); assert(ret == 0); assert(res_len == m1_len + crypto_secretstream_xchacha20poly1305_ABYTES); /* Force a counter overflow, check that the key has been updated * even though the tag was not changed to REKEY */ memset(state->nonce, 0xff, 4U); state_copy = *state; ret = crypto_secretstream_xchacha20poly1305_push (state, c2, NULL, m2, m2_len, ad, 0, 0); assert(ret == 0); assert(memcmp(state_copy.k, state->k, sizeof state->k) != 0); assert(memcmp(state_copy.nonce, state->nonce, sizeof state->nonce) != 0); assert(state->nonce[0] == 1U); assert(sodium_is_zero(state->nonce + 1, 3U)); ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k); assert(ret == 0); ret = crypto_secretstream_xchacha20poly1305_pull (state, m1, &res_len, &tag, c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); assert(tag == crypto_secretstream_xchacha20poly1305_TAG_PUSH); assert(memcmp(m1, m1_, m1_len) == 0); assert(res_len == m1_len); memset(state->nonce, 0xff, 4U); ret = crypto_secretstream_xchacha20poly1305_pull (state, m2, NULL, &tag, c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0); assert(ret == 0); assert(tag == 0); assert(memcmp(m2, m2_, m2_len) == 0); sodium_free(m3_); sodium_free(m2_); sodium_free(m1_); sodium_free(m3); sodium_free(m2); sodium_free(m1); sodium_free(ad); sodium_free(csave); sodium_free(c3); sodium_free(c2); sodium_free(c1); sodium_free(k); sodium_free(header); sodium_free(statesave); sodium_free(state); assert(crypto_secretstream_xchacha20poly1305_abytes() == crypto_secretstream_xchacha20poly1305_ABYTES); assert(crypto_secretstream_xchacha20poly1305_headerbytes() == crypto_secretstream_xchacha20poly1305_HEADERBYTES); assert(crypto_secretstream_xchacha20poly1305_keybytes() == crypto_secretstream_xchacha20poly1305_KEYBYTES); assert(crypto_secretstream_xchacha20poly1305_messagebytes_max() == crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX); assert(crypto_secretstream_xchacha20poly1305_tag_message() == crypto_secretstream_xchacha20poly1305_TAG_MESSAGE); assert(crypto_secretstream_xchacha20poly1305_tag_push() == crypto_secretstream_xchacha20poly1305_TAG_PUSH); assert(crypto_secretstream_xchacha20poly1305_tag_rekey() == crypto_secretstream_xchacha20poly1305_TAG_REKEY); assert(crypto_secretstream_xchacha20poly1305_tag_final() == crypto_secretstream_xchacha20poly1305_TAG_FINAL); printf("OK\n"); return 0; }
Upload File
Create Folder