#include"auxFormat.h" #define PRH_ROUNDS 140 #define hash_RATE (64 / 8) unsigned char constant8Format_hash[140] = { /*constant8_hash_512*/ 0x01, 0x04, 0x10, 0x40, 0x03, 0x0d, 0x35, 0xd4, 0x52, 0x4a, 0x2b, 0xac, 0xb0, 0xc1, 0x06, 0x19, 0x65, 0x97, 0x5c, 0x72, 0xca, 0x2a, 0xa8, 0xa0, 0x81, 0x05, 0x14, 0x50, 0x43, 0x0e, 0x38, 0xe1, 0x86, 0x18, 0x61, 0x87, 0x1c, 0x71, 0xc7, 0x1f, 0x7c, 0xf2, 0xcb, 0x2e, 0xb8, 0xe0, 0x82, 0x08, 0x21, 0x84, 0x11, 0x44, 0x13, 0x4d, 0x36, 0xd9, 0x67, 0x9e, 0x79, 0xe6, 0x9b, 0x6d, 0xb6, 0xd8, 0x63, 0x8e, 0x39, 0xe5, 0x96, 0x58, 0x62, 0x8a, 0x29, 0xa5, 0x95, 0x55, 0x57, 0x5e, 0x7b, 0xef, 0xbe, 0xf9, 0xe7, 0x9f, 0x7d, 0xf6, 0xdb, 0x6e, 0xbb, 0xed, 0xb7, 0xdc, 0x73, 0xce, 0x3a, 0xe8, 0xa3, 0x8c, 0x30, 0xc0, 0x02, 0x09, 0x25, 0x94, 0x51, 0x47, 0x1e, 0x78, 0xe2, 0x8b, 0x2d, 0xb5, 0xd5, 0x56, 0x5a, 0x6b, 0xaf, 0xbd, 0xf4, 0xd2, 0x4b, 0x2f, 0xbc, 0xf0, 0xc2, 0x0b, 0x2c, 0xb1, 0xc5, 0x16, 0x59, 0x66, 0x9a, 0x69, 0xa6, 0x98, 0x60, 0x83, 0x0c, 0x31, }; #define Processing_Data(data) \ do { \ packU64FormatToFourPacket(dataFormat, data);\ s[0] ^= dataFormat[0];\ s[1] ^= dataFormat[1];\ s[2] ^= dataFormat[2];\ s[3] ^= dataFormat[3];\ } while (0) #define ABSORB(inlen,in) \ do { \ } while (0) //sequeez #define SEQUEEZ() \ {\ unpackU128FormatToFourPacket(out, s); \ unpackU128FormatToFourPacket((out + 16), (s + 4)); \ for (i = 0; i < PRH_ROUNDS; i++) { \ ROUND512(i); \ } \ out += CRYPTO_BYTES / 2; \ unpackU128FormatToFourPacket(out, s); \ unpackU128FormatToFourPacket((out + 16),( s + 4)); \ } while (0) int crypto_hash(unsigned char *out, const unsigned char *in, unsigned long long inlen) { //r=64 u8 i; u32 dataFormat[4] = { 0 }; u32 t1, t2, t3, t8, t9, t5, t6, t11; // initialization u32 s[16] = { 0 }; u8 tempData[32]; u32 s_temp[16] = { 0 }; //absorb while (inlen >= hash_RATE) { Processing_Data(in); for (i = 0; i < PRH_ROUNDS; i++) { ROUND512(i); } inlen -= hash_RATE; in += hash_RATE; } memset(tempData, 0, sizeof(tempData)); memcpy(tempData, in, inlen * sizeof(unsigned char)); tempData[inlen] = 0x01; Processing_Data(tempData); for (i = 0; i < PRH_ROUNDS; i++) { ROUND512(i); } //sequeez unpackU128FormatToFourPacket(out, s); unpackU128FormatToFourPacket((out + 16), (s + 4)); for (i = 0; i < PRH_ROUNDS; i++) { ROUND512(i); } out += CRYPTO_BYTES / 2; unpackU128FormatToFourPacket(out, s); unpackU128FormatToFourPacket((out + 16), (s + 4)); return 0; }