Skip to content

Commit 6e2ef4a

Browse files
committed
Namespace macro: STACK_* and KECCAK_F1600_ROUNDS
- The STACK_SIZE should namespace as MLK_STACK_SIZE to avoid clashing with symbols in consuming libraries. - Also, found a missing namespace macro called KECCAK_F1600_ROUNDS, also namespace it. - This commit also namespace rej_uniform_asm Signed-off-by: willieyz <[email protected]>
1 parent e06ba17 commit 6e2ef4a

12 files changed

+686
-686
lines changed

dev/aarch64_clean/src/rej_uniform_asm.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
// We save the output on the stack first, and copy to the actual
4545
// output buffer only in the end. This is because the main loop can overwrite
4646
// by up to 62 bytes, which we account for here (we use 64 bytes for alignment).
47-
#define STACK_SIZE (2*MLKEM_N + 64)
47+
#define MLK_STACK_SIZE (2*MLKEM_N + 64)
4848

4949
.macro push_stack
50-
sub sp, sp, #STACK_SIZE
50+
sub sp, sp, #MLK_STACK_SIZE
5151
.endm
5252

5353
.macro pop_stack
54-
add sp, sp, #STACK_SIZE
54+
add sp, sp, #MLK_STACK_SIZE
5555
.endm
5656

5757
/* Parameters */
@@ -458,7 +458,7 @@ rej_uniform_return:
458458

459459
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
460460
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
461-
#undef STACK_SIZE
461+
#undef MLK_STACK_SIZE
462462

463463
/* simpasm: footer-start */
464464
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */

dev/aarch64_opt/src/rej_uniform_asm.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
// We save the output on the stack first, and copy to the actual
4545
// output buffer only in the end. This is because the main loop can overwrite
4646
// by up to 62 bytes, which we account for here (we use 64 bytes for alignment).
47-
#define STACK_SIZE (2*MLKEM_N + 64)
47+
#define MLK_STACK_SIZE (2*MLKEM_N + 64)
4848

4949
.macro push_stack
50-
sub sp, sp, #STACK_SIZE
50+
sub sp, sp, #MLK_STACK_SIZE
5151
.endm
5252

5353
.macro pop_stack
54-
add sp, sp, #STACK_SIZE
54+
add sp, sp, #MLK_STACK_SIZE
5555
.endm
5656

5757
/* Parameters */
@@ -458,7 +458,7 @@ rej_uniform_return:
458458

459459
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
460460
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
461-
#undef STACK_SIZE
461+
#undef MLK_STACK_SIZE
462462

463463
/* simpasm: footer-start */
464464
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */

dev/fips202/aarch64/src/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ keccak_f1600_x1_scalar_asm.S: ../../aarch64_symbolic/keccak_f1600_x1_scalar_symb
2626
-c reserved_regs="[x18,sp]" \
2727
-c variable_size \
2828
-c inputs_are_outputs \
29-
-c outputs="[hint_STACK_LOC_COUNT]" \
29+
-c outputs="[hint_MLK_STACK_LOC_COUNT]" \
3030
-c constraints.stalls_first_attempt=64 \
3131
-c constraints.allow_spills \
3232
-c constraints.minimize_spills \
@@ -48,7 +48,7 @@ keccak_f1600_x4_v8a_scalar_hybrid_asm.S: ../../aarch64_symbolic/keccak_f1600_x4_
4848
-c split_heuristic_preprocess_naive_interleaving_strategy="alternate" \
4949
-c split_heuristic_estimate_performance=False \
5050
-c absorb_spills=False \
51-
-c outputs="[hint_STACK_OFFSET_COUNT]" \
51+
-c outputs="[hint_MLK_STACK_OFFSET_COUNT]" \
5252
-s keccak_f1600_x4_v8a_scalar_hybrid_initial \
5353
-e keccak_f1600_x4_v8a_scalar_hybrid_loop
5454

