summaryrefslogtreecommitdiff
path: root/src/libsodium/crypto_sign/try.c
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2014-08-11 14:04:41 -0400
committerMicah Anderson <micah@riseup.net>2014-08-11 14:04:41 -0400
commit94cc35faeb6248d75841a5f47a41a266086b4d16 (patch)
treeadef88a73becc807b0485ddf1b7670865b8e680f /src/libsodium/crypto_sign/try.c
parent2e59f9740a29439df7c7a56cf0ae83dec3081d31 (diff)
initial import of upstream sourcesupstream/latestupstream/0.6.1
Diffstat (limited to 'src/libsodium/crypto_sign/try.c')
-rw-r--r--src/libsodium/crypto_sign/try.c87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/libsodium/crypto_sign/try.c b/src/libsodium/crypto_sign/try.c
deleted file mode 100644
index 8ea81b6..0000000
--- a/src/libsodium/crypto_sign/try.c
+++ /dev/null
@@ -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;
-}