Skip to content

Commit 9ff0bad

Browse files
committed
native: Allow tables to be declared static
When building single-CU builds and MLK_CONFIG_INTERNAL_API_QUALIFIER is set to make internal API static, also make the data tables static. This makes the data symbols local instead of global, hiding them from the scope of the rest of the application. Add MLK_INTERNAL_DATA_DECLARATION (defaulting to extern) and MLK_INTERNAL_DATA_DEFINITION (defaulting to empty) macros. When MLK_CONFIG_INTERNAL_API_QUALIFIER is set, both expand to its value (e.g. static). Also add explicit lengths to all constant array declarations and refactor scripts/autogen to use a new emit_c_array() helper for all generated C array definitions, so sizes are always explicit (e.g., mlk_rej_uniform_table[4096] instead of mlk_rej_uniform_table[]). Ports pq-code-package/mldsa-native#1043 Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
1 parent 9c6cae6 commit 9ff0bad

63 files changed

Lines changed: 3425 additions & 3285 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev/aarch64_clean/src/aarch64_zetas.c

Lines changed: 143 additions & 135 deletions
Large diffs are not rendered by default.

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
MLK_NAMESPACE(aarch64_zetas_mulcache_twisted_native)
2222
#define mlk_rej_uniform_table MLK_NAMESPACE(rej_uniform_table)
2323

24-
extern const int16_t mlk_aarch64_ntt_zetas_layer12345[];
25-
extern const int16_t mlk_aarch64_ntt_zetas_layer67[];
26-
extern const int16_t mlk_aarch64_invntt_zetas_layer12345[];
27-
extern const int16_t mlk_aarch64_invntt_zetas_layer67[];
28-
extern const int16_t mlk_aarch64_zetas_mulcache_native[];
29-
extern const int16_t mlk_aarch64_zetas_mulcache_twisted_native[];
30-
extern const uint8_t mlk_rej_uniform_table[];
24+
MLK_INTERNAL_DATA_DECLARATION const int16_t
25+
mlk_aarch64_ntt_zetas_layer12345[80];
26+
MLK_INTERNAL_DATA_DECLARATION const int16_t mlk_aarch64_ntt_zetas_layer67[384];
27+
MLK_INTERNAL_DATA_DECLARATION const int16_t
28+
mlk_aarch64_invntt_zetas_layer12345[80];
29+
MLK_INTERNAL_DATA_DECLARATION const int16_t
30+
mlk_aarch64_invntt_zetas_layer67[384];
31+
MLK_INTERNAL_DATA_DECLARATION const int16_t
32+
mlk_aarch64_zetas_mulcache_native[128];
33+
MLK_INTERNAL_DATA_DECLARATION const int16_t
34+
mlk_aarch64_zetas_mulcache_twisted_native[128];
35+
MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_rej_uniform_table[4096];
3136

