23 #ifndef ASCON_UTIL_SNP_H
24 #define ASCON_UTIL_SNP_H
39 #if defined(ASCON_BACKEND_SLICED32)
43 #define ascon_separator(state) ((state)->W[8] ^= 0x01)
44 #define ascon_pad(state, offset) \
45 ((state)->W[((offset) / 8) * 2 + 1] ^= \
46 (0x80000000U >> (((offset) & 7) * 4)))
48 #define ascon_absorb_8(state, data, offset) \
49 ascon_absorb_sliced((state), (data), (offset) / 8)
50 #define ascon_absorb_16(state, data, offset) \
52 ascon_absorb_sliced((state), (data), (offset) / 8); \
53 ascon_absorb_sliced((state), (data) + 8, (offset) / 8 + 1); \
55 #define ascon_absorb_partial(state, data, offset, count) \
56 ascon_add_bytes((state), (data), (offset), (count))
58 #define ascon_squeeze_8(state, data, offset) \
59 ascon_squeeze_sliced((state), (data), (offset) / 8)
60 #define ascon_squeeze_16(state, data, offset) \
62 ascon_squeeze_sliced((state), (data), (offset) / 8); \
63 ascon_squeeze_sliced((state), (data) + 8, (offset) / 8 + 1); \
65 #define ascon_squeeze_partial(state, data, offset, count) \
66 ascon_extract_bytes((state), (data), (offset), (count))
68 #define ascon_encrypt_8(state, dest, src, offset) \
69 ascon_encrypt_sliced((state), (dest), (src), (offset) / 8)
70 #define ascon_encrypt_16(state, dest, src, offset) \
72 ascon_encrypt_sliced((state), (dest), (src), (offset) / 8); \
73 ascon_encrypt_sliced((state), (dest) + 8, (src) + 8, (offset) / 8 + 1); \
75 #define ascon_encrypt_partial(state, dest, src, offset, count) \
77 ascon_add_bytes((state), (src), (offset), (count)); \
78 ascon_extract_bytes((state), (dest), (offset), (count)); \
81 #define ascon_decrypt_8(state, dest, src, offset) \
82 ascon_decrypt_sliced((state), (dest), (src), (offset) / 8)
83 #define ascon_decrypt_16(state, dest, src, offset) \
85 ascon_decrypt_sliced((state), (dest), (src), (offset) / 8); \
86 ascon_decrypt_sliced((state), (dest) + 8, (src) + 8, (offset) / 8 + 1); \
88 #define ascon_decrypt_partial(state, dest, src, offset, count) \
89 ascon_extract_and_overwrite_bytes((state), (src), (dest), (offset), (count))
91 #elif defined(ASCON_BACKEND_SLICED64)
93 #define ascon_separator(state) ((state)->S[4] ^= 0x01)
94 #define ascon_pad(state, offset) \
95 ((state)->S[(offset) / 8] ^= \
96 (0x8000000000000000ULL >> (((offset) & 7) * 8)))
98 #define ascon_absorb_8(state, data, offset) \
99 ((state)->S[(offset) / 8] ^= be_load_word64((data)))
100 #define ascon_absorb_16(state, data, offset) \
102 ((state)->S[(offset) / 8] ^= be_load_word64((data))); \
103 ((state)->S[(offset) / 8 + 1] ^= be_load_word64((data) + 8)); \
105 #define ascon_absorb_partial(state, data, offset, count) \
106 ascon_add_bytes((state), (data), (offset), (count))
108 #define ascon_squeeze_8(state, data, offset) \
109 be_store_word64((data), (state)->S[(offset) / 8])
110 #define ascon_squeeze_16(state, data, offset) \
112 be_store_word64((data), (state)->S[(offset) / 8]); \
113 be_store_word64((data) + 8, (state)->S[(offset) / 8 + 1]); \
115 #define ascon_squeeze_partial(state, data, offset, count) \
116 ascon_extract_bytes((state), (data), (offset), (count))
118 #define ascon_encrypt_8(state, dest, src, offset) \
120 (state)->S[(offset) / 8] ^= be_load_word64((src)); \
121 be_store_word64((dest), (state)->S[(offset) / 8]); \
123 #define ascon_encrypt_16(state, dest, src, offset) \
125 (state)->S[(offset) / 8] ^= be_load_word64((src)); \
126 (state)->S[(offset) / 8 + 1] ^= be_load_word64((src) + 8); \
127 be_store_word64((dest), (state)->S[(offset) / 8]); \
128 be_store_word64((dest) + 8, (state)->S[(offset) / 8 + 1]); \
130 #define ascon_encrypt_partial(state, dest, src, offset, count) \
132 ascon_add_bytes((state), (src), (offset), (count)); \
133 ascon_extract_bytes((state), (dest), (offset), (count)); \
136 #define ascon_decrypt_8(state, dest, src, offset) \
138 uint64_t word = be_load_word64((src)); \
139 be_store_word64((dest), word ^ (state)->S[(offset) / 8]); \
140 (state)->S[(offset) / 8] = word; \
142 #define ascon_decrypt_16(state, dest, src, offset) \
144 uint64_t word = be_load_word64((src)); \
145 be_store_word64((dest), word ^ (state)->S[(offset) / 8]); \
146 (state)->S[(offset) / 8] = word; \
147 word = be_load_word64((src) + 8); \
148 be_store_word64((dest) + 8, word ^ (state)->S[(offset) / 8 + 1]); \
149 (state)->S[(offset) / 8 + 1] = word; \
151 #define ascon_decrypt_partial(state, dest, src, offset, count) \
152 ascon_extract_and_overwrite_bytes((state), (src), (dest), (offset), (count))
154 #elif defined(ASCON_BACKEND_DIRECT_XOR) && !defined(ASCON_FORCE_GENERIC)
156 #define ascon_separator(state) ((state)->B[39] ^= 0x01)
157 #define ascon_pad(state, offset) ((state)->B[(offset)] ^= 0x80)
159 #define ascon_absorb_8(state, data, offset) \
160 lw_xor_block((state)->B + (offset), (data), 8)
161 #define ascon_absorb_16(state, data, offset) \
162 lw_xor_block((state)->B + (offset), (data), 16)
163 #define ascon_absorb_partial(state, data, offset, count) \
164 lw_xor_block((state)->B + (offset), (data), (count))
166 #define ascon_squeeze_8(state, data, offset) \
167 memcpy((data), (state)->B + (offset), 8)
168 #define ascon_squeeze_16(state, data, offset) \
169 memcpy((data), (state)->B + (offset), 16)
170 #define ascon_squeeze_partial(state, data, offset, count) \
171 memcpy((data), (state)->B + (offset), (count))
173 #define ascon_encrypt_8(state, dest, src, offset) \
174 lw_xor_block_2_dest((dest), (state)->B + (offset), (src), 8)
175 #define ascon_encrypt_16(state, dest, src, offset) \
176 lw_xor_block_2_dest((dest), (state)->B + (offset), (src), 16)
177 #define ascon_encrypt_partial(state, dest, src, offset, count) \
178 lw_xor_block_2_dest((dest), (state)->B + (offset), (src), (count))
180 #define ascon_decrypt_8(state, dest, src, offset) \
181 lw_xor_block_swap((dest), (state)->B + (offset), (src), 8)
182 #define ascon_decrypt_16(state, dest, src, offset) \
183 lw_xor_block_swap((dest), (state)->B + (offset), (src), 16)
184 #define ascon_decrypt_partial(state, dest, src, offset, count) \
185 lw_xor_block_swap((dest), (state)->B + (offset), (src), (count))
189 #define ascon_separator(state) \
191 uint8_t sep = 0x01; \
192 ascon_add_bytes((state), &sep, 39, 1); \
194 #define ascon_pad(state, offset) \
196 uint8_t padding = 0x80; \
197 ascon_add_bytes((state), &padding, (offset), 1); \
200 #define ascon_absorb_8(state, data, offset) \
201 ascon_add_bytes((state), (data), (offset), 8)
202 #define ascon_absorb_16(state, data, offset) \
203 ascon_add_bytes((state), (data), (offset), 16)
204 #define ascon_absorb_partial(state, data, offset, count) \
205 ascon_add_bytes((state), (data), (offset), (count))
207 #define ascon_squeeze_8(state, data, offset) \
208 ascon_extract_bytes((state), (data), (offset), 8)
209 #define ascon_squeeze_16(state, data, offset) \
210 ascon_extract_bytes((state), (data), (offset), 16)
211 #define ascon_squeeze_partial(state, data, offset, count) \
212 ascon_extract_bytes((state), (data), (offset), (count))
214 #define ascon_encrypt_8(state, dest, src, offset) \
216 ascon_add_bytes((state), (src), (offset), 8); \
217 ascon_extract_bytes((state), (dest), (offset), 8); \
219 #define ascon_encrypt_16(state, dest, src, offset) \
221 ascon_add_bytes((state), (src), (offset), 16); \
222 ascon_extract_bytes((state), (dest), (offset), 16); \
224 #define ascon_encrypt_partial(state, dest, src, offset, count) \
226 ascon_add_bytes((state), (src), (offset), (count)); \
227 ascon_extract_bytes((state), (dest), (offset), (count)); \
230 #define ascon_decrypt_8(state, dest, src, offset) \
231 ascon_extract_and_overwrite_bytes((state), (src), (dest), (offset), 8)
232 #define ascon_decrypt_16(state, dest, src, offset) \
233 ascon_extract_and_overwrite_bytes((state), (src), (dest), (offset), 16)
234 #define ascon_decrypt_partial(state, dest, src, offset, count) \
235 ascon_extract_and_overwrite_bytes((state), (src), (dest), (offset), (count))
239 #if defined(ASCON_BACKEND_INIT)
248 #define ascon_backend_init(state) do { ; } while (0)
251 #if defined(ASCON_BACKEND_FREE)
260 #define ascon_backend_free(state) do { ; } while (0)
#define ascon_backend_free(state)
#define ascon_backend_init(state)
Direct access to the ASCON permutation primitive.
ascon_state_t state
[snippet_key]
Structure of the internal state of the ASCON permutation.