libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_verify / try.c
blob06684e781aad64287f40e0c3a2bf02445675dc12
1 /*
2 * crypto_verify/try.c version 20090118
3 * D. J. Bernstein
4 * Public domain.
5 */
7 #include <stdlib.h>
8 #include "crypto_verify.h"
9 #include "windows/windows-quirks.h"
11 extern unsigned char *alignedcalloc(unsigned long long);
13 const char *primitiveimplementation = crypto_verify_IMPLEMENTATION;
15 static unsigned char *x;
16 static unsigned char *y;
18 void preallocate(void)
22 void allocate(void)
24 x = alignedcalloc(crypto_verify_BYTES);
25 y = alignedcalloc(crypto_verify_BYTES);
28 void predoit(void)
32 void doit(void)
34 crypto_verify(x,y);
37 static const char *check(void)
39 int r = crypto_verify(x,y);
40 if (r == 0) {
41 if (memcmp(x,y,crypto_verify_BYTES)) return "different strings pass verify";
42 } else if (r == -1) {
43 if (!memcmp(x,y,crypto_verify_BYTES)) return "equal strings fail verify";
44 } else {
45 return "weird return value from verify";
47 return 0;
50 char checksum[2];
52 const char *checksum_compute(void)
54 long long tests;
55 long long i;
56 long long j;
57 const char *c;
59 for (tests = 0;tests < 100000;++tests) {
60 for (i = 0;i < crypto_verify_BYTES;++i) x[i] = rand();
61 for (i = 0;i < crypto_verify_BYTES;++i) y[i] = rand();
62 c = check(); if (c) return c;
63 for (i = 0;i < crypto_verify_BYTES;++i) y[i] = x[i];
64 c = check(); if (c) return c;
65 y[rand() % crypto_verify_BYTES] = rand();
66 c = check(); if (c) return c;
67 y[rand() % crypto_verify_BYTES] = rand();
68 c = check(); if (c) return c;
69 y[rand() % crypto_verify_BYTES] = rand();
70 c = check(); if (c) return c;
73 checksum[0] = '0';
74 checksum[1] = 0;
75 return 0;