mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 17:57:21 +09:00
Make the tests a little bit more readable
This commit is contained in:
+17
-16
@@ -10,22 +10,23 @@ unsigned char a[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
crypto_auth(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");
|
||||
}
|
||||
int i;
|
||||
|
||||
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());
|
||||
crypto_auth(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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,12 @@ 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;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ unsigned char a[32] = {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
+23
-22
@@ -10,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(a,c,clen,key);
|
||||
if (crypto_auth_verify(a,c,clen,key) != 0) {
|
||||
printf("fail %d\n",clen);
|
||||
return 100;
|
||||
int clen;
|
||||
|
||||
for (clen = 0;clen < 10000;++clen) {
|
||||
randombytes(key,sizeof key);
|
||||
randombytes(c,clen);
|
||||
crypto_auth(a,c,clen,key);
|
||||
if (crypto_auth_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_verify(a,c,clen,key) == 0) {
|
||||
printf("forgery %d\n",clen);
|
||||
return 100;
|
||||
}
|
||||
a[rand() % sizeof a] += 1 + (rand() % 255);
|
||||
if (crypto_auth_verify(a,c,clen,key) == 0) {
|
||||
printf("forgery %d\n",clen);
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clen > 0) {
|
||||
c[rand() % clen] += 1 + (rand() % 255);
|
||||
if (crypto_auth_verify(a,c,clen,key) == 0) {
|
||||
printf("forgery %d\n",clen);
|
||||
return 100;
|
||||
}
|
||||
a[rand() % sizeof a] += 1 + (rand() % 255);
|
||||
if (crypto_auth_verify(a,c,clen,key) == 0) {
|
||||
printf("forgery %d\n",clen);
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@ 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;
|
||||
}
|
||||
|
||||
+23
-22
@@ -10,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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
+26
-27
@@ -51,33 +51,32 @@ unsigned char c[163];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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");
|
||||
int i;
|
||||
|
||||
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());
|
||||
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");
|
||||
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
+9
-10
@@ -51,15 +51,14 @@ unsigned char m[163];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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");
|
||||
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");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+18
-17
@@ -13,24 +13,25 @@ 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(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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("ciphertext fails verification\n");
|
||||
}
|
||||
} else {
|
||||
printf("ciphertext fails verification\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+24
-23
@@ -15,29 +15,30 @@ 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(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+14
-13
@@ -11,17 +11,18 @@ unsigned char seed[32] = {
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
unsigned char sk[32];
|
||||
unsigned char pk[32];
|
||||
crypto_box_seed_keypair(pk, sk, seed);
|
||||
for (i = 0;i < 32;++i) {
|
||||
printf(",0x%02x",(unsigned int) pk[i]);
|
||||
if (i % 8 == 7) printf("\n");
|
||||
}
|
||||
for (i = 0;i < 32;++i) {
|
||||
printf(",0x%02x",(unsigned int) sk[i]);
|
||||
if (i % 8 == 7) printf("\n");
|
||||
}
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -40,5 +40,5 @@ int main(void)
|
||||
assert(crypto_stream_chacha20_keybytes() > 0U);
|
||||
assert(crypto_stream_chacha20_noncebytes() > 0U);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+18
-12
@@ -20,18 +20,24 @@ 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");
|
||||
}
|
||||
int i;
|
||||
|
||||
assert(crypto_core_hsalsa20_outputbytes() > 0U);
|
||||
assert(crypto_core_hsalsa20_inputbytes() > 0U);
|
||||
assert(crypto_core_hsalsa20_keybytes() > 0U);
|
||||
assert(crypto_core_hsalsa20_constbytes() > 0U);
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+15
-8
@@ -23,12 +23,19 @@ 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;
|
||||
}
|
||||
|
||||
+19
-16
@@ -26,22 +26,25 @@ 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");
|
||||
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);
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+15
-8
@@ -23,12 +23,19 @@ 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;
|
||||
}
|
||||
|
||||
+10
-7
@@ -23,11 +23,14 @@ 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;
|
||||
}
|
||||
|
||||
+20
-18
@@ -23,26 +23,28 @@ unsigned char out[64];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ static const unsigned char keypair_seed[crypto_sign_ed25519_SEEDBYTES] = {
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
@@ -11,7 +11,7 @@ int main(void)
|
||||
};
|
||||
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;
|
||||
|
||||
|
||||
+12
-9
@@ -7,15 +7,18 @@ 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");
|
||||
size_t i;
|
||||
|
||||
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_bytes());
|
||||
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;
|
||||
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_bytes());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,13 @@ 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");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+13
-12
@@ -33,17 +33,18 @@ unsigned char a[16];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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");
|
||||
}
|
||||
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());
|
||||
int i;
|
||||
|
||||
return 0;
|
||||
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");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,6 @@ unsigned char a[16] = {
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("%d\n",crypto_onetimeauth_verify(a,c,131,rs));
|
||||
return 0;
|
||||
printf("%d\n",crypto_onetimeauth_verify(a,c,131,rs));
|
||||
return 0;
|
||||
}
|
||||
|
||||
+23
-22
@@ -10,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(a,c,clen,key);
|
||||
if (crypto_onetimeauth_verify(a,c,clen,key) != 0) {
|
||||
printf("fail %d\n",clen);
|
||||
return 100;
|
||||
int clen;
|
||||
|
||||
for (clen = 0;clen < 10000;++clen) {
|
||||
randombytes(key,sizeof key);
|
||||
randombytes(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,19 @@ unsigned long long freq[256];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned long long i;
|
||||
unsigned long long i;
|
||||
|
||||
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;
|
||||
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+22
-14
@@ -13,19 +13,27 @@ unsigned char alicepk[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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());
|
||||
int i;
|
||||
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,20 @@ unsigned char bobpk[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,20 @@ unsigned char k[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,20 @@ unsigned char k[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
+20
-21
@@ -44,27 +44,26 @@ unsigned char c[163];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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");
|
||||
int i;
|
||||
|
||||
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());
|
||||
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");
|
||||
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -44,15 +44,14 @@ unsigned char m[163];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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");
|
||||
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;
|
||||
}
|
||||
|
||||
+17
-16
@@ -10,23 +10,24 @@ 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(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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("ciphertext fails verification\n");
|
||||
}
|
||||
} else {
|
||||
printf("ciphertext fails verification\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+23
-22
@@ -12,28 +12,29 @@ 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(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -40,23 +40,23 @@ unsigned char mac[crypto_secretbox_MACBYTES];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
size_t i;
|
||||
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_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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
+12
-10
@@ -21,16 +21,18 @@ unsigned char h[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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");
|
||||
int i;
|
||||
|
||||
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());
|
||||
crypto_stream(output,4194304,nonce,firstkey);
|
||||
crypto_hash_sha256(h,output,sizeof output);
|
||||
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ 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");
|
||||
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);
|
||||
assert(crypto_stream_salsa20_keybytes() > 0U);
|
||||
assert(crypto_stream_salsa20_noncebytes() > 0U);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ unsigned char rs[32];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
+11
-8
@@ -43,12 +43,15 @@ unsigned char c[163];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
+19
-19
@@ -8,29 +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));
|
||||
|
||||
assert(crypto_verify_16_bytes() == 16U);
|
||||
assert(crypto_verify_32_bytes() == 32U);
|
||||
assert(crypto_verify_64_bytes() == 64U);
|
||||
assert(crypto_verify_16_bytes() == 16U);
|
||||
assert(crypto_verify_32_bytes() == 32U);
|
||||
assert(crypto_verify_64_bytes() == 64U);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user