32#ifndef __Random123_ars_dot_hpp__
33#define __Random123_ars_dot_hpp__
40#ifndef ARS1xm128i_DEFAULT_ROUNDS
41#define ARS1xm128i_DEFAULT_ROUNDS 7
45enum r123_enum_ars1xm128i { ars1xm128i_rounds = ARS1xm128i_DEFAULT_ROUNDS };
49typedef struct r123array1xm128i ars1xm128i_ctr_t;
51typedef struct r123array1xm128i ars1xm128i_key_t;
53typedef struct r123array1xm128i ars1xm128i_ukey_t;
55R123_STATIC_INLINE ars1xm128i_key_t ars1xm128ikeyinit(ars1xm128i_ukey_t uk) {
return uk; }
57R123_STATIC_INLINE ars1xm128i_ctr_t ars1xm128i_R(
unsigned int Nrounds, ars1xm128i_ctr_t in, ars1xm128i_key_t k) {
58 __m128i kweyl = _mm_set_epi64x(R123_64BIT(0xBB67AE8584CAA73B),
59 R123_64BIT(0x9E3779B97F4A7C15));
63 __m128i kk = k.v[0].m;
64 __m128i v = _mm_xor_si128(in.v[0].m, kk);
68 kk = _mm_add_epi64(kk, kweyl);
69 v = _mm_aesenc_si128(v, kk);
72 kk = _mm_add_epi64(kk, kweyl);
73 v = _mm_aesenc_si128(v, kk);
76 kk = _mm_add_epi64(kk, kweyl);
77 v = _mm_aesenc_si128(v, kk);
80 kk = _mm_add_epi64(kk, kweyl);
81 v = _mm_aesenc_si128(v, kk);
84 kk = _mm_add_epi64(kk, kweyl);
85 v = _mm_aesenc_si128(v, kk);
88 kk = _mm_add_epi64(kk, kweyl);
89 v = _mm_aesenc_si128(v, kk);
92 kk = _mm_add_epi64(kk, kweyl);
93 v = _mm_aesenc_si128(v, kk);
96 kk = _mm_add_epi64(kk, kweyl);
97 v = _mm_aesenc_si128(v, kk);
100 kk = _mm_add_epi64(kk, kweyl);
101 v = _mm_aesenc_si128(v, kk);
103 kk = _mm_add_epi64(kk, kweyl);
104 v = _mm_aesenclast_si128(v, kk);
113#define ars1xm128i(c, k) ars1xm128i_R(ars1xm128i_rounds, c, k)
116typedef struct r123array4x32 ars4x32_ctr_t;
118typedef struct r123array4x32 ars4x32_key_t;
120typedef struct r123array4x32 ars4x32_ukey_t;
122enum r123_enum_ars4x32 { ars4x32_rounds = ARS1xm128i_DEFAULT_ROUNDS };
126R123_STATIC_INLINE ars4x32_ctr_t ars4x32_R(
unsigned int Nrounds, ars4x32_ctr_t c, ars4x32_key_t k) {
127 ars1xm128i_ctr_t c128;
128 ars1xm128i_key_t k128;
129 c128.v[0].m = _mm_set_epi32(c.v[3], c.v[2], c.v[1], c.v[0]);
130 k128.v[0].m = _mm_set_epi32(k.v[3], k.v[2], k.v[1], k.v[0]);
131 c128 = ars1xm128i_R(Nrounds, c128, k128);
132 _mm_storeu_si128((__m128i*)&c.v[0], c128.v[0].m);
139#define ars4x32(c, k) ars4x32_R(ars4x32_rounds, c, k)
164template<
unsigned int ROUNDS>
struct ARS1xm128i_R {
165 typedef ars1xm128i_ctr_t ctr_type;
166 typedef ars1xm128i_key_t key_type;
167 typedef ars1xm128i_key_t ukey_type;
168 static unsigned int const rounds = ROUNDS;
169 R123_FORCE_INLINE(ctr_type
operator()(ctr_type ctr, key_type key)
const) {
return ars1xm128i_R(ROUNDS, ctr, key); }
176template<
unsigned int ROUNDS>
struct ARS4x32_R {
177 typedef ars4x32_ctr_t ctr_type;
178 typedef ars4x32_key_t key_type;
179 typedef ars4x32_key_t ukey_type;
180 static unsigned int const rounds = ROUNDS;
181 R123_FORCE_INLINE(ctr_type
operator()(ctr_type ctr, key_type key)
const) {
return ars4x32_R(ROUNDS, ctr, key); }
191typedef ARS1xm128i_R<ars1xm128i_rounds> ARS1xm128i;
192typedef ARS4x32_R<ars4x32_rounds> ARS4x32;
#define R123_STATIC_INLINE
#define R123_FORCE_INLINE(decl)