@@ -63,7 +63,7 @@ keccak_f1600_x4_v8a_scalar_hybrid_asm.S: ../../aarch64_symbolic/keccak_f1600_x4_
6363
-c split_heuristic_preprocess_naive_interleaving \
6464
-c split_heuristic_preprocess_naive_interleaving_strategy="alternate" \
6565
-c split_heuristic_estimate_performance=False \
66-
-c outputs="[hint_STACK_OFFSET_COUNT]" \
66+
-c outputs="[hint_MLK_STACK_OFFSET_COUNT]" \
6767
-c absorb_spills=False \
6868
-s keccak_f1600_x4_v8a_scalar_hybrid_loop \
6969
-e keccak_f1600_x4_v8a_scalar_hybrid_loop_end
@@ -81,7 +81,7 @@ keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S: ../../aarch64_symbolic/keccak_f160
8181
-c split_heuristic_preprocess_naive_interleaving_strategy="alternate" \
8282
-c split_heuristic_estimate_performance=False \
8383
-c absorb_spills=False \
84-
-c outputs="[hint_STACK_OFFSET_COUNT]" \
84+
-c outputs="[hint_MLK_STACK_OFFSET_COUNT]" \
8585
-s keccak_f1600_x4_v8a_v84a_scalar_hybrid_initial \
8686
-e keccak_f1600_x4_v8a_v84a_scalar_hybrid_loop
8787

@@ -96,7 +96,7 @@ keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S: ../../aarch64_symbolic/keccak_f160
9696
-c split_heuristic_preprocess_naive_interleaving \
9797
-c split_heuristic_preprocess_naive_interleaving_strategy="alternate" \
9898
-c split_heuristic_estimate_performance=False \
99-
-c outputs="[hint_STACK_OFFSET_COUNT]" \
99+
-c outputs="[hint_MLK_STACK_OFFSET_COUNT]" \
100100
-c absorb_spills=False \
101101
-s keccak_f1600_x4_v8a_v84a_scalar_hybrid_loop \
102102
-e keccak_f1600_x4_v8a_v84a_scalar_hybrid_loop_end

dev/fips202/aarch64/src/keccak_f1600_x1_scalar_asm.S

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,39 @@
7171

7272
/************************ MACROS ****************************/
7373

74-
#define STACK_LOCS 4
74+
#define MLK_STACK_LOCS 4
7575

76-
#define STACK_SIZE (16*6 + (STACK_LOCS) * 8)
77-
#define STACK_BASE_GPRS (3*8+8)
78-
#define STACK_LOC_INPUT (0*8)
79-
#define STACK_LOC_CONST (1*8)
80-
#define STACK_LOC_COUNT (2*8)
81-
#define STACK_LOC_MISC0 (3*8)
76+
#define MLK_STACK_SIZE (16*6 + (MLK_STACK_LOCS) * 8)
77+
#define MLK_STACK_BASE_GPRS (3*8+8)
78+
#define MLK_STACK_LOC_INPUT (0*8)
79+
#define MLK_STACK_LOC_CONST (1*8)
80+
#define MLK_STACK_LOC_COUNT (2*8)
81+
#define MLK_STACK_LOC_MISC0 (3*8)
8282

8383
.macro alloc_stack
84-
sub sp, sp, #(STACK_SIZE)
84+
sub sp, sp, #(MLK_STACK_SIZE)
8585
.endm
8686

8787
.macro free_stack
88-
add sp, sp, #(STACK_SIZE)
88+
add sp, sp, #(MLK_STACK_SIZE)
8989
.endm
9090

