23 #ifndef LW_INTERNAL_ASCON_H
24 #define LW_INTERNAL_ASCON_H
26 #include "internal-util.h"
44 #define ASCON_SLICED 1
46 #define ASCON_SLICED 0
101 #define ascon_bit_permute_step(_y, mask, shift) \
104 uint32_t t = ((y >> (shift)) ^ y) & (mask); \
105 (_y) = (y ^ t) ^ (t << (shift)); \
116 #define ascon_separate(x) \
118 ascon_bit_permute_step((x), 0x22222222, 1); \
119 ascon_bit_permute_step((x), 0x0c0c0c0c, 2); \
120 ascon_bit_permute_step((x), 0x00f000f0, 4); \
121 ascon_bit_permute_step((x), 0x0000ff00, 8); \
123 #define ascon_combine(x) \
125 ascon_bit_permute_step((x), 0x0000aaaa, 15); \
126 ascon_bit_permute_step((x), 0x0000cccc, 14); \
127 ascon_bit_permute_step((x), 0x0000f0f0, 12); \
128 ascon_bit_permute_step((x), 0x0000ff00, 8); \
141 #define ascon_set_sliced(state, data, offset) \
143 ascon_state_t *s = (state); \
144 uint32_t high = be_load_word32((data)); \
145 uint32_t low = be_load_word32((data) + 4); \
146 ascon_separate(high); \
147 ascon_separate(low); \
148 s->W[(offset) * 2] = (high << 16) | (low & 0x0000FFFFU); \
149 s->W[(offset) * 2 + 1] = (high & 0xFFFF0000U) | (low >> 16); \
160 #define ascon_absorb_sliced(state, data, offset) \
162 ascon_state_t *s = (state); \
163 uint32_t high = be_load_word32((data)); \
164 uint32_t low = be_load_word32((data) + 4); \
165 ascon_separate(high); \
166 ascon_separate(low); \
167 s->W[(offset) * 2] ^= (high << 16) | (low & 0x0000FFFFU); \
168 s->W[(offset) * 2 + 1] ^= (high & 0xFFFF0000U) | (low >> 16); \
181 #define ascon_absorb32_low_sliced(state, data, offset) \
183 ascon_state_t *s = (state); \
184 uint32_t low = be_load_word32((data)); \
185 ascon_separate(low); \
186 s->W[(offset) * 2] ^= (low & 0x0000FFFFU); \
187 s->W[(offset) * 2 + 1] ^= (low >> 16); \
200 #define ascon_absorb32_high_sliced(state, data, offset) \
202 ascon_state_t *s = (state); \
203 uint32_t high = be_load_word32((data)); \
204 ascon_separate(high); \
205 s->W[(offset) * 2] ^= (high << 16); \
206 s->W[(offset) * 2 + 1] ^= (high & 0xFFFF0000U); \
217 #define ascon_squeeze_sliced(state, data, offset) \
219 ascon_state_t *s = (state); \
220 uint32_t high, low; \
221 high = (s->W[(offset) * 2] >> 16) | \
222 (s->W[(offset) * 2 + 1] & 0xFFFF0000U); \
223 low = (s->W[(offset) * 2] & 0x0000FFFFU) | \
224 (s->W[(offset) * 2 + 1] << 16); \
225 ascon_combine(high); \
226 ascon_combine(low); \
227 be_store_word32((data), high); \
228 be_store_word32((data) + 4, low); \
240 #define ascon_encrypt_sliced(state, c, m, offset) \
242 ascon_state_t *s = (state); \
243 uint32_t high = be_load_word32((m)); \
244 uint32_t low = be_load_word32((m) + 4); \
245 ascon_separate(high); \
246 ascon_separate(low); \
247 s->W[(offset) * 2] ^= (high << 16) | (low & 0x0000FFFFU); \
248 s->W[(offset) * 2 + 1] ^= (high & 0xFFFF0000U) | (low >> 16); \
249 high = (s->W[(offset) * 2] >> 16) | \
250 (s->W[(offset) * 2 + 1] & 0xFFFF0000U); \
251 low = (s->W[(offset) * 2] & 0x0000FFFFU) | \
252 (s->W[(offset) * 2 + 1] << 16); \
253 ascon_combine(high); \
254 ascon_combine(low); \
255 be_store_word32((c), high); \
256 be_store_word32((c) + 4, low); \
268 #define ascon_decrypt_sliced(state, m, c, offset) \
270 ascon_state_t *s = (state); \
271 uint32_t high, low, high2, low2; \
272 high = be_load_word32((c)); \
273 low = be_load_word32((c) + 4); \
274 ascon_separate(high); \
275 ascon_separate(low); \
276 high2 = high ^ ((s->W[(offset) * 2] >> 16) | \
277 (s->W[(offset) * 2 + 1] & 0xFFFF0000U)); \
278 low2 = low ^ ((s->W[(offset) * 2] & 0x0000FFFFU) | \
279 (s->W[(offset) * 2 + 1] << 16)); \
280 s->W[(offset) * 2] = (high << 16) | (low & 0x0000FFFFU); \
281 s->W[(offset) * 2 + 1] = (high & 0xFFFF0000U) | (low >> 16); \
282 ascon_combine(high2); \
283 ascon_combine(low2); \
284 be_store_word32((m), high2); \
285 be_store_word32((m) + 4, low2); \
void ascon_permute_sliced(ascon_state_t *state, uint8_t first_round)
Permutes the ASCON state in sliced form.
Definition: internal-ascon.c:124
Structure of the internal state of the ASCON permutation.
Definition: internal-ascon.h:52
void ascon_permute(ascon_state_t *state, uint8_t first_round)
Permutes the ASCON state.
Definition: internal-ascon.c:39
void ascon_to_sliced(ascon_state_t *state)
Converts an ASCON state from byte form into sliced form.
Definition: internal-ascon.c:96
void ascon_from_sliced(ascon_state_t *state)
Converts an ASCON state from sliced form into byte form.
Definition: internal-ascon.c:110