25 #if defined(ASCON_MASKED_WORD_BACKEND_DIRECT_XOR)
30 typedef union { uint64_t w; uint8_t b[8]; } random_bytes_t;
37 for (index = 0; index < 8; ++index)
38 word->
B[index + 8] = word->
B[index];
53 for (index = 0; index < 8; ++index)
54 word->
B[index] =
data[index] ^ word->
B[index + 8];
69 for (index = 0; index < size; ++index)
70 word->
B[index] =
data[index] ^ word->
B[index + 8];
71 for (; index < 8; ++index)
72 word->
B[index] = word->
B[index + 8];
87 for (index = 0; index < 4; ++index) {
88 word->
B[index] = data1[index] ^ word->
B[index + 8];
89 word->
B[index + 4] = data2[index] ^ word->
B[index + 12];
91 #if ASCON_MASKED_MAX_SHARES >= 3
94 #if ASCON_MASKED_MAX_SHARES >= 4
103 for (index = 0; index < 8; ++index)
104 data[index] = word->
B[index] ^ word->
B[index + 8];
111 for (index = 0; index < size; ++index)
112 data[index] = word->
B[index] ^ word->
B[index + 8];
119 random_bytes_t random;
122 for (index = 0; index < 8; ++index) {
123 dest->
B[index] = src->
B[index] ^ random.b[index];
124 dest->
B[index + 8] = src->
B[index + 8] ^ random.b[index];
132 for (index = 0; index < 8; ++index) {
133 dest->
B[index] ^= src->
B[index];
134 dest->
B[index + 8] ^= src->
B[index + 8];
142 for (index = 0; index < size; ++index) {
143 dest->
B[index] = src->
B[index];
144 dest->
B[index + 8] = src->
B[index + 8];
148 #if ASCON_MASKED_MAX_SHARES >= 3
154 random_bytes_t random;
157 for (index = 0; index < 8; ++index) {
158 dest->
B[index] = random.b[index] ^ src->
B[index];
160 (random.b[index] ^ src->
B[index + 8]) ^ src->
B[index + 16];
163 #if ASCON_MASKED_MAX_SHARES >= 4
170 #if ASCON_MASKED_MAX_SHARES >= 4
176 random_bytes_t random;
179 for (index = 0; index < 8; ++index) {
181 (random.b[index] ^ src->
B[index]) ^ src->
B[index + 16];
183 (random.b[index] ^ src->
B[index + 8]) ^ src->
B[index + 24];
191 #if ASCON_MASKED_MAX_SHARES >= 3
199 for (index = 0; index < 8; ++index)
200 word->
B[index] = word->
B[index + 8] ^ word->
B[index + 16];
213 for (index = 0; index < 8; ++index) {
215 (word->
B[index + 8] ^
data[index]) ^ word->
B[index + 16];
217 #if ASCON_MASKED_MAX_SHARES >= 4
229 for (index = 0; index < size; ++index) {
231 (word->
B[index + 8] ^
data[index]) ^ word->
B[index + 16];
233 for (; index < 8; ++index)
234 word->
B[index] = word->
B[index + 8] ^ word->
B[index + 16];
247 for (index = 0; index < 4; ++index) {
249 (word->
B[index + 8] ^ data1[index]) ^ word->
B[index + 16];
251 (word->
B[index + 12] ^ data2[index]) ^ word->
B[index + 20];
253 #if ASCON_MASKED_MAX_SHARES >= 4
262 for (index = 0; index < 8; ++index)
263 data[index] = word->
B[index] ^ word->
B[index + 8] ^ word->
B[index + 16];
270 for (index = 0; index < size; ++index)
271 data[index] = word->
B[index] ^ word->
B[index + 8] ^ word->
B[index + 16];
278 random_bytes_t random1;
279 random_bytes_t random2;
283 for (index = 0; index < 8; ++index) {
285 = (random1.b[index] ^ src->
B[index]) ^ random2.b[index];
286 dest->
B[index + 8] = src->
B[index + 8] ^ random1.b[index];
287 dest->
B[index + 16] = src->
B[index + 16] ^ random2.b[index];
295 for (index = 0; index < 8; ++index) {
296 dest->
B[index] ^= src->
B[index];
297 dest->
B[index + 8] ^= src->
B[index + 8];
298 dest->
B[index + 16] ^= src->
B[index + 16];
306 for (index = 0; index < size; ++index) {
307 dest->
B[index] = src->
B[index];
308 dest->
B[index + 8] = src->
B[index + 8];
309 dest->
B[index + 16] = src->
B[index + 16];
317 random_bytes_t random1;
318 random_bytes_t random2;
322 for (index = 0; index < 8; ++index) {
323 dest->
B[index] = (random1.b[index] ^ src->
B[index]) ^ random2.b[index];
324 dest->
B[index + 8] = (random1.b[index] ^ src->
B[index + 8]);
325 dest->
B[index + 16] = random2.b[index];
327 #if ASCON_MASKED_MAX_SHARES >= 4
332 #if ASCON_MASKED_MAX_SHARES >= 4
338 random_bytes_t random1;
339 random_bytes_t random2;
343 for (index = 0; index < 8; ++index) {
345 ((random1.b[index] ^ src->
B[index]) ^ random2.b[index]) ^
347 dest->
B[index + 8] = (random1.b[index] ^ src->
B[index + 8]);
348 dest->
B[index + 16] = (random2.b[index] ^ src->
B[index + 16]);
357 #if ASCON_MASKED_MAX_SHARES >= 4
366 for (index = 0; index < 8; ++index) {
368 word->
B[index + 8] ^ word->
B[index + 16] ^ word->
B[index + 24];
380 for (index = 0; index < 8; ++index) {
382 (word->
B[index + 8] ^
data[index]) ^ word->
B[index + 16] ^
395 for (index = 0; index < size; ++index) {
397 (word->
B[index + 8] ^
data[index]) ^ word->
B[index + 16] ^
400 for (; index < 8; ++index) {
402 word->
B[index + 8] ^ word->
B[index + 16] ^ word->
B[index + 24];
414 for (index = 0; index < 4; ++index) {
416 (word->
B[index + 8] ^ data1[index]) ^ word->
B[index + 16] ^
419 (word->
B[index + 12] ^ data2[index]) ^ word->
B[index + 20] ^
428 for (index = 0; index < 8; ++index) {
430 word->
B[index] ^ word->
B[index + 8] ^
431 word->
B[index + 16] ^ word->
B[index + 24];
439 for (index = 0; index < size; ++index) {
441 word->
B[index] ^ word->
B[index + 8] ^
442 word->
B[index + 16] ^ word->
B[index + 24];
450 random_bytes_t random1;
451 random_bytes_t random2;
452 random_bytes_t random3;
457 for (index = 0; index < 8; ++index) {
459 = (random1.b[index] ^ src->
B[index]) ^ random2.b[index] ^
461 dest->
B[index + 8] = src->
B[index + 8] ^ random1.b[index];
462 dest->
B[index + 16] = src->
B[index + 16] ^ random2.b[index];
463 dest->
B[index + 24] = src->
B[index + 24] ^ random3.b[index];
471 for (index = 0; index < 8; ++index) {
472 dest->
B[index] ^= src->
B[index];
473 dest->
B[index + 8] ^= src->
B[index + 8];
474 dest->
B[index + 16] ^= src->
B[index + 16];
475 dest->
B[index + 24] ^= src->
B[index + 24];
483 for (index = 0; index < size; ++index) {
484 dest->
B[index] = src->
B[index];
485 dest->
B[index + 8] = src->
B[index + 8];
486 dest->
B[index + 16] = src->
B[index + 16];
487 dest->
B[index + 24] = src->
B[index + 24];
495 random_bytes_t random1;
496 random_bytes_t random2;
497 random_bytes_t random3;
502 for (index = 0; index < 8; ++index) {
504 (random1.b[index] ^ src->
B[index]) ^
505 random2.b[index] ^ random3.b[index];
506 dest->
B[index + 8] = (random1.b[index] ^ src->
B[index + 8]);
507 dest->
B[index + 16] = random2.b[index];
508 dest->
B[index + 24] = random3.b[index];
516 random_bytes_t random1;
517 random_bytes_t random2;
518 random_bytes_t random3;
523 for (index = 0; index < 8; ++index) {
525 (random1.b[index] ^ src->
B[index]) ^
526 random2.b[index] ^ random3.b[index];
527 dest->
B[index + 8] = (random1.b[index] ^ src->
B[index + 8]);
528 dest->
B[index + 16] = (random2.b[index] ^ src->
B[index + 16]);
529 dest->
B[index + 24] = random3.b[index];
537 word->
B[offset] ^= 0x80;
#define ASCON_MASKED_MAX_SHARES
Maximum number of shares to use in the library.
void ascon_masked_word_x4_load_32(ascon_masked_word_t *word, const uint8_t *data1, const uint8_t *data2, ascon_trng_state_t *trng)
Loads two 32-bit big endian values from buffers, masks them, and writes the result to a x4 masked wor...
void ascon_masked_word_pad(ascon_masked_word_t *word, unsigned offset)
Adds a padding marker to a masked word.
void ascon_masked_word_x3_replace(ascon_masked_word_t *dest, const ascon_masked_word_t *src, unsigned size)
Replace part of a destination x3 masked word with part of a source.
void ascon_masked_word_x2_store_partial(uint8_t *data, unsigned size, const ascon_masked_word_t *word)
Unmasks and stores the contents of a x2 masked word structure to a partial buffer.
void ascon_masked_word_x2_load(ascon_masked_word_t *word, const uint8_t *data, ascon_trng_state_t *trng)
Loads a 64-bit big endian value from buffer, masks it, and writes it to a x2 masked word structure.
void ascon_masked_word_x2_store(uint8_t *data, const ascon_masked_word_t *word)
Unmasks and stores the contents of a x2 masked word structure.
void ascon_masked_word_x4_from_x2(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Converts a x2 masked word into a x4 masked word.
void ascon_masked_word_x3_store_partial(uint8_t *data, unsigned size, const ascon_masked_word_t *word)
Unmasks and stores the contents of a x3 masked word structure to a partial buffer.
void ascon_masked_word_x3_from_x2(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Converts a x2 masked word into a x3 masked word.
void ascon_masked_word_x2_from_x4(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Converts a x4 masked word into a x2 masked word.
void ascon_masked_word_x4_load(ascon_masked_word_t *word, const uint8_t *data, ascon_trng_state_t *trng)
Loads a 64-bit big endian value from buffer, masks it, and writes it to a x4 masked word structure.
void ascon_masked_word_x2_zero(ascon_masked_word_t *word, ascon_trng_state_t *trng)
Sets a x2 masked word to zero.
void ascon_masked_word_x4_load_partial(ascon_masked_word_t *word, const uint8_t *data, unsigned size, ascon_trng_state_t *trng)
Loads a 8-bit to 56-bit big endian value from buffer, masks it, and writes it to a x4 masked word str...
void ascon_masked_word_separator(ascon_masked_word_t *word)
Adds a separator marker to a masked word.
void ascon_masked_word_x3_load(ascon_masked_word_t *word, const uint8_t *data, ascon_trng_state_t *trng)
Loads a 64-bit big endian value from buffer, masks it, and writes it to a x3 masked word structure.
void ascon_masked_word_x2_from_x3(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Converts a x3 masked word into a x2 masked word.
void ascon_masked_word_x3_load_32(ascon_masked_word_t *word, const uint8_t *data1, const uint8_t *data2, ascon_trng_state_t *trng)
Loads two 32-bit big endian values from buffers, masks them, and writes the result to a x3 masked wor...
void ascon_masked_word_x3_from_x4(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Converts a x4 masked word into a x3 masked word.
void ascon_masked_word_x4_replace(ascon_masked_word_t *dest, const ascon_masked_word_t *src, unsigned size)
Replace part of a destination x4 masked word with part of a source.
void ascon_masked_word_x4_store_partial(uint8_t *data, unsigned size, const ascon_masked_word_t *word)
Unmasks and stores the contents of a x4 masked word structure to a partial buffer.
void ascon_masked_word_x2_load_partial(ascon_masked_word_t *word, const uint8_t *data, unsigned size, ascon_trng_state_t *trng)
Loads a 8-bit to 56-bit big endian value from buffer, masks it, and writes it to a x2 masked word str...
void ascon_masked_word_x3_randomize(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Randomizes a x3 masked word by incorporating fresh randomness.
void ascon_masked_word_x2_load_32(ascon_masked_word_t *word, const uint8_t *data1, const uint8_t *data2, ascon_trng_state_t *trng)
Loads two 32-bit big endian values from buffers, masks them, and writes the result to a x2 masked wor...
void ascon_masked_word_x4_from_x3(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Converts a x3 masked word into a x4 masked word.
void ascon_masked_word_x4_xor(ascon_masked_word_t *dest, const ascon_masked_word_t *src)
XOR's a source x4 masked word against a destination x4 masked word.
void ascon_masked_word_x2_replace(ascon_masked_word_t *dest, const ascon_masked_word_t *src, unsigned size)
Replace part of a destination x2 masked word with part of a source.
void ascon_masked_word_x3_load_partial(ascon_masked_word_t *word, const uint8_t *data, unsigned size, ascon_trng_state_t *trng)
Loads a 8-bit to 56-bit big endian value from buffer, masks it, and writes it to a x3 masked word str...
void ascon_masked_word_x3_xor(ascon_masked_word_t *dest, const ascon_masked_word_t *src)
XOR's a source x3 masked word against a destination x3 masked word.
void ascon_masked_word_x4_randomize(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Randomizes a x4 masked word by incorporating fresh randomness.
void ascon_masked_word_x4_zero(ascon_masked_word_t *word, ascon_trng_state_t *trng)
Sets a x4 masked word to zero.
void ascon_masked_word_x4_store(uint8_t *data, const ascon_masked_word_t *word)
Unmasks and stores the contents of a x4 masked word structure.
void ascon_masked_word_x3_zero(ascon_masked_word_t *word, ascon_trng_state_t *trng)
Sets a x3 masked word to zero.
void ascon_masked_word_x3_store(uint8_t *data, const ascon_masked_word_t *word)
Unmasks and stores the contents of a x3 masked word structure.
void ascon_masked_word_x2_xor(ascon_masked_word_t *dest, const ascon_masked_word_t *src)
XOR's a source x2 masked word against a destination x2 masked word.
void ascon_masked_word_x2_randomize(ascon_masked_word_t *dest, const ascon_masked_word_t *src, ascon_trng_state_t *trng)
Randomizes a x2 masked word by incorporating fresh randomness.
Utility functions for operating on masked words.
uint64_t ascon_trng_generate_64(ascon_trng_state_t *state)
Generates a 64-bit random value for masking operations.
unsigned char data[8]
[snippet_key]
State of the random number source.
Masked 64-bit word with up to ASCON_MASKED_MAX_SHARES shares.
uint64_t S[ASCON_MASKED_MAX_SHARES]
uint8_t B[ASCON_MASKED_MAX_SHARES *8]