mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-24 04:25:10 -07:00
random() doesn't exist on Win32. Just use rand()
This commit is contained in:
parent
b50e6fb5e7
commit
c4f75c4896
@ -60,12 +60,12 @@ const char *checksum_compute(void)
|
||||
long long klen = crypto_auth_KEYBYTES;
|
||||
long long hlen = crypto_auth_BYTES;
|
||||
|
||||
for (j = -16;j < 0;++j) h[j] = random();
|
||||
for (j = -16;j < 0;++j) k[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = random();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) h[j] = rand();
|
||||
for (j = -16;j < 0;++j) k[j] = rand();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = rand();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < hlen + 16;++j) h2[j] = h[j];
|
||||
for (j = -16;j < klen + 16;++j) k2[j] = k[j];
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
@ -77,12 +77,12 @@ const char *checksum_compute(void)
|
||||
for (j = -16;j < 0;++j) if (h[j] != h2[j]) return "crypto_auth writes before output";
|
||||
for (j = hlen;j < hlen + 16;++j) if (h[j] != h2[j]) return "crypto_auth writes after output";
|
||||
|
||||
for (j = -16;j < 0;++j) h[j] = random();
|
||||
for (j = -16;j < 0;++j) k[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = random();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) h[j] = rand();
|
||||
for (j = -16;j < 0;++j) k[j] = rand();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = rand();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < hlen + 16;++j) h2[j] = h[j];
|
||||
for (j = -16;j < klen + 16;++j) k2[j] = k[j];
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
|
@ -93,19 +93,19 @@ const char *checksum_compute(void)
|
||||
long long tlen = i + crypto_box_ZEROBYTES;
|
||||
long long clen = i + crypto_box_ZEROBYTES;
|
||||
|
||||
for (j = -16;j < 0;++j) ska[j] = random();
|
||||
for (j = -16;j < 0;++j) skb[j] = random();
|
||||
for (j = -16;j < 0;++j) pka[j] = random();
|
||||
for (j = -16;j < 0;++j) pkb[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) n[j] = random();
|
||||
for (j = -16;j < 0;++j) ska[j] = rand();
|
||||
for (j = -16;j < 0;++j) skb[j] = rand();
|
||||
for (j = -16;j < 0;++j) pka[j] = rand();
|
||||
for (j = -16;j < 0;++j) pkb[j] = rand();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = -16;j < 0;++j) n[j] = rand();
|
||||
|
||||
for (j = sklen;j < sklen + 16;++j) ska[j] = random();
|
||||
for (j = sklen;j < sklen + 16;++j) skb[j] = random();
|
||||
for (j = pklen;j < pklen + 16;++j) pka[j] = random();
|
||||
for (j = pklen;j < pklen + 16;++j) pkb[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = nlen;j < nlen + 16;++j) n[j] = random();
|
||||
for (j = sklen;j < sklen + 16;++j) ska[j] = rand();
|
||||
for (j = sklen;j < sklen + 16;++j) skb[j] = rand();
|
||||
for (j = pklen;j < pklen + 16;++j) pka[j] = rand();
|
||||
for (j = pklen;j < pklen + 16;++j) pkb[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = nlen;j < nlen + 16;++j) n[j] = rand();
|
||||
|
||||
for (j = -16;j < sklen + 16;++j) ska2[j] = ska[j];
|
||||
for (j = -16;j < sklen + 16;++j) skb2[j] = skb[j];
|
||||
@ -113,7 +113,7 @@ const char *checksum_compute(void)
|
||||
for (j = -16;j < pklen + 16;++j) pkb2[j] = pkb[j];
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
for (j = -16;j < nlen + 16;++j) n2[j] = n[j];
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j] = random();
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j] = rand();
|
||||
|
||||
if (crypto_box(c,m,mlen,n,pkb,ska) != 0) return "crypto_box returns nonzero";
|
||||
|
||||
@ -129,10 +129,10 @@ const char *checksum_compute(void)
|
||||
for (j = -16;j < pklen + 16;++j) if (pka2[j] != pka[j]) return "crypto_box overwrites pka";
|
||||
for (j = -16;j < pklen + 16;++j) if (pkb2[j] != pkb[j]) return "crypto_box overwrites pkb";
|
||||
|
||||
for (j = -16;j < 0;++j) c[j] = random();
|
||||
for (j = clen;j < clen + 16;++j) c[j] = random();
|
||||
for (j = -16;j < 0;++j) c[j] = rand();
|
||||
for (j = clen;j < clen + 16;++j) c[j] = rand();
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j];
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = random();
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = rand();
|
||||
|
||||
if (crypto_box_open(t,c,clen,n,pka,skb) != 0) return "crypto_box_open returns nonzero";
|
||||
|
||||
@ -150,7 +150,7 @@ const char *checksum_compute(void)
|
||||
|
||||
for (j = 0;j < mlen;++j) if (t[j] != m[j]) return "plaintext does not match";
|
||||
|
||||
for (j = -16;j < slen + 16;++j) s2[j] = s[j] = random();
|
||||
for (j = -16;j < slen + 16;++j) s2[j] = s[j] = rand();
|
||||
if (crypto_box_beforenm(s,pkb,ska) != 0) return "crypto_box_beforenm returns nonzero";
|
||||
for (j = -16;j < pklen + 16;++j) if (pka2[j] != pka[j]) return "crypto_box_open overwrites pk";
|
||||
for (j = -16;j < sklen + 16;++j) if (skb2[j] != skb[j]) return "crypto_box_open overwrites sk";
|
||||
@ -158,7 +158,7 @@ const char *checksum_compute(void)
|
||||
for (j = slen;j < slen + 16;++j) if (s2[j] != s[j]) return "crypto_box_beforenm writes after output";
|
||||
|
||||
for (j = -16;j < slen + 16;++j) s2[j] = s[j];
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = random();
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = rand();
|
||||
if (crypto_box_afternm(t,m,mlen,n,s) != 0) return "crypto_box_afternm returns nonzero";
|
||||
for (j = -16;j < slen + 16;++j) if (s2[j] != s[j]) return "crypto_box_afternm overwrites s";
|
||||
for (j = -16;j < mlen + 16;++j) if (m2[j] != m[j]) return "crypto_box_afternm overwrites m";
|
||||
@ -171,7 +171,7 @@ const char *checksum_compute(void)
|
||||
|
||||
if (crypto_box_beforenm(s,pka,skb) != 0) return "crypto_box_beforenm returns nonzero";
|
||||
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = random();
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = rand();
|
||||
if (crypto_box_open_afternm(t,c,clen,n,s) != 0) return "crypto_box_open_afternm returns nonzero";
|
||||
for (j = -16;j < slen + 16;++j) if (s2[j] != s[j]) return "crypto_box_open_afternm overwrites s";
|
||||
for (j = -16;j < mlen + 16;++j) if (m2[j] != m[j]) return "crypto_box_open_afternm overwrites m";
|
||||
|
@ -52,11 +52,11 @@ const char *checksum_compute(void)
|
||||
for (i = 0;i < CHECKSUM_BYTES;++i) {
|
||||
long long hlen = crypto_hash_BYTES;
|
||||
long long mlen = i;
|
||||
for (j = -16;j < 0;++j) h[j] = random();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = random();
|
||||
for (j = -16;j < 0;++j) h[j] = rand();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = rand();
|
||||
for (j = -16;j < hlen + 16;++j) h2[j] = h[j];
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
if (crypto_hash(h,m,mlen) != 0) return "crypto_hash returns nonzero";
|
||||
for (j = -16;j < mlen + 16;++j) if (m2[j] != m[j]) return "crypto_hash writes to input";
|
||||
|
@ -52,11 +52,11 @@ const char *checksum_compute(void)
|
||||
for (i = 0;i < CHECKSUM_BYTES;++i) {
|
||||
long long hlen = crypto_hashblocks_STATEBYTES;
|
||||
long long mlen = i;
|
||||
for (j = -16;j < 0;++j) h[j] = random();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = random();
|
||||
for (j = -16;j < 0;++j) h[j] = rand();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = rand();
|
||||
for (j = -16;j < hlen + 16;++j) h2[j] = h[j];
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
if (crypto_hashblocks(h,m,mlen) != 0) return "crypto_hashblocks returns nonzero";
|
||||
for (j = -16;j < mlen + 16;++j) if (m2[j] != m[j]) return "crypto_hashblocks writes to input";
|
||||
|
@ -66,12 +66,12 @@ checksum_compute(void)
|
||||
long long klen = crypto_onetimeauth_KEYBYTES;
|
||||
long long hlen = crypto_onetimeauth_BYTES;
|
||||
|
||||
for (j = -16;j < 0;++j) h[j] = random();
|
||||
for (j = -16;j < 0;++j) k[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = random();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) h[j] = rand();
|
||||
for (j = -16;j < 0;++j) k[j] = rand();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = rand();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < hlen + 16;++j) h2[j] = h[j];
|
||||
for (j = -16;j < klen + 16;++j) k2[j] = k[j];
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
@ -83,12 +83,12 @@ checksum_compute(void)
|
||||
for (j = -16;j < 0;++j) if (h[j] != h2[j]) return "crypto_onetimeauth writes before output";
|
||||
for (j = hlen;j < hlen + 16;++j) if (h[j] != h2[j]) return "crypto_onetimeauth writes after output";
|
||||
|
||||
for (j = -16;j < 0;++j) h[j] = random();
|
||||
for (j = -16;j < 0;++j) k[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = random();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) h[j] = rand();
|
||||
for (j = -16;j < 0;++j) k[j] = rand();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = hlen;j < hlen + 16;++j) h[j] = rand();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < hlen + 16;++j) h2[j] = h[j];
|
||||
for (j = -16;j < klen + 16;++j) k2[j] = k[j];
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
|
@ -72,10 +72,10 @@ const char *checksum_compute(void)
|
||||
for (i = 0;i < qlen;++i) q[i] = i + 3;
|
||||
for (i = 0;i < rlen;++i) r[i] = i + 4;
|
||||
|
||||
for (i = -16;i < 0;++i) p[i] = random();
|
||||
for (i = -16;i < 0;++i) n[i] = random();
|
||||
for (i = plen;i < plen + 16;++i) p[i] = random();
|
||||
for (i = nlen;i < nlen + 16;++i) n[i] = random();
|
||||
for (i = -16;i < 0;++i) p[i] = rand();
|
||||
for (i = -16;i < 0;++i) n[i] = rand();
|
||||
for (i = plen;i < plen + 16;++i) p[i] = rand();
|
||||
for (i = nlen;i < nlen + 16;++i) n[i] = rand();
|
||||
for (i = -16;i < plen + 16;++i) p2[i] = p[i];
|
||||
for (i = -16;i < nlen + 16;++i) n2[i] = n[i];
|
||||
|
||||
@ -86,12 +86,12 @@ const char *checksum_compute(void)
|
||||
for (i = plen;i < plen + 16;++i) if (p2[i] != p[i]) return "crypto_scalarmult_base writes after output";
|
||||
|
||||
for (tests = 0;tests < 100;++tests) {
|
||||
for (i = -16;i < 0;++i) q[i] = random();
|
||||
for (i = -16;i < 0;++i) p[i] = random();
|
||||
for (i = -16;i < 0;++i) m[i] = random();
|
||||
for (i = qlen;i < qlen + 16;++i) q[i] = random();
|
||||
for (i = plen;i < plen + 16;++i) p[i] = random();
|
||||
for (i = mlen;i < mlen + 16;++i) m[i] = random();
|
||||
for (i = -16;i < 0;++i) q[i] = rand();
|
||||
for (i = -16;i < 0;++i) p[i] = rand();
|
||||
for (i = -16;i < 0;++i) m[i] = rand();
|
||||
for (i = qlen;i < qlen + 16;++i) q[i] = rand();
|
||||
for (i = plen;i < plen + 16;++i) p[i] = rand();
|
||||
for (i = mlen;i < mlen + 16;++i) m[i] = rand();
|
||||
for (i = -16;i < qlen + 16;++i) q2[i] = q[i];
|
||||
for (i = -16;i < plen + 16;++i) p2[i] = p[i];
|
||||
for (i = -16;i < mlen + 16;++i) m2[i] = m[i];
|
||||
|
@ -72,16 +72,16 @@ const char *checksum_compute(void)
|
||||
long long tlen = i + crypto_secretbox_ZEROBYTES;
|
||||
long long clen = i + crypto_secretbox_ZEROBYTES;
|
||||
|
||||
for (j = -16;j < 0;++j) k[j] = random();
|
||||
for (j = -16;j < 0;++j) n[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = random();
|
||||
for (j = nlen;j < nlen + 16;++j) n[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) k[j] = rand();
|
||||
for (j = -16;j < 0;++j) n[j] = rand();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = rand();
|
||||
for (j = nlen;j < nlen + 16;++j) n[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = -16;j < klen + 16;++j) k2[j] = k[j];
|
||||
for (j = -16;j < nlen + 16;++j) n2[j] = n[j];
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j] = random();
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j] = rand();
|
||||
|
||||
if (crypto_secretbox(c,m,mlen,n,k) != 0) return "crypto_secretbox returns nonzero";
|
||||
|
||||
@ -93,10 +93,10 @@ const char *checksum_compute(void)
|
||||
for (j = 0;j < crypto_secretbox_BOXZEROBYTES;++j)
|
||||
if (c[j] != 0) return "crypto_secretbox does not clear extra bytes";
|
||||
|
||||
for (j = -16;j < 0;++j) c[j] = random();
|
||||
for (j = clen;j < clen + 16;++j) c[j] = random();
|
||||
for (j = -16;j < 0;++j) c[j] = rand();
|
||||
for (j = clen;j < clen + 16;++j) c[j] = rand();
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j];
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = random();
|
||||
for (j = -16;j < tlen + 16;++j) t2[j] = t[j] = rand();
|
||||
|
||||
if (crypto_secretbox_open(t,c,clen,n,k) != 0) return "crypto_secretbox_open returns nonzero";
|
||||
|
||||
|
@ -69,7 +69,7 @@ const char *checksum_compute(void)
|
||||
if (t[i] != m[i])
|
||||
return "crypto_sign_open does not match contents";
|
||||
|
||||
j = random() % smlen;
|
||||
j = rand() % smlen;
|
||||
sm[j] ^= 1;
|
||||
if (crypto_sign_open(t,&tlen,sm,smlen,pk) == 0) {
|
||||
if (tlen != mlen) return "crypto_sign_open allows trivial forgery of length";
|
||||
|
@ -67,16 +67,16 @@ const char *checksum_compute(void)
|
||||
long long slen = i;
|
||||
long long klen = crypto_stream_KEYBYTES;
|
||||
long long nlen = crypto_stream_NONCEBYTES;
|
||||
for (j = -16;j < 0;++j) m[j] = random();
|
||||
for (j = -16;j < 0;++j) c[j] = random();
|
||||
for (j = -16;j < 0;++j) s[j] = random();
|
||||
for (j = -16;j < 0;++j) n[j] = random();
|
||||
for (j = -16;j < 0;++j) k[j] = random();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = random();
|
||||
for (j = clen;j < clen + 16;++j) c[j] = random();
|
||||
for (j = slen;j < slen + 16;++j) s[j] = random();
|
||||
for (j = nlen;j < nlen + 16;++j) n[j] = random();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = random();
|
||||
for (j = -16;j < 0;++j) m[j] = rand();
|
||||
for (j = -16;j < 0;++j) c[j] = rand();
|
||||
for (j = -16;j < 0;++j) s[j] = rand();
|
||||
for (j = -16;j < 0;++j) n[j] = rand();
|
||||
for (j = -16;j < 0;++j) k[j] = rand();
|
||||
for (j = mlen;j < mlen + 16;++j) m[j] = rand();
|
||||
for (j = clen;j < clen + 16;++j) c[j] = rand();
|
||||
for (j = slen;j < slen + 16;++j) s[j] = rand();
|
||||
for (j = nlen;j < nlen + 16;++j) n[j] = rand();
|
||||
for (j = klen;j < klen + 16;++j) k[j] = rand();
|
||||
for (j = -16;j < mlen + 16;++j) m2[j] = m[j];
|
||||
for (j = -16;j < clen + 16;++j) c2[j] = c[j];
|
||||
for (j = -16;j < slen + 16;++j) s2[j] = s[j];
|
||||
|
@ -57,16 +57,16 @@ const char *checksum_compute(void)
|
||||
const char *c;
|
||||
|
||||
for (tests = 0;tests < 100000;++tests) {
|
||||
for (i = 0;i < crypto_verify_BYTES;++i) x[i] = random();
|
||||
for (i = 0;i < crypto_verify_BYTES;++i) y[i] = random();
|
||||
for (i = 0;i < crypto_verify_BYTES;++i) x[i] = rand();
|
||||
for (i = 0;i < crypto_verify_BYTES;++i) y[i] = rand();
|
||||
c = check(); if (c) return c;
|
||||
for (i = 0;i < crypto_verify_BYTES;++i) y[i] = x[i];
|
||||
c = check(); if (c) return c;
|
||||
y[random() % crypto_verify_BYTES] = random();
|
||||
y[rand() % crypto_verify_BYTES] = rand();
|
||||
c = check(); if (c) return c;
|
||||
y[random() % crypto_verify_BYTES] = random();
|
||||
y[rand() % crypto_verify_BYTES] = rand();
|
||||
c = check(); if (c) return c;
|
||||
y[random() % crypto_verify_BYTES] = random();
|
||||
y[rand() % crypto_verify_BYTES] = rand();
|
||||
c = check(); if (c) return c;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user