3237
#define mlk_ntt_asm MLK_NAMESPACE(ntt_asm)
3338
void mlk_ntt_asm(int16_t p[256], const int16_t twiddles12345[80],

dev/aarch64_clean/src/rej_uniform_table.c

Lines changed: 514 additions & 513 deletions
Large diffs are not rendered by default.

dev/aarch64_opt/src/aarch64_zetas.c

Lines changed: 143 additions & 135 deletions
Large diffs are not rendered by default.

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
MLK_NAMESPACE(aarch64_zetas_mulcache_twisted_native)
2222
#define mlk_rej_uniform_table MLK_NAMESPACE(rej_uniform_table)
2323

24-
extern const int16_t mlk_aarch64_ntt_zetas_layer12345[];
25-
extern const int16_t mlk_aarch64_ntt_zetas_layer67[];
26-
extern const int16_t mlk_aarch64_invntt_zetas_layer12345[];
27-
extern const int16_t mlk_aarch64_invntt_zetas_layer67[];
28-
extern const int16_t mlk_aarch64_zetas_mulcache_native[];
29-
extern const int16_t mlk_aarch64_zetas_mulcache_twisted_native[];
30-
extern const uint8_t mlk_rej_uniform_table[];
24+
MLK_INTERNAL_DATA_DECLARATION const int16_t
25+
mlk_aarch64_ntt_zetas_layer12345[80];
26+
MLK_INTERNAL_DATA_DECLARATION const int16_t mlk_aarch64_ntt_zetas_layer67[384];
27+
MLK_INTERNAL_DATA_DECLARATION const int16_t
28+
mlk_aarch64_invntt_zetas_layer12345[80];
29+
MLK_INTERNAL_DATA_DECLARATION const int16_t
30+
mlk_aarch64_invntt_zetas_layer67[384];
31+
MLK_INTERNAL_DATA_DECLARATION const int16_t
32+
mlk_aarch64_zetas_mulcache_native[128];
33+
MLK_INTERNAL_DATA_DECLARATION const int16_t
34+
mlk_aarch64_zetas_mulcache_twisted_native[128];
35+
MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_rej_uniform_table[4096];
3136

3237
#define mlk_ntt_asm MLK_NAMESPACE(ntt_asm)
3338
void mlk_ntt_asm(int16_t p[256], const int16_t twiddles12345[80],

dev/aarch64_opt/src/rej_uniform_table.c

Lines changed: 514 additions & 513 deletions
Large diffs are not rendered by default.

dev/fips202/aarch64/src/fips202_native_aarch64.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#define mlk_keccakf1600_round_constants \
1212
MLK_NAMESPACE(keccakf1600_round_constants)
13-
extern const uint64_t mlk_keccakf1600_round_constants[];
13+
MLK_INTERNAL_DATA_DECLARATION const uint64_t
14+
mlk_keccakf1600_round_constants[24];
1415

1516
#define mlk_keccak_f1600_x1_scalar_asm MLK_NAMESPACE(keccak_f1600_x1_scalar_asm)
1617
void mlk_keccak_f1600_x1_scalar_asm(uint64_t state[25], const uint64_t rc[24])

dev/fips202/aarch64/src/keccakf1600_round_constants.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020

2121
#include "fips202_native_aarch64.h"
2222

23-
MLK_ALIGN const uint64_t mlk_keccakf1600_round_constants[] = {
24-
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
25-
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
26-
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
27-
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
28-
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
29-
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
30-
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
31-
0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
23+
MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint64_t
24+
mlk_keccakf1600_round_constants[24] = {
25+
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
26+
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
27+
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
28+
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
29+
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
30+
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
31+
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
32+
0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
3233
};
3334

3435
#else /* (MLK_FIPS202_AARCH64_NEED_X1_SCALAR || \

dev/fips202/armv81m/src/fips202_native_armv81m.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
/* Keccak round constants in bit-interleaved form */
1111
#define mlk_keccakf1600_round_constants \
1212
MLK_NAMESPACE(keccakf1600_round_constants)
13-
extern const uint32_t mlk_keccakf1600_round_constants[48];
13+
MLK_INTERNAL_DATA_DECLARATION const uint32_t
14+
mlk_keccakf1600_round_constants[48];
1415

1516
#define mlk_keccak_f1600_x4_mve_asm MLK_NAMESPACE(keccak_f1600_x4_mve_asm)
1617
void mlk_keccak_f1600_x4_mve_asm(uint64_t state[100], uint64_t tmpstate[100],

dev/fips202/armv81m/src/keccakf1600_round_constants.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,32 @@
1616
* - low word contains even-indexed bits
1717
* - high word contains odd-indexed bits
1818
*/
19-
MLK_ALIGN const uint32_t mlk_keccakf1600_round_constants[48] = {
20-
0x00000001, 0x00000000, /* RC0 */
21-
0x00000000, 0x00000089, /* RC1 */
22-
0x00000000, 0x8000008b, /* RC2 */
23-
0x00000000, 0x80008080, /* RC3 */
24-
0x00000001, 0x0000008b, /* RC4 */
25-
0x00000001, 0x00008000, /* RC5 */
26-
0x00000001, 0x80008088, /* RC6 */
27-
0x00000001, 0x80000082, /* RC7 */
28-
0x00000000, 0x0000000b, /* RC8 */
29-
0x00000000, 0x0000000a, /* RC9 */
30-
0x00000001, 0x00008082, /* RC10 */
31-
0x00000000, 0x00008003, /* RC11 */
32-
0x00000001, 0x0000808b, /* RC12 */
33-
0x00000001, 0x8000000b, /* RC13 */
34-
0x00000001, 0x8000008a, /* RC14 */
35-
0x00000001, 0x80000081, /* RC15 */
36-
0x00000000, 0x80000081, /* RC16 */
37-
0x00000000, 0x80000008, /* RC17 */
38-
0x00000000, 0x00000083, /* RC18 */
39-
0x00000000, 0x80008003, /* RC19 */
40-
0x00000001, 0x80008088, /* RC20 */
41-
0x00000000, 0x80000088, /* RC21 */
42-
0x00000001, 0x00008000, /* RC22 */
43-
0x00000000, 0x80008082, /* RC23 */
19+
MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint32_t
20+
mlk_keccakf1600_round_constants[48] = {
21+
0x00000001, 0x00000000, /* RC0 */
22+
0x00000000, 0x00000089, /* RC1 */
23+
0x00000000, 0x8000008b, /* RC2 */
24+
0x00000000, 0x80008080, /* RC3 */
25+
0x00000001, 0x0000008b, /* RC4 */
26+
0x00000001, 0x00008000, /* RC5 */
27+
0x00000001, 0x80008088, /* RC6 */
28+
0x00000001, 0x80000082, /* RC7 */
29+
0x00000000, 0x0000000b, /* RC8 */
30+
0x00000000, 0x0000000a, /* RC9 */
31+
0x00000001, 0x00008082, /* RC10 */
32+
0x00000000, 0x00008003, /* RC11 */
33+
0x00000001, 0x0000808b, /* RC12 */
34+
0x00000001, 0x8000000b, /* RC13 */
35+
0x00000001, 0x8000008a, /* RC14 */
36+
0x00000001, 0x80000081, /* RC15 */
37+
0x00000000, 0x80000081, /* RC16 */
38+
0x00000000, 0x80000008, /* RC17 */
39+
0x00000000, 0x00000083, /* RC18 */
40+
0x00000000, 0x80008003, /* RC19 */
41+
0x00000001, 0x80008088, /* RC20 */
42+
0x00000000, 0x80000088, /* RC21 */
43+
0x00000001, 0x00008000, /* RC22 */
44+
0x00000000, 0x80008082, /* RC23 */
4445
};
4546

4647
#else /* MLK_FIPS202_ARMV81M_NEED_X4 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */

0 commit comments

Comments
 (0)