9191
.macro save_gprs
92-
stp x19, x20, [sp, #(STACK_BASE_GPRS + 16*0)]
93-
stp x21, x22, [sp, #(STACK_BASE_GPRS + 16*1)]
94-
stp x23, x24, [sp, #(STACK_BASE_GPRS + 16*2)]
95-
stp x25, x26, [sp, #(STACK_BASE_GPRS + 16*3)]
96-
stp x27, x28, [sp, #(STACK_BASE_GPRS + 16*4)]
97-
stp x29, x30, [sp, #(STACK_BASE_GPRS + 16*5)]
92+
stp x19, x20, [sp, #(MLK_STACK_BASE_GPRS + 16*0)]
93+
stp x21, x22, [sp, #(MLK_STACK_BASE_GPRS + 16*1)]
94+
stp x23, x24, [sp, #(MLK_STACK_BASE_GPRS + 16*2)]
95+
stp x25, x26, [sp, #(MLK_STACK_BASE_GPRS + 16*3)]
96+
stp x27, x28, [sp, #(MLK_STACK_BASE_GPRS + 16*4)]
97+
stp x29, x30, [sp, #(MLK_STACK_BASE_GPRS + 16*5)]
9898
.endm
9999

100100
.macro restore_gprs
101-
ldp x19, x20, [sp, #(STACK_BASE_GPRS + 16*0)]
102-
ldp x21, x22, [sp, #(STACK_BASE_GPRS + 16*1)]
103-
ldp x23, x24, [sp, #(STACK_BASE_GPRS + 16*2)]
104-
ldp x25, x26, [sp, #(STACK_BASE_GPRS + 16*3)]
105-
ldp x27, x28, [sp, #(STACK_BASE_GPRS + 16*4)]
106-
ldp x29, x30, [sp, #(STACK_BASE_GPRS + 16*5)]
101+
ldp x19, x20, [sp, #(MLK_STACK_BASE_GPRS + 16*0)]
102+
ldp x21, x22, [sp, #(MLK_STACK_BASE_GPRS + 16*1)]
103+
ldp x23, x24, [sp, #(MLK_STACK_BASE_GPRS + 16*2)]
104+
ldp x25, x26, [sp, #(MLK_STACK_BASE_GPRS + 16*3)]
105+
ldp x27, x28, [sp, #(MLK_STACK_BASE_GPRS + 16*4)]
106+
ldp x29, x30, [sp, #(MLK_STACK_BASE_GPRS + 16*5)]
107107
.endm
108108

109109
.macro load_state
@@ -164,7 +164,7 @@
164164
ror Asu, Asu,#(64-55)
165165
.endm
166166

167-
#define KECCAK_F1600_ROUNDS 24
167+
#define MLK_KECCAK_F1600_ROUNDS 24
168168

169169
.text
170170
.global MLK_ASM_NAMESPACE(keccak_f1600_x1_scalar_asm)
@@ -175,9 +175,9 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x1_scalar_asm)
175175

176176
keccak_f1600_x1_scalar_initial:
177177
mov const_addr, input_rc
178-
str input_rc, [sp, #STACK_LOC_CONST]
178+
str input_rc, [sp, #MLK_STACK_LOC_CONST]
179179
load_state
180-
str input_addr, [sp, #STACK_LOC_INPUT] // @slothy:writes=STACK_LOC_INPUT
180+
str input_addr, [sp, #MLK_STACK_LOC_INPUT] // @slothy:writes=MLK_STACK_LOC_INPUT
181181

182182
// (Optimized for Cortex-A55)
183183
// Instructions: 107
@@ -209,7 +209,7 @@ keccak_f1600_x1_scalar_initial:
209209
eor x30, x30, x29, ror #63 // .........*............................................
210210
eor x22, x22, x30 // ..........*...........................................
211211
eor x23, x23, x30 // ..........*...........................................
212-
str x23, [sp, #STACK_LOC_MISC0] // ...........*..........................................
212+
str x23, [sp, #MLK_STACK_LOC_MISC0] // ...........*..........................................
213213
eor x23, x14, x15 // ...........*..........................................
214214
eor x14, x14, x0 // ............*.........................................
215215
eor x23, x23, x11 // ............*.........................................
@@ -237,7 +237,7 @@ keccak_f1600_x1_scalar_initial:
237237
eor x12, x3, x27 // ........................*.............................
238238
bic x3, x13, x17, ror #19 // ........................*.............................
239239
eor x5, x5, x27 // .........................*............................
240-
ldr x27, [sp, #STACK_LOC_MISC0] // .........................*............................
240+
ldr x27, [sp, #MLK_STACK_LOC_MISC0] // .........................*............................
241241
bic x25, x17, x2, ror #5 // ..........................*...........................
242242
eor x9, x9, x29 // ..........................*...........................
243243
eor x23, x25, x5, ror #52 // ...........................*..........................
@@ -267,12 +267,12 @@ keccak_f1600_x1_scalar_initial:
267267
eor x12, x15, x12, ror #58 // .......................................*..............
268268
eor x15, x5, x27, ror #27 // .......................................*..............
269269
eor x5, x20, x11, ror #41 // ........................................*.............
270-
ldr x11, [sp, #STACK_LOC_CONST] // ........................................*.............
270+
ldr x11, [sp, #MLK_STACK_LOC_CONST] // ........................................*.............
271271
eor x20, x17, x4, ror #21 // .........................................*............
272272
eor x17, x24, x9, ror #47 // .........................................*............
273273
mov x24, #1 // ..........................................*...........
274274
bic x9, x0, x16, ror #9 // ..........................................*...........
275-
str x24, [sp, #STACK_LOC_COUNT] // ...........................................*..........
275+
str x24, [sp, #MLK_STACK_LOC_COUNT] // ...........................................*..........
276276
bic x24, x29, x1, ror #44 // ...........................................*..........
277277
bic x27, x1, x21, ror #50 // ............................................*.........
278278
bic x4, x26, x29, ror #63 // ............................................*.........
@@ -323,7 +323,7 @@ keccak_f1600_x1_scalar_initial:
323323
ror x26, x26, #58 // ........*................................................
324324
eor x16, x30, x16 // .........*...............................................
325325
eor x28, x30, x28, ror #63 // .........*...............................................
326-
str x28, [sp, #STACK_LOC_MISC0] // ..........*..............................................
326+
str x28, [sp, #MLK_STACK_LOC_MISC0] // ..........*..............................................
327327
eor x29, x29, x17, ror #36 // ..........*..............................................
328328
eor x28, x1, x2, ror #61 // ...........*.............................................
329329
eor x19, x30, x19, ror #37 // ...........*.............................................
@@ -377,9 +377,9 @@ keccak_f1600_x1_scalar_initial:
377377
eor x16, x21, x19, ror #43 // ....................................*....................
378378
eor x21, x17, x25, ror #30 // ....................................*....................
379379
bic x19, x25, x19, ror #57 // .....................................*...................
380-
ldr x25, [sp, #STACK_LOC_COUNT] // .....................................*...................
380+
ldr x25, [sp, #MLK_STACK_LOC_COUNT] // .....................................*...................
381381
eor x17, x10, x9, ror #47 // ......................................*..................
382-
ldr x9, [sp, #STACK_LOC_CONST] // ......................................*..................
382+
ldr x9, [sp, #MLK_STACK_LOC_CONST] // ......................................*..................
383383
eor x15, x20, x28, ror #27 // .......................................*.................
384384
bic x20, x4, x28, ror #2 // .......................................*.................
385385
eor x10, x20, x1, ror #50 // ........................................*................
@@ -388,10 +388,10 @@ keccak_f1600_x1_scalar_initial:
388388
bic x4, x28, x1, ror #48 // .........................................*...............
389389
bic x1, x1, x11, ror #57 // ..........................................*..............
390390
ldr x28, [x9, x25, LSL #3] // ..........................................*..............
391-
ldr x9, [sp, #STACK_LOC_MISC0] // ...........................................*.............
391+
ldr x9, [sp, #MLK_STACK_LOC_MISC0] // ...........................................*.............
392392
add x25, x25, #1 // ...........................................*.............
393-
str x25, [sp, #STACK_LOC_COUNT] // ............................................*............
394-
cmp x25, #(KECCAK_F1600_ROUNDS-1) // ............................................*............
393+
str x25, [sp, #MLK_STACK_LOC_COUNT] // ............................................*............
394+
cmp x25, #(MLK_KECCAK_F1600_ROUNDS-1) // ............................................*............
395395
eor x25, x1, x27, ror #53 // .............................................*...........
396396
bic x27, x30, x26, ror #47 // .............................................*...........
397397
eor x1, x5, x28 // ..............................................*..........
@@ -419,7 +419,7 @@ keccak_f1600_x1_scalar_initial:
419419
ble keccak_f1600_x1_scalar_loop
420420

421421
final_rotate
422-
ldr input_addr, [sp, #STACK_LOC_INPUT]
422+
ldr input_addr, [sp, #MLK_STACK_LOC_INPUT]
423423
store_state
424424

425425
restore_gprs
@@ -458,14 +458,14 @@ keccak_f1600_x1_scalar_initial:
458458

459459
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
460460
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
461-
#undef STACK_LOCS
462-
#undef STACK_SIZE
463-
#undef STACK_BASE_GPRS
464-
#undef STACK_LOC_INPUT
465-
#undef STACK_LOC_CONST
466-
#undef STACK_LOC_COUNT
467-
#undef STACK_LOC_MISC0
468-
#undef KECCAK_F1600_ROUNDS
461+
#undef MLK_STACK_LOCS
462+
#undef MLK_STACK_SIZE
463+
#undef MLK_STACK_BASE_GPRS
464+
#undef MLK_STACK_LOC_INPUT
465+
#undef MLK_STACK_LOC_CONST
466+
#undef MLK_STACK_LOC_COUNT
467+
#undef MLK_STACK_LOC_MISC0
468+
#undef MLK_KECCAK_F1600_ROUNDS
469469

470470
/* simpasm: footer-start */
471471
#endif /* MLK_FIPS202_AARCH64_NEED_X1_SCALAR && \

dev/fips202/aarch64/src/keccak_f1600_x1_v84a_asm.S

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@
216216
str Asud, [input_addr, #0xC0]
217217
.endm
218218

219-
#define STACK_SIZE (16*4) /* VREGS (16*4) */
219+
#define MLK_STACK_SIZE (16*4) /* VREGS (16*4) */
220220

221-
#define STACK_BASE_GPRS (16*4)
221+
#define MLK_STACK_BASE_GPRS (16*4)
222222
.macro alloc_stack
223-
sub sp, sp, #(STACK_SIZE)
223+
sub sp, sp, #(MLK_STACK_SIZE)
224224
.endm
225225

226226
.macro free_stack
227-
add sp, sp, #(STACK_SIZE)
227+
add sp, sp, #(MLK_STACK_SIZE)
228228
.endm
229229

230230
.macro save_vregs
@@ -339,7 +339,7 @@
339339

340340
.endm
341341

342-
#define KECCAK_F1600_ROUNDS 24
342+
#define MLK_KECCAK_F1600_ROUNDS 24
343343

344344
.text
345345
.global MLK_ASM_NAMESPACE(keccak_f1600_x1_v84a_asm)
@@ -349,7 +349,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x1_v84a_asm)
349349
save_vregs
350350
load_input
351351

352-
mov count, #(KECCAK_F1600_ROUNDS)
352+
mov count, #(MLK_KECCAK_F1600_ROUNDS)
353353
keccak_f1600_x1_v84a_loop:
354354
keccak_f1600_round
355355
sub count, count, #1
@@ -478,9 +478,9 @@ keccak_f1600_x1_v84a_loop:
478478

479479
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
480480
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
481-
#undef STACK_SIZE
482-
#undef STACK_BASE_GPRS
483-
#undef KECCAK_F1600_ROUNDS
481+
#undef MLK_STACK_SIZE
482+
#undef MLK_STACK_BASE_GPRS
483+
#undef MLK_KECCAK_F1600_ROUNDS
484484

485485
/* simpasm: footer-start */
486486
#endif /* __ARM_FEATURE_SHA3 */

dev/fips202/aarch64/src/keccak_f1600_x2_v84a_asm.S

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@
198198
store_lane_single Asu, 12
199199
.endm
200200

201-
#define STACK_SIZE (16*4) /* VREGS (16*4) */
201+
#define MLK_STACK_SIZE (16*4) /* VREGS (16*4) */
202202

203-
#define STACK_BASE_GPRS (16*4)
203+
#define MLK_STACK_BASE_GPRS (16*4)
204204
.macro alloc_stack
205-
sub sp, sp, #(STACK_SIZE)
205+
sub sp, sp, #(MLK_STACK_SIZE)
206206
.endm
207207

208208
.macro free_stack
209-
add sp, sp, #(STACK_SIZE)
209+
add sp, sp, #(MLK_STACK_SIZE)
210210
.endm
211211

212212
.macro save_vregs
@@ -321,7 +321,7 @@
321321

322322
.endm
323323

324-
#define KECCAK_F1600_ROUNDS 24
324+
#define MLK_KECCAK_F1600_ROUNDS 24
325325

326326
.text
327327
.global MLK_ASM_NAMESPACE(keccak_f1600_x2_v84a_asm)
@@ -332,7 +332,7 @@ MLK_ASM_FN_SYMBOL(keccak_f1600_x2_v84a_asm)
332332
save_vregs
333333
load_input
334334

335-
mov count, #(KECCAK_F1600_ROUNDS)
335+
mov count, #(MLK_KECCAK_F1600_ROUNDS)
336336
keccak_f1600_x2_v84a_loop:
337337
keccak_f1600_round
338338
sub count, count, #1
@@ -423,9 +423,9 @@ keccak_f1600_x2_v84a_loop:
423423

424424
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
425425
* Don't modify by hand -- this is auto-generated by scripts/autogen. */
426-
#undef STACK_SIZE
427-
#undef STACK_BASE_GPRS
428-
#undef KECCAK_F1600_ROUNDS
426+
#undef MLK_STACK_SIZE
427+
#undef MLK_STACK_BASE_GPRS
428+
#undef MLK_KECCAK_F1600_ROUNDS
429429

430430
/* simpasm: footer-start */
431431
#endif /* __ARM_FEATURE_SHA3 */

0 commit comments

Comments
 (0)