|
| 1 | +#include "evohash.h" |
| 2 | +#include <stdlib.h> |
| 3 | +#include <stdint.h> |
| 4 | +#include <string.h> |
| 5 | +#include <stdio.h> |
| 6 | + |
| 7 | +#include "sha3/sph_groestl.h" |
| 8 | +#include "sha3/sph_keccak.h" |
| 9 | +#include "sha3/sph_jh.h" |
| 10 | +#include "sha3/sph_bmw.h" |
| 11 | +#include "sha3/sph_skein.h" |
| 12 | +#include "sha3/sph_cubehash.h" |
| 13 | +#include "sha3/sph_luffa.h" |
| 14 | +#include "sha3/sph_shavite.h" |
| 15 | +#include "sha3/sph_simd.h" |
| 16 | +#include "sha3/sph_echo.h" |
| 17 | +#include "sha3/sph_hamsi.h" |
| 18 | +#include "sha3/sph_fugue.h" |
| 19 | +#include "sha3/sph_whirlpool.h" |
| 20 | +#include "sha3/sph_shabal.h" |
| 21 | +#include "Lyra2.h" |
| 22 | + |
| 23 | +#define _ALIGN(x) __attribute__ ((aligned(x))) |
| 24 | + |
| 25 | +void evohash_hash(const char* input, char* output, uint32_t len) |
| 26 | +{ |
| 27 | + sph_groestl512_context ctx_groestl; |
| 28 | + sph_keccak512_context ctx_keccak; |
| 29 | + sph_cubehash512_context ctx_cubehash; |
| 30 | + sph_luffa512_context ctx_luffa; |
| 31 | + sph_echo512_context ctx_echo; |
| 32 | + sph_simd512_context ctx_simd; |
| 33 | + sph_shavite512_context ctx_shavite; |
| 34 | + sph_hamsi512_context ctx_hamsi; |
| 35 | + sph_fugue512_context ctx_fugue; |
| 36 | + sph_whirlpool_context ctx_whirlpool; |
| 37 | + sph_skein512_context ctx_skein; |
| 38 | + sph_shabal512_context ctx_shabal; |
| 39 | + sph_bmw512_context ctx_bmw; |
| 40 | + sph_jh512_context ctx_jh; |
| 41 | + |
| 42 | + unsigned char hash[128] = { 0 }; |
| 43 | + unsigned char hashA[64] = { 0 }; |
| 44 | + unsigned char hashB[64] = { 0 }; |
| 45 | + |
| 46 | + sph_cubehash512_init(&ctx_cubehash); |
| 47 | + sph_cubehash512(&ctx_cubehash, input, len); |
| 48 | + sph_cubehash512_close(&ctx_cubehash, (void*)hash); |
| 49 | + |
| 50 | + sph_bmw512_init(&ctx_bmw); |
| 51 | + sph_bmw512(&ctx_bmw, (const void*) hash, 64); |
| 52 | + sph_bmw512_close(&ctx_bmw, hashB); |
| 53 | + |
| 54 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 55 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 56 | + |
| 57 | + sph_groestl512_init(&ctx_groestl); |
| 58 | + sph_groestl512 (&ctx_groestl, hashA, 64); |
| 59 | + sph_groestl512_close(&ctx_groestl, hash); |
| 60 | + |
| 61 | + sph_hamsi512_init(&ctx_hamsi); |
| 62 | + sph_hamsi512(&ctx_hamsi, (const void*) hash, 64); |
| 63 | + sph_hamsi512_close(&ctx_hamsi, hashB); |
| 64 | + |
| 65 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 66 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 67 | + //print_hash("lyra2re_2", hashA, 32); |
| 68 | + //printf("Hashing complete.\n"); |
| 69 | + |
| 70 | + sph_fugue512_init(&ctx_fugue); |
| 71 | + sph_fugue512(&ctx_fugue, (const void*) hashA, 64); |
| 72 | + sph_fugue512_close(&ctx_fugue, hash); |
| 73 | + //print_hash("fugue512", hash, 16); |
| 74 | + //printf("Hashing complete.\n"); |
| 75 | + |
| 76 | + sph_simd512_init(&ctx_simd); |
| 77 | + sph_simd512(&ctx_simd, (const void*) hash, 64); |
| 78 | + sph_simd512_close(&ctx_simd, hashB); |
| 79 | + //print_hash("simd512", hashB, 16); |
| 80 | + //printf("Hashing complete.\n"); |
| 81 | + |
| 82 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 83 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 84 | + //print_hash("lyra2re_3", hashA, 32); |
| 85 | + //printf("Hashing complete.\n"); |
| 86 | + |
| 87 | + sph_echo512_init(&ctx_echo); |
| 88 | + sph_echo512(&ctx_echo, (const void*) hashA, 64); |
| 89 | + sph_echo512_close(&ctx_echo, hash); |
| 90 | + //print_hash("echo512", hash, 16); |
| 91 | + //printf("Hashing complete.\n"); |
| 92 | + |
| 93 | + sph_cubehash512_init(&ctx_cubehash); |
| 94 | + sph_cubehash512(&ctx_cubehash, (const void*) hash, 64); |
| 95 | + sph_cubehash512_close(&ctx_cubehash, hashB); |
| 96 | + //print_hash("cubehash512_2", hashB, 16); |
| 97 | + //printf("Hashing complete.\n"); |
| 98 | + |
| 99 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 100 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 101 | + //print_hash("lyra2re_4", hashA, 32); |
| 102 | + //printf("Hashing complete.\n"); |
| 103 | + |
| 104 | + sph_shavite512_init(&ctx_shavite); |
| 105 | + sph_shavite512(&ctx_shavite, (const void*) hashA, 64); |
| 106 | + sph_shavite512_close(&ctx_shavite, hash); |
| 107 | + //print_hash("shavite512_1", hash, 16); |
| 108 | + //printf("Hashing complete.\n"); |
| 109 | + |
| 110 | + sph_luffa512_init(&ctx_luffa); |
| 111 | + sph_luffa512(&ctx_luffa, (const void*) hash, 64); |
| 112 | + sph_luffa512_close (&ctx_luffa, hashB); |
| 113 | + //print_hash("luffa512_1", hashB, 16); |
| 114 | + //printf("Hashing complete.\n"); |
| 115 | + |
| 116 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 117 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 118 | + //print_hash("lyra2re_5", hashA, 32); |
| 119 | + //printf("Hashing complete.\n"); |
| 120 | + |
| 121 | + sph_shavite512_init(&ctx_shavite); |
| 122 | + sph_shavite512(&ctx_shavite, (const void*) hashA, 64); |
| 123 | + sph_shavite512_close(&ctx_shavite, hash); |
| 124 | + //print_hash("shavite512_2", hash, 16); |
| 125 | + //printf("Hashing complete.\n"); |
| 126 | + |
| 127 | + sph_luffa512_init(&ctx_luffa); |
| 128 | + sph_luffa512(&ctx_luffa, (const void*) hash, 64); |
| 129 | + sph_luffa512_close (&ctx_luffa, hashB); |
| 130 | + //print_hash("luffa512_2", hashB, 16); |
| 131 | + //printf("Hashing complete.\n"); |
| 132 | + |
| 133 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 134 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 135 | + //print_hash("lyra2re_6", hashA, 32); |
| 136 | + //printf("Hashing complete.\n"); |
| 137 | + |
| 138 | + sph_whirlpool_init(&ctx_whirlpool); |
| 139 | + sph_whirlpool (&ctx_whirlpool, (const void*) hashA, 64); |
| 140 | + sph_whirlpool_close(&ctx_whirlpool, hash); |
| 141 | + //print_hash("whirlpool", hash, 16); |
| 142 | + //printf("Hashing complete.\n"); |
| 143 | + |
| 144 | + sph_shabal512_init(&ctx_shabal); |
| 145 | + sph_shabal512(&ctx_shabal, (const void*) hash, 64); |
| 146 | + sph_shabal512_close(&ctx_shabal, hashB); |
| 147 | + //print_hash("shabal512", hashB, 16); |
| 148 | + //printf("Hashing complete.\n"); |
| 149 | + |
| 150 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 151 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 152 | + //print_hash("lyra2re_7", hashA, 32); |
| 153 | + //printf("Hashing complete.\n"); |
| 154 | + |
| 155 | + sph_jh512_init(&ctx_jh); |
| 156 | + sph_jh512(&ctx_jh, (const void*) hashA, 64); |
| 157 | + sph_jh512_close(&ctx_jh, hash); |
| 158 | + //print_hash("jh512", hash, 16); |
| 159 | + //printf("Hashing complete.\n"); |
| 160 | + |
| 161 | + sph_keccak512_init(&ctx_keccak); |
| 162 | + sph_keccak512 (&ctx_keccak, hash, 64); |
| 163 | + sph_keccak512_close(&ctx_keccak, hashB); |
| 164 | + //print_hash("keccak512", hashB, 16); |
| 165 | + //printf("Hashing complete.\n"); |
| 166 | + |
| 167 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 168 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 169 | + //print_hash("lyra2re_8", hashA, 32); |
| 170 | + //printf("Hashing complete.\n"); |
| 171 | + |
| 172 | + sph_skein512_init(&ctx_skein); |
| 173 | + sph_skein512(&ctx_skein, (const void*)hashA, 64); |
| 174 | + sph_skein512_close(&ctx_skein, (void*)hash); |
| 175 | + //print_hash("skein512", hash, 16); |
| 176 | + //printf("Hashing complete.\n"); |
| 177 | + |
| 178 | + for (int i=0; i<32; i++) |
| 179 | + hash[i] ^= hash[i+32]; |
| 180 | + |
| 181 | + memcpy(output, hash, 32); |
| 182 | + //printf("Hashing complete.\n"); |
| 183 | + //getchar(); |
| 184 | +} |
0 commit comments