|
| 1 | +#include <stdint.h> |
| 2 | +#include <stdio.h> |
| 3 | +#include <assert.h> |
| 4 | +#include <sys/time.h> |
| 5 | + |
| 6 | +#ifndef sha256 |
| 7 | +#define sha256 sha256_avx |
| 8 | +#endif |
| 9 | + |
| 10 | +void sha256(void *input_data, uint32_t digest[8], uint32_t num_blks); |
| 11 | +int main(int argc, char *argv[]) { |
| 12 | + static const uint32_t ostate[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; |
| 13 | + uint32_t state[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; |
| 14 | + uint8_t block[64] = "AnatolyYakovenko11/2/201712pmPSTAnatolyYakovenko11/2/201712pmPST"; |
| 15 | + uint32_t *blkptr = (void*)block; |
| 16 | + uint64_t i=0; |
| 17 | + FILE *f = fopen(argv[1], "a+"); |
| 18 | + struct timeval start, now; |
| 19 | + if(!fseek(f, -40, SEEK_END)) { |
| 20 | + assert(8 == fread(&i, 1, 8, f)); |
| 21 | + i = i<<20; |
| 22 | + assert(32 == fread(blkptr, 1, 32, f)); |
| 23 | + blkptr[8] = blkptr[0]; |
| 24 | + blkptr[9] = blkptr[1]; |
| 25 | + blkptr[10] = blkptr[2]; |
| 26 | + blkptr[11] = blkptr[3]; |
| 27 | + blkptr[12] = blkptr[4]; |
| 28 | + blkptr[13] = blkptr[5]; |
| 29 | + blkptr[14] = blkptr[6]; |
| 30 | + blkptr[15] = blkptr[7]; |
| 31 | + assert(0 == fseek(f, 0, SEEK_END)); |
| 32 | + } |
| 33 | + printf("block %04x%04x%04x%04x\n", blkptr[0], blkptr[1], blkptr[2], blkptr[3]); |
| 34 | + printf(" %04x%04x%04x%04x\n", blkptr[4], blkptr[5], blkptr[6], blkptr[7]); |
| 35 | + printf(" %04x%04x%04x%04x\n", blkptr[8], blkptr[9], blkptr[10], blkptr[11]); |
| 36 | + printf(" %04x%04x%04x%04x\n", blkptr[12], blkptr[13], blkptr[14], blkptr[15]); |
| 37 | + printf("state %04x%04x%04x%04x\n", state[0], state[1], state[2], state[3]); |
| 38 | + printf(" %04x%04x%04x%04x\n", state[4], state[5], state[6], state[7]); |
| 39 | + assert(!gettimeofday(&start, 0)); |
| 40 | + for(i; ;++i) { |
| 41 | + if(__builtin_expect((i & 0xfffff) == 0, 0)) { |
| 42 | + double total; |
| 43 | + uint64_t ix = i >> 20; |
| 44 | + assert(!gettimeofday(&now, 0)); |
| 45 | + total = now.tv_usec + (double)now.tv_sec * 1000000 ; |
| 46 | + total = total - (start.tv_usec + (double)start.tv_sec * 1000000); |
| 47 | + fwrite(&ix, 8, 1, f); |
| 48 | + fwrite(blkptr, 4, 8, f); |
| 49 | + fflush(f); |
| 50 | + printf("block %04x%04x%04x%04x\n", blkptr[0], blkptr[1], blkptr[2], blkptr[3]); |
| 51 | + printf(" %04x%04x%04x%04x\n", blkptr[4], blkptr[5], blkptr[6], blkptr[7]); |
| 52 | + printf(" %04x%04x%04x%04x\n", blkptr[8], blkptr[9], blkptr[10], blkptr[11]); |
| 53 | + printf(" %04x%04x%04x%04x\n", blkptr[12], blkptr[13], blkptr[14], blkptr[15]); |
| 54 | + printf("speed %lu %G %G\n", i, total, i/total); |
| 55 | + } |
| 56 | + sha256(block, state, 1); |
| 57 | + blkptr[0] = state[0]; |
| 58 | + blkptr[1] = state[1]; |
| 59 | + blkptr[2] = state[2]; |
| 60 | + blkptr[3] = state[3]; |
| 61 | + blkptr[4] = state[4]; |
| 62 | + blkptr[5] = state[5]; |
| 63 | + blkptr[6] = state[6]; |
| 64 | + blkptr[7] = state[7]; |
| 65 | + blkptr[8] = state[0]; |
| 66 | + blkptr[9] = state[1]; |
| 67 | + blkptr[10] = state[2]; |
| 68 | + blkptr[11] = state[3]; |
| 69 | + blkptr[12] = state[4]; |
| 70 | + blkptr[13] = state[5]; |
| 71 | + blkptr[14] = state[6]; |
| 72 | + blkptr[15] = state[7]; |
| 73 | + |
| 74 | + state[0] = ostate[0]; |
| 75 | + state[1] = ostate[1]; |
| 76 | + state[2] = ostate[2]; |
| 77 | + state[3] = ostate[3]; |
| 78 | + state[4] = ostate[4]; |
| 79 | + state[5] = ostate[5]; |
| 80 | + state[6] = ostate[6]; |
| 81 | + state[7] = ostate[7]; |
| 82 | + |
| 83 | + } |
| 84 | +} |
| 85 | + |
0 commit comments