Remove try.c

These tests are still in git and may be added to the test suite later.
This commit is contained in:
Frank Denis
2014-08-02 15:50:22 -07:00
parent 92b3d09e89
commit 5aee93a277
8 changed files with 0 additions and 929 deletions
-119
View File
@@ -1,119 +0,0 @@
/*
* crypto_auth/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_hash_sha256.h"
#include "crypto_auth.h"
#include "utils.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_auth_IMPLEMENTATION;
#define MAXTEST_BYTES 10000
#define CHECKSUM_BYTES 4096
#define TUNE_BYTES 1536
static unsigned char *h;
static unsigned char *m;
static unsigned char *k;
static unsigned char *h2;
static unsigned char *m2;
static unsigned char *k2;
void preallocate(void)
{
}
void allocate(void)
{
h = alignedcalloc(crypto_auth_BYTES);
m = alignedcalloc(MAXTEST_BYTES);
k = alignedcalloc(crypto_auth_KEYBYTES);
h2 = alignedcalloc(crypto_auth_BYTES);
m2 = alignedcalloc(MAXTEST_BYTES + crypto_auth_BYTES);
k2 = alignedcalloc(crypto_auth_KEYBYTES + crypto_auth_BYTES);
}
void predoit(void)
{
}
void doit(void)
{
crypto_auth(h,m,TUNE_BYTES,k);
crypto_auth_verify(h,m,TUNE_BYTES,k);
}
char checksum[crypto_auth_BYTES * 2 + 1];
const char *checksum_compute(void)
{
long long i;
long long j;
for (i = 0;i < CHECKSUM_BYTES;++i) {
long long mlen = i;
long long klen = crypto_auth_KEYBYTES;
long long hlen = crypto_auth_BYTES;
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];
if (crypto_auth(h,m,mlen,k) != 0) return "crypto_auth returns nonzero";
for (j = -16;j < klen + 16;++j) if (k[j] != k2[j]) return "crypto_auth overwrites k";
for (j = -16;j < mlen + 16;++j) if (m[j] != m2[j]) return "crypto_auth overwrites m";
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] = 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];
if (crypto_auth(m2,m2,mlen,k) != 0) return "crypto_auth returns nonzero";
for (j = 0;j < hlen;++j) if (m2[j] != h[j]) return "crypto_auth does not handle m overlap";
for (j = 0;j < hlen;++j) m2[j] = m[j];
if (crypto_auth(k2,m2,mlen,k2) != 0) return "crypto_auth returns nonzero";
for (j = 0;j < hlen;++j) if (k2[j] != h[j]) return "crypto_auth does not handle k overlap";
for (j = 0;j < hlen;++j) k2[j] = k[j];
if (crypto_auth_verify(h,m,mlen,k) != 0) return "crypto_auth_verify returns nonzero";
for (j = -16;j < hlen + 16;++j) if (h[j] != h2[j]) return "crypto_auth overwrites h";
for (j = -16;j < klen + 16;++j) if (k[j] != k2[j]) return "crypto_auth overwrites k";
for (j = -16;j < mlen + 16;++j) if (m[j] != m2[j]) return "crypto_auth overwrites m";
crypto_hash_sha256(h2,h,hlen);
for (j = 0;j < klen;++j) k[j] ^= h2[j % 32];
if (crypto_auth(h,m,mlen,k) != 0) return "crypto_auth returns nonzero";
if (crypto_auth_verify(h,m,mlen,k) != 0) return "crypto_auth_verify returns nonzero";
crypto_hash_sha256(h2,h,hlen);
for (j = 0;j < mlen;++j) m[j] ^= h2[j % 32];
m[mlen] = h2[0];
}
if (crypto_auth(h,m,CHECKSUM_BYTES,k) != 0) return "crypto_auth returns nonzero";
if (crypto_auth_verify(h,m,CHECKSUM_BYTES,k) != 0) return "crypto_auth_verify returns nonzero";
sodium_bin2hex(checksum, sizeof checksum, h, crypto_auth_BYTES);
return 0;
}
-195
View File
@@ -1,195 +0,0 @@
/*
* crypto_box/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_box.h"
#include "utils.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_box_IMPLEMENTATION;
#define MAXTEST_BYTES 10000
#define CHECKSUM_BYTES 4096
#define TUNE_BYTES 1536
static unsigned char *ska;
static unsigned char *pka;
static unsigned char *skb;
static unsigned char *pkb;
static unsigned char *s;
static unsigned char *n;
static unsigned char *m;
static unsigned char *c;
static unsigned char *t;
static unsigned char *ska2;
static unsigned char *pka2;
static unsigned char *skb2;
static unsigned char *pkb2;
static unsigned char *s2;
static unsigned char *n2;
static unsigned char *m2;
static unsigned char *c2;
static unsigned char *t2;
#define sklen crypto_box_SECRETKEYBYTES
#define pklen crypto_box_PUBLICKEYBYTES
#define nlen crypto_box_NONCEBYTES
#define slen crypto_box_BEFORENMBYTES
void preallocate(void)
{
}
void allocate(void)
{
ska = alignedcalloc(sklen);
pka = alignedcalloc(pklen);
skb = alignedcalloc(sklen);
pkb = alignedcalloc(pklen);
n = alignedcalloc(nlen);
m = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
c = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
t = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
s = alignedcalloc(slen);
ska2 = alignedcalloc(sklen);
pka2 = alignedcalloc(pklen);
skb2 = alignedcalloc(sklen);
pkb2 = alignedcalloc(pklen);
n2 = alignedcalloc(nlen);
m2 = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
c2 = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
t2 = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
s2 = alignedcalloc(slen);
}
void predoit(void)
{
}
void doit(void)
{
crypto_box(c,m,TUNE_BYTES + crypto_box_ZEROBYTES,n,pka,skb);
crypto_box_open(t,c,TUNE_BYTES + crypto_box_ZEROBYTES,n,pkb,ska);
}
char checksum[nlen * 2 + 1];
const char *checksum_compute(void)
{
long long i;
long long j;
if (crypto_box_keypair(pka,ska) != 0) return "crypto_box_keypair returns nonzero";
if (crypto_box_keypair(pkb,skb) != 0) return "crypto_box_keypair returns nonzero";
for (j = 0;j < crypto_box_ZEROBYTES;++j) m[j] = 0;
for (i = 0;i < CHECKSUM_BYTES;++i) {
long long mlen = i + crypto_box_ZEROBYTES;
long long tlen = i + crypto_box_ZEROBYTES;
long long clen = i + crypto_box_ZEROBYTES;
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] = 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];
for (j = -16;j < pklen + 16;++j) pka2[j] = pka[j];
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] = rand();
if (crypto_box(c,m,mlen,n,pkb,ska) != 0) return "crypto_box returns nonzero";
for (j = -16;j < mlen + 16;++j) if (m2[j] != m[j]) return "crypto_box overwrites m";
for (j = -16;j < nlen + 16;++j) if (n2[j] != n[j]) return "crypto_box overwrites n";
for (j = -16;j < 0;++j) if (c2[j] != c[j]) return "crypto_box writes before output";
for (j = clen;j < clen + 16;++j) if (c2[j] != c[j]) return "crypto_box writes after output";
for (j = 0;j < crypto_box_BOXZEROBYTES;++j)
if (c[j] != 0) return "crypto_box does not clear extra bytes";
for (j = -16;j < sklen + 16;++j) if (ska2[j] != ska[j]) return "crypto_box overwrites ska";
for (j = -16;j < sklen + 16;++j) if (skb2[j] != skb[j]) return "crypto_box overwrites skb";
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] = 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] = rand();
if (crypto_box_open(t,c,clen,n,pka,skb) != 0) return "crypto_box_open returns nonzero";
for (j = -16;j < clen + 16;++j) if (c2[j] != c[j]) return "crypto_box_open overwrites c";
for (j = -16;j < nlen + 16;++j) if (n2[j] != n[j]) return "crypto_box_open overwrites n";
for (j = -16;j < 0;++j) if (t2[j] != t[j]) return "crypto_box_open writes before output";
for (j = tlen;j < tlen + 16;++j) if (t2[j] != t[j]) return "crypto_box_open writes after output";
for (j = 0;j < crypto_box_ZEROBYTES;++j)
if (t[j] != 0) return "crypto_box_open does not clear extra bytes";
for (j = -16;j < sklen + 16;++j) if (ska2[j] != ska[j]) return "crypto_box_open overwrites ska";
for (j = -16;j < sklen + 16;++j) if (skb2[j] != skb[j]) return "crypto_box_open overwrites skb";
for (j = -16;j < pklen + 16;++j) if (pka2[j] != pka[j]) return "crypto_box_open overwrites pka";
for (j = -16;j < pklen + 16;++j) if (pkb2[j] != pkb[j]) return "crypto_box_open overwrites pkb";
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] = 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";
for (j = -16;j < 0;++j) if (s2[j] != s[j]) return "crypto_box_beforenm writes before output";
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] = 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";
for (j = -16;j < nlen + 16;++j) if (n2[j] != n[j]) return "crypto_box_afternm overwrites n";
for (j = -16;j < 0;++j) if (t2[j] != t[j]) return "crypto_box_afternm writes before output";
for (j = tlen;j < tlen + 16;++j) if (t2[j] != t[j]) return "crypto_box_afternm writes after output";
for (j = 0;j < crypto_box_BOXZEROBYTES;++j)
if (t[j] != 0) return "crypto_box_afternm does not clear extra bytes";
for (j = 0;j < mlen;++j) if (t[j] != c[j]) return "crypto_box_afternm does not match crypto_box";
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] = 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";
for (j = -16;j < nlen + 16;++j) if (n2[j] != n[j]) return "crypto_box_open_afternm overwrites n";
for (j = -16;j < 0;++j) if (t2[j] != t[j]) return "crypto_box_open_afternm writes before output";
for (j = tlen;j < tlen + 16;++j) if (t2[j] != t[j]) return "crypto_box_open_afternm writes after output";
for (j = 0;j < crypto_box_ZEROBYTES;++j)
if (t[j] != 0) return "crypto_box_open_afternm does not clear extra bytes";
for (j = 0;j < mlen;++j) if (t[j] != m[j]) return "crypto_box_open_afternm does not match crypto_box_open";
for (j = 0;j < i;++j) n[j % nlen] ^= c[j + crypto_box_BOXZEROBYTES];
if (i == 0) m[crypto_box_ZEROBYTES] = 0;
m[i + crypto_box_ZEROBYTES] = m[crypto_box_ZEROBYTES];
for (j = 0;j < i;++j) m[j + crypto_box_ZEROBYTES] ^= c[j + crypto_box_BOXZEROBYTES];
}
sodium_bin2hex(checksum, sizeof checksum, n, nlen);
return 0;
}
-76
View File
@@ -1,76 +0,0 @@
/*
* crypto_hash/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_hash.h"
#include "utils.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_hash_IMPLEMENTATION;
#define MAXTEST_BYTES (10000 + crypto_hash_BYTES)
#define CHECKSUM_BYTES 4096
#define TUNE_BYTES 1536
static unsigned char *h;
static unsigned char *h2;
static unsigned char *m;
static unsigned char *m2;
void preallocate(void)
{
}
void allocate(void)
{
h = alignedcalloc(crypto_hash_BYTES);
h2 = alignedcalloc(crypto_hash_BYTES);
m = alignedcalloc(MAXTEST_BYTES);
m2 = alignedcalloc(MAXTEST_BYTES);
}
void predoit(void)
{
}
void doit(void)
{
crypto_hash(h,m,TUNE_BYTES);
}
char checksum[crypto_hash_BYTES * 2 + 1];
const char *checksum_compute(void)
{
long long i;
long long j;
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] = 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] = 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";
for (j = -16;j < 0;++j) if (h2[j] != h[j]) return "crypto_hash writes before output";
for (j = hlen;j < hlen + 16;++j) if (h2[j] != h[j]) return "crypto_hash writes after output";
if (crypto_hash(m2,m2,mlen) != 0) return "crypto_hash returns nonzero";
for (j = 0;j < hlen;++j) if (m2[j] != h[j]) return "crypto_hash does not handle overlap";
for (j = 0;j < mlen;++j) m[j] ^= h[j % hlen];
m[mlen] = h[0];
}
if (crypto_hash(h,m,CHECKSUM_BYTES) != 0) return "crypto_hash returns nonzero";
sodium_bin2hex(checksum, sizeof checksum, h, crypto_hash_BYTES);
return 0;
}
-125
View File
@@ -1,125 +0,0 @@
/*
* crypto_scalarmult/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_scalarmult.h"
#include "utils.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_scalarmult_IMPLEMENTATION;
#define mlen crypto_scalarmult_SCALARBYTES
#define nlen crypto_scalarmult_SCALARBYTES
#define plen crypto_scalarmult_BYTES
#define qlen crypto_scalarmult_BYTES
#define rlen crypto_scalarmult_BYTES
static unsigned char *m;
static unsigned char *n;
static unsigned char *p;
static unsigned char *q;
static unsigned char *r;
static unsigned char *m2;
static unsigned char *n2;
static unsigned char *p2;
static unsigned char *q2;
static unsigned char *r2;
void preallocate(void)
{
}
void allocate(void)
{
m = alignedcalloc(mlen);
n = alignedcalloc(nlen);
p = alignedcalloc(plen);
q = alignedcalloc(qlen);
r = alignedcalloc(rlen);
m2 = alignedcalloc(mlen + crypto_scalarmult_BYTES);
n2 = alignedcalloc(nlen + crypto_scalarmult_BYTES);
p2 = alignedcalloc(plen + crypto_scalarmult_BYTES);
q2 = alignedcalloc(qlen + crypto_scalarmult_BYTES);
r2 = alignedcalloc(rlen + crypto_scalarmult_BYTES);
}
void predoit(void)
{
}
void doit(void)
{
crypto_scalarmult(q,n,p);
crypto_scalarmult_base(r,n);
}
char checksum[crypto_scalarmult_BYTES * 2 + 1];
const char *checksum_compute(void)
{
long long i;
long long j;
long long tests;
for (i = 0;i < mlen;++i) m[i] = i;
for (i = 0;i < nlen;++i) n[i] = i + 1;
for (i = 0;i < plen;++i) p[i] = i + 2;
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] = 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];
if (crypto_scalarmult_base(p,n) != 0) return "crypto_scalarmult_base returns nonzero";
for (i = -16;i < nlen + 16;++i) if (n2[i] != n[i]) return "crypto_scalarmult_base overwrites input";
for (i = -16;i < 0;++i) if (p2[i] != p[i]) return "crypto_scalarmult_base writes before output";
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] = 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];
if (crypto_scalarmult(q,m,p) != 0) return "crypto_scalarmult returns nonzero";
for (i = -16;i < mlen + 16;++i) if (m2[i] != m[i]) return "crypto_scalarmult overwrites n input";
for (i = -16;i < plen + 16;++i) if (p2[i] != p[i]) return "crypto_scalarmult overwrites p input";
for (i = -16;i < 0;++i) if (q2[i] != q[i]) return "crypto_scalarmult writes before output";
for (i = qlen;i < qlen + 16;++i) if (q2[i] != q[i]) return "crypto_scalarmult writes after output";
if (crypto_scalarmult(m2,m2,p) != 0) return "crypto_scalarmult returns nonzero";
for (i = 0;i < qlen;++i) if (q[i] != m2[i]) return "crypto_scalarmult does not handle n overlap";
for (i = 0;i < qlen;++i) m2[i] = m[i];
if (crypto_scalarmult(p2,m2,p2) != 0) return "crypto_scalarmult returns nonzero";
for (i = 0;i < qlen;++i) if (q[i] != p2[i]) return "crypto_scalarmult does not handle p overlap";
if (crypto_scalarmult(r,n,q) != 0) return "crypto_scalarmult returns nonzero";
if (crypto_scalarmult(q,n,p) != 0) return "crypto_scalarmult returns nonzero";
if (crypto_scalarmult(p,m,q) != 0) return "crypto_scalarmult returns nonzero";
for (j = 0;j < plen;++j) if (p[j] != r[j]) return "crypto_scalarmult not associative";
for (j = 0;j < mlen;++j) m[j] ^= q[j % qlen];
for (j = 0;j < nlen;++j) n[j] ^= p[j % plen];
}
sodium_bin2hex(checksum, sizeof checksum, p, crypto_scalarmult_BYTES);
return 0;
}
-129
View File
@@ -1,129 +0,0 @@
/*
* crypto_secretbox/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_secretbox.h"
#include "utils.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_secretbox_IMPLEMENTATION;
#define MAXTEST_BYTES 10000
#define CHECKSUM_BYTES 4096
#define TUNE_BYTES 1536
static unsigned char *k;
static unsigned char *n;
static unsigned char *m;
static unsigned char *c;
static unsigned char *t;
static unsigned char *k2;
static unsigned char *n2;
static unsigned char *m2;
static unsigned char *c2;
static unsigned char *t2;
#define klen crypto_secretbox_KEYBYTES
#define nlen crypto_secretbox_NONCEBYTES
void preallocate(void)
{
}
void allocate(void)
{
k = alignedcalloc(klen);
n = alignedcalloc(nlen);
m = alignedcalloc(MAXTEST_BYTES + crypto_secretbox_ZEROBYTES);
c = alignedcalloc(MAXTEST_BYTES + crypto_secretbox_ZEROBYTES);
t = alignedcalloc(MAXTEST_BYTES + crypto_secretbox_ZEROBYTES);
k2 = alignedcalloc(klen);
n2 = alignedcalloc(nlen);
m2 = alignedcalloc(MAXTEST_BYTES + crypto_secretbox_ZEROBYTES);
c2 = alignedcalloc(MAXTEST_BYTES + crypto_secretbox_ZEROBYTES);
t2 = alignedcalloc(MAXTEST_BYTES + crypto_secretbox_ZEROBYTES);
}
void predoit(void)
{
}
void doit(void)
{
crypto_secretbox(c,m,TUNE_BYTES + crypto_secretbox_ZEROBYTES,n,k);
crypto_secretbox_open(t,c,TUNE_BYTES + crypto_secretbox_ZEROBYTES,n,k);
}
char checksum[klen * 2 + 1];
const char *checksum_compute(void)
{
long long i;
long long j;
for (j = 0;j < crypto_secretbox_ZEROBYTES;++j) m[j] = 0;
for (i = 0;i < CHECKSUM_BYTES;++i) {
long long mlen = i + crypto_secretbox_ZEROBYTES;
long long tlen = i + crypto_secretbox_ZEROBYTES;
long long clen = i + crypto_secretbox_ZEROBYTES;
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] = rand();
if (crypto_secretbox(c,m,mlen,n,k) != 0) return "crypto_secretbox returns nonzero";
for (j = -16;j < mlen + 16;++j) if (m2[j] != m[j]) return "crypto_secretbox overwrites m";
for (j = -16;j < nlen + 16;++j) if (n2[j] != n[j]) return "crypto_secretbox overwrites n";
for (j = -16;j < klen + 16;++j) if (k2[j] != k[j]) return "crypto_secretbox overwrites k";
for (j = -16;j < 0;++j) if (c2[j] != c[j]) return "crypto_secretbox writes before output";
for (j = clen;j < clen + 16;++j) if (c2[j] != c[j]) return "crypto_secretbox writes after output";
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] = 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] = rand();
if (crypto_secretbox_open(t,c,clen,n,k) != 0) return "crypto_secretbox_open returns nonzero";
for (j = -16;j < clen + 16;++j) if (c2[j] != c[j]) return "crypto_secretbox_open overwrites c";
for (j = -16;j < nlen + 16;++j) if (n2[j] != n[j]) return "crypto_secretbox_open overwrites n";
for (j = -16;j < klen + 16;++j) if (k2[j] != k[j]) return "crypto_secretbox_open overwrites k";
for (j = -16;j < 0;++j) if (t2[j] != t[j]) return "crypto_secretbox_open writes before output";
for (j = tlen;j < tlen + 16;++j) if (t2[j] != t[j]) return "crypto_secretbox_open writes after output";
for (j = 0;j < crypto_secretbox_ZEROBYTES;++j)
if (t[j] != 0) return "crypto_secretbox_open does not clear extra bytes";
for (j = 0;j < i;++j) if (t[j] != m[j]) return "plaintext does not match";
for (j = 0;j < i;++j)
k[j % klen] ^= c[j + crypto_secretbox_BOXZEROBYTES];
crypto_secretbox(c,m,mlen,n,k);
for (j = 0;j < i;++j)
n[j % nlen] ^= c[j + crypto_secretbox_BOXZEROBYTES];
crypto_secretbox(c,m,mlen,n,k);
if (i == 0) m[crypto_secretbox_ZEROBYTES + 0] = 0;
m[crypto_secretbox_ZEROBYTES + i] = m[crypto_secretbox_ZEROBYTES + 0];
for (j = 0;j < i;++j)
m[j + crypto_secretbox_ZEROBYTES] ^= c[j + crypto_secretbox_BOXZEROBYTES];
}
sodium_bin2hex(checksum, sizeof checksum, k, klen);
return 0;
}
-87
View File
@@ -1,87 +0,0 @@
/*
* crypto_sign/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "randombytes.h"
#include "crypto_sign.h"
#include "windows/windows-quirks.h"
#define MAXTEST_BYTES 10000
#define TUNE_BYTES 1536
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_sign_IMPLEMENTATION;
static unsigned char *pk;
static unsigned char *sk;
static unsigned char *m; unsigned long long mlen;
static unsigned char *sm; unsigned long long smlen;
static unsigned char *t; unsigned long long tlen;
void preallocate(void)
{
#ifdef RAND_R_PRNG_NOT_SEEDED
RAND_status();
#endif
}
void allocate(void)
{
pk = alignedcalloc(crypto_sign_PUBLICKEYBYTES);
sk = alignedcalloc(crypto_sign_SECRETKEYBYTES);
m = alignedcalloc(MAXTEST_BYTES + crypto_sign_BYTES);
sm = alignedcalloc(MAXTEST_BYTES + crypto_sign_BYTES);
t = alignedcalloc(MAXTEST_BYTES + crypto_sign_BYTES);
}
void predoit(void)
{
crypto_sign_keypair(pk,sk);
mlen = TUNE_BYTES;
smlen = 0;
randombytes(m,mlen);
crypto_sign(sm,&smlen,m,mlen,sk);
}
void doit(void)
{
crypto_sign_open(t,&tlen,sm,smlen,pk);
}
char checksum[crypto_sign_BYTES * 2 + 1];
const char *checksum_compute(void)
{
long long mlen;
long long i;
long long j;
if (crypto_sign_keypair(pk,sk) != 0) return "crypto_sign_keypair returns nonzero";
for (mlen = 0;mlen < MAXTEST_BYTES;mlen += 1 + (mlen / 16)) {
if (crypto_sign(sm,&smlen,m,mlen,sk) != 0) return "crypto_sign returns nonzero";
if (crypto_sign_open(t,&tlen,sm,smlen,pk) != 0) return "crypto_sign_open returns nonzero";
if (tlen != mlen) return "crypto_sign_open does not match length";
for (i = 0;i < tlen;++i)
if (t[i] != m[i])
return "crypto_sign_open does not match contents";
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";
for (i = 0;i < tlen;++i)
if (t[i] != m[i])
return "crypto_sign_open allows trivial forgery of contents";
}
sm[j] ^= 1;
}
/* do some long-term checksum */
checksum[0] = 0;
return 0;
}
-122
View File
@@ -1,122 +0,0 @@
/*
* crypto_stream/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_stream.h"
#include "utils.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_stream_IMPLEMENTATION;
#define MAXTEST_BYTES 10000
#define CHECKSUM_BYTES 4096
#define TUNE_BYTES 1536
static unsigned char *k;
static unsigned char *n;
static unsigned char *m;
static unsigned char *c;
static unsigned char *s;
static unsigned char *k2;
static unsigned char *n2;
static unsigned char *m2;
static unsigned char *c2;
static unsigned char *s2;
void preallocate(void)
{
}
void allocate(void)
{
k = alignedcalloc(crypto_stream_KEYBYTES);
n = alignedcalloc(crypto_stream_NONCEBYTES);
m = alignedcalloc(MAXTEST_BYTES);
c = alignedcalloc(MAXTEST_BYTES);
s = alignedcalloc(MAXTEST_BYTES);
k2 = alignedcalloc(crypto_stream_KEYBYTES);
n2 = alignedcalloc(crypto_stream_NONCEBYTES);
m2 = alignedcalloc(MAXTEST_BYTES);
c2 = alignedcalloc(MAXTEST_BYTES);
s2 = alignedcalloc(MAXTEST_BYTES);
}
void predoit(void)
{
}
void doit(void)
{
crypto_stream_xor(c,m,TUNE_BYTES,n,k);
}
char checksum[crypto_stream_KEYBYTES * 2 + 1];
const char *checksum_compute(void)
{
long long i;
long long j;
for (i = 0;i < CHECKSUM_BYTES;++i) {
long long mlen = i;
long long clen = i;
long long slen = i;
long long klen = crypto_stream_KEYBYTES;
long long nlen = crypto_stream_NONCEBYTES;
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];
for (j = -16;j < nlen + 16;++j) n2[j] = n[j];
for (j = -16;j < klen + 16;++j) k2[j] = k[j];
crypto_stream_xor(c,m,mlen,n,k);
for (j = -16;j < mlen + 16;++j) if (m[j] != m2[j]) return "crypto_stream_xor overwrites m";
for (j = -16;j < slen + 16;++j) if (s[j] != s2[j]) return "crypto_stream_xor overwrites s";
for (j = -16;j < nlen + 16;++j) if (n[j] != n2[j]) return "crypto_stream_xor overwrites n";
for (j = -16;j < klen + 16;++j) if (k[j] != k2[j]) return "crypto_stream_xor overwrites k";
for (j = -16;j < 0;++j) if (c[j] != c2[j]) return "crypto_stream_xor writes before output";
for (j = clen;j < clen + 16;++j) if (c[j] != c2[j]) return "crypto_stream_xor writes after output";
for (j = -16;j < clen + 16;++j) c2[j] = c[j];
crypto_stream(s,slen,n,k);
for (j = -16;j < mlen + 16;++j) if (m[j] != m2[j]) return "crypto_stream overwrites m";
for (j = -16;j < clen + 16;++j) if (c[j] != c2[j]) return "crypto_stream overwrites c";
for (j = -16;j < nlen + 16;++j) if (n[j] != n2[j]) return "crypto_stream overwrites n";
for (j = -16;j < klen + 16;++j) if (k[j] != k2[j]) return "crypto_stream overwrites k";
for (j = -16;j < 0;++j) if (s[j] != s2[j]) return "crypto_stream writes before output";
for (j = slen;j < slen + 16;++j) if (s[j] != s2[j]) return "crypto_stream writes after output";
for (j = 0;j < mlen;++j)
if ((s[j] ^ m[j]) != c[j]) return "crypto_stream_xor does not match crypto_stream";
for (j = 0;j < clen;++j) k[j % klen] ^= c[j];
crypto_stream_xor(m,c,clen,n,k);
crypto_stream(s,slen,n,k);
for (j = 0;j < mlen;++j)
if ((s[j] ^ m[j]) != c[j]) return "crypto_stream_xor does not match crypto_stream";
for (j = 0;j < mlen;++j) n[j % nlen] ^= m[j];
m[mlen] = 0;
}
sodium_bin2hex(checksum, sizeof checksum, k, crypto_stream_KEYBYTES);
return 0;
}
-76
View File
@@ -1,76 +0,0 @@
/*
* crypto_verify/try.c version 20090118
* D. J. Bernstein
* Public domain.
*/
#include <stdlib.h>
#include "crypto_verify.h"
#include "windows/windows-quirks.h"
extern unsigned char *alignedcalloc(unsigned long long);
const char *primitiveimplementation = crypto_verify_IMPLEMENTATION;
static unsigned char *x;
static unsigned char *y;
void preallocate(void)
{
}
void allocate(void)
{
x = alignedcalloc(crypto_verify_BYTES);
y = alignedcalloc(crypto_verify_BYTES);
}
void predoit(void)
{
}
void doit(void)
{
crypto_verify(x,y);
}
static const char *check(void)
{
int r = crypto_verify(x,y);
if (r == 0) {
if (memcmp(x,y,crypto_verify_BYTES)) return "different strings pass verify";
} else if (r == -1) {
if (!memcmp(x,y,crypto_verify_BYTES)) return "equal strings fail verify";
} else {
return "weird return value from verify";
}
return 0;
}
char checksum[2];
const char *checksum_compute(void)
{
long long tests;
long long i;
long long j;
const char *c;
for (tests = 0;tests < 100000;++tests) {
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[rand() % crypto_verify_BYTES] = rand();
c = check(); if (c) return c;
y[rand() % crypto_verify_BYTES] = rand();
c = check(); if (c) return c;
y[rand() % crypto_verify_BYTES] = rand();
c = check(); if (c) return c;
}
checksum[0] = '0';
checksum[1] = 0;
return 0;
}