23 #ifndef ASCON_AEAD_MASKED_COMMON_H
24 #define ASCON_AEAD_MASKED_COMMON_H
81 const unsigned char *src,
size_t len, uint8_t first_round,
98 const unsigned char *src,
size_t len, uint8_t first_round,
115 const unsigned char *src,
size_t len, uint8_t first_round,
132 const unsigned char *src,
size_t len, uint8_t first_round,
137 #if ASCON_MASKED_KEY_SHARES == 2
139 #define ascon_masked_key_load(word, data, trng) \
140 ascon_masked_word_x2_load((word), (data), (trng))
141 #define ascon_masked_key_store(data, word) \
142 ascon_masked_word_x2_store((data), (word))
143 #define ascon_masked_key_xor(dest, src) \
144 ascon_masked_word_x2_xor((dest), (const ascon_masked_word_t *)(src))
145 #define ascon_masked_key_permute(state, first_round, preserve) \
146 ascon_x2_permute((state), (first_round), (preserve))
147 #define ascon_masked_key_randomize(state, trng) \
148 ascon_x2_randomize((state), (trng))
149 #define ascon_copy_key_to_x1(state_x1, state) \
150 ascon_x2_copy_to_x1((state_x1), (state))
151 #define ascon_copy_key_to_x2(state, trng) do { ; } while (0)
152 #define ascon_copy_key_from_x1(state, state_x1, trng) \
153 ascon_x2_copy_from_x1((state), (state_x1), (trng))
154 #define ascon_copy_key_from_x2(state, trng) \
155 ascon_x2_randomize((state), (trng))
157 #elif ASCON_MASKED_KEY_SHARES == 3
159 #define ascon_masked_key_load(word, data, trng) \
160 ascon_masked_word_x3_load((word), (data), (trng))
161 #define ascon_masked_key_store(data, word) \
162 ascon_masked_word_x3_store((data), (word))
163 #define ascon_masked_key_xor(dest, src) \
164 ascon_masked_word_x3_xor((dest), (const ascon_masked_word_t *)(src))
165 #define ascon_masked_key_permute(state, first_round, preserve) \
166 ascon_x3_permute((state), (first_round), (preserve))
167 #define ascon_masked_key_randomize(state, trng) \
168 ascon_x3_randomize((state), (trng))
169 #define ascon_copy_key_to_x1(state_x1, state) \
170 ascon_x3_copy_to_x1((state_x1), (state))
171 #define ascon_copy_key_to_x2(state, trng) \
172 ascon_x2_copy_from_x3((state), (state), (trng))
173 #define ascon_copy_key_to_x3(state, trng) do { ; } while (0)
174 #define ascon_copy_key_from_x1(state, state_x1, trng) \
175 ascon_x3_copy_from_x1((state), (state_x1), (trng))
176 #define ascon_copy_key_from_x2(state, trng) \
177 ascon_x3_copy_from_x2((state), (state), (trng))
178 #define ascon_copy_key_from_x3(state, trng) \
179 ascon_x3_randomize((state), (trng))
183 #define ascon_masked_key_load(word, data, trng) \
184 ascon_masked_word_x4_load((word), (data), (trng))
185 #define ascon_masked_key_store(data, word) \
186 ascon_masked_word_x4_store((data), (word))
187 #define ascon_masked_key_xor(dest, src) \
188 ascon_masked_word_x4_xor((dest), (const ascon_masked_word_t *)(src))
189 #define ascon_masked_key_permute(state, first_round, preserve) \
190 ascon_x4_permute((state), (first_round), (preserve))
191 #define ascon_masked_key_randomize(state, trng) \
192 ascon_x4_randomize((state), (trng))
193 #define ascon_copy_key_to_x1(state_x1, state) \
194 ascon_x4_copy_to_x1((state_x1), (state))
195 #define ascon_copy_key_to_x2(state, trng) \
196 ascon_x2_copy_from_x4((state), (state), (trng))
197 #define ascon_copy_key_to_x3(state, trng) \
198 ascon_x3_copy_from_x4((state), (state), (trng))
199 #define ascon_copy_key_to_x4(state, trng) do { ; } while (0)
200 #define ascon_copy_key_from_x1(state, state_x1, trng) \
201 ascon_x4_copy_from_x1((state), (state_x1), (trng))
202 #define ascon_copy_key_from_x2(state, trng) \
203 ascon_x4_copy_from_x2((state), (state), (trng))
204 #define ascon_copy_key_from_x3(state, trng) \
205 ascon_x4_copy_from_x3((state), (state), (trng))
206 #define ascon_copy_key_from_x4(state, trng) \
207 ascon_x4_randomize((state), (trng))
211 #if ASCON_MASKED_DATA_SHARES == 1
215 #elif ASCON_MASKED_DATA_SHARES == 2
217 #define ascon_masked_data_load(word, data, trng) \
218 ascon_masked_word_x2_load((word), (data), (trng))
219 #define ascon_masked_data_load_partial(word, data, len, trng) \
220 ascon_masked_word_x2_load_partial((word), (data), len, (trng))
221 #define ascon_masked_data_store(data, word) \
222 ascon_masked_word_x2_store((data), (word))
223 #define ascon_masked_data_store_partial(data, len, word) \
224 ascon_masked_word_x2_store_partial((data), (len), (word))
225 #define ascon_masked_data_xor(dest, src) \
226 ascon_masked_word_x2_xor((dest), (src))
227 #define ascon_masked_data_permute(state, first_round, preserve) \
228 ascon_x2_permute((state), (first_round), (preserve))
229 #define ascon_masked_data_replace(dest, src, size) \
230 ascon_masked_word_x2_replace((dest), (src), (size))
232 #elif ASCON_MASKED_DATA_SHARES == 3
234 #define ascon_masked_data_load(word, data, trng) \
235 ascon_masked_word_x3_load((word), (data), (trng))
236 #define ascon_masked_data_load_partial(word, data, len, trng) \
237 ascon_masked_word_x3_load_partial((word), (data), len, (trng))
238 #define ascon_masked_data_store(data, word) \
239 ascon_masked_word_x3_store((data), (word))
240 #define ascon_masked_data_store_partial(data, len, word) \
241 ascon_masked_word_x3_store_partial((data), (len), (word))
242 #define ascon_masked_data_xor(dest, src) \
243 ascon_masked_word_x3_xor((dest), (src))
244 #define ascon_masked_data_permute(state, first_round, preserve) \
245 ascon_x3_permute((state), (first_round), (preserve))
246 #define ascon_masked_data_replace(dest, src, size) \
247 ascon_masked_word_x3_replace((dest), (src), (size))
251 #define ascon_masked_data_load(word, data, trng) \
252 ascon_masked_word_x4_load((word), (data), (trng))
253 #define ascon_masked_data_load_partial(word, data, len, trng) \
254 ascon_masked_word_x4_load_partial((word), (data), len, (trng))
255 #define ascon_masked_data_store(data, word) \
256 ascon_masked_word_x4_store((data), (word))
257 #define ascon_masked_data_store_partial(data, len, word) \
258 ascon_masked_word_x4_store_partial((data), (len), (word))
259 #define ascon_masked_data_xor(dest, src) \
260 ascon_masked_word_x4_xor((dest), (src))
261 #define ascon_masked_data_permute(state, first_round, preserve) \
262 ascon_x4_permute((state), (first_round), (preserve))
263 #define ascon_masked_data_replace(dest, src, size) \
264 ascon_masked_word_x4_replace((dest), (src), (size))
Masked ASCON-128 encryption algorithm and related family members.
void ascon_masked_aead_decrypt_16(ascon_masked_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Decrypts a block of data with an ASCON state and a 16-byte rate.
void ascon_masked_aead_absorb_8(ascon_masked_state_t *state, const unsigned char *data, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Absorbs data into a masked ASCON state with an 8-byte rate.
void ascon_masked_aead_encrypt_16(ascon_masked_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Encrypts a block of data with a masked ASCON state and a 16-byte rate.
void ascon_masked_aead_absorb_16(ascon_masked_state_t *state, const unsigned char *data, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Absorbs data into a masked ASCON state with a 16-byte rate.
void ascon_masked_aead_decrypt_8(ascon_masked_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Decrypts a block of data with a masked ASCON state and an 8-byte rate.
void ascon_masked_aead_encrypt_8(ascon_masked_state_t *state, unsigned char *dest, const unsigned char *src, size_t len, uint8_t first_round, ascon_masked_word_t *word, uint64_t *preserve, ascon_trng_state_t *trng)
Encrypts a block of data with a masked ASCON state and an 8-byte rate.
Configures the number of shares to use for masked AEAD modes.
Utility functions for operating on masked ASCON states with between 2 and 4 shares.
ascon_state_t state
[snippet_key]
unsigned char data[8]
[snippet_key]
State of the ASCON permutation which has been masked with up to 4 shares.
State of the random number source.
Masked 64-bit word with up to ASCON_MASKED_MAX_SHARES shares.