|
| 1 | +/* |
| 2 | + * |
| 3 | + * main.cpp |
| 4 | + * Purpose of review and rewrite is optimization. (https://github.com/BaseMax/) |
| 5 | + * Copyright (c) 2017, SUMOKOIN |
| 6 | + * |
| 7 | + */ |
| 8 | +#include <iostream> |
| 9 | +#include <string.h> |
| 10 | +#include "pow_hash/cn_slow_hash.hpp" |
| 11 | + |
| 12 | +extern "C" void blake256_hash(uint8_t*, const uint8_t*); |
| 13 | +extern "C" void groestl(const unsigned char*, unsigned char*); |
| 14 | +extern "C" void jh_hash(const unsigned char*, unsigned char*); |
| 15 | +extern "C" void skein_hash(const unsigned char*,unsigned char*); |
| 16 | + |
| 17 | +int main(int argc, char **argv) |
| 18 | +{ |
| 19 | + uint8_t hash[32]; |
| 20 | + const uint8_t correct1[32] = { 0xeb, 0x14, 0xe8, 0xa8, 0x33, 0xfa, 0xc6, 0xfe, 0x9a, 0x43, 0xb5, 0x7b, 0x33, 0x67, 0x89, 0xc4, |
| 21 | + 0x6f, 0xfe, 0x93, 0xf2, 0x86, 0x84, 0x52, 0x24, 0x07, 0x20, 0x60, 0x7b, 0x14, 0x38, 0x7e, 0x11}; |
| 22 | + const uint8_t correct2[32] = { 0x80, 0x47, 0x42, 0xcb, 0x8f, 0x59, 0xd8, 0x44, 0x6b, 0xc3, 0xc7, 0xc4, 0x39, 0x51, 0x4e, 0xc1, |
| 23 | + 0xb8, 0xff, 0xce, 0x73, 0x4e, 0xc1, 0x43, 0xcc, 0x28, 0xa6, 0x83, 0x50, 0x75, 0xdc, 0x21, 0xcd }; |
| 24 | + cn_pow_hash_v2 v2; |
| 25 | + v2.hash("", 0, hash); |
| 26 | + if(memcmp(hash, correct2, 32) == 0) |
| 27 | + printf("Hash B verified!\n"); |
| 28 | + else |
| 29 | + printf("Hash B FAILED!\n"); |
| 30 | + for(size_t i=0; i < 3; i++) |
| 31 | + { |
| 32 | + cn_pow_hash_v1 v1 = cn_pow_hash_v1::make_borrowed(v2); |
| 33 | + v1.hash("", 0, hash); |
| 34 | + if(memcmp(hash, correct1, 32) == 0) |
| 35 | + printf("Hash A verified!\n"); |
| 36 | + else |
| 37 | + printf("Hash A FAILED!\n"); |
| 38 | + } |
| 39 | + v2.hash("", 0, hash); |
| 40 | + if(memcmp(hash, correct2, 32) == 0) |
| 41 | + printf("Hash B verified!\n"); |
| 42 | + else |
| 43 | + printf("Hash B FAILED!\n"); |
| 44 | + uint8_t msg[200]; |
| 45 | + for(uint8_t i=0; i < 200; i++) |
| 46 | + msg[i] = i; |
| 47 | + blake256_hash(hash, msg); |
| 48 | + if(memcmp(hash, "\xc4\xd9\x44\xc2\xb1\xc0\x0a\x8e\xe6\x27\x72\x6b\x35\xd4\xcd\x7f\xe0\x18\xde\x09\x0b\xc6\x37\x55\x3c\xc7\x82\xe2\x5f\x97\x4c\xba", 32) == 0) |
| 49 | + printf("blake256_hash verified!\n"); |
| 50 | + else |
| 51 | + printf("blake256_hash FAILED!\n"); |
| 52 | + groestl(msg,hash); |
| 53 | + if(memcmp(hash, "\x5e\x48\x74\x94\x12\x76\xba\xcd\x43\xcf\x9f\x50\x78\xa5\xd6\x20\x14\x3b\x0b\x10\x5f\x63\x3f\x44\xd6\x5e\xd1\x3d\x27\xf6\xa8\x49", 32) == 0) |
| 54 | + printf("groestl verified!\n"); |
| 55 | + else |
| 56 | + printf("groestl FAILED!\n"); |
| 57 | + |
| 58 | + jh_hash(msg,hash); |
| 59 | + if(memcmp(hash, "\x4a\xe8\xdb\xb5\xad\x87\x64\x0f\xf6\x6f\x12\x53\x80\xd2\x5d\x3c\x69\x14\x64\xd9\x69\x0e\xaa\x2d\xf5\x77\xe5\xfe\x11\xc7\xb7\x6b", 32) == 0) |
| 60 | + printf("jh_hash verified!\n"); |
| 61 | + else |
| 62 | + printf("jh_hash FAILED!\n"); |
| 63 | + skein_hash(msg,hash); |
| 64 | + if(memcmp(hash, "\x44\x69\x61\x76\x82\xc7\x66\x62\x7a\xa0\x83\x84\xcb\x41\x50\x2a\x02\x88\xc7\x11\xa6\xcc\x15\xc1\xa5\xf8\x01\x63\x10\xe5\xb5\x52", 32) == 0) |
| 65 | + printf("skein_hash verified!\n"); |
| 66 | + else |
| 67 | + printf("skein_hash FAILED!\n"); |
| 68 | + return 0; |
| 69 | +} |
0 commit comments