|
| 1 | +#include <stdlib.h> |
| 2 | +#include <stdint.h> |
| 3 | +#include <string.h> |
| 4 | +#include <stdio.h> |
| 5 | + |
| 6 | +#include "sha3/sph_cubehash.h" |
| 7 | +#include "sha3/sph_jh.h" |
| 8 | +#include "sha3/sph_echo.h" |
| 9 | +#include "sha3/sph_skein.h" |
| 10 | + |
| 11 | +#include "sha3/gost_streebog.h" |
| 12 | + |
| 13 | +#include "Lyra2.h" |
| 14 | + |
| 15 | +#define _ALIGN(x) __attribute__ ((aligned(x))) |
| 16 | + |
| 17 | +void phi2_hash(const char* input, char* output, uint32_t len) |
| 18 | +{ |
| 19 | + unsigned char _ALIGN(128) hash[64]; |
| 20 | + unsigned char _ALIGN(128) hashA[64]; |
| 21 | + unsigned char _ALIGN(128) hashB[64]; |
| 22 | + |
| 23 | + sph_cubehash512_context ctx_cubehash; |
| 24 | + sph_jh512_context ctx_jh; |
| 25 | + sph_gost512_context ctx_gost; |
| 26 | + sph_echo512_context ctx_echo; |
| 27 | + sph_skein512_context ctx_skein; |
| 28 | + |
| 29 | + sph_cubehash512_init(&ctx_cubehash); |
| 30 | + sph_cubehash512(&ctx_cubehash, input, len); |
| 31 | + sph_cubehash512_close(&ctx_cubehash, (void*)hashB); |
| 32 | + |
| 33 | + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); |
| 34 | + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); |
| 35 | + |
| 36 | + sph_jh512_init(&ctx_jh); |
| 37 | + sph_jh512(&ctx_jh, (const void*)hashA, 64); |
| 38 | + sph_jh512_close(&ctx_jh, (void*)hash); |
| 39 | + |
| 40 | + if (hash[0] & 1) { |
| 41 | + sph_gost512_init(&ctx_gost); |
| 42 | + sph_gost512(&ctx_gost, (const void*)hash, 64); |
| 43 | + sph_gost512_close(&ctx_gost, (void*)hash); |
| 44 | + } else { |
| 45 | + sph_echo512_init(&ctx_echo); |
| 46 | + sph_echo512(&ctx_echo, (const void*)hash, 64); |
| 47 | + sph_echo512_close(&ctx_echo, (void*)hash); |
| 48 | + |
| 49 | + sph_echo512_init(&ctx_echo); |
| 50 | + sph_echo512(&ctx_echo, (const void*)hash, 64); |
| 51 | + sph_echo512_close(&ctx_echo, (void*)hash); |
| 52 | + } |
| 53 | + |
| 54 | + sph_skein512_init(&ctx_skein); |
| 55 | + sph_skein512(&ctx_skein, (const void*)hash, 64); |
| 56 | + sph_skein512_close(&ctx_skein, (void*)hash); |
| 57 | + |
| 58 | + for (int i=0; i<32; i++) |
| 59 | + hash[i] ^= hash[i+32]; |
| 60 | + |
| 61 | + memcpy(output, hash, 32); |
| 62 | +} |
0 commit comments