Skip to content

Commit e3834a0

Browse files
author
apache
committed
first commit
0 parents  commit e3834a0

File tree

228 files changed

+15568
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+15568
-0
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
compile: make-dq.sh
2+
sh -e make-dq.sh
3+
clean:
4+
rm -rf build

conf-cc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
gcc -O3 -fomit-frame-pointer -funroll-loops
2+
clang -O3 -fomit-frame-pointer -funroll-loops
3+
cc -O3 -fomit-frame-pointer -funroll-loops
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
20141017
3+
Jan Mojzis
4+
Public domain.
5+
*/
6+
7+
#include "misc.h"
8+
#include "crypto_box_curve25519xsalsa20poly1305.h"
9+
10+
#define SPACESIZE 5232
11+
12+
static unsigned char m[SPACESIZE + 16];
13+
static unsigned char n[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES + 16];
14+
static unsigned char c[SPACESIZE + 16 + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES];
15+
static unsigned char pk[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES + 16];
16+
static unsigned char sk[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES + 16];
17+
18+
static unsigned char test_pseudorandom_checksum[32] = {
19+
0xb7, 0xd4, 0xf1, 0x92, 0x3d, 0x4b, 0x80, 0xf0,
20+
0xb5, 0x3c, 0xdb, 0x38, 0xdb, 0x53, 0xcf, 0xb6,
21+
0xe8, 0x3d, 0x52, 0x96, 0xb6, 0x73, 0x61, 0x07,
22+
0x95, 0x72, 0x37, 0x69, 0xad, 0xda, 0x65, 0x8b
23+
};
24+
25+
26+
static void zerobytes(void *yv, long long ylen) {
27+
28+
long long i;
29+
char *y = yv;
30+
31+
for (i = 0; i < ylen; ++i) y[i] = 0;
32+
}
33+
34+
35+
static void copy(void *yv, long long ylen, const void *xv) {
36+
37+
long long i;
38+
const char *x = xv;
39+
char *y = yv;
40+
41+
for (i = 0; i < ylen; ++i) y[i] = x[i];
42+
}
43+
44+
45+
static unsigned char skdata[1080][32] = {
46+
#include "precomp.data"
47+
};
48+
49+
static unsigned char pkdata[1080][32] = {
50+
#include "precomp_curve25519.data"
51+
};
52+
53+
54+
static void test_pseudorandom(void) {
55+
56+
long long i, j;
57+
58+
checksum_zero();
59+
i = 0;
60+
for (j = crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; j < SPACESIZE; j += 1 + j / 16) {
61+
62+
pseudorandombytes(m + i, j);
63+
pseudorandombytes(n + i, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES);
64+
zerobytes(m + i, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES);
65+
66+
copy(sk + i, 32, skdata[i]);
67+
copy(pk + i, 32, pkdata[i]);
68+
69+
crypto_box_curve25519xsalsa20poly1305(c + i, m + i, j, n, pk + i, sk + i);
70+
checksum(c + i, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES);
71+
72+
zerobytes(c + i, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES);
73+
if (crypto_box_curve25519xsalsa20poly1305_open(m + i, c + i, j, n, pk + i, sk + i) != 0) {
74+
fail_printdata("m", m + i, j);
75+
fail_printdata("c", c + i, j);
76+
fail_printdata("pk", pk + i, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES);
77+
fail_printdata("sk", sk + i, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES);
78+
fail_printdata("n", n + i, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES);
79+
fail("crypto_box_curve25519xsalsa20poly1305_open() failure");
80+
}
81+
++i;
82+
i %= 16;
83+
}
84+
fail_whenbadchecksum(test_pseudorandom_checksum);
85+
}
86+
87+
88+
int main(void) {
89+
90+
test_pseudorandom();
91+
92+
_exit(0);
93+
}

