summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2014-11-11 11:18:18 -0500
committerMicah Anderson <micah@riseup.net>2014-11-11 11:18:18 -0500
commitc73b6c9ba513fea3e18b696e659049df69931171 (patch)
treea001cd6acbecead76b9a55f324278e8d077fe3d5 /test
parenteabdc6e3d62550679476899dd861c23b63937142 (diff)
update to 1.0.0-1 version of the package
Diffstat (limited to 'test')
-rw-r--r--test/default/Makefile.am44
-rw-r--r--test/default/aead_chacha20poly1305.c68
-rw-r--r--test/default/aead_chacha20poly1305.exp8
-rw-r--r--test/default/auth.c57
-rw-r--r--test/default/auth.exp22
-rw-r--r--test/default/auth2.c43
-rw-r--r--test/default/auth2.exp4
-rw-r--r--test/default/auth3.c42
-rw-r--r--test/default/auth3.exp1
-rw-r--r--test/default/auth5.c48
-rw-r--r--test/default/auth5.exp0
-rw-r--r--test/default/auth6.c17
-rw-r--r--test/default/auth6.exp8
-rw-r--r--test/default/auth7.c48
-rw-r--r--test/default/auth7.exp0
-rw-r--r--test/default/box.c125
-rw-r--r--test/default/box.exp38
-rw-r--r--test/default/box2.c99
-rw-r--r--test/default/box2.exp34
-rw-r--r--test/default/box7.c38
-rw-r--r--test/default/box7.exp0
-rw-r--r--test/default/box8.c52
-rw-r--r--test/default/box8.exp0
-rw-r--r--test/default/box_easy.c74
-rw-r--r--test/default/box_easy.exp19
-rw-r--r--test/default/box_easy2.c8
-rw-r--r--test/default/box_easy2.exp2
-rw-r--r--test/default/box_seed.c40
-rw-r--r--test/default/box_seed.exp8
-rw-r--r--test/default/chacha20.c62
-rw-r--r--test/default/chacha20.exp8
-rw-r--r--test/default/cmptest.h4
-rw-r--r--test/default/core1.c45
-rw-r--r--test/default/core1.exp4
-rw-r--r--test/default/core2.c47
-rw-r--r--test/default/core2.exp4
-rw-r--r--test/default/core3.c56
-rw-r--r--test/default/core3.exp1
-rw-r--r--test/default/core4.c45
-rw-r--r--test/default/core4.exp8
-rw-r--r--test/default/core5.c40
-rw-r--r--test/default/core5.exp4
-rw-r--r--test/default/core6.c67
-rw-r--r--test/default/core6.exp4
-rw-r--r--test/default/ed25519_convert.c44
-rw-r--r--test/default/ed25519_convert.exp3
-rw-r--r--test/default/generichash.c74
-rw-r--r--test/default/generichash.exp66
-rw-r--r--test/default/generichash2.c43
-rw-r--r--test/default/generichash2.exp64
-rw-r--r--test/default/generichash3.c178
-rw-r--r--test/default/generichash3.exp75
-rw-r--r--test/default/hash.c37
-rw-r--r--test/default/hash.exp4
-rw-r--r--test/default/hash2.exp1
-rw-r--r--test/default/hash3.c17
-rw-r--r--test/default/hash3.exp1
-rw-r--r--test/default/onetimeauth.c80
-rw-r--r--test/default/onetimeauth.exp4
-rw-r--r--test/default/onetimeauth2.c52
-rw-r--r--test/default/onetimeauth2.exp1
-rw-r--r--test/default/onetimeauth7.c48
-rw-r--r--test/default/onetimeauth7.exp0
-rw-r--r--test/default/pwhash.c344
-rw-r--r--test/default/pwhash.exp31
-rw-r--r--test/default/pwhash_scrypt_ll.c68
-rw-r--r--test/default/pwhash_scrypt_ll.exp15
-rw-r--r--test/default/randombytes.c93
-rw-r--r--test/default/randombytes.exp1
-rw-r--r--test/default/scalarmult.c43
-rw-r--r--test/default/scalarmult.exp4
-rw-r--r--test/default/scalarmult2.c35
-rw-r--r--test/default/scalarmult2.exp4
-rw-r--r--test/default/scalarmult5.c45
-rw-r--r--test/default/scalarmult5.exp4
-rw-r--r--test/default/scalarmult6.c45
-rw-r--r--test/default/scalarmult6.exp4
-rw-r--r--test/default/scalarmult7.c31
-rw-r--r--test/default/scalarmult7.exp1
-rw-r--r--test/default/secretbox.c95
-rw-r--r--test/default/secretbox.exp19
-rw-r--r--test/default/secretbox2.c77
-rw-r--r--test/default/secretbox2.exp17
-rw-r--r--test/default/secretbox7.c36
-rw-r--r--test/default/secretbox7.exp0
-rw-r--r--test/default/secretbox8.c50
-rw-r--r--test/default/secretbox8.exp0
-rw-r--r--test/default/secretbox_easy.c98
-rw-r--r--test/default/secretbox_easy.exp38
-rw-r--r--test/default/secretbox_easy2.c8
-rw-r--r--test/default/secretbox_easy2.exp2
-rw-r--r--test/default/shorthash.c27
-rw-r--r--test/default/shorthash.exp64
-rw-r--r--test/default/sign.c114
-rw-r--r--test/default/sign.exp3
-rw-r--r--test/default/sodium_core.c9
-rw-r--r--test/default/sodium_core.exp1
-rw-r--r--test/default/sodium_utils.c85
-rw-r--r--test/default/sodium_utils.exp13
-rw-r--r--test/default/sodium_utils2.c72
-rw-r--r--test/default/sodium_utils2.exp3
-rw-r--r--test/default/sodium_utils3.c50
-rw-r--r--test/default/sodium_utils3.exp2
-rw-r--r--test/default/sodium_version.c9
-rw-r--r--test/default/sodium_version.exp3
-rw-r--r--test/default/stream.c40
-rw-r--r--test/default/stream.exp1
-rw-r--r--test/default/stream2.c32
-rw-r--r--test/default/stream2.exp1
-rw-r--r--test/default/stream3.c36
-rw-r--r--test/default/stream3.exp4
-rw-r--r--test/default/stream4.c81
-rw-r--r--test/default/stream4.exp17
-rw-r--r--test/default/stream5.c29
-rw-r--r--test/default/stream6.c54
-rw-r--r--test/default/verify1.c38
-rw-r--r--test/default/verify1.exp6
117 files changed, 2795 insertions, 1345 deletions
diff --git a/test/default/Makefile.am b/test/default/Makefile.am
index 8ad3c1f..11d76e0 100644
--- a/test/default/Makefile.am
+++ b/test/default/Makefile.am
@@ -23,6 +23,7 @@ EXTRA_DIST = \
core4.exp \
core5.exp \
core6.exp \
+ ed25519_convert.exp \
generichash.exp \
generichash2.exp \
generichash3.exp \
@@ -34,10 +35,12 @@ EXTRA_DIST = \
onetimeauth7.exp \
pwhash.exp \
pwhash_scrypt_ll.exp \
+ randombytes.exp \
scalarmult.exp \
scalarmult2.exp \
scalarmult5.exp \
scalarmult6.exp \
+ scalarmult7.exp \
secretbox.exp \
secretbox2.exp \
secretbox7.exp \
@@ -48,13 +51,13 @@ EXTRA_DIST = \
sign.exp \
sodium_core.exp \
sodium_utils.exp \
+ sodium_utils2.exp \
+ sodium_utils3.exp \
sodium_version.exp \
stream.exp \
stream2.exp \
stream3.exp \
stream4.exp \
- stream5.exp \
- stream6.exp \
verify1.exp
DISTCLEANFILES = \
@@ -79,6 +82,7 @@ DISTCLEANFILES = \
core4.res \
core5.res \
core6.res \
+ ed25519_convert.res \
generichash.res \
generichash2.res \
generichash3.res \
@@ -90,10 +94,12 @@ DISTCLEANFILES = \
onetimeauth7.res \
pwhash.res \
pwhash_scrypt_ll.res \
+ randombytes.res \
scalarmult.res \
scalarmult2.res \
scalarmult5.res \
scalarmult6.res \
+ scalarmult7.res \
secretbox.res \
secretbox2.res \
secretbox7.res \
@@ -104,13 +110,13 @@ DISTCLEANFILES = \
sign.res \
sodium_core.res \
sodium_utils.res \
+ sodium_utils2.res \
+ sodium_utils3.res \
sodium_version.res \
stream.res \
stream2.res \
stream3.res \
stream4.res \
- stream5.res \
- stream6.res \
verify1.res
AM_CPPFLAGS = \
@@ -143,6 +149,7 @@ TESTS_TARGETS = \
core4 \
core5 \
core6 \
+ ed25519_convert \
generichash \
generichash2 \
generichash3 \
@@ -158,6 +165,7 @@ TESTS_TARGETS = \
scalarmult2 \
scalarmult5 \
scalarmult6 \
+ scalarmult7 \
secretbox \
secretbox2 \
secretbox7 \
@@ -168,6 +176,8 @@ TESTS_TARGETS = \
sign \
sodium_core \
sodium_utils \
+ sodium_utils2 \
+ sodium_utils3 \
sodium_version \
stream \
stream2 \
@@ -175,12 +185,6 @@ TESTS_TARGETS = \
stream4 \
verify1
-if !MINIMAL
-TESTS_TARGETS += \
- stream5 \
- stream6
-endif
-
check_PROGRAMS = $(TESTS_TARGETS)
TESTS = $(TESTS_TARGETS)
@@ -251,6 +255,9 @@ 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)
@@ -281,7 +288,7 @@ pwhash_LDADD = $(TESTS_LDADD)
pwhash_scrypt_ll_SOURCE = cmptest.h pwhash_scrypt_ll.c
pwhash_scrypt_ll_LDADD = $(TESTS_LDADD)
-randombytes_SOURCE = randombytes.c
+randombytes_SOURCE = cmptest.h randombytes.c
randombytes_LDADD = $(TESTS_LDADD)
scalarmult_SOURCE = cmptest.h scalarmult.c
@@ -296,6 +303,9 @@ scalarmult5_LDADD = $(TESTS_LDADD)
scalarmult6_SOURCE = cmptest.h scalarmult6.c
scalarmult6_LDADD = $(TESTS_LDADD)
+scalarmult7_SOURCE = cmptest.h scalarmult7.c
+scalarmult7_LDADD = $(TESTS_LDADD)
+
secretbox_SOURCE = cmptest.h secretbox.c
secretbox_LDADD = $(TESTS_LDADD)
@@ -326,6 +336,12 @@ 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)
@@ -341,12 +357,6 @@ stream3_LDADD = $(TESTS_LDADD)
stream4_SOURCE = cmptest.h stream4.c
stream4_LDADD = $(TESTS_LDADD)
-stream5_SOURCE = cmptest.h stream5.c
-stream5_LDADD = $(TESTS_LDADD)
-
-stream6_SOURCE = cmptest.h stream6.c
-stream6_LDADD = $(TESTS_LDADD)
-
verify1_SOURCE = cmptest.h verify1.c
verify1_LDADD = $(TESTS_LDADD)
diff --git a/test/default/aead_chacha20poly1305.c b/test/default/aead_chacha20poly1305.c
index 036d001..c587e96 100644
--- a/test/default/aead_chacha20poly1305.c
+++ b/test/default/aead_chacha20poly1305.c
@@ -1,36 +1,29 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "aead_chacha20poly1305"
#include "cmptest.h"
-static 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 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 unsigned char m[10U] = {
- 0x86, 0xd0, 0x99, 0x74, 0x84, 0x0b, 0xde, 0xd2, 0xa5, 0xca
-};
+static unsigned char m[10U]
+ = { 0x86, 0xd0, 0x99, 0x74, 0x84, 0x0b, 0xde, 0xd2, 0xa5, 0xca };
-static unsigned char nonce[crypto_aead_chacha20poly1305_NPUBBYTES] = {
- 0xcd, 0x7c, 0xf6, 0x7b, 0xe3, 0x9c, 0x79, 0x4a
-};
+static unsigned char nonce[crypto_aead_chacha20poly1305_NPUBBYTES]
+ = { 0xcd, 0x7c, 0xf6, 0x7b, 0xe3, 0x9c, 0x79, 0x4a };
-static unsigned char ad[10U] = {
- 0x87, 0xe2, 0x29, 0xd4, 0x50, 0x08, 0x45, 0xa0, 0x79, 0xc0
-};
+static unsigned char ad[10U]
+ = { 0x87, 0xe2, 0x29, 0xd4, 0x50, 0x08, 0x45, 0xa0, 0x79, 0xc0 };
static unsigned char c[10U + crypto_aead_chacha20poly1305_ABYTES];
int main(void)
{
- unsigned char m2[10U];
+ unsigned char m2[10U];
unsigned long long clen;
unsigned long long m2len;
- size_t i;
+ size_t i;
crypto_aead_chacha20poly1305_encrypt(c, &clen, m, sizeof m, ad, sizeof ad,
NULL, nonce, firstkey);
@@ -38,16 +31,15 @@ int main(void)
printf("clen is not properly set\n");
}
for (i = 0U; i < sizeof c; ++i) {
- printf(",0x%02x", (unsigned int) c[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, sizeof c,
- ad, sizeof ad,
- nonce, firstkey) != 0) {
+ if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, sizeof c, ad,
+ sizeof ad, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed\n");
}
if (m2len != sizeof c - crypto_aead_chacha20poly1305_abytes()) {
@@ -60,21 +52,20 @@ int main(void)
for (i = 0U; i < sizeof c; i++) {
c[i] ^= (i + 1U);
if (crypto_aead_chacha20poly1305_decrypt(m2, NULL, NULL, c, sizeof c,
- ad, sizeof ad,
- nonce, firstkey) == 0 ||
- memcmp(m, m2, sizeof m) == 0) {
+ ad, sizeof ad, nonce, firstkey)
+ == 0 || memcmp(m, m2, sizeof m) == 0) {
printf("message can be forged\n");
}
c[i] ^= (i + 1U);
}
- crypto_aead_chacha20poly1305_encrypt(c, &clen, m, sizeof m, NULL, 0U,
- NULL, nonce, firstkey);
+ crypto_aead_chacha20poly1305_encrypt(c, &clen, m, sizeof m, NULL, 0U, NULL,
+ nonce, firstkey);
if (clen != sizeof m + crypto_aead_chacha20poly1305_abytes()) {
printf("clen is not properly set (adlen=0)\n");
}
for (i = 0U; i < sizeof c; ++i) {
- printf(",0x%02x", (unsigned int) c[i]);
+ printf(",0x%02x", (unsigned int)c[i]);
if (i % 8 == 7) {
printf("\n");
}
@@ -82,8 +73,7 @@ int main(void)
printf("\n");
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, sizeof c,
- NULL, 0U,
- nonce, firstkey) != 0) {
+ NULL, 0U, nonce, firstkey) != 0) {
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
}
if (m2len != sizeof c - crypto_aead_chacha20poly1305_abytes()) {
@@ -93,5 +83,21 @@ int main(void)
printf("m != m2 (adlen=0)\n");
}
+ if (crypto_aead_chacha20poly1305_decrypt(
+ m2, &m2len, NULL, c, crypto_aead_chacha20poly1305_ABYTES / 2, NULL,
+ 0U, nonce, firstkey) != -1) {
+ printf("crypto_aead_chacha20poly1305_decrypt() worked with a short "
+ "ciphertext\n");
+ }
+ 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");
+ }
+
+ assert(crypto_aead_chacha20poly1305_keybytes() > 0U);
+ assert(crypto_aead_chacha20poly1305_npubbytes() > 0U);
+ assert(crypto_aead_chacha20poly1305_nsecbytes() == 0U);
+
return 0;
}
diff --git a/test/default/aead_chacha20poly1305.exp b/test/default/aead_chacha20poly1305.exp
new file mode 100644
index 0000000..14355fa
--- /dev/null
+++ b/test/default/aead_chacha20poly1305.exp
@@ -0,0 +1,8 @@
+,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
diff --git a/test/default/auth.c b/test/default/auth.c
index 88c8207..913ada4 100644
--- a/test/default/auth.c
+++ b/test/default/auth.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#define TEST_NAME "auth"
#include "cmptest.h"
@@ -7,15 +6,55 @@
unsigned char key[32] = "Jefe";
unsigned char c[] = "what do ya want for nothing?";
-unsigned char a[32];
+/* Hacker manifesto */
+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.";
+
+unsigned char a[crypto_auth_BYTES];
+unsigned char a2[crypto_auth_hmacsha512_BYTES];
int main(void)
{
- int i;
- crypto_auth_hmacsha512256(a,c,sizeof c - 1U,key);
- for (i = 0;i < 32;++i) {
- printf(",0x%02x",(unsigned int) a[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ crypto_auth_hmacsha512_state st;
+ int i;
+
+ 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");
+ }
+
+ 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());
+
+ return 0;
}
diff --git a/test/default/auth.exp b/test/default/auth.exp
new file mode 100644
index 0000000..b18278c
--- /dev/null
+++ b/test/default/auth.exp
@@ -0,0 +1,22 @@
+,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
diff --git a/test/default/auth2.c b/test/default/auth2.c
index b3301cf..ffab022 100644
--- a/test/default/auth2.c
+++ b/test/default/auth2.c
@@ -1,36 +1,31 @@
/* "Test Case AUTH256-4" from RFC 4868 */
-#include <stdio.h>
-
#define TEST_NAME "auth2"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
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;
+ 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;
}
diff --git a/test/default/auth2.exp b/test/default/auth2.exp
new file mode 100644
index 0000000..955951a
--- /dev/null
+++ b/test/default/auth2.exp
@@ -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
diff --git a/test/default/auth3.c b/test/default/auth3.c
index 08e275a..3a299da 100644
--- a/test/default/auth3.c
+++ b/test/default/auth3.c
@@ -1,36 +1,28 @@
/* "Test Case AUTH256-4" from RFC 4868 */
-#include <stdio.h>
-
#define TEST_NAME "auth3"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
-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
-} ;
+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)
{
- printf("%d\n",crypto_auth_hmacsha256_verify(a,c,sizeof c,key));
- return 0;
+ printf("%d\n", crypto_auth_hmacsha256_verify(a, c, sizeof c, key));
+
+ return 0;
}
diff --git a/test/default/auth3.exp b/test/default/auth3.exp
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/default/auth3.exp
@@ -0,0 +1 @@
+0
diff --git a/test/default/auth5.c b/test/default/auth5.c
index ded9489..7557bd7 100644
--- a/test/default/auth5.c
+++ b/test/default/auth5.c
@@ -1,5 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
+
#include "windows/windows-quirks.h"
#define TEST_NAME "auth5"
@@ -11,27 +10,28 @@ unsigned char a[32];
int main(void)
{
- int clen;
- for (clen = 0;clen < 10000;++clen) {
- randombytes(key,sizeof key);
- randombytes(c,clen);
- crypto_auth_hmacsha512256(a,c,clen,key);
- if (crypto_auth_hmacsha512256_verify(a,c,clen,key) != 0) {
- printf("fail %d\n",clen);
- return 100;
- }
- if (clen > 0) {
- c[rand() % clen] += 1 + (rand() % 255);
- if (crypto_auth_hmacsha512256_verify(a,c,clen,key) == 0) {
- printf("forgery %d\n",clen);
- return 100;
- }
- a[rand() % sizeof a] += 1 + (rand() % 255);
- if (crypto_auth_hmacsha512256_verify(a,c,clen,key) == 0) {
- printf("forgery %d\n",clen);
- return 100;
- }
+ size_t clen;
+
+ for (clen = 0; clen < 10000; ++clen) {
+ randombytes_buf(key, sizeof 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;
+ }
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/test/default/auth5.exp b/test/default/auth5.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/auth5.exp
diff --git a/test/default/auth6.c b/test/default/auth6.c
index 5bf0500..9e7b671 100644
--- a/test/default/auth6.c
+++ b/test/default/auth6.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#define TEST_NAME "auth6"
#include "cmptest.h"
@@ -11,11 +10,13 @@ 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;
+ 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;
}
diff --git a/test/default/auth6.exp b/test/default/auth6.exp
new file mode 100644
index 0000000..da0c528
--- /dev/null
+++ b/test/default/auth6.exp
@@ -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
diff --git a/test/default/auth7.c b/test/default/auth7.c
index be67312..9a1e90c 100644
--- a/test/default/auth7.c
+++ b/test/default/auth7.c
@@ -1,5 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
+
#include "windows/windows-quirks.h"
#define TEST_NAME "auth7"
@@ -11,27 +10,28 @@ unsigned char a[64];
int main(void)
{
- int clen;
- for (clen = 0;clen < 10000;++clen) {
- randombytes(key,sizeof key);
- randombytes(c,clen);
- crypto_auth_hmacsha512(a,c,clen,key);
- if (crypto_auth_hmacsha512_verify(a,c,clen,key) != 0) {
- printf("fail %d\n",clen);
- return 100;
- }
- if (clen > 0) {
- c[rand() % clen] += 1 + (rand() % 255);
- if (crypto_auth_hmacsha512_verify(a,c,clen,key) == 0) {
- printf("forgery %d\n",clen);
- return 100;
- }
- a[rand() % sizeof a] += 1 + (rand() % 255);
- if (crypto_auth_hmacsha512_verify(a,c,clen,key) == 0) {
- printf("forgery %d\n",clen);
- return 100;
- }
+ int clen;
+
+ for (clen = 0; clen < 10000; ++clen) {
+ randombytes_buf(key, sizeof key);
+ randombytes_buf(c, clen);
+ crypto_auth_hmacsha512(a, c, clen, key);
+ if (crypto_auth_hmacsha512_verify(a, c, clen, key) != 0) {
+ printf("fail %d\n", clen);
+ return 100;
+ }
+ if (clen > 0) {
+ c[rand() % clen] += 1 + (rand() % 255);
+ if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
+ printf("forgery %d\n", clen);
+ return 100;
+ }
+ a[rand() % sizeof a] += 1 + (rand() % 255);
+ if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
+ printf("forgery %d\n", clen);
+ return 100;
+ }
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/test/default/auth7.exp b/test/default/auth7.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/auth7.exp
diff --git a/test/default/box.c b/test/default/box.c
index d9f2629..b9ba1cc 100644
--- a/test/default/box.c
+++ b/test/default/box.c
@@ -1,65 +1,88 @@
-#include <stdio.h>
#define TEST_NAME "box"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
-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
-} ;
+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
-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
-} ;
+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 };
unsigned char c[163];
int main(void)
{
- int i;
- crypto_box_curve25519xsalsa20poly1305(
- c,m,163,nonce,bobpk,alicesk
- );
- for (i = 16;i < 163;++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
- }
- printf("\n");
- return 0;
+ unsigned char k[crypto_box_BEFORENMBYTES];
+ int i;
+
+ crypto_box(c, m, 163, nonce, bobpk, alicesk);
+ for (i = 16; i < 163; ++i) {
+ printf(",0x%02x", (unsigned int)c[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ printf("\n");
+
+ memset(c, 0, sizeof c);
+ crypto_box_beforenm(k, bobpk, alicesk);
+ 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");
+
+ 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(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());
+
+ return 0;
}
diff --git a/test/default/box.exp b/test/default/box.exp
new file mode 100644
index 0000000..25db669
--- /dev/null
+++ b/test/default/box.exp
@@ -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
diff --git a/test/default/box2.c b/test/default/box2.c
index 7af2f58..93785f8 100644
--- a/test/default/box2.c
+++ b/test/default/box2.c
@@ -1,66 +1,63 @@
-#include <stdio.h>
#define TEST_NAME "box2"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
-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
-} ;
+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
-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
-} ;
+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 };
unsigned char m[163];
int main(void)
{
- int i;
- if (crypto_box_curve25519xsalsa20poly1305_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");
+ unsigned char k[crypto_box_BEFORENMBYTES];
+ int i;
+
+ 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");
+ }
+
+ memset(m, 0, sizeof m);
+ crypto_box_beforenm(k, alicepk, bobsk);
+ 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");
}
- printf("\n");
- }
- return 0;
+ return 0;
}
diff --git a/test/default/box2.exp b/test/default/box2.exp
new file mode 100644
index 0000000..51deccd
--- /dev/null
+++ b/test/default/box2.exp
@@ -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
diff --git a/test/default/box7.c b/test/default/box7.c
index ea7b484..e9b1db5 100644
--- a/test/default/box7.c
+++ b/test/default/box7.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#define TEST_NAME "box7"
#include "cmptest.h"
@@ -14,24 +13,27 @@ unsigned char m2[10000];
int main(void)
{
- size_t mlen;
- size_t i;
+ size_t mlen;
+ size_t i;
- for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) {
- crypto_box_keypair(alicepk,alicesk);
- crypto_box_keypair(bobpk,bobsk);
- randombytes(n,crypto_box_NONCEBYTES);
- randombytes(m + crypto_box_ZEROBYTES,mlen);
- crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk);
- 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;
+ for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
+ ++mlen) {
+ crypto_box_keypair(alicepk, alicesk);
+ crypto_box_keypair(bobpk, bobsk);
+ randombytes_buf(n, crypto_box_NONCEBYTES);
+ randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
+ crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
+ 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");
}
- } else {
- printf("ciphertext fails verification\n");
}
- }
- return 0;
+ return 0;
}
diff --git a/test/default/box7.exp b/test/default/box7.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/box7.exp
diff --git a/test/default/box8.c b/test/default/box8.c
index cc85057..fbfcff8 100644
--- a/test/default/box8.c
+++ b/test/default/box8.c
@@ -1,5 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
+
#include "windows/windows-quirks.h"
#define TEST_NAME "box8"
@@ -16,29 +15,32 @@ unsigned char m2[10000];
int main(void)
{
- size_t mlen;
- size_t i;
- int caught;
+ size_t mlen;
+ size_t i;
+ int caught;
- for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) {
- crypto_box_keypair(alicepk,alicesk);
- crypto_box_keypair(bobpk,bobsk);
- randombytes(n,crypto_box_NONCEBYTES);
- randombytes(m + crypto_box_ZEROBYTES,mlen);
- crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk);
- caught = 0;
- while (caught < 10) {
- 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 {
- ++caught;
- }
+ for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
+ ++mlen) {
+ crypto_box_keypair(alicepk, alicesk);
+ crypto_box_keypair(bobpk, bobsk);
+ randombytes_buf(n, crypto_box_NONCEBYTES);
+ randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
+ crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
+ caught = 0;
+ while (caught < 10) {
+ 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 {
+ ++caught;
+ }
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/test/default/box8.exp b/test/default/box8.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/box8.exp
diff --git a/test/default/box_easy.c b/test/default/box_easy.c
index d3b899f..e4ce8a6 100644
--- a/test/default/box_easy.c
+++ b/test/default/box_easy.c
@@ -1,47 +1,33 @@
-#include <stdio.h>
#define TEST_NAME "box_easy"
#include "cmptest.h"
-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
-} ;
-
-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
-} ;
-
-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
-} ;
-
-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
-} ;
+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 };
+
+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 };
+
+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 };
+
+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 };
unsigned char c[147 + crypto_box_MACBYTES];
@@ -51,9 +37,13 @@ int main(void)
crypto_box_easy(c, m, 131, nonce, bobpk, alicesk);
for (i = 0; i < 131 + crypto_box_MACBYTES; ++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
+ printf(",0x%02x", (unsigned int)c[i]);
+ if (i % 8 == 7)
+ printf("\n");
}
printf("\n");
+
+ assert(crypto_box_easy(c, m, SIZE_MAX - 1U, nonce, bobpk, alicesk) == -1);
+
return 0;
}
diff --git a/test/default/box_easy.exp b/test/default/box_easy.exp
new file mode 100644
index 0000000..2b6c51e
--- /dev/null
+++ b/test/default/box_easy.exp
@@ -0,0 +1,19 @@
+,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
diff --git a/test/default/box_easy2.c b/test/default/box_easy2.c
index c8753ee..5e22677 100644
--- a/test/default/box_easy2.c
+++ b/test/default/box_easy2.c
@@ -1,5 +1,3 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "box_easy2"
#include "cmptest.h"
@@ -21,12 +19,12 @@ int main(void)
crypto_box_keypair(alicepk, alicesk);
crypto_box_keypair(bobpk, bobsk);
- mlen = (unsigned long long) randombytes_uniform((uint32_t) sizeof m);
+ mlen = (unsigned long long)randombytes_uniform((uint32_t)sizeof m);
randombytes_buf(m, mlen);
randombytes_buf(nonce, sizeof nonce);
crypto_box_easy(c, m, mlen, nonce, bobpk, alicesk);
- if (crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES,
- nonce, alicepk, bobsk) != 0) {
+ if (crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES, nonce, alicepk,
+ bobsk) != 0) {
printf("open() failed");
return 1;
}
diff --git a/test/default/box_easy2.exp b/test/default/box_easy2.exp
new file mode 100644
index 0000000..aa47d0d
--- /dev/null
+++ b/test/default/box_easy2.exp
@@ -0,0 +1,2 @@
+0
+0
diff --git a/test/default/box_seed.c b/test/default/box_seed.c
index 6533d8c..5af2a50 100644
--- a/test/default/box_seed.c
+++ b/test/default/box_seed.c
@@ -1,28 +1,28 @@
-#include <stdio.h>
#define TEST_NAME "box_seed"
#include "cmptest.h"
-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
-};
+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_curve25519xsalsa20poly1305_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;
+ 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;
}
diff --git a/test/default/box_seed.exp b/test/default/box_seed.exp
new file mode 100644
index 0000000..20e6806
--- /dev/null
+++ b/test/default/box_seed.exp
@@ -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
diff --git a/test/default/chacha20.c b/test/default/chacha20.c
index 6dbc16c..b4334a8 100644
--- a/test/default/chacha20.c
+++ b/test/default/chacha20.c
@@ -1,7 +1,4 @@
-#include <stdio.h>
-#include <string.h>
-
#define TEST_NAME "chacha20"
#include "cmptest.h"
@@ -10,36 +7,59 @@ 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"}
- };
+ } 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 out[60];
- char out_hex[60 * 2 + 1];
- size_t i = 0U;
+ unsigned char out[160];
+ char out_hex[160 * 2 + 1];
+ size_t i = 0U;
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);
+ 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);
} while (++i < (sizeof tests) / (sizeof tests[0]));
+
+ memset(out, 0x42, sizeof out);
+
+ 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);
+
+ 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);
};
int main(void)
{
tv();
- return 0;
-}
+ assert(crypto_stream_chacha20_keybytes() > 0U);
+ assert(crypto_stream_chacha20_noncebytes() > 0U);
+ return 0;
+}
diff --git a/test/default/chacha20.exp b/test/default/chacha20.exp
new file mode 100644
index 0000000..b669430
--- /dev/null
+++ b/test/default/chacha20.exp
@@ -0,0 +1,8 @@
+[76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee65869f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29b721769ce64e43d57133b074d839d531ed1f28510afb45ace10a1f4b794d6f2d09a0e663266ce1ae7ed1081968a0758e718e997bd362c6b0c34634a9a0b35d]
+[4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea817e9ad275ae5469633aeb5224ecf849929b9d828db1ced4dd832025e8018b8160b82284f3c949aa5a8eca00bbb4a73bdad192b5c42f73f2fd4e273644c8b36125a64addeb006c13a096d68b9ff7b57e7090f880392effd5b297a83bbaf2fbe8cf5d4618965e3dc776]
+[de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df137821031e85a050278a7084527214f73efc7fa5b5277062eb7a0433e445f41e31afab757283547e3d3d30ee0371c1e6025ff4c91b794a291cf7568d48ff84b37329e2730b12738a072a2b2c7169e326fe4893a7b2421bb910b79599a7ce4fbaee86be427c5ee0e8225eb6f48231fd504939d59eac8bd106cc138779b893c54da8758f62a]
+[ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd138e50d32111e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d6bbdb0041b2f586b5305e5e44aff19b235936144675efbe4409eb7e8e5f1430f5f5836aeb49bb5328b017c4b9dc11f8a03863fa803dc71d5726b2b6b31aa32708afe5af1d6b690584d58792b271e5fdb92c486051c48b79a4d48a109bb2d0477956e74c25e93c3c2]
+[f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5a97a5f576fe064025]
+[b5dae3cbb3d7a42bc0521db92649f5373d15dfe15440bed1ae43ee14ba18818376e616393179040372008b06420b552b4791fc1ba85e11b31b54571e69aa66587a42c9d864fe77d65c6606553ec89c24cb9cd7640bc49b1acbb922aa046b8bffd818895e835afc147cfbf1e6e630ba6c4be5a53a0b69146cb5514cca9da27385dffb96b585eadb5759d8051270f47d81c7661da216a19f18d5e7b734bc440267]
+[42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242]
+[7a42c9d864fe77d65c6606553ec89c24cb9cd7640bc49b1acbb922aa046b8bffd818895e835afc147cfbf1e6e630ba6c4be5a53a0b69146cb5514cca9da27385dffb96b585eadb5759d8051270f47d81c7661da216a19f18d5e7b734bc440267918c466e1428f08745f37a99c77c7f2b1b244bd4162e8b86e4a8bf85358202954ced04b52fef7b3ba787744e715554285ecb0ed6e133c528d69d346abc0ce8b0]
diff --git a/test/default/cmptest.h b/test/default/cmptest.h
index ae84e43..156640c 100644
--- a/test/default/cmptest.h
+++ b/test/default/cmptest.h
@@ -2,7 +2,11 @@
#ifndef __CMPTEST_H__
#define __CMPTEST_H__
+#include <assert.h>
#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
#include "sodium.h"
diff --git a/test/default/core1.c b/test/default/core1.c
index 4c9453f..44f90c4 100644
--- a/test/default/core1.c
+++ b/test/default/core1.c
@@ -1,32 +1,39 @@
-#include <stdio.h>
#define TEST_NAME "core1"
#include "cmptest.h"
-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
-} ;
+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 };
unsigned char zero[32] = { 0 };
-unsigned char c[16] = {
- 0x65,0x78,0x70,0x61,0x6e,0x64,0x20,0x33
-,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,0x6b
-} ;
+unsigned char c[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
+ 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
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");
- }
- return 0;
+ 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;
}
diff --git a/test/default/core1.exp b/test/default/core1.exp
new file mode 100644
index 0000000..715a489
--- /dev/null
+++ b/test/default/core1.exp
@@ -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
diff --git a/test/default/core2.c b/test/default/core2.c
index b07df8d..6870acb 100644
--- a/test/default/core2.c
+++ b/test/default/core2.c
@@ -1,35 +1,36 @@
-#include <stdio.h>
#define TEST_NAME "core2"
#include "cmptest.h"
-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
-} ;
+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 };
-unsigned char nonceprefix[16] = {
- 0x69,0x69,0x6e,0xe9,0x55,0xb6,0x2b,0x73
-,0xcd,0x62,0xbd,0xa8,0x75,0xfc,0x73,0xd6
-} ;
+unsigned char nonceprefix[16]
+ = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
+ 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6 };
-unsigned char c[16] = {
- 0x65,0x78,0x70,0x61,0x6e,0x64,0x20,0x33
-,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,0x6b
-} ;
+unsigned char c[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
+ 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
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;
+ 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;
}
diff --git a/test/default/core2.exp b/test/default/core2.exp
new file mode 100644
index 0000000..f4682af
--- /dev/null
+++ b/test/default/core2.exp
@@ -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
diff --git a/test/default/core3.c b/test/default/core3.c
index 5d24fdd..210e25c 100644
--- a/test/default/core3.c
+++ b/test/default/core3.c
@@ -1,25 +1,19 @@
-#include <stdio.h>
#define TEST_NAME "core3"
#include "cmptest.h"
-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
-} ;
+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 };
-unsigned char noncesuffix[8] = {
- 0x82,0x19,0xe0,0x03,0x6b,0x7a,0x0b,0x37
-} ;
+unsigned char noncesuffix[8]
+ = { 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
-unsigned char c[16] = {
- 0x65,0x78,0x70,0x61,0x6e,0x64,0x20,0x33
-,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,0x6b
-} ;
+unsigned char c[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
+ 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
-unsigned char in[16] = { 0 } ;
+unsigned char in[16] = { 0 };
unsigned char output[64 * 256 * 256];
@@ -27,16 +21,26 @@ unsigned char h[32];
int main(void)
{
- int i;
- long long pos = 0;
- for (i = 0;i < 8;++i) in[i] = noncesuffix[i];
- do {
+ int i;
+ long long pos = 0;
+
+ for (i = 0; i < 8; ++i)
+ in[i] = noncesuffix[i];
do {
- crypto_core_salsa20(output + pos,in,secondkey,c);
- pos += 64;
- } while (++in[8]);
- } while (++in[9]);
- crypto_hash_sha256(h,output,sizeof output);
- for (i = 0;i < 32;++i) printf("%02x",h[i]); printf("\n");
- return 0;
+ do {
+ crypto_core_salsa20(output + pos, in, secondkey, c);
+ pos += 64;
+ } while (++in[8]);
+ } while (++in[9]);
+ crypto_hash_sha256(h, output, sizeof output);
+ for (i = 0; i < 32; ++i) {
+ printf("%02x", h[i]);
+ }
+ printf("\n");
+ assert(crypto_core_salsa20_outputbytes() > 0U);
+ assert(crypto_core_salsa20_inputbytes() > 0U);
+ assert(crypto_core_salsa20_keybytes() > 0U);
+ assert(crypto_core_salsa20_constbytes() > 0U);
+
+ return 0;
}
diff --git a/test/default/core3.exp b/test/default/core3.exp
new file mode 100644
index 0000000..5fa208c
--- /dev/null
+++ b/test/default/core3.exp
@@ -0,0 +1 @@
+662b9d0e3463029156069b12f918691a98f7dfb2ca0393c96bbfc6b1fbd630a2
diff --git a/test/default/core4.c b/test/default/core4.c
index d818723..611d392 100644
--- a/test/default/core4.c
+++ b/test/default/core4.c
@@ -1,35 +1,34 @@
-#include <stdio.h>
#define TEST_NAME "core4"
#include "cmptest.h"
-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
-} ;
+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 };
-unsigned char in[16] = {
- 101,102,103,104,105,106,107,108
-,109,110,111,112,113,114,115,116
-} ;
+unsigned char in[16] = { 101, 102, 103, 104, 105, 106, 107, 108,
+ 109, 110, 111, 112, 113, 114, 115, 116 };
-unsigned char c[16] = {
- 101,120,112, 97,110,100, 32, 51
-, 50, 45, 98,121,116,101, 32,107
-} ;
+unsigned char c[16] = { 101, 120, 112, 97, 110, 100, 32, 51,
+ 50, 45, 98, 121, 116, 101, 32, 107 };
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("%3d",(unsigned int) out[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ int i;
+
+ crypto_core_salsa20(out, in, k, c);
+ for (i = 0; i < 64; ++i) {
+ if (i > 0) {
+ printf(",");
+ } else {
+ printf(" ");
+ }
+ printf("%3d", (unsigned int)out[i]);
+ if (i % 8 == 7) {
+ printf("\n");
+ }
+ }
+ return 0;
}
diff --git a/test/default/core4.exp b/test/default/core4.exp
new file mode 100644
index 0000000..d04e5b5
--- /dev/null
+++ b/test/default/core4.exp
@@ -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
diff --git a/test/default/core5.c b/test/default/core5.c
index 467b27a..cf37397 100644
--- a/test/default/core5.c
+++ b/test/default/core5.c
@@ -1,34 +1,30 @@
-#include <stdio.h>
#define TEST_NAME "core5"
#include "cmptest.h"
-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
-} ;
+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 };
-unsigned char in[16] = {
- 0x81,0x91,0x8e,0xf2,0xa5,0xe0,0xda,0x9b
-,0x3e,0x90,0x60,0x52,0x1e,0x4b,0xb3,0x52
-} ;
+unsigned char in[16] = { 0x81, 0x91, 0x8e, 0xf2, 0xa5, 0xe0, 0xda, 0x9b,
+ 0x3e, 0x90, 0x60, 0x52, 0x1e, 0x4b, 0xb3, 0x52 };
-unsigned char c[16] = {
- 101,120,112, 97,110,100, 32, 51
-, 50, 45, 98,121,116,101, 32,107
-} ;
+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;
+ 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;
}
diff --git a/test/default/core5.exp b/test/default/core5.exp
new file mode 100644
index 0000000..562cf71
--- /dev/null
+++ b/test/default/core5.exp
@@ -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
diff --git a/test/default/core6.c b/test/default/core6.c
index 8a98696..67be323 100644
--- a/test/default/core6.c
+++ b/test/default/core6.c
@@ -1,49 +1,48 @@
-#include <stdio.h>
#define TEST_NAME "core6"
#include "cmptest.h"
-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
-} ;
+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 };
-unsigned char in[16] = {
- 0x81,0x91,0x8e,0xf2,0xa5,0xe0,0xda,0x9b
-,0x3e,0x90,0x60,0x52,0x1e,0x4b,0xb3,0x52
-} ;
+unsigned char in[16] = { 0x81, 0x91, 0x8e, 0xf2, 0xa5, 0xe0, 0xda, 0x9b,
+ 0x3e, 0x90, 0x60, 0x52, 0x1e, 0x4b, 0xb3, 0x52 };
-unsigned char c[16] = {
- 101,120,112, 97,110,100, 32, 51
-, 50, 45, 98,121,116,101, 32,107
-} ;
+unsigned char c[16] = { 101, 120, 112, 97, 110, 100, 32, 51,
+ 50, 45, 98, 121, 116, 101, 32, 107 };
unsigned char out[64];
-void print(unsigned char *x,unsigned char *y)
+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 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;
+ 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;
}
diff --git a/test/default/core6.exp b/test/default/core6.exp
new file mode 100644
index 0000000..562cf71
--- /dev/null
+++ b/test/default/core6.exp
@@ -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
diff --git a/test/default/ed25519_convert.c b/test/default/ed25519_convert.c
new file mode 100644
index 0000000..02c0641
--- /dev/null
+++ b/test/default/ed25519_convert.c
@@ -0,0 +1,44 @@
+
+#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;
+
+ crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, keypair_seed);
+ crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk);
+ 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);
+ crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk);
+ 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");
+ }
+ }
+ printf("ok\n");
+
+ return 0;
+}
diff --git a/test/default/ed25519_convert.exp b/test/default/ed25519_convert.exp
new file mode 100644
index 0000000..cba2b7b
--- /dev/null
+++ b/test/default/ed25519_convert.exp
@@ -0,0 +1,3 @@
+curve25519 pk: [f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50]
+curve25519 sk: [8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166]
+ok
diff --git a/test/default/generichash.c b/test/default/generichash.c
index 42a4a39..71c12e4 100644
--- a/test/default/generichash.c
+++ b/test/default/generichash.c
@@ -1,6 +1,3 @@
-#include <stdio.h>
-
-#include "crypto_uint8.h"
#define TEST_NAME "generichash"
#include "cmptest.h"
@@ -8,20 +5,67 @@
int main(void)
{
#define MAXLEN 64
- crypto_uint8 in[MAXLEN], out[crypto_generichash_BYTES_MAX], k[crypto_generichash_KEYBYTES_MAX];
- size_t h,i,j;
-
- for(h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h) k[h] = h;
-
- for(i = 0; i < MAXLEN; ++i) {
- in[i]=i;
- crypto_generichash(out, 1 + i % crypto_generichash_BYTES_MAX,
- in, i,
- k, 1 + i % crypto_generichash_KEYBYTES_MAX);
- for (j = 0;j < 1 + i % crypto_generichash_BYTES_MAX;++j) {
- printf("%02x",(unsigned int) out[j]);
+ unsigned char in[MAXLEN], out[crypto_generichash_BYTES_MAX],
+ k[crypto_generichash_KEYBYTES_MAX];
+ size_t h, i, j;
+
+ for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h)
+ k[h] = h;
+
+ for (i = 0; i < MAXLEN; ++i) {
+ in[i] = i;
+ crypto_generichash(out, 1 + i % crypto_generichash_BYTES_MAX, in, i, k,
+ 1 + i % crypto_generichash_KEYBYTES_MAX);
+ for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
+ printf("%02x", (unsigned int)out[j]);
}
printf("\n");
}
+
+ memset(out, 0, sizeof out);
+ crypto_generichash(out, crypto_generichash_BYTES_MAX, in, i, k, 0U);
+ for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) {
+ printf("%02x", (unsigned int)out[j]);
+ }
+ printf("\n");
+
+ memset(out, 0, sizeof out);
+ crypto_generichash(out, crypto_generichash_BYTES_MAX, in, i, NULL, 1U);
+ for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) {
+ printf("%02x", (unsigned int)out[j]);
+ }
+ printf("\n");
+
+ assert(crypto_generichash(out, 0U, in, sizeof in, k, sizeof k) == -1);
+ assert(crypto_generichash(out, crypto_generichash_BYTES_MAX + 1U, in, sizeof in,
+ k, sizeof k) == -1);
+ assert(crypto_generichash(out, sizeof out, in, sizeof in,
+ k, crypto_generichash_KEYBYTES_MAX + 1U) == -1);
+
+ assert(crypto_generichash_bytes_min() > 0U);
+ assert(crypto_generichash_bytes_max() > 0U);
+ assert(crypto_generichash_bytes() > 0U);
+ assert(crypto_generichash_bytes() >= crypto_generichash_bytes_min());
+ assert(crypto_generichash_bytes() <= crypto_generichash_bytes_max());
+ assert(crypto_generichash_keybytes_min() > 0U);
+ assert(crypto_generichash_keybytes_max() > 0U);
+ assert(crypto_generichash_keybytes() > 0U);
+ assert(crypto_generichash_keybytes() >= crypto_generichash_keybytes_min());
+ assert(crypto_generichash_keybytes() <= crypto_generichash_keybytes_max());
+ assert(strcmp(crypto_generichash_primitive(), "blake2b") == 0);
+ assert(crypto_generichash_bytes_min()
+ == crypto_generichash_blake2b_bytes_min());
+ assert(crypto_generichash_bytes_max()
+ == crypto_generichash_blake2b_bytes_max());
+ assert(crypto_generichash_bytes() == crypto_generichash_blake2b_bytes());
+ assert(crypto_generichash_keybytes_min()
+ == crypto_generichash_blake2b_keybytes_min());
+ assert(crypto_generichash_keybytes_max()
+ == crypto_generichash_blake2b_keybytes_max());
+ assert(crypto_generichash_keybytes()
+ == crypto_generichash_blake2b_keybytes());
+ assert(crypto_generichash_blake2b_saltbytes() > 0U);
+ assert(crypto_generichash_blake2b_personalbytes() > 0U);
+
return 0;
}
diff --git a/test/default/generichash.exp b/test/default/generichash.exp
new file mode 100644
index 0000000..4a918f9
--- /dev/null
+++ b/test/default/generichash.exp
@@ -0,0 +1,66 @@
+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
+2fc6e69fa26a89a5ed269092cb9b2a449a4409a7a44011eecad13d7c4b0456602d402fa5844f1a7a758136ce3d5d8d0e8b86921ffff4f692dd95bdc8e5ff0052
diff --git a/test/default/generichash2.c b/test/default/generichash2.c
index 4693a5f..cd9c889 100644
--- a/test/default/generichash2.c
+++ b/test/default/generichash2.c
@@ -1,6 +1,3 @@
-#include <stdio.h>
-
-#include "crypto_uint8.h"
#define TEST_NAME "generichash2"
#include "cmptest.h"
@@ -9,23 +6,43 @@ int main(void)
{
#define MAXLEN 64
crypto_generichash_state st;
- crypto_uint8 in[MAXLEN], out[crypto_generichash_BYTES_MAX], k[crypto_generichash_KEYBYTES_MAX];
- size_t h,i,j;
+ unsigned char in[MAXLEN], out[crypto_generichash_BYTES_MAX],
+ k[crypto_generichash_KEYBYTES_MAX];
+ size_t h, i, j;
- for(h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h) k[h] = h;
+ for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h)
+ k[h] = h;
- for(i = 0; i < MAXLEN; ++i) {
- in[i]=i;
- crypto_generichash_init(&st, k, 1 + i % crypto_generichash_KEYBYTES_MAX,
- 1 + i % crypto_generichash_BYTES_MAX);
+ for (i = 0; i < MAXLEN; ++i) {
+ in[i] = 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);
- crypto_generichash_final(&st, out, 1 + i % crypto_generichash_BYTES_MAX);
- for (j = 0;j < 1 + i % crypto_generichash_BYTES_MAX;++j) {
- printf("%02x",(unsigned int) out[j]);
+ crypto_generichash_final(&st, out,
+ 1 + i % crypto_generichash_BYTES_MAX);
+ for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
+ printf("%02x", (unsigned int)out[j]);
}
printf("\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);
return 0;
}
diff --git a/test/default/generichash2.exp b/test/default/generichash2.exp
new file mode 100644
index 0000000..5ee6f60
--- /dev/null
+++ b/test/default/generichash2.exp
@@ -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
diff --git a/test/default/generichash3.c b/test/default/generichash3.c
index dcd29e0..dca852d 100644
--- a/test/default/generichash3.c
+++ b/test/default/generichash3.c
@@ -1,6 +1,3 @@
-#include <stdio.h>
-
-#include "crypto_uint8.h"
#define TEST_NAME "generichash3"
#include "cmptest.h"
@@ -9,28 +6,165 @@ int main(void)
{
#define MAXLEN 64
crypto_generichash_blake2b_state st;
- crypto_uint8 salt[crypto_generichash_blake2b_SALTBYTES] = {
- '5', 'b', '6', 'b', '4', '1', 'e', 'd', '9', 'b', '3', '4', '3', 'f', 'e', '0'
- };
- crypto_uint8 personal[crypto_generichash_blake2b_PERSONALBYTES] = {
- '5', '1', '2', '6', 'f', 'b', '2', 'a', '3', '7', '4', '0', '0', 'd', '2', 'a'
- };
- crypto_uint8 in[MAXLEN], out[crypto_generichash_blake2b_BYTES_MAX], k[crypto_generichash_blake2b_KEYBYTES_MAX];
- size_t h,i,j;
-
- for(h = 0; h < crypto_generichash_blake2b_KEYBYTES_MAX; ++h) k[h] = h;
-
- for(i = 0; i < MAXLEN; ++i) {
- in[i]=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);
+ 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], out[crypto_generichash_blake2b_BYTES_MAX],
+ k[crypto_generichash_blake2b_KEYBYTES_MAX];
+ size_t h, i, j;
+
+ for (h = 0; h < crypto_generichash_blake2b_KEYBYTES_MAX; ++h)
+ k[h] = h;
+
+ for (i = 0; i < MAXLEN; ++i) {
+ in[i] = 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, 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]);
+ 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);
+ assert(crypto_generichash_blake2b_final(
+ &st, out, crypto_generichash_blake2b_BYTES_MAX + 1U) == -1);
+ 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, 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, 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");
+
+ 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, 0U,
+ salt, personal) == -1);
+ assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k,
+ crypto_generichash_BYTES_MAX + 1U,
+ salt, personal) == -1);
+ assert(crypto_generichash_blake2b_init_salt_personal(&st, k,
+ crypto_generichash_KEYBYTES_MAX + 1U,
+ sizeof out, salt, personal) == -1);
+
+ assert(crypto_generichash_blake2b_salt_personal(out, 0U, in, MAXLEN,
+ k, sizeof k,
+ salt, personal) == -1);
+ assert(crypto_generichash_blake2b_salt_personal(out, crypto_generichash_BYTES_MAX + 1U,
+ in, MAXLEN, k, sizeof k,
+ salt, personal) == -1);
+ assert(crypto_generichash_blake2b_salt_personal(out, sizeof out, in, MAXLEN,
+ k, crypto_generichash_KEYBYTES_MAX + 1U,
+ salt, personal) == -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;
}
diff --git a/test/default/generichash3.exp b/test/default/generichash3.exp
new file mode 100644
index 0000000..75a62d4
--- /dev/null
+++ b/test/default/generichash3.exp
@@ -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
diff --git a/test/default/hash.c b/test/default/hash.c
index c24f9c4..c220bd4 100644
--- a/test/default/hash.c
+++ b/test/default/hash.c
@@ -1,16 +1,41 @@
-#include <stdio.h>
#define TEST_NAME "hash"
#include "cmptest.h"
unsigned char x[] = "testing\n";
+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.";
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;
+ 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());
+
+ return 0;
}
diff --git a/test/default/hash.exp b/test/default/hash.exp
new file mode 100644
index 0000000..f26c0b0
--- /dev/null
+++ b/test/default/hash.exp
@@ -0,0 +1,4 @@
+24f950aac7b9ea9b3cb728228a0c82b67c39e96b4b344798870d5daee93e3ae5931baae8c7cacfea4b629452c38026a81d138bc7aad1af3ef7bfd5ec646d6c28
+a77abe1ccf8f5497e228fbc0acd73a521ededb21b89726684a6ebbc3baa32361aca5a244daa84f24bf19c68baf78e6907625a659b15479eb7bd426fc62aafa73
+12a61f4e173fb3a11c05d6471f74728f76231b4a5fcd9667cef3af87a3ae4dc2
+71cc8123fef8c236e451d3c3ddf1adae9aa6cd9521e7041769d737024900a03a
diff --git a/test/default/hash2.exp b/test/default/hash2.exp
new file mode 100644
index 0000000..df58217
--- /dev/null
+++ b/test/default/hash2.exp
@@ -0,0 +1 @@
+24f950aac7b9ea9b3cb728228a0c82b67c39e96b4b344798870d5daee93e3ae5931baae8c7cacfea4b629452c38026a81d138bc7aad1af3ef7bfd5ec646d6c28
diff --git a/test/default/hash3.c b/test/default/hash3.c
index a546125..01df6f0 100644
--- a/test/default/hash3.c
+++ b/test/default/hash3.c
@@ -1,16 +1,19 @@
-#include <stdio.h>
#define TEST_NAME "hash3"
#include "cmptest.h"
unsigned char x[] = "testing\n";
-unsigned char h[crypto_hash_sha512_BYTES];
+unsigned char h[crypto_hash_BYTES];
int main(void)
{
- size_t i;
- crypto_hash_sha512(h,x,sizeof x - 1U);
- for (i = 0;i < crypto_hash_sha512_BYTES;++i) printf("%02x",(unsigned int) h[i]);
- printf("\n");
- return 0;
+ 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;
}
diff --git a/test/default/hash3.exp b/test/default/hash3.exp
new file mode 100644
index 0000000..df58217
--- /dev/null
+++ b/test/default/hash3.exp
@@ -0,0 +1 @@
+24f950aac7b9ea9b3cb728228a0c82b67c39e96b4b344798870d5daee93e3ae5931baae8c7cacfea4b629452c38026a81d138bc7aad1af3ef7bfd5ec646d6c28
diff --git a/test/default/onetimeauth.c b/test/default/onetimeauth.c
index ddeb8ee..9a8b4f5 100644
--- a/test/default/onetimeauth.c
+++ b/test/default/onetimeauth.c
@@ -1,44 +1,56 @@
-#include <stdio.h>
#define TEST_NAME "onetimeauth"
#include "cmptest.h"
-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
-} ;
-
-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
-} ;
+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 };
+
+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 };
unsigned char a[16];
int main(void)
{
- int i;
- crypto_onetimeauth_poly1305(a,c,131,rs);
- for (i = 0;i < 16;++i) {
- printf(",0x%02x",(unsigned int) a[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ crypto_onetimeauth_state st;
+ int i;
+
+ 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 + 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());
+
+ return 0;
}
diff --git a/test/default/onetimeauth.exp b/test/default/onetimeauth.exp
new file mode 100644
index 0000000..33973bd
--- /dev/null
+++ b/test/default/onetimeauth.exp
@@ -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
diff --git a/test/default/onetimeauth2.c b/test/default/onetimeauth2.c
index 2114e29..e33a9fe 100644
--- a/test/default/onetimeauth2.c
+++ b/test/default/onetimeauth2.c
@@ -1,42 +1,30 @@
-#include <stdio.h>
#define TEST_NAME "onetimeauth2"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
-unsigned char a[16] = {
- 0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
-,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
-} ;
+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_poly1305_verify(a,c,131,rs));
- return 0;
+ printf("%d\n", crypto_onetimeauth_verify(a, c, 131, rs));
+ return 0;
}
diff --git a/test/default/onetimeauth2.exp b/test/default/onetimeauth2.exp
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/default/onetimeauth2.exp
@@ -0,0 +1 @@
+0
diff --git a/test/default/onetimeauth7.c b/test/default/onetimeauth7.c
index 6d99134..18d1186 100644
--- a/test/default/onetimeauth7.c
+++ b/test/default/onetimeauth7.c
@@ -1,5 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
+
#include "windows/windows-quirks.h"
#define TEST_NAME "onetimeauth7"
@@ -11,27 +10,28 @@ unsigned char a[16];
int main(void)
{
- int clen;
- for (clen = 0;clen < 10000;++clen) {
- randombytes(key,sizeof key);
- randombytes(c,clen);
- crypto_onetimeauth_poly1305(a,c,clen,key);
- if (crypto_onetimeauth_poly1305_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_poly1305_verify(a,c,clen,key) == 0) {
- printf("forgery %d\n",clen);
- return 100;
- }
- a[rand() % sizeof a] += 1 + (rand() % 255);
- if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) == 0) {
- printf("forgery %d\n",clen);
- return 100;
- }
+ int clen;
+
+ for (clen = 0; clen < 10000; ++clen) {
+ randombytes_buf(key, sizeof 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;
+ return 0;
}
diff --git a/test/default/onetimeauth7.exp b/test/default/onetimeauth7.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/onetimeauth7.exp
diff --git a/test/default/pwhash.c b/test/default/pwhash.c
index 7d00902..f61214f 100644
--- a/test/default/pwhash.c
+++ b/test/default/pwhash.c
@@ -1,5 +1,3 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "pwhash"
#include "cmptest.h"
@@ -7,42 +5,102 @@
static void tv(void)
{
static struct {
- const char *passwd_hex;
- unsigned long long passwdlen;
- const char *salt_hex;
- unsigned long long outlen;
- unsigned long long opslimit;
- size_t memlimit;
+ const char *passwd_hex;
+ unsigned long long passwdlen;
+ const char *salt_hex;
+ unsigned long long outlen;
+ unsigned long long opslimit;
+ size_t memlimit;
} tests[] = {
- {"a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae065577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08da232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f58d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6", 127, "5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2", 155, 481326, 7256678},
- {"e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e00cc2890277f0fd3c622115772f7048adaebed86e", 86, "f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d", 250, 535778, 7849083},
- {"92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f4915d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746711f58c8c392016b2fdfc09c64f0f6b6ab7b", 183, "3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194", 249, 311757, 7994791},
- {"027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b6451a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce69bb078ed1f0d31e7f9b8062409f37f19f8550aae", 152, "eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5", 5, 643464, 1397645},
- {"4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d43ced68642bfb8bbbdd0f50b30118f5e", 82, "39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258", 190, 758010, 5432947},
- {"1845e375479537e9dd4f4486d5c91ac72775d66605eeb11a787b78a7745f1fd0052d526c67235dbae1b2a4d575a74cb551c8e9096c593a497aee74ba3047d911358ede57bc27c9ea1829824348daaab606217cc931dcb6627787bd6e4e5854f0e8", 97, "3ee91a805aa62cfbe8dce29a2d9a44373a5006f4a4ce24022aca9cecb29d1473", 212, 233177, 13101817},
- {"c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e8261cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f", 156, "039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6", 178, 234753, 4886999},
- {"8f3a06e2fd8711350a517bb12e31f3d3423e8dc0bb14aac8240fca0995938d59bb37bd0a7dfc9c9cc0705684b46612e8c8b1d6655fb0f9887562bb9899791a0250d1320f945eda48cdc20c233f40a5bb0a7e3ac5ad7250ce684f68fc0b8c9633bfd75aad116525af7bdcdbbdb4e00ab163fd4df08f243f12557e", 122, "90631f686a8c3dbc0703ffa353bc1fdf35774568ac62406f98a13ed8f47595fd", 55, 695191, 15738350},
- {"b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f17b", 34, "44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb", 231, 78652, 6631659},
- {"a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb676a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b301560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d55a3b4169f22cccb0745a2689407ea1901a0a766eb99", 220, "3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf", 167, 717248, 10784179},
- };
- char passwd[256];
+ { "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;
+ 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, tests[i].outlen,
- passwd, tests[i].passwdlen,
- (const unsigned char *) salt,
- tests[i].opslimit,
- tests[i].memlimit) != 0) {
+ 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, 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);
@@ -53,28 +111,169 @@ static void tv(void)
static void tv2(void)
{
static struct {
- const char *passwd;
- const char *out;
+ const char *passwd_hex;
+ unsigned long long passwdlen;
+ const char *salt_hex;
+ unsigned long long outlen;
+ unsigned long long opslimit;
+ size_t memlimit;
} 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"},
- };
+ { "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 {
- if (crypto_pwhash_scryptsalsa208sha256_str_verify(tests[i].out,
- tests[i].passwd,
- strlen(tests[i].passwd)) != 0) {
- printf("pwhash_str failure\n");
+ 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, 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$"
+ "" },
+ };
+ char *out;
+ char *passwd;
+ size_t i = 0U;
+
+ do {
+ out = (char *) sodium_malloc(strlen(tests[i].out) + 1U);
+ memcpy(out, tests[i].out, strlen(tests[i].out) + 1U);
+ passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
+ 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]));
}
@@ -84,43 +283,52 @@ static void tv2(void)
int main(void)
{
- char str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES];
- char str_out2[crypto_pwhash_scryptsalsa208sha256_STRBYTES];
- unsigned char out[OUT_LEN];
- char out_hex[OUT_LEN * 2 + 1];
- const char *salt = "[<~A 32-bytes salt for scrypt~>]";
- const char *passwd = "Correct Horse Battery Staple";
- size_t i;
+ char str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES];
+ char str_out2[crypto_pwhash_scryptsalsa208sha256_STRBYTES];
+ unsigned char out[OUT_LEN];
+ char out_hex[OUT_LEN * 2 + 1];
+ const char *salt = "[<~A 32-bytes salt for scrypt~>]";
+ const char *passwd = "Correct Horse Battery Staple";
+ size_t i;
tv();
tv2();
+ tv3();
if (crypto_pwhash_scryptsalsa208sha256_str(str_out, passwd, strlen(passwd),
- OPSLIMIT, MEMLIMIT) != 0) {
+ OPSLIMIT, MEMLIMIT) != 0) {
printf("pwhash_str failure\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str(str_out2, passwd, strlen(passwd),
- OPSLIMIT, MEMLIMIT) != 0) {
+ 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_verify(str_out, passwd,
- strlen(passwd)) != 0) {
+ strlen(passwd)) != 0) {
printf("pwhash_str_verify failure\n");
}
if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
- strlen(passwd)) != 0) {
+ strlen(passwd)) != 0) {
printf("pwhash_str_verify failure\n");
}
- for (i = 14U; i < sizeof str_out; i++) {
- str_out[i]++;
- if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
- strlen(passwd)) == 0) {
- printf("pwhash_str_verify(2) failure\n");
- }
- str_out[i]--;
+ 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(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_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;
diff --git a/test/default/pwhash.exp b/test/default/pwhash.exp
new file mode 100644
index 0000000..5c58d53
--- /dev/null
+++ b/test/default/pwhash.exp
@@ -0,0 +1,31 @@
+8d40f5f8c6a1791204f03e19a98cd74f918b6e331b39cfc2415e5014d7738b7bb0a83551fb14a035e07fdd4dc0c60c1a6822ac253918979f6324ff0c87cba75d3b91f88f41ca5414a0f152bdc4d636f42ab2250afd058c19ec31a3374d1bd7133289bf21513ff67cbf8482e626aee9864c58fd05f9ea02e508a10182b7d838157119866f072004987ef6c56683ed207705923921af9d76444a331a
+d985d4c278343a46d82af0c4268b7ae6b6d1d2dd289675ef45bfb6d0648bffe5bab8c91228f3a31b091154a9c1142670a07b92e70a298333066de07db9300e046fd7cacc99780804683df7babdfc9d019047178400b2875bde0a1ad824dda7a422d9ed48475af9a3876378dd3a2f206e34984e223afb82c0c1e4644c9a458f4666379fdd3e2d9206d87e3c32c3977f35826a27590baaa1ec1a3bd7d15a92bc84c95dcfc56c14fca7c4c9810162dfdf9dc08a191e79fe40250b7e07d3a9317d9a5cb56e1062c419a6cd6a9b73128e8ad79ab7efffbb3cc52c1f49f86d2ebb46e6e4846aecdb14c2d046f5380517ff8cc794e4a772a58b93083dad
+ee7e9e1369267ec555981f0ea088ff6f93953abfcb767d88ec3c46393d24cfbaba5e4e26e0f35b5d5259647748476d65cd8881c96f8cda049d9c877b2d33d932e67f4c0df2cb434b4b4900e0c49c3f8ba9663795420577e65d0b456201ad9162fbc485c7b44f2b34e6673aa3692c123021ee3b624c3bb22b808b89613d8ecc7b87da47f57152eb3f7b10ad206f6b09cb6935b347b5e42bc3b8c9c9bcd8d7b7c44929b367fc279dec48ea78e6ee3e2620d7459700bd0aedb1c9aa5a323ca94403927f5e5c2b73bda7c5c3287b62fe51874cfeb1dc3151cd886b26d83ece68833229d2d432798c602d85b0505947207d8430febbe901164b12ce
+1828b82997
+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]
+OK
diff --git a/test/default/pwhash_scrypt_ll.c b/test/default/pwhash_scrypt_ll.c
index db72e4e..9b3951a 100644
--- a/test/default/pwhash_scrypt_ll.c
+++ b/test/default/pwhash_scrypt_ll.c
@@ -1,6 +1,3 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
#define TEST_NAME "pwhash_scrypt_ll"
#include "cmptest.h"
@@ -9,47 +6,44 @@
static const char *password1 = "";
static const char *salt1 = "";
-static uint64_t N1 = 16U;
-static uint32_t r1 = 1U;
-static uint32_t p1 = 1U;
+static uint64_t N1 = 16U;
+static uint32_t r1 = 1U;
+static uint32_t p1 = 1U;
static const char *password2 = "password";
static const char *salt2 = "NaCl";
-static uint64_t N2 = 1024U;
-static uint32_t r2 = 8U;
-static uint32_t p2 = 16U;
+static uint64_t N2 = 1024U;
+static uint32_t r2 = 8U;
+static uint32_t p2 = 16U;
static const char *password3 = "pleaseletmein";
-static const char *salt3 = "SodiumChloride";
-static uint64_t N3 = 16384U;
-static uint32_t r3 = 8U;
-static uint32_t p3 = 1U;
+static const char *salt3 = "SodiumChloride";
+static uint64_t N3 = 16384U;
+static uint32_t r3 = 8U;
+static uint32_t p3 = 1U;
-static void test_vector(const char *password, const char *salt,
- uint64_t N, uint32_t r, uint32_t p)
+static void test_vector(const char *password, 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 passwordLength = strlen(password);
- size_t saltLenght = strlen(salt);
- int lineitems = 0;
- int lineitemsLimit = 15;
-
- if (crypto_pwhash_scryptsalsa208sha256_ll((const uint8_t *) password,
- passwordLength,
- (const uint8_t *) salt,
- saltLenght,
- N, r, p, data, olen) != 0) {
- printf("pwhash_scryptsalsa208sha256_ll([%s],[%s]) failure\n",
- password, salt);
+ size_t i;
+ size_t olen = (sizeof data / sizeof data[0]);
+ size_t passwordLength = strlen(password);
+ size_t saltLenght = strlen(salt);
+ int lineitems = 0;
+ int lineitemsLimit = 15;
+
+ if (crypto_pwhash_scryptsalsa208sha256_ll(
+ (const uint8_t *)password, passwordLength, (const uint8_t *)salt,
+ saltLenght, N, r, p, data, olen) != 0) {
+ printf("pwhash_scryptsalsa208sha256_ll([%s],[%s]) failure\n", password,
+ salt);
return;
}
- printf("scrypt('%s', '%s', %llu, %lu, %lu, %lu) =\n",
- password, salt,
- (unsigned long long) N, (unsigned long) r, (unsigned long) p,
- (unsigned long) olen);
+ printf("scrypt('%s', '%s', %llu, %lu, %lu, %lu) =\n", password, salt,
+ (unsigned long long)N, (unsigned long)r, (unsigned long)p,
+ (unsigned long)olen);
for (i = 0; i < olen; ++i) {
printf("%02x%c", data[i], lineitems < lineitemsLimit ? ' ' : '\n');
@@ -59,9 +53,9 @@ static void test_vector(const char *password, const char *salt,
int main(void)
{
- test_vector(password1, salt1, N1, r1, p1);
- test_vector(password2, salt2, N2, r2, p2);
- test_vector(password3, salt3, N3, r3, p3);
+ test_vector(password1, salt1, N1, r1, p1);
+ test_vector(password2, salt2, N2, r2, p2);
+ test_vector(password3, salt3, N3, r3, p3);
- return 0;
+ return 0;
}
diff --git a/test/default/pwhash_scrypt_ll.exp b/test/default/pwhash_scrypt_ll.exp
new file mode 100644
index 0000000..9b7f6a7
--- /dev/null
+++ b/test/default/pwhash_scrypt_ll.exp
@@ -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
diff --git a/test/default/randombytes.c b/test/default/randombytes.c
index f805c47..f9f337f 100644
--- a/test/default/randombytes.c
+++ b/test/default/randombytes.c
@@ -1,16 +1,93 @@
-#include "randombytes.h"
+
+#define TEST_NAME "randombytes"
+#include "cmptest.h"
unsigned char x[65536];
unsigned long long freq[256];
-int main(void)
+static int compat_tests(void)
{
- unsigned long long i;
+ 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)
+{
+ unsigned int i;
+
+ assert(strcmp(randombytes_implementation_name(), "sysrandom") == 0);
- 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]) return 111;
+ randombytes(x, 1U);
+ 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();
+ randombytes_set_implementation(&randombytes_salsa20_implementation);
+ assert(strcmp(randombytes_implementation_name(), "salsa20") == 0);
+ 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_close();
+
+ randombytes(x, 1U);
+ randombytes_close();
+
+ return 0;
+}
+
+int main(void)
+{
+ compat_tests();
+ randombytes_tests();
+ printf("OK\n");
- return 0;
+ return 0;
}
diff --git a/test/default/randombytes.exp b/test/default/randombytes.exp
new file mode 100644
index 0000000..d86bac9
--- /dev/null
+++ b/test/default/randombytes.exp
@@ -0,0 +1 @@
+OK
diff --git a/test/default/scalarmult.c b/test/default/scalarmult.c
index 957bc9c..f931555 100644
--- a/test/default/scalarmult.c
+++ b/test/default/scalarmult.c
@@ -1,25 +1,38 @@
-#include <stdio.h>
#define TEST_NAME "scalarmult"
#include "cmptest.h"
-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
-} ;
+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 };
unsigned char alicepk[32];
int main(void)
{
- int i;
- crypto_scalarmult_curve25519_base(alicepk,alicesk);
- for (i = 0;i < 32;++i) {
- if (i > 0) printf(","); else printf(" ");
- printf("0x%02x",(unsigned int) alicepk[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ int i;
+
+ crypto_scalarmult_base(alicepk, alicesk);
+
+ for (i = 0; i < 32; ++i) {
+ if (i > 0) {
+ printf(",");
+ } else {
+ printf(" ");
+ }
+ printf("0x%02x", (unsigned int)alicepk[i]);
+ if (i % 8 == 7) {
+ printf("\n");
+ }
+ }
+ assert(crypto_scalarmult_bytes() > 0U);
+ assert(crypto_scalarmult_scalarbytes() > 0U);
+ assert(strcmp(crypto_scalarmult_primitive(), "curve25519") == 0);
+ assert(crypto_scalarmult_bytes() == crypto_scalarmult_curve25519_bytes());
+ assert(crypto_scalarmult_scalarbytes()
+ == crypto_scalarmult_curve25519_scalarbytes());
+ assert(crypto_scalarmult_bytes() == crypto_scalarmult_scalarbytes());
+
+ return 0;
}
diff --git a/test/default/scalarmult.exp b/test/default/scalarmult.exp
new file mode 100644
index 0000000..ddd130d
--- /dev/null
+++ b/test/default/scalarmult.exp
@@ -0,0 +1,4 @@
+ 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
diff --git a/test/default/scalarmult2.c b/test/default/scalarmult2.c
index 93a37d0..b5593df 100644
--- a/test/default/scalarmult2.c
+++ b/test/default/scalarmult2.c
@@ -1,25 +1,30 @@
-#include <stdio.h>
#define TEST_NAME "scalarmult2"
#include "cmptest.h"
-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
-} ;
+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 };
unsigned char bobpk[32];
int main(void)
{
- int i;
- crypto_scalarmult_curve25519_base(bobpk,bobsk);
- for (i = 0;i < 32;++i) {
- if (i > 0) printf(","); else printf(" ");
- printf("0x%02x",(unsigned int) bobpk[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ int i;
+
+ crypto_scalarmult_base(bobpk, bobsk);
+
+ for (i = 0; i < 32; ++i) {
+ if (i > 0) {
+ printf(",");
+ } else {
+ printf(" ");
+ }
+ printf("0x%02x", (unsigned int)bobpk[i]);
+ if (i % 8 == 7) {
+ printf("\n");
+ }
+ }
+ return 0;
}
diff --git a/test/default/scalarmult2.exp b/test/default/scalarmult2.exp
new file mode 100644
index 0000000..b539186
--- /dev/null
+++ b/test/default/scalarmult2.exp
@@ -0,0 +1,4 @@
+ 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
diff --git a/test/default/scalarmult5.c b/test/default/scalarmult5.c
index b6852a9..3dc6977 100644
--- a/test/default/scalarmult5.c
+++ b/test/default/scalarmult5.c
@@ -1,32 +1,35 @@
-#include <stdio.h>
#define TEST_NAME "scalarmult5"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
unsigned char k[32];
int main(void)
{
- int i;
- crypto_scalarmult_curve25519(k,alicesk,bobpk);
- for (i = 0;i < 32;++i) {
- if (i > 0) printf(","); else printf(" ");
- printf("0x%02x",(unsigned int) k[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ int i;
+
+ crypto_scalarmult(k, alicesk, bobpk);
+
+ for (i = 0; i < 32; ++i) {
+ if (i > 0) {
+ printf(",");
+ } else {
+ printf(" ");
+ }
+ printf("0x%02x", (unsigned int)k[i]);
+ if (i % 8 == 7) {
+ printf("\n");
+ }
+ }
+ return 0;
}
diff --git a/test/default/scalarmult5.exp b/test/default/scalarmult5.exp
new file mode 100644
index 0000000..bec2113
--- /dev/null
+++ b/test/default/scalarmult5.exp
@@ -0,0 +1,4 @@
+ 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
diff --git a/test/default/scalarmult6.c b/test/default/scalarmult6.c
index c1ac885..6b4e576 100644
--- a/test/default/scalarmult6.c
+++ b/test/default/scalarmult6.c
@@ -1,32 +1,35 @@
-#include <stdio.h>
#define TEST_NAME "scalarmult6"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
unsigned char k[32];
int main(void)
{
- int i;
- crypto_scalarmult_curve25519(k,bobsk,alicepk);
- for (i = 0;i < 32;++i) {
- if (i > 0) printf(","); else printf(" ");
- printf("0x%02x",(unsigned int) k[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ int i;
+
+ crypto_scalarmult(k, bobsk, alicepk);
+
+ for (i = 0; i < 32; ++i) {
+ if (i > 0) {
+ printf(",");
+ } else {
+ printf(" ");
+ }
+ printf("0x%02x", (unsigned int)k[i]);
+ if (i % 8 == 7) {
+ printf("\n");
+ }
+ }
+ return 0;
}
diff --git a/test/default/scalarmult6.exp b/test/default/scalarmult6.exp
new file mode 100644
index 0000000..bec2113
--- /dev/null
+++ b/test/default/scalarmult6.exp
@@ -0,0 +1,4 @@
+ 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
diff --git a/test/default/scalarmult7.c b/test/default/scalarmult7.c
new file mode 100644
index 0000000..e83493e
--- /dev/null
+++ b/test/default/scalarmult7.c
@@ -0,0 +1,31 @@
+
+#define TEST_NAME "scalarmult7"
+#include "cmptest.h"
+
+unsigned char p1[32] = {
+ 0x72, 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, 0xea
+};
+
+unsigned char p2[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
+};
+
+unsigned char scalar[32];
+unsigned char out1[32];
+unsigned char out2[32];
+
+int main(void)
+{
+ scalar[0] = 1U;
+ crypto_scalarmult_curve25519(out1, scalar, p1);
+ crypto_scalarmult_curve25519(out2, scalar, p2);
+ printf("%d\n", !!memcmp(out1, out2, 32));
+
+ return 0;
+}
diff --git a/test/default/scalarmult7.exp b/test/default/scalarmult7.exp
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/test/default/scalarmult7.exp
@@ -0,0 +1 @@
+1
diff --git a/test/default/secretbox.c b/test/default/secretbox.c
index 485a97a..6a06b29 100644
--- a/test/default/secretbox.c
+++ b/test/default/secretbox.c
@@ -1,58 +1,63 @@
-#include <stdio.h>
#define TEST_NAME "secretbox"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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
-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
-} ;
+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 };
unsigned char c[163];
int main(void)
{
- int i;
- crypto_secretbox_xsalsa20poly1305(
- c,m,163,nonce,firstkey
- );
- for (i = 16;i < 163;++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
- }
- printf("\n");
- return 0;
+ int i;
+
+ crypto_secretbox(c, m, 163, nonce, firstkey);
+ for (i = 16; i < 163; ++i) {
+ printf(",0x%02x", (unsigned int)c[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ printf("\n");
+
+ assert(crypto_secretbox_keybytes() > 0U);
+ assert(crypto_secretbox_noncebytes() > 0U);
+ assert(crypto_secretbox_zerobytes() > 0U);
+ assert(crypto_secretbox_boxzerobytes() > 0U);
+ assert(crypto_secretbox_macbytes() > 0U);
+ assert(strcmp(crypto_secretbox_primitive(), "xsalsa20poly1305") == 0);
+ assert(crypto_secretbox_keybytes()
+ == crypto_secretbox_xsalsa20poly1305_keybytes());
+ assert(crypto_secretbox_noncebytes()
+ == crypto_secretbox_xsalsa20poly1305_noncebytes());
+ assert(crypto_secretbox_zerobytes()
+ == crypto_secretbox_xsalsa20poly1305_zerobytes());
+ assert(crypto_secretbox_boxzerobytes()
+ == crypto_secretbox_xsalsa20poly1305_boxzerobytes());
+ assert(crypto_secretbox_macbytes()
+ == crypto_secretbox_xsalsa20poly1305_macbytes());
+
+ return 0;
}
diff --git a/test/default/secretbox.exp b/test/default/secretbox.exp
new file mode 100644
index 0000000..2b6c51e
--- /dev/null
+++ b/test/default/secretbox.exp
@@ -0,0 +1,19 @@
+,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
diff --git a/test/default/secretbox2.c b/test/default/secretbox2.c
index 5af6c41..37fc634 100644
--- a/test/default/secretbox2.c
+++ b/test/default/secretbox2.c
@@ -1,59 +1,46 @@
-#include <stdio.h>
#define TEST_NAME "secretbox2"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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
-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
-} ;
+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 };
unsigned char m[163];
int main(void)
{
- int i;
- if (crypto_secretbox_xsalsa20poly1305_open(
- m,c,163,nonce,firstkey
- ) == 0) {
- for (i = 32;i < 163;++i) {
- printf(",0x%02x",(unsigned int) m[i]);
- if (i % 8 == 7) printf("\n");
+ int i;
+
+ if (crypto_secretbox_open(m, c, 163, nonce, firstkey) == 0) {
+ for (i = 32; i < 163; ++i) {
+ printf(",0x%02x", (unsigned int)m[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ printf("\n");
}
- printf("\n");
- }
- return 0;
+ return 0;
}
diff --git a/test/default/secretbox2.exp b/test/default/secretbox2.exp
new file mode 100644
index 0000000..c61d455
--- /dev/null
+++ b/test/default/secretbox2.exp
@@ -0,0 +1,17 @@
+,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
diff --git a/test/default/secretbox7.c b/test/default/secretbox7.c
index 337f081..492dd34 100644
--- a/test/default/secretbox7.c
+++ b/test/default/secretbox7.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#define TEST_NAME "secretbox7"
#include "cmptest.h"
@@ -11,23 +10,26 @@ unsigned char m2[10000];
int main(void)
{
- size_t mlen;
- size_t i;
+ size_t mlen;
+ size_t i;
- for (mlen = 0;mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;++mlen) {
- randombytes(k,crypto_secretbox_KEYBYTES);
- randombytes(n,crypto_secretbox_NONCEBYTES);
- randombytes(m + crypto_secretbox_ZEROBYTES,mlen);
- crypto_secretbox(c,m,mlen + crypto_secretbox_ZEROBYTES,n,k);
- if (crypto_secretbox_open(m2,c,mlen + crypto_secretbox_ZEROBYTES,n,k) == 0) {
- for (i = 0;i < mlen + crypto_secretbox_ZEROBYTES;++i)
- if (m2[i] != m[i]) {
- printf("bad decryption\n");
- break;
+ for (mlen = 0; mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;
+ ++mlen) {
+ randombytes_buf(k, crypto_secretbox_KEYBYTES);
+ randombytes_buf(n, crypto_secretbox_NONCEBYTES);
+ randombytes_buf(m + crypto_secretbox_ZEROBYTES, mlen);
+ crypto_secretbox(c, m, mlen + crypto_secretbox_ZEROBYTES, n, k);
+ if (crypto_secretbox_open(m2, c, mlen + crypto_secretbox_ZEROBYTES, n,
+ k) == 0) {
+ for (i = 0; i < mlen + crypto_secretbox_ZEROBYTES; ++i) {
+ if (m2[i] != m[i]) {
+ printf("bad decryption\n");
+ break;
+ }
+ }
+ } else {
+ printf("ciphertext fails verification\n");
}
- } else {
- printf("ciphertext fails verification\n");
}
- }
- return 0;
+ return 0;
}
diff --git a/test/default/secretbox7.exp b/test/default/secretbox7.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/secretbox7.exp
diff --git a/test/default/secretbox8.c b/test/default/secretbox8.c
index 94808dc..7fbb811 100644
--- a/test/default/secretbox8.c
+++ b/test/default/secretbox8.c
@@ -1,5 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
+
#include "windows/windows-quirks.h"
#define TEST_NAME "secretbox8"
@@ -13,28 +12,31 @@ unsigned char m2[10000];
int main(void)
{
- size_t mlen;
- size_t i;
- int caught;
+ size_t mlen;
+ size_t i;
+ int caught;
- for (mlen = 0;mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;++mlen) {
- randombytes(k,crypto_secretbox_KEYBYTES);
- randombytes(n,crypto_secretbox_NONCEBYTES);
- randombytes(m + crypto_secretbox_ZEROBYTES,mlen);
- crypto_secretbox(c,m,mlen + crypto_secretbox_ZEROBYTES,n,k);
- caught = 0;
- while (caught < 10) {
- c[rand() % (mlen + crypto_secretbox_ZEROBYTES)] = rand();
- if (crypto_secretbox_open(m2,c,mlen + crypto_secretbox_ZEROBYTES,n,k) == 0) {
- for (i = 0;i < mlen + crypto_secretbox_ZEROBYTES;++i)
- if (m2[i] != m[i]) {
- printf("forgery\n");
- return 100;
- }
- } else {
- ++caught;
- }
+ for (mlen = 0; mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;
+ ++mlen) {
+ randombytes_buf(k, crypto_secretbox_KEYBYTES);
+ randombytes_buf(n, crypto_secretbox_NONCEBYTES);
+ randombytes_buf(m + crypto_secretbox_ZEROBYTES, mlen);
+ crypto_secretbox(c, m, mlen + crypto_secretbox_ZEROBYTES, n, k);
+ caught = 0;
+ while (caught < 10) {
+ c[rand() % (mlen + crypto_secretbox_ZEROBYTES)] = rand();
+ if (crypto_secretbox_open(m2, c, mlen + crypto_secretbox_ZEROBYTES,
+ n, k) == 0) {
+ for (i = 0; i < mlen + crypto_secretbox_ZEROBYTES; ++i) {
+ if (m2[i] != m[i]) {
+ printf("forgery\n");
+ return 100;
+ }
+ }
+ } else {
+ ++caught;
+ }
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/test/default/secretbox8.exp b/test/default/secretbox8.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/default/secretbox8.exp
diff --git a/test/default/secretbox_easy.c b/test/default/secretbox_easy.c
index dc3f3bd..df85070 100644
--- a/test/default/secretbox_easy.c
+++ b/test/default/secretbox_easy.c
@@ -1,63 +1,57 @@
-#include <stdio.h>
#define TEST_NAME "secretbox_easy"
#include "cmptest.h"
-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
-} ;
-
-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
-} ;
-
-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
-} ;
+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 };
+
+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 };
+
+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 };
unsigned char c[147 + crypto_secretbox_MACBYTES];
unsigned char mac[crypto_secretbox_MACBYTES];
int main(void)
{
- size_t i;
-
- crypto_secretbox_easy(c, m, 131, nonce, firstkey);
- for (i = 0;i < 131 + crypto_secretbox_MACBYTES; ++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
- }
- printf("\n");
-
- crypto_secretbox_detached(c, mac, m, 131, nonce, firstkey);
- for (i = 0;i < crypto_secretbox_MACBYTES; ++i) {
- printf(",0x%02x",(unsigned int) mac[i]);
- if (i % 8 == 7) printf("\n");
- }
- for (i = 0;i < 131; ++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ size_t i;
+
+ crypto_secretbox_easy(c, m, 131, nonce, firstkey);
+ for (i = 0; i < 131 + crypto_secretbox_MACBYTES; ++i) {
+ printf(",0x%02x", (unsigned int)c[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ printf("\n");
+
+ crypto_secretbox_detached(c, mac, m, 131, nonce, firstkey);
+ for (i = 0; i < crypto_secretbox_MACBYTES; ++i) {
+ printf(",0x%02x", (unsigned int)mac[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ for (i = 0; i < 131; ++i) {
+ printf(",0x%02x", (unsigned int)c[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+
+ assert(crypto_secretbox_easy(c, m, SIZE_MAX - 1U, nonce, firstkey) == -1);
+
+ return 0;
}
diff --git a/test/default/secretbox_easy.exp b/test/default/secretbox_easy.exp
new file mode 100644
index 0000000..c4b4066
--- /dev/null
+++ b/test/default/secretbox_easy.exp
@@ -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 \ No newline at end of file
diff --git a/test/default/secretbox_easy2.c b/test/default/secretbox_easy2.c
index 63105b6..3ad71ce 100644
--- a/test/default/secretbox_easy2.c
+++ b/test/default/secretbox_easy2.c
@@ -1,5 +1,3 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "secretbox_easy2"
#include "cmptest.h"
@@ -17,12 +15,12 @@ int main(void)
unsigned long long i;
randombytes_buf(k, sizeof k);
- mlen = (unsigned long long) randombytes_uniform((uint32_t) sizeof m);
+ mlen = (unsigned long long)randombytes_uniform((uint32_t)sizeof m);
randombytes_buf(m, mlen);
randombytes_buf(nonce, sizeof nonce);
crypto_secretbox_easy(c, m, mlen, nonce, k);
- crypto_secretbox_open_easy(m2, c, mlen + crypto_secretbox_MACBYTES,
- nonce, k);
+ crypto_secretbox_open_easy(m2, c, mlen + crypto_secretbox_MACBYTES, nonce,
+ k);
printf("%d\n", memcmp(m, m2, mlen));
for (i = 0; i < mlen + crypto_secretbox_MACBYTES - 1; i++) {
diff --git a/test/default/secretbox_easy2.exp b/test/default/secretbox_easy2.exp
new file mode 100644
index 0000000..aa47d0d
--- /dev/null
+++ b/test/default/secretbox_easy2.exp
@@ -0,0 +1,2 @@
+0
+0
diff --git a/test/default/shorthash.c b/test/default/shorthash.c
index 6f1d7f3..18081cd 100644
--- a/test/default/shorthash.c
+++ b/test/default/shorthash.c
@@ -1,6 +1,3 @@
-#include <stdio.h>
-
-#include "crypto_uint8.h"
#define TEST_NAME "shorthash"
#include "cmptest.h"
@@ -8,16 +5,26 @@
int main(void)
{
#define MAXLEN 64
- crypto_uint8 in[MAXLEN], out[crypto_shorthash_BYTES], k[crypto_shorthash_KEYBYTES];
- size_t i,j;
+ unsigned char in[MAXLEN], out[crypto_shorthash_BYTES],
+ k[crypto_shorthash_KEYBYTES];
+ size_t i, j;
- for( i = 0; i < crypto_shorthash_KEYBYTES; ++i ) k[i] = i;
+ for (i = 0; i < crypto_shorthash_KEYBYTES; ++i)
+ k[i] = i;
- for(i=0;i<MAXLEN;++i) {
- in[i]=i;
- crypto_shorthash( out, in, i, k );
- for (j = 0;j < crypto_shorthash_BYTES;++j) printf("%02x",(unsigned int) out[j]);
+ for (i = 0; i < MAXLEN; ++i) {
+ in[i] = i;
+ crypto_shorthash(out, in, i, k);
+ for (j = 0; j < crypto_shorthash_BYTES; ++j)
+ printf("%02x", (unsigned int)out[j]);
printf("\n");
}
+ assert(crypto_shorthash_bytes() > 0);
+ assert(crypto_shorthash_keybytes() > 0);
+ assert(strcmp(crypto_shorthash_primitive(), "siphash24") == 0);
+ assert(crypto_shorthash_bytes() == crypto_shorthash_siphash24_bytes());
+ assert(crypto_shorthash_keybytes()
+ == crypto_shorthash_siphash24_keybytes());
+
return 0;
}
diff --git a/test/default/shorthash.exp b/test/default/shorthash.exp
new file mode 100644
index 0000000..6ec8684
--- /dev/null
+++ b/test/default/shorthash.exp
@@ -0,0 +1,64 @@
+310e0edd47db6f72
+fd67dc93c539f874
+5a4fa9d909806c0d
+2d7efbd796666785
+b7877127e09427cf
+8da699cd64557618
+cee3fe586e46c9cb
+37d1018bf50002ab
+6224939a79f5f593
+b0e4a90bdf82009e
+f3b9dd94c5bb5d7a
+a7ad6b22462fb3f4
+fbe50e86bc8f1e75
+903d84c02756ea14
+eef27a8e90ca23f7
+e545be4961ca29a1
+db9bc2577fcc2a3f
+9447be2cf5e99a69
+9cd38d96f0b3c14b
+bd6179a71dc96dbb
+98eea21af25cd6be
+c7673b2eb0cbf2d0
+883ea3e395675393
+c8ce5ccd8c030ca8
+94af49f6c650adb8
+eab8858ade92e1bc
+f315bb5bb835d817
+adcf6b0763612e2f
+a5c91da7acaa4dde
+716595876650a2a6
+28ef495c53a387ad
+42c341d8fa92d832
+ce7cf2722f512771
+e37859f94623f3a7
+381205bb1ab0e012
+ae97a10fd434e015
+b4a31508beff4d31
+81396229f0907902
+4d0cf49ee5d4dcca
+5c73336a76d8bf9a
+d0a704536ba93e0e
+925958fcd6420cad
+a915c29bc8067318
+952b79f3bc0aa6d4
+f21df2e41d4535f9
+87577519048f53a9
+10a56cf5dfcd9adb
+eb75095ccd986cd0
+51a9cb9ecba312e6
+96afadfc2ce666c7
+72fe52975a4364ee
+5a1645b276d592a1
+b274cb8ebf87870a
+6f9bb4203de7b381
+eaecb2a30b22a87f
+9924a43cc1315724
+bd838d3aafbf8db7
+0b1a2a3265d51aea
+135079a3231ce660
+932b2846e4d70666
+e1915f5cb1eca46c
+f325965ca16d629f
+575ff28e60381be5
+724506eb4c328a95
diff --git a/test/default/sign.c b/test/default/sign.c
index 7267491..99ed085 100644
--- a/test/default/sign.c
+++ b/test/default/sign.c
@@ -1,23 +1,14 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "sign"
#include "cmptest.h"
-#define KEYPAIR_SEED "1@ABCFGHLOPRSTUWabcdefghiklmnopq"
-
-#define crypto_sign_SECRETKEYBYTES_WITHOUT_PK \
- (crypto_sign_SECRETKEYBYTES - crypto_sign_PUBLICKEYBYTES)
-
-static const unsigned char keypair_seed[] = {
- 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
-};
+static const unsigned char keypair_seed[]
+ = { 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 };
typedef struct TestData_ {
- const unsigned char sk[crypto_sign_SECRETKEYBYTES_WITHOUT_PK];
+ const unsigned char sk[crypto_sign_SEEDBYTES];
const unsigned char pk[crypto_sign_PUBLICKEYBYTES];
const unsigned char sig[crypto_sign_BYTES];
const char *m;
@@ -1052,26 +1043,29 @@ static TestData test_data[] = {
int main(void)
{
- unsigned char sig[crypto_sign_BYTES];
- unsigned char sm[1024 + crypto_sign_BYTES];
- unsigned char m[1024];
- unsigned char skpk[crypto_sign_SECRETKEYBYTES +
- crypto_sign_PUBLICKEYBYTES];
- unsigned char pk[crypto_sign_PUBLICKEYBYTES];
- unsigned char sk[crypto_sign_SECRETKEYBYTES];
- char pk_hex[crypto_sign_PUBLICKEYBYTES * 2 + 1];
- char sk_hex[crypto_sign_SECRETKEYBYTES * 2 + 1];
+ unsigned char extracted_seed[crypto_sign_ed25519_SEEDBYTES];
+ unsigned char extracted_pk[crypto_sign_ed25519_PUBLICKEYBYTES];
+ unsigned char sig[crypto_sign_BYTES];
+ unsigned char sm[1024 + crypto_sign_BYTES];
+ unsigned char m[1024];
+ unsigned char skpk[crypto_sign_SECRETKEYBYTES];
+ unsigned char pk[crypto_sign_PUBLICKEYBYTES];
+ unsigned char sk[crypto_sign_SECRETKEYBYTES];
+ char pk_hex[crypto_sign_PUBLICKEYBYTES * 2 + 1];
+ char sk_hex[crypto_sign_SECRETKEYBYTES * 2 + 1];
unsigned long long siglen;
unsigned long long smlen;
unsigned long long mlen;
- unsigned int i;
+ unsigned int i;
+ unsigned int j;
+ memset(sig, 0, sizeof sig);
for (i = 0U; i < (sizeof test_data) / (sizeof test_data[0]); i++) {
- memcpy(skpk, test_data[i].sk, crypto_sign_SECRETKEYBYTES_WITHOUT_PK);
- memcpy(skpk + crypto_sign_SECRETKEYBYTES_WITHOUT_PK,
- test_data[i].pk, crypto_sign_PUBLICKEYBYTES);
- if (crypto_sign(sm, &smlen,
- (const unsigned char *) test_data[i].m, i, skpk) != 0) {
+ memcpy(skpk, test_data[i].sk, crypto_sign_SEEDBYTES);
+ memcpy(skpk + crypto_sign_SEEDBYTES, test_data[i].pk,
+ crypto_sign_PUBLICKEYBYTES);
+ if (crypto_sign(sm, &smlen, (const unsigned char *)test_data[i].m, i,
+ skpk) != 0) {
printf("crypto_sign() failure: [%u]\n", i);
continue;
}
@@ -1083,7 +1077,7 @@ int main(void)
printf("crypto_sign_open() failure: [%u]\n", i);
continue;
}
- if (memcmp(test_data[i].m, m, (size_t) mlen) != 0) {
+ if (memcmp(test_data[i].m, m, (size_t)mlen) != 0) {
printf("message verification failure: [%u]\n", i);
continue;
}
@@ -1095,12 +1089,12 @@ int main(void)
if (crypto_sign_open(m, &mlen, sm, i % crypto_sign_BYTES,
test_data[i].pk) == 0) {
printf("short signed message verifies: [%u]\n",
- i % crypto_sign_BYTES);
+ i % crypto_sign_BYTES);
continue;
}
if (crypto_sign_detached(sig, &siglen,
- (const unsigned char *) test_data[i].m, i,
- test_data[i].sk) != 0) {
+ (const unsigned char *)test_data[i].m, i, skpk)
+ != 0) {
printf("detached signature failed: [%u]\n", i);
continue;
}
@@ -1113,7 +1107,7 @@ int main(void)
continue;
}
if (crypto_sign_verify_detached(sig,
- (const unsigned char *) test_data[i].m,
+ (const unsigned char *)test_data[i].m,
i, test_data[i].pk) != 0) {
printf("detached signature verification failed: [%u]\n", i);
continue;
@@ -1121,6 +1115,37 @@ int main(void)
}
printf("%u tests\n", i);
+ i--;
+
+ memcpy(sm, test_data[i].m, i);
+ if (crypto_sign(sm, &smlen, sm, i, skpk) != 0) {
+ printf("crypto_sign() with overlap failed\n");
+ }
+ if (crypto_sign_open(sm, &mlen, sm, smlen, test_data[i].pk) != 0) {
+ printf("crypto_sign_open() with overlap failed\n");
+ }
+ if (memcmp(test_data[i].m, sm, (size_t)mlen) != 0) {
+ printf("crypto_sign_open() with overlap failed (content)\n");
+ }
+
+ for (j = 1U; j < 8U; j++) {
+ sig[63] ^= (j << 5);
+ if (crypto_sign_verify_detached(sig,
+ (const unsigned char *)test_data[i].m,
+ i, test_data[i].pk) != -1) {
+ printf("detached signature verification should have failed\n");
+ continue;
+ }
+ sig[63] ^= (j << 5);
+ }
+
+ memset(pk, 0, sizeof pk);
+ if (crypto_sign_verify_detached(sig,
+ (const unsigned char *)test_data[i].m,
+ i, pk) != -1) {
+ printf("detached signature verification should have failed\n");
+ }
+
if (crypto_sign_keypair(pk, sk) != 0) {
printf("crypto_sign_keypair() failure\n");
}
@@ -1128,11 +1153,32 @@ int main(void)
printf("crypto_sign_seed_keypair() failure\n");
return -1;
}
+ crypto_sign_ed25519_sk_to_seed(extracted_seed, sk);
+ if (memcmp(extracted_seed, keypair_seed, crypto_sign_ed25519_SEEDBYTES)
+ != 0) {
+ printf("crypto_sign_ed25519_sk_to_seed() failure\n");
+ }
+ crypto_sign_ed25519_sk_to_pk(extracted_pk, sk);
+ if (memcmp(extracted_pk, pk, crypto_sign_ed25519_PUBLICKEYBYTES) != 0) {
+ printf("crypto_sign_ed25519_sk_to_pk() failure\n");
+ }
sodium_bin2hex(pk_hex, sizeof pk_hex, pk, sizeof pk);
sodium_bin2hex(sk_hex, sizeof sk_hex, sk, sizeof sk);
printf("pk: [%s]\n", pk_hex);
printf("sk: [%s]\n", sk_hex);
+ assert(crypto_sign_bytes() > 0U);
+ assert(crypto_sign_seedbytes() > 0U);
+ assert(crypto_sign_publickeybytes() > 0U);
+ assert(crypto_sign_secretkeybytes() > 0U);
+ assert(strcmp(crypto_sign_primitive(), "ed25519") == 0);
+ assert(crypto_sign_bytes() == crypto_sign_ed25519_bytes());
+ assert(crypto_sign_seedbytes() == crypto_sign_ed25519_seedbytes());
+ assert(crypto_sign_publickeybytes()
+ == crypto_sign_ed25519_publickeybytes());
+ assert(crypto_sign_secretkeybytes()
+ == crypto_sign_ed25519_secretkeybytes());
+
return 0;
}
diff --git a/test/default/sign.exp b/test/default/sign.exp
new file mode 100644
index 0000000..04bf653
--- /dev/null
+++ b/test/default/sign.exp
@@ -0,0 +1,3 @@
+1024 tests
+pk: [b5076a8474a832daee4dd5b4040983b6623b5f344aca57d4d6ee4baf3f259e6e]
+sk: [421151a459faeade3d247115f94aedae42318124095afabe4d1451a559faedeeb5076a8474a832daee4dd5b4040983b6623b5f344aca57d4d6ee4baf3f259e6e]
diff --git a/test/default/sodium_core.c b/test/default/sodium_core.c
index 7bdcca8..89599ab 100644
--- a/test/default/sodium_core.c
+++ b/test/default/sodium_core.c
@@ -1,11 +1,14 @@
-#include <stdio.h>
#define TEST_NAME "sodium_core"
#include "cmptest.h"
int main(void)
{
- printf ("%d\n", sodium_init());
+ printf("%d\n", sodium_init());
- return 0;
+ (void)sodium_runtime_has_neon();
+ (void)sodium_runtime_has_sse2();
+ (void)sodium_runtime_has_sse3();
+
+ return 0;
}
diff --git a/test/default/sodium_core.exp b/test/default/sodium_core.exp
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/test/default/sodium_core.exp
@@ -0,0 +1 @@
+1
diff --git a/test/default/sodium_utils.c b/test/default/sodium_utils.c
index e50de24..89274de 100644
--- a/test/default/sodium_utils.c
+++ b/test/default/sodium_utils.c
@@ -1,35 +1,64 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "sodium_utils"
#include "cmptest.h"
int main(void)
{
- unsigned char buf1[1000];
- unsigned char buf2[1000];
- char buf3[33];
- unsigned char buf4[4];
- const char *hex;
- size_t bin_len;
-
- randombytes(buf1, sizeof buf1);
- memcpy(buf2, buf1, sizeof buf2);
- printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
- sodium_memzero(buf1, 0U);
- printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
- sodium_memzero(buf1, sizeof buf1 / 2);
- printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
- printf("%d\n", sodium_memcmp(buf1, buf2, 0U));
- sodium_memzero(buf2, sizeof buf2 / 2);
- printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
- printf("%s\n", sodium_bin2hex(buf3, 33U,
- (const unsigned char *)
- "0123456789ABCDEF", 16U));
- 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]);
-
- return 0;
+ unsigned char buf1[1000];
+ unsigned char buf2[1000];
+ char buf3[33];
+ unsigned char buf4[4];
+ const char *hex;
+ const char *hex_end;
+ size_t bin_len;
+
+ randombytes_buf(buf1, sizeof buf1);
+ memcpy(buf2, buf1, sizeof buf2);
+ printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
+ sodium_memzero(buf1, 0U);
+ printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
+ sodium_memzero(buf1, sizeof buf1 / 2);
+ printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
+ printf("%d\n", sodium_memcmp(buf1, buf2, 0U));
+ sodium_memzero(buf2, sizeof buf2 / 2);
+ printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
+ printf("%s\n",
+ sodium_bin2hex(buf3, 33U, (const unsigned char *)"0123456789ABCDEF",
+ 16U));
+ 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[2], buf4[3],
+ 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) != 0) {
+ 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) != 0) {
+ printf("sodium_hex2bin() with an odd input length\n");
+ }
+ printf("dt5: %ld\n", (long) (hex_end - hex));
+
+ return 0;
}
diff --git a/test/default/sodium_utils.exp b/test/default/sodium_utils.exp
new file mode 100644
index 0000000..e087a91
--- /dev/null
+++ b/test/default/sodium_utils.exp
@@ -0,0 +1,13 @@
+0
+0
+-1
+0
+0
+30313233343536373839414243444546
+4:cafe6942
+dt1: 11
+4:69426942
+dt2: 2
+dt3: 11
+dt4: 11
+dt5: 11
diff --git a/test/default/sodium_utils2.c b/test/default/sodium_utils2.c
new file mode 100644
index 0000000..11f1df6
--- /dev/null
+++ b/test/default/sodium_utils2.c
@@ -0,0 +1,72 @@
+
+#include <sys/types.h>
+
+#include <limits.h>
+#include <signal.h>
+
+#define TEST_NAME "sodium_utils2"
+#include "cmptest.h"
+
+static void segv_handler(int sig)
+{
+ printf("Intentional segfault / bus error caught\n");
+ printf("OK\n");
+#ifdef SIGSEGV
+ signal(SIGSEGV, SIG_DFL);
+#endif
+#ifdef SIGBUS
+ signal(SIGBUS, SIG_DFL);
+#endif
+#ifdef SIGABRT
+ signal(SIGABRT, SIG_DFL);
+#endif
+ exit(0);
+}
+
+int main(void)
+{
+ void *buf;
+ size_t size;
+ unsigned int i;
+
+ if (sodium_malloc(SIZE_MAX - 1U) != NULL) {
+ return 1;
+ }
+ if (sodium_allocarray(SIZE_MAX / 2U + 1U, SIZE_MAX / 2U) != NULL) {
+ return 1;
+ }
+ buf = sodium_allocarray(1000U, 50U);
+ memset(buf, 0, 50000U);
+ sodium_free(buf);
+
+ sodium_free(sodium_malloc(0U));
+ sodium_free(NULL);
+ for (i = 0U; i < 10000U; i++) {
+ size = randombytes_uniform(100000U);
+ buf = sodium_malloc(size);
+ memset(buf, i, size);
+ sodium_mprotect_readonly(buf);
+ sodium_free(buf);
+ }
+ printf("OK\n");
+
+#ifdef SIGSEGV
+ signal(SIGSEGV, segv_handler);
+#endif
+#ifdef SIGBUS
+ signal(SIGBUS, segv_handler);
+#endif
+#ifdef SIGABRT
+ signal(SIGABRT, segv_handler);
+#endif
+ size = randombytes_uniform(100000U);
+ buf = sodium_malloc(size);
+ sodium_mprotect_readonly(buf);
+ sodium_mprotect_readwrite(buf);
+ sodium_memzero(((unsigned char *)buf) + size, 1U);
+ sodium_mprotect_noaccess(buf);
+ sodium_free(buf);
+ printf("Overflow not caught\n");
+
+ return 0;
+}
diff --git a/test/default/sodium_utils2.exp b/test/default/sodium_utils2.exp
new file mode 100644
index 0000000..f796351
--- /dev/null
+++ b/test/default/sodium_utils2.exp
@@ -0,0 +1,3 @@
+OK
+Intentional segfault / bus error caught
+OK
diff --git a/test/default/sodium_utils3.c b/test/default/sodium_utils3.c
new file mode 100644
index 0000000..f2bcdae
--- /dev/null
+++ b/test/default/sodium_utils3.c
@@ -0,0 +1,50 @@
+
+#include <sys/types.h>
+
+#include <limits.h>
+#include <signal.h>
+
+#define TEST_NAME "sodium_utils3"
+#include "cmptest.h"
+
+static void segv_handler(int sig)
+{
+ printf("Intentional segfault / bus error caught\n");
+ printf("OK\n");
+#ifdef SIGSEGV
+ signal(SIGSEGV, SIG_DFL);
+#endif
+#ifdef SIGBUS
+ signal(SIGBUS, SIG_DFL);
+#endif
+#ifdef SIGABRT
+ signal(SIGABRT, SIG_DFL);
+#endif
+ exit(0);
+}
+
+int main(void)
+{
+ void *buf;
+ size_t size;
+
+#ifdef SIGSEGV
+ signal(SIGSEGV, segv_handler);
+#endif
+#ifdef SIGBUS
+ signal(SIGBUS, segv_handler);
+#endif
+#ifdef SIGABRT
+ signal(SIGABRT, segv_handler);
+#endif
+ size = randombytes_uniform(100000U);
+ buf = sodium_malloc(size);
+ sodium_mprotect_noaccess(buf);
+ sodium_mprotect_readwrite(buf);
+ sodium_memzero(((unsigned char *)buf) - 8, 8U);
+ sodium_mprotect_readonly(buf);
+ sodium_free(buf);
+ printf("Underflow not caught\n");
+
+ return 0;
+}
diff --git a/test/default/sodium_utils3.exp b/test/default/sodium_utils3.exp
new file mode 100644
index 0000000..37e114f
--- /dev/null
+++ b/test/default/sodium_utils3.exp
@@ -0,0 +1,2 @@
+Intentional segfault / bus error caught
+OK
diff --git a/test/default/sodium_version.c b/test/default/sodium_version.c
index 0b63d38..d32fd79 100644
--- a/test/default/sodium_version.c
+++ b/test/default/sodium_version.c
@@ -1,13 +1,12 @@
-#include <stdio.h>
#define TEST_NAME "sodium_version"
#include "cmptest.h"
int main(void)
{
- printf ("%d\n", sodium_version_string() != NULL);
- printf ("%d\n", sodium_library_version_major() > 0);
- printf ("%d\n", sodium_library_version_minor() >= 0);
+ printf("%d\n", sodium_version_string() != NULL);
+ printf("%d\n", sodium_library_version_major() > 0);
+ printf("%d\n", sodium_library_version_minor() >= 0);
- return 0;
+ return 0;
}
diff --git a/test/default/sodium_version.exp b/test/default/sodium_version.exp
new file mode 100644
index 0000000..e8183f0
--- /dev/null
+++ b/test/default/sodium_version.exp
@@ -0,0 +1,3 @@
+1
+1
+1
diff --git a/test/default/stream.c b/test/default/stream.c
index cc6d416..5e3d5dc 100644
--- a/test/default/stream.c
+++ b/test/default/stream.c
@@ -1,20 +1,15 @@
-#include <stdio.h>
#define TEST_NAME "stream"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
unsigned char output[4194304];
@@ -22,9 +17,20 @@ unsigned char h[32];
int main(void)
{
- int i;
- crypto_stream_xsalsa20(output,4194304,nonce,firstkey);
- crypto_hash_sha256(h,output,sizeof output);
- for (i = 0;i < 32;++i) printf("%02x",h[i]); printf("\n");
- return 0;
+ int i;
+
+ crypto_stream(output, 4194304, nonce, firstkey);
+ crypto_hash_sha256(h, output, sizeof output);
+
+ for (i = 0; i < 32; ++i)
+ printf("%02x", h[i]);
+ printf("\n");
+
+ assert(crypto_stream_keybytes() > 0U);
+ assert(crypto_stream_noncebytes() > 0U);
+ assert(strcmp(crypto_stream_primitive(), "xsalsa20") == 0);
+ assert(crypto_stream_keybytes() == crypto_stream_xsalsa20_keybytes());
+ assert(crypto_stream_noncebytes() == crypto_stream_xsalsa20_noncebytes());
+
+ return 0;
}
diff --git a/test/default/stream.exp b/test/default/stream.exp
new file mode 100644
index 0000000..5fa208c
--- /dev/null
+++ b/test/default/stream.exp
@@ -0,0 +1 @@
+662b9d0e3463029156069b12f918691a98f7dfb2ca0393c96bbfc6b1fbd630a2
diff --git a/test/default/stream2.c b/test/default/stream2.c
index 25cdb35..b3c5ac5 100644
--- a/test/default/stream2.c
+++ b/test/default/stream2.c
@@ -1,18 +1,14 @@
-#include <stdio.h>
#define TEST_NAME "stream2"
#include "cmptest.h"
-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
-} ;
+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 };
-unsigned char noncesuffix[8] = {
- 0x82,0x19,0xe0,0x03,0x6b,0x7a,0x0b,0x37
-} ;
+unsigned char noncesuffix[8]
+ = { 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
unsigned char output[4194304];
@@ -20,9 +16,15 @@ unsigned char h[32];
int main(void)
{
- int i;
- crypto_stream_salsa20(output,4194304,noncesuffix,secondkey);
- crypto_hash_sha256(h,output,sizeof output);
- for (i = 0;i < 32;++i) printf("%02x",h[i]); printf("\n");
- return 0;
+ int i;
+ crypto_stream_salsa20(output, 4194304, noncesuffix, secondkey);
+ crypto_hash_sha256(h, output, sizeof output);
+ for (i = 0; i < 32; ++i)
+ printf("%02x", h[i]);
+ printf("\n");
+
+ assert(crypto_stream_salsa20_keybytes() > 0U);
+ assert(crypto_stream_salsa20_noncebytes() > 0U);
+
+ return 0;
}
diff --git a/test/default/stream2.exp b/test/default/stream2.exp
new file mode 100644
index 0000000..5fa208c
--- /dev/null
+++ b/test/default/stream2.exp
@@ -0,0 +1 @@
+662b9d0e3463029156069b12f918691a98f7dfb2ca0393c96bbfc6b1fbd630a2
diff --git a/test/default/stream3.c b/test/default/stream3.c
index 3a1f559..d121228 100644
--- a/test/default/stream3.c
+++ b/test/default/stream3.c
@@ -1,30 +1,28 @@
-#include <stdio.h>
#define TEST_NAME "stream3"
#include "cmptest.h"
-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
-} ;
+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 };
-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
-} ;
+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 };
unsigned char rs[32];
int main(void)
{
- int i;
- crypto_stream_xsalsa20(rs,32,nonce,firstkey);
- for (i = 0;i < 32;++i) {
- printf(",0x%02x",(unsigned int) rs[i]);
- if (i % 8 == 7) printf("\n");
- }
- return 0;
+ int i;
+
+ crypto_stream(rs, 32, nonce, firstkey);
+
+ for (i = 0; i < 32; ++i) {
+ printf(",0x%02x", (unsigned int)rs[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ return 0;
}
diff --git a/test/default/stream3.exp b/test/default/stream3.exp
new file mode 100644
index 0000000..9cd7879
--- /dev/null
+++ b/test/default/stream3.exp
@@ -0,0 +1,4 @@
+,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
diff --git a/test/default/stream4.c b/test/default/stream4.c
index 91c724f..37d8203 100644
--- a/test/default/stream4.c
+++ b/test/default/stream4.c
@@ -1,55 +1,46 @@
-#include <stdio.h>
#define TEST_NAME "stream4"
#include "cmptest.h"
-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
-} ;
-
-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
-} ;
-
-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
-} ;
+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 };
+
+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 };
+
+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 };
unsigned char c[163];
int main(void)
{
- int i;
- crypto_stream_xsalsa20_xor(c,m,163,nonce,firstkey);
- for (i = 32;i < 163;++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
- }
- printf("\n");
- return 0;
+ int i;
+
+ crypto_stream_xor(c, m, 163, nonce, firstkey);
+
+ for (i = 32; i < 163; ++i) {
+ printf(",0x%02x", (unsigned int)c[i]);
+ if (i % 8 == 7)
+ printf("\n");
+ }
+ printf("\n");
+
+ return 0;
}
diff --git a/test/default/stream4.exp b/test/default/stream4.exp
new file mode 100644
index 0000000..0d3d8e9
--- /dev/null
+++ b/test/default/stream4.exp
@@ -0,0 +1,17 @@
+,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
diff --git a/test/default/stream5.c b/test/default/stream5.c
deleted file mode 100644
index 58aa36f..0000000
--- a/test/default/stream5.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <stdio.h>
-
-#define TEST_NAME "stream5"
-#include "cmptest.h"
-
-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
-} ;
-
-unsigned char nonce[16] = {
- 0x69,0x69,0x6e,0xe9,0x55,0xb6,0x2b,0x73
-,0xcd,0x62,0xbd,0xa8,0x75,0xfc,0x73,0xd6
-} ;
-
-unsigned char output[4194304];
-
-unsigned char h[32];
-
-int main(void)
-{
- int i;
- crypto_stream_aes256estream(output,4194304,nonce,firstkey);
- crypto_hash_sha256(h,output,sizeof output);
- for (i = 0;i < 32;++i) printf("%02x",h[i]); printf("\n");
- return 0;
-}
diff --git a/test/default/stream6.c b/test/default/stream6.c
deleted file mode 100644
index 668389f..0000000
--- a/test/default/stream6.c
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <stdio.h>
-
-#define TEST_NAME "stream6"
-#include "cmptest.h"
-
-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
-} ;
-
-unsigned char nonce[16] = {
- 0x69,0x69,0x6e,0xe9,0x55,0xb6,0x2b,0x73
-,0xcd,0x62,0xbd,0xa8,0x75,0xfc,0x73,0xd6
-} ;
-
-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
-} ;
-
-unsigned char c[163];
-
-int main(void)
-{
- int i;
- crypto_stream_aes256estream_xor(c,m,163,nonce,firstkey);
- for (i = 32;i < 163;++i) {
- printf(",0x%02x",(unsigned int) c[i]);
- if (i % 8 == 7) printf("\n");
- }
- printf("\n");
- return 0;
-}
diff --git a/test/default/verify1.c b/test/default/verify1.c
index def6421..d3f7e17 100644
--- a/test/default/verify1.c
+++ b/test/default/verify1.c
@@ -1,5 +1,3 @@
-#include <stdio.h>
-#include <string.h>
#define TEST_NAME "verify1"
#include "cmptest.h"
@@ -10,25 +8,29 @@ unsigned char v64[64], v64x[64];
int main(void)
{
- randombytes_buf(v16, sizeof v16);
- randombytes_buf(v32, sizeof v32);
- randombytes_buf(v64, sizeof v64);
+ randombytes_buf(v16, sizeof v16);
+ randombytes_buf(v32, sizeof v32);
+ randombytes_buf(v64, sizeof v64);
- memcpy(v16x, v16, sizeof v16);
- memcpy(v32x, v32, sizeof v32);
- memcpy(v64x, v64, sizeof v64);
+ memcpy(v16x, v16, sizeof v16);
+ memcpy(v32x, v32, sizeof v32);
+ memcpy(v64x, v64, sizeof v64);
- printf("%d\n", crypto_verify_16(v16, v16x));
- printf("%d\n", crypto_verify_32(v32, v32x));
- printf("%d\n", crypto_verify_64(v64, v64x));
+ printf("%d\n", crypto_verify_16(v16, v16x));
+ printf("%d\n", crypto_verify_32(v32, v32x));
+ printf("%d\n", crypto_verify_64(v64, v64x));
- v16x[randombytes_random() & 15U]++;
- v32x[randombytes_random() & 31U]++;
- v64x[randombytes_random() & 63U]++;
+ v16x[randombytes_random() & 15U]++;
+ v32x[randombytes_random() & 31U]++;
+ v64x[randombytes_random() & 63U]++;
- printf("%d\n", crypto_verify_16(v16, v16x));
- printf("%d\n", crypto_verify_32(v32, v32x));
- printf("%d\n", crypto_verify_64(v64, v64x));
+ printf("%d\n", crypto_verify_16(v16, v16x));
+ printf("%d\n", crypto_verify_32(v32, v32x));
+ printf("%d\n", crypto_verify_64(v64, v64x));
- return 0;
+ assert(crypto_verify_16_bytes() == 16U);
+ assert(crypto_verify_32_bytes() == 32U);
+ assert(crypto_verify_64_bytes() == 64U);
+
+ return 0;
}
diff --git a/test/default/verify1.exp b/test/default/verify1.exp
new file mode 100644
index 0000000..2b84500
--- /dev/null
+++ b/test/default/verify1.exp
@@ -0,0 +1,6 @@
+0
+0
+0
+-1
+-1
+-1