| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <stdint.h> |
| 30 |
#include <stddef.h> |
| 31 |
#include <stdio.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <string.h> |
| 34 |
#include <errno.h> |
| 35 |
#include "crypto/hash-ops.h" |
| 36 |
|
| 37 |
extern volatile int use_v4_jit_flag; |
| 38 |
|
| 39 |
static int test(const uint8_t *data, size_t len, uint64_t height) |
| 40 |
{ |
| 41 |
char hash0[32], hash1[32]; |
| 42 |
use_v4_jit_flag = 0; |
| 43 |
cn_slow_hash(data, len, hash0, 4, 0, height); |
| 44 |
use_v4_jit_flag = 1; |
| 45 |
cn_slow_hash(data, len, hash1, 4, 0, height); |
| 46 |
return memcmp(hash0, hash1, 32); |
| 47 |
} |
| 48 |
|
| 49 |
int main(int argc, char **argv) |
| 50 |
{ |
| 51 |
uint8_t data[64]; |
| 52 |
uint64_t start_height = 1788000; |
| 53 |
uint64_t end_height = 1788001; |
| 54 |
|
| 55 |
if (argc != 1 && argc != 2 && argc != 3) |
| 56 |
{ |
| 57 |
fprintf(stderr, "usage: %s [<start_height> [<end_height>]]\n", argv[0]); |
| 58 |
return 1; |
| 59 |
} |
| 60 |
if (argc > 1) |
| 61 |
{ |
| 62 |
errno = 0; |
| 63 |
start_height = strtoull(argv[1], NULL, 10); |
| 64 |
if ((start_height == 0 && errno) || start_height == ULLONG_MAX) |
| 65 |
{ |
| 66 |
fprintf(stderr, "invalid start_height\n"); |
| 67 |
return 1; |
| 68 |
} |
| 69 |
end_height = start_height; |
| 70 |
if (argc > 2) |
| 71 |
{ |
| 72 |
errno = 0; |
| 73 |
end_height = strtoull(argv[2], NULL, 10); |
| 74 |
if ((end_height == 0 && errno) || end_height == ULLONG_MAX) |
| 75 |
{ |
| 76 |
fprintf(stderr, "invalid end_height\n"); |
| 77 |
return 1; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
if (start_height == end_height) |
| 83 |
{ |
| 84 |
uint64_t counter = 0; |
| 85 |
while (1) |
| 86 |
{ |
| 87 |
printf("\r%llu", (unsigned long long)counter); |
| 88 |
fflush(stdout); |
| 89 |
size_t offset = 0; |
| 90 |
while (offset + 8 < sizeof(data)) |
| 91 |
{ |
| 92 |
memcpy(data + offset, &counter, sizeof(counter)); |
| 93 |
offset += 8; |
| 94 |
} |
| 95 |
if (test(data, sizeof(data), start_height)) |
| 96 |
{ |
| 97 |
fprintf(stderr, "\nFailure at height %llu, counter %llu\n", (unsigned long long)start_height, (unsigned long long)counter); |
| 98 |
return 0; |
| 99 |
} |
| 100 |
++counter; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
memset(data, 0x42, sizeof(data)); |
| 105 |
for (uint64_t h = start_height; h < end_height; ++h) |
| 106 |
{ |
| 107 |
printf("\r%llu/%llu", (unsigned long long)(h-start_height), (unsigned long long)(end_height-start_height)); |
| 108 |
fflush(stdout); |
| 109 |
if (test(data, sizeof(data), h)) |
| 110 |
{ |
| 111 |
fprintf(stderr, "\nFailure at height %llu\n", (unsigned long long)h); |
| 112 |
return 0; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
printf("\r"); |
| 117 |
|
| 118 |
return 0; |
| 119 |
} |