crypto-tests/crypto_hash_sha512test.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
20141018
3+
Jan Mojzis
4+
Public domain.
5+
*/
6+
7+
#include "misc.h"
8+
#include "crypto_hash_sha512.h"
9+
10+
#define SPACESIZE 5232
11+
12+
static unsigned char space[SPACESIZE + 16];
13+
static unsigned char buf[crypto_hash_sha512_BYTES + 16];
14+
15+
static unsigned char test_pseudorandom_checksum[32] = {
16+
0xa1, 0x57, 0x2f, 0x67, 0x19, 0xa6, 0x88, 0x2f,
17+
0x54, 0xa5, 0xa4, 0x7d, 0xe2, 0xd3, 0xa3, 0xfd,
18+
0xd1, 0x1a, 0x73, 0x58, 0x84, 0xc7, 0xb9, 0xfd,
19+
0x7f, 0xa2, 0x33, 0xbf, 0x86, 0xf7, 0x15, 0xee
20+
};
21+
22+
static void test_pseudorandom(void) {
23+
24+
long long i, j;
25+
26+
checksum_zero();
27+
i = 0;
28+
for (j = 0; j < SPACESIZE; j += 1 + j / 16) {
29+
pseudorandombytes(space + i, j);
30+
crypto_hash_sha512(buf + i, space + i, j);
31+
checksum(buf + i, crypto_hash_sha512_BYTES);
32+
++i;
33+
i %= 16;
34+
}
35+
fail_whenbadchecksum(test_pseudorandom_checksum);
36+
}
37+
38+
int main(void) {
39+
40+
test_pseudorandom();
41+
_exit(0);
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
20141017
3+
Jan Mojzis
4+
Public domain.
5+
*/
6+
7+
#include "misc.h"
8+
#include "crypto_onetimeauth_poly1305.h"
9+
10+
#define SPACESIZE 5232
11+
12+
static unsigned char space[SPACESIZE + 16];
13+
static unsigned char key[crypto_onetimeauth_poly1305_KEYBYTES + 16];
14+
static unsigned char buf[crypto_onetimeauth_poly1305_BYTES + 16];
15+
16+
static unsigned char test_pseudorandom_checksum[32] = {
17+
0xaf, 0xe7, 0xbb, 0x79, 0x2a, 0xe5, 0x81, 0xee,
18+
0xbc, 0x1f, 0x5b, 0x79, 0x96, 0xb7, 0x27, 0x1a,
19+
0xc2, 0x74, 0x65, 0x0e, 0x1d, 0xb5, 0xb7, 0x06,
20+
0x10, 0x42, 0x6a, 0x50, 0x57, 0x8b, 0xf1, 0xb0
21+
};
22+
23+
24+
static void test_pseudorandom(void) {
25+
26+
long long i, j;
27+
28+
checksum_zero();
29+
i = 0;
30+
for (j = 0; j < SPACESIZE; j += 1 + j / 16) {
31+
32+
pseudorandombytes(space + i, j);
33+
pseudorandombytes(key + i, crypto_onetimeauth_poly1305_KEYBYTES);
34+
35+
crypto_onetimeauth_poly1305(buf + i, space + i, j, key + i);
36+
checksum(buf + i, crypto_onetimeauth_poly1305_BYTES);
37+
38+
if (crypto_onetimeauth_poly1305_verify(buf + i, space + i, j, key + i) != 0) {
39+
fail_printdata("m", space + i, j);
40+
fail_printdata("key", key + i, crypto_onetimeauth_poly1305_KEYBYTES);
41+
fail_printdata("a", buf + i, crypto_onetimeauth_poly1305_BYTES);
42+
fail("crypto_onetimeauth_poly1305_verify() failure");
43+
}
44+
++i;
45+
i %= 16;
46+
}
47+
fail_whenbadchecksum(test_pseudorandom_checksum);
48+
}
49+
50+
51+
int main(void) {
52+
53+
test_pseudorandom();
54+
55+
_exit(0);
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
20141017
3+
Jan Mojzis
4+
Public domain.
5+
*/
6+
7+
#include "misc.h"
8+
#include "crypto_scalarmult_curve25519.h"
9+
10+
#define BYTES crypto_scalarmult_curve25519_BYTES
11+
#define SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES
12+
13+
static unsigned char pk[BYTES];
14+
15+
static unsigned char S[BYTES] = { 9 };
16+
17+
static unsigned char R[BYTES] = {
18+
0xf9, 0xc3, 0xda, 0xc2, 0x10, 0x4c, 0x80, 0xb2,
19+
0x52, 0xd0, 0xae, 0xec, 0x37, 0x7a, 0xfd, 0x5d,
20+
0x1e, 0xf2, 0xc8, 0xc3, 0x48, 0xc2, 0x9e, 0x12,
21+
0xdd, 0xb2, 0xd0, 0xc8, 0xb1, 0x98, 0xff, 0x7f
22+
};
23+
24+
static unsigned char d[SCALARBYTES] = {
25+
0x56, 0x2c, 0x1e, 0xb5, 0xfd, 0xb2, 0x81, 0x29,
26+
0xbd, 0x37, 0x49, 0x58, 0x35, 0xd4, 0xb1, 0x30,
27+
0x7d, 0xdb, 0x57, 0x38, 0x80, 0x12, 0x17, 0x42,
28+
0xf7, 0x13, 0xf1, 0x05, 0x67, 0x69, 0xd5, 0xbf
29+
};
30+
31+
static void test_vector(void) {
32+
33+
long long j;
34+
unsigned char r[BYTES];
35+
36+
if (crypto_scalarmult_curve25519(r, d, S) != 0) fail("crypto_scalarmult_curve25519() failure");
37+
for (j = 0; j < BYTES; ++j) if (r[j] != R[j]) fail("crypto_scalarmult_curve25519() failure");
38+
}
39+
40+
static unsigned char skdata[1080][32] = {
41+
#include "precomp.data"
42+
};
43+
44+
static unsigned char pkdata[1080][32] = {
45+
#include "precomp_curve25519.data"
46+
};
47+
48+
static void test_base(void) {
49+
50+
long long i, j;
51+
52+
checksum_zero();
53+
for (i = 0; i < 1080; ++i) {
54+
if (crypto_scalarmult_curve25519_base(pk, skdata[i]) != 0) {
55+
fail_printdata("sk", skdata[i], SCALARBYTES);
56+
fail("crypto_scalarmult_curve25519_base() failure, please report it !!!!!!!!!");
57+
}
58+
for (j = 0; j < BYTES; ++j) if (pk[j] != pkdata[i][j]) {
59+
fail_printdata("pk_computed", pk, BYTES);
60+
fail_printdata("pk_expected", pkdata[i], BYTES);
61+
fail_printdata("sk", skdata[i], SCALARBYTES);
62+
fail("crypto_scalarmult_curve25519() failure, please report it !!!!!!!!!");
63+
}
64+
}
65+
}
66+
67+
static const unsigned char basepoint[BYTES] = { 9 };
68+
69+
static unsigned char test_scalarmult_checksum[32] = {
70+
0xca, 0xf4, 0xa3, 0xbe, 0x00, 0x9c, 0x6f, 0x01,
71+
0xb8, 0x4e, 0xf8, 0x0d, 0x0a, 0x17, 0x16, 0x42,
72+
0xfe, 0x01, 0x59, 0x40, 0x74, 0xd4, 0xa6, 0x48,
73+
0x07, 0x94, 0x95, 0x94, 0xab, 0xa4, 0x5e, 0x6d
74+
};
75+
76+
static void test_scalarmult(void) {
77+
78+
long long i, j;
79+
unsigned char outpk[BYTES];
80+
81+
for (i = 0; i < BYTES; ++i) pk[i] = basepoint[i];
82+
83+
checksum_zero();
84+
for (i = 0; i < 1080; ++i) {
85+
pk[31] |= 128;
86+
if (crypto_scalarmult_curve25519(outpk, skdata[i], pk) != 0) {
87+
fail_printdata("pk", pk, BYTES);
88+
fail_printdata("sk", skdata[i], SCALARBYTES);
89+
fail("crypto_scalarmult_curve25519() failure, please report it !!!!!!!!!");
90+
}
91+
checksum(outpk, BYTES);
92+
for (j = 0; j < BYTES; ++j) pk[j] = outpk[j];
93+
}
94+
fail_whenbadchecksum(test_scalarmult_checksum);
95+
}
96+
97+
static void test_random(void) {
98+
99+
long long i, j;
100+
unsigned char sk1[SCALARBYTES + 16];
101+
unsigned char pk1[BYTES + 16];
102+
unsigned char k1[BYTES + 16];
103+
unsigned char sk2[SCALARBYTES + 16];
104+
unsigned char pk2[BYTES + 16];
105+
unsigned char k2[BYTES + 16];
106+
107+
108+
for (i = 0; i < 16; ++i) {
109+
unsaferandombytes(sk1 + i, SCALARBYTES);
110+
unsaferandombytes(sk2 + i, SCALARBYTES);
111+
if (crypto_scalarmult_curve25519_base(pk1 + i, sk1 + i) != 0) goto fail;
112+
pk1[31 + i] |= 128;
113+
if (crypto_scalarmult_curve25519_base(pk2 + i, sk2 + i) != 0) goto fail;
114+
pk2[31 + i] |= 128;
115+
if (crypto_scalarmult_curve25519(k1 + i, sk1 + i, pk2 + i) != 0) goto fail;
116+
if (crypto_scalarmult_curve25519(k2 + i, sk2 + i, pk1 + i) != 0) goto fail;
117+
for (j = 0; j < BYTES; ++j) if (k1[j + i] != k2[j + i]) goto fail;
118+
}
119+
return;
120+
121+
fail:
122+
fail_printdata("sk1", sk1 + i, SCALARBYTES);
123+
fail_printdata("sk2", sk2 + i, SCALARBYTES);
124+
fail("crypto_scalarmult_curve25519() failure, please report it !!!!!!!!!");
125+
}
126+
127+
int main(void) {
128+
129+
test_vector();
130+
test_base();
131+
test_scalarmult();
132+
test_random();
133+
_exit(0);
134+
}

0 commit comments

Comments
 (0)