-
Notifications
You must be signed in to change notification settings - Fork 3
/
haraka_portable.h
84 lines (64 loc) · 2.52 KB
/
haraka_portable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef SPX_HARAKA_H
#define SPX_HARAKA_H
#include "immintrin.h"
#define NUMROUNDS 5
#ifdef _WIN32
typedef unsigned long long u64;
#else
typedef unsigned long u64;
#endif
typedef __m128i u128;
extern void aesenc(unsigned char *s, const unsigned char *rk);
#define AES2_EMU(s0, s1, rci) \
aesenc((unsigned char *)&s0, (unsigned char *)&(rc[rci])); \
aesenc((unsigned char *)&s1, (unsigned char *)&(rc[rci + 1])); \
aesenc((unsigned char *)&s0, (unsigned char *)&(rc[rci + 2])); \
aesenc((unsigned char *)&s1, (unsigned char *)&(rc[rci + 3]));
typedef unsigned int uint32_t;
static inline __m128i _mm_unpacklo_epi32_emu(__m128i a, __m128i b)
{
uint32_t result[4];
uint32_t *tmp1 = (uint32_t *)&a, *tmp2 = (uint32_t *)&b;
result[0] = tmp1[0];
result[1] = tmp2[0];
result[2] = tmp1[1];
result[3] = tmp2[1];
return *(__m128i *)result;
}
static inline __m128i _mm_unpackhi_epi32_emu(__m128i a, __m128i b)
{
uint32_t result[4];
uint32_t *tmp1 = (uint32_t *)&a, *tmp2 = (uint32_t *)&b;
result[0] = tmp1[2];
result[1] = tmp2[2];
result[2] = tmp1[3];
result[3] = tmp2[3];
return *(__m128i *)result;
}
#define MIX2_EMU(s0, s1) \
tmp = _mm_unpacklo_epi32_emu(s0, s1); \
s1 = _mm_unpackhi_epi32_emu(s0, s1); \
s0 = tmp;
/* load constants */
void load_constants_port();
/* Tweak constants with seed */
void tweak_constants(const unsigned char *pk_seed, const unsigned char *sk_seed,
unsigned long long seed_length);
/* Haraka Sponge */
void haraka_S(unsigned char *out, unsigned long long outlen,
const unsigned char *in, unsigned long long inlen);
/* Applies the 512-bit Haraka permutation to in. */
void haraka512_perm(unsigned char *out, const unsigned char *in);
/* Implementation of Haraka-512 */
void haraka512_port(unsigned char *out, const unsigned char *in);
/* Implementation of Haraka-512 */
void haraka512_port_keyed(unsigned char *out, const unsigned char *in, const u128 *rc);
/* Applies the 512-bit Haraka permutation to in, using zero key. */
void haraka512_perm_zero(unsigned char *out, const unsigned char *in);
/* Implementation of Haraka-512, using zero key */
void haraka512_port_zero(unsigned char *out, const unsigned char *in);
/* Implementation of Haraka-256 */
void haraka256_port(unsigned char *out, const unsigned char *in);
/* Implementation of Haraka-256 using sk.seed constants */
void haraka256_sk(unsigned char *out, const unsigned char *in);
#endif