Skip to content

Commit

Permalink
Namespacing: Use mlk_xxx prefix for all identifiers of global scope
Browse files Browse the repository at this point in the history
This commit changes the name of all identifiers in global scope
by adding a prefix `mlk_`. For example, `check_pk` becomes `mlk_check_pk`,
and the struct `poly` becomes `mlk_poly`.

Excluded is the standard crypto_kem_xxx API, which stays as is.

Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
  • Loading branch information
hanno-becker committed Feb 6, 2025
1 parent 94c8b47 commit bc96b5d
Show file tree
Hide file tree
Showing 247 changed files with 2,019 additions and 1,942 deletions.
6 changes: 3 additions & 3 deletions dev/aarch64_clean/src/aarch64_zetas.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Table of zeta values used in the AArch64 forward NTT
* See autogen for details.
*/
MLK_ALIGN const int16_t aarch64_ntt_zetas_layer01234[] = {
MLK_ALIGN const int16_t mlk_aarch64_ntt_zetas_layer01234[] = {
-1600, -15749, -749, -7373, -40, -394, -687, -6762, 630, 6201,
-1432, -14095, 848, 8347, 0, 0, 1062, 10453, 296, 2914,
-882, -8682, 0, 0, -1410, -13879, 1339, 13180, 1476, 14529,
Expand All @@ -31,7 +31,7 @@ MLK_ALIGN const int16_t aarch64_ntt_zetas_layer01234[] = {
0, 0, -1583, -15582, -1355, -13338, 821, 8081, 0, 0,
};

MLK_ALIGN const int16_t aarch64_ntt_zetas_layer56[] = {
MLK_ALIGN const int16_t mlk_aarch64_ntt_zetas_layer56[] = {
289, 289, 331, 331, -76, -76, -1573, -1573, 2845,
2845, 3258, 3258, -748, -748, -15483, -15483, 17, 17,
583, 583, 1637, 1637, -1041, -1041, 167, 167, 5739,
Expand Down Expand Up @@ -88,7 +88,7 @@ MLK_ALIGN const int16_t aarch64_invntt_zetas_layer01234[] = {
-848, -8347, 1432, 14095, -630, -6201, 687, 6762, 0, 0,
};

MLK_ALIGN const int16_t aarch64_invntt_zetas_layer56[] = {
MLK_ALIGN const int16_t mlk_aarch64_invntt_zetas_layer56[] = {
-910, -910, -1227, -1227, 219, 219, 855, 855, -8957,
-8957, -12078, -12078, 2156, 2156, 8416, 8416, 1175, 1175,
394, 394, -1029, -1029, -1212, -1212, 11566, 11566, 3878,
Expand Down
44 changes: 23 additions & 21 deletions dev/aarch64_clean/src/arith_native_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,51 @@
#include <stdint.h>
#include "../../../common.h"

#define aarch64_ntt_zetas_layer01234 MLK_NAMESPACE(aarch64_ntt_zetas_layer01234)
#define aarch64_ntt_zetas_layer56 MLK_NAMESPACE(aarch64_ntt_zetas_layer56)
#define mlk_aarch64_ntt_zetas_layer01234 \
MLK_NAMESPACE(aarch64_ntt_zetas_layer01234)
#define mlk_aarch64_ntt_zetas_layer56 MLK_NAMESPACE(aarch64_ntt_zetas_layer56)
#define aarch64_invntt_zetas_layer01234 \
MLK_NAMESPACE(aarch64_invntt_zetas_layer01234)
#define aarch64_invntt_zetas_layer56 MLK_NAMESPACE(aarch64_invntt_zetas_layer56)
#define mlk_aarch64_invntt_zetas_layer56 \
MLK_NAMESPACE(aarch64_invntt_zetas_layer56)
#define aarch64_zetas_mulcache_native \
MLK_NAMESPACE(aarch64_zetas_mulcache_native)
#define aarch64_zetas_mulcache_twisted_native \
MLK_NAMESPACE(aarch64_zetas_mulcache_twisted_native)
#define rej_uniform_table MLK_NAMESPACE(rej_uniform_table)
#define mlk_rej_uniform_table MLK_NAMESPACE(rej_uniform_table)

extern const int16_t aarch64_ntt_zetas_layer01234[];
extern const int16_t aarch64_ntt_zetas_layer56[];
extern const int16_t mlk_aarch64_ntt_zetas_layer01234[];
extern const int16_t mlk_aarch64_ntt_zetas_layer56[];
extern const int16_t aarch64_invntt_zetas_layer01234[];
extern const int16_t aarch64_invntt_zetas_layer56[];
extern const int16_t mlk_aarch64_invntt_zetas_layer56[];
extern const int16_t aarch64_zetas_mulcache_native[];
extern const int16_t aarch64_zetas_mulcache_twisted_native[];
extern const uint8_t rej_uniform_table[];
extern const uint8_t mlk_rej_uniform_table[];

#define ntt_asm_clean MLK_NAMESPACE(ntt_asm_clean)
void ntt_asm_clean(int16_t *, const int16_t *, const int16_t *);
#define mlk_ntt_asm_clean MLK_NAMESPACE(ntt_asm_clean)
void mlk_ntt_asm_clean(int16_t *, const int16_t *, const int16_t *);

#define intt_asm_clean MLK_NAMESPACE(intt_asm_clean)
void intt_asm_clean(int16_t *, const int16_t *, const int16_t *);
#define mlk_intt_asm_clean MLK_NAMESPACE(intt_asm_clean)
void mlk_intt_asm_clean(int16_t *, const int16_t *, const int16_t *);

#define rej_uniform_asm_clean MLK_NAMESPACE(rej_uniform_asm_clean)
unsigned rej_uniform_asm_clean(int16_t *r, const uint8_t *buf, unsigned buflen,
const uint8_t *table);
#define mlk_rej_uniform_asm_clean MLK_NAMESPACE(rej_uniform_asm_clean)
unsigned mlk_rej_uniform_asm_clean(int16_t *r, const uint8_t *buf,
unsigned buflen, const uint8_t *table);

#define poly_reduce_asm_clean MLK_NAMESPACE(poly_reduce_asm_clean)
void poly_reduce_asm_clean(int16_t *);
#define mlk_poly_reduce_asm_clean MLK_NAMESPACE(poly_reduce_asm_clean)
void mlk_poly_reduce_asm_clean(int16_t *);

#define poly_tomont_asm_clean MLK_NAMESPACE(poly_tomont_asm_clean)
void poly_tomont_asm_clean(int16_t *);
#define mlk_poly_tomont_asm_clean MLK_NAMESPACE(poly_tomont_asm_clean)
void mlk_poly_tomont_asm_clean(int16_t *);

#define poly_mulcache_compute_asm_clean \
MLK_NAMESPACE(poly_mulcache_compute_asm_clean)
void poly_mulcache_compute_asm_clean(int16_t *, const int16_t *,
const int16_t *, const int16_t *);


#define poly_tobytes_asm_clean MLK_NAMESPACE(poly_tobytes_asm_clean)
void poly_tobytes_asm_clean(uint8_t *r, const int16_t *a);
#define mlk_poly_tobytes_asm_clean MLK_NAMESPACE(poly_tobytes_asm_clean)
void mlk_poly_tobytes_asm_clean(uint8_t *r, const int16_t *a);

#define polyvec_basemul_acc_montgomery_cached_asm_k2_clean \
MLK_NAMESPACE(polyvec_basemul_acc_montgomery_cached_asm_k2_clean)
Expand Down
15 changes: 8 additions & 7 deletions dev/aarch64_clean/src/clean_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@

static MLK_INLINE void ntt_native(int16_t data[MLKEM_N])
{
ntt_asm_clean(data, aarch64_ntt_zetas_layer01234, aarch64_ntt_zetas_layer56);
mlk_ntt_asm_clean(data, mlk_aarch64_ntt_zetas_layer01234,
mlk_aarch64_ntt_zetas_layer56);
}

static MLK_INLINE void intt_native(int16_t data[MLKEM_N])
{
intt_asm_clean(data, aarch64_invntt_zetas_layer01234,
aarch64_invntt_zetas_layer56);
mlk_intt_asm_clean(data, aarch64_invntt_zetas_layer01234,
mlk_aarch64_invntt_zetas_layer56);
}

static MLK_INLINE void poly_reduce_native(int16_t data[MLKEM_N])
{
poly_reduce_asm_clean(data);
mlk_poly_reduce_asm_clean(data);
}

static MLK_INLINE void poly_tomont_native(int16_t data[MLKEM_N])
{
poly_tomont_asm_clean(data);
mlk_poly_tomont_asm_clean(data);
}

static MLK_INLINE void poly_mulcache_compute_native(int16_t x[MLKEM_N / 2],
Expand Down Expand Up @@ -76,7 +77,7 @@ static MLK_INLINE void polyvec_basemul_acc_montgomery_cached_k4_native(
static MLK_INLINE void poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
const int16_t a[MLKEM_N])
{
poly_tobytes_asm_clean(r, a);
mlk_poly_tobytes_asm_clean(r, a);
}

static MLK_INLINE int rej_uniform_native(int16_t *r, unsigned len,
Expand All @@ -86,7 +87,7 @@ static MLK_INLINE int rej_uniform_native(int16_t *r, unsigned len,
{
return -1;
}
return (int)rej_uniform_asm_clean(r, buf, buflen, rej_uniform_table);
return (int)mlk_rej_uniform_asm_clean(r, buf, buflen, mlk_rej_uniform_table);
}

#endif /* MLK_ARITH_PROFILE_IMPL_H */
Expand Down
4 changes: 2 additions & 2 deletions dev/aarch64_clean/src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <stdint.h>
#include "../../../common.h"

#define zetas_mulcache_native MLK_NAMESPACE(zetas_mulcache_native)
extern const int16_t zetas_mulcache_native[256];
#define mlk_zetas_mulcache_native MLK_NAMESPACE(zetas_mulcache_native)
extern const int16_t mlk_zetas_mulcache_native[256];

#define zetas_mulcache_twisted_native \
MLK_NAMESPACE(zetas_mulcache_twisted_native)
Expand Down
10 changes: 5 additions & 5 deletions dev/aarch64_clean/src/intt_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
mulmod \dst3, \src3, ninv, ninv_tw
.endm

.macro barrett_reduce a
.macro mlk_barrett_reduce a
sqdmulh t0.8h, \a\().8h, consts.h[1]
srshr t0.8h, t0.8h, #11
mls \a\().8h, t0.8h, consts.h[0]
Expand Down Expand Up @@ -271,10 +271,10 @@ layer3456_start:

// Not all of those reductions are needed, but the bounds tracking
// is easier if we uniformly reduce at this point.
barrett_reduce data0
barrett_reduce data2
barrett_reduce data1
barrett_reduce data3
mlk_barrett_reduce data0
mlk_barrett_reduce data2
mlk_barrett_reduce data1
mlk_barrett_reduce data3

// Bounds: q/2

Expand Down
2 changes: 1 addition & 1 deletion dev/aarch64_clean/src/ntt_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ MLK_ASM_NAMESPACE(ntt_asm_clean):
// is modified through the addition/subtraction of a Montgomery
// product of a twiddle of absolute value < q/2 and a layer-N value.
// - Recalling that for C such that |a| < C * q and |t|<q/2, we have
// |fqmul(a,t)| < q * (0.0254*C + 1/2), we see that the coefficients
// |mlk_fqmul(a,t)| < q * (0.0254*C + 1/2), we see that the coefficients
// of layer N (starting with layer 0 = input data) are bound by q * f^N(1),
// where f(C) = 1/2 + 1.0508*C.
// For N=7, we get the bound of f^7(1) * q < 18295.
Expand Down
20 changes: 10 additions & 10 deletions dev/aarch64_clean/src/optimize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
TARGET_NAME="Cortex-A55"
TARGET=Arm_Cortex_A55

echo "* polyvec_basemul_acc_montgomery_cached, K=2, ${TARGET_NAME}"
echo "* mlk_polyvec_basemul_acc_montgomery_cached, K=2, ${TARGET_NAME}"

cp polyvec_clean.S polyvec_opt.S

Expand All @@ -23,7 +23,7 @@ slothy-cli Arm_AArch64 $TARGET \
-c variable_size \
-c constraints.stalls_first_attempt=64

echo "* polyvec_basemul_acc_montgomery_cached, K=3, ${TARGET_NAME}"
echo "* mlk_polyvec_basemul_acc_montgomery_cached, K=3, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
polyvec_opt.S -o polyvec_opt.S \
Expand All @@ -37,7 +37,7 @@ slothy-cli Arm_AArch64 $TARGET \
-c variable_size \
-c constraints.stalls_first_attempt=64

echo "* polyvec_basemul_acc_montgomery_cached, K=4, ${TARGET_NAME}"
echo "* mlk_polyvec_basemul_acc_montgomery_cached, K=4, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
polyvec_opt.S -o polyvec_opt.S \
Expand All @@ -53,11 +53,11 @@ slothy-cli Arm_AArch64 $TARGET \

cp poly_clean.S poly_opt.S

echo "* poly_reduce, ${TARGET_NAME}"
echo "* mlk_poly_reduce, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
poly_opt.S -o poly_opt.S \
-r poly_reduce_asm_clean,poly_reduce_asm_opt \
-r mlk_poly_reduce_asm_clean,mlk_poly_reduce_asm_opt \
-l loop_start \
-c sw_pipelining.enabled=true \
-c inputs_are_outputs \
Expand All @@ -66,7 +66,7 @@ slothy-cli Arm_AArch64 $TARGET \
-c variable_size \
-c constraints.stalls_first_attempt=64

echo "* poly_mulcache_compute, ${TARGET_NAME}"
echo "* mlk_poly_mulcache_compute, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
poly_opt.S -o poly_opt.S \
Expand All @@ -79,11 +79,11 @@ slothy-cli Arm_AArch64 $TARGET \
-c variable_size \
-c constraints.stalls_first_attempt=64

echo "* poly_tomont, ${TARGET_NAME}"
echo "* mlk_poly_tomont, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
poly_opt.S -o poly_opt.S \
-r poly_tomont_asm_clean,poly_tomont_asm_opt \
-r mlk_poly_tomont_asm_clean,mlk_poly_tomont_asm_opt \
-l poly_tomont_asm_loop \
-c sw_pipelining.enabled=true \
-c inputs_are_outputs \
Expand All @@ -96,7 +96,7 @@ echo " * ntt, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
ntt_clean.S -o ntt_opt.S \
-r ntt_asm_clean,ntt_asm_opt \
-r mlk_ntt_asm_clean,mlk_ntt_asm_opt \
-l layer123_start \
-l layer4567_start \
-c sw_pipelining.enabled=true \
Expand All @@ -110,7 +110,7 @@ echo " * intt, ${TARGET_NAME}"

slothy-cli Arm_AArch64 $TARGET \
intt_clean.S -o intt_opt.S \
-r intt_asm_clean,intt_asm_opt \
-r mlk_intt_asm_clean,mlk_intt_asm_opt \
-l layer123_start \
-l layer4567_start \
-c sw_pipelining.enabled=true \
Expand Down
2 changes: 1 addition & 1 deletion dev/aarch64_clean/src/poly_mulcache_compute_asm_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.endm

/********************************************
* poly_mulcache_compute() *
* mlk_poly_mulcache_compute() *
********************************************/

cache_ptr .req x0
Expand Down
12 changes: 6 additions & 6 deletions dev/aarch64_clean/src/poly_reduce_asm_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* simpasm: header-end */

/* Barrett reduction */
.macro barrett_reduce a
.macro mlk_barrett_reduce a
sqdmulh tmp.8h, \a\().8h, modulus_twisted.h[0]
srshr tmp.8h, tmp.8h, #11
mls \a\().8h, tmp.8h, modulus.h[0]
Expand All @@ -26,7 +26,7 @@
.endm

/**********************************
* poly_reduce() *
* mlk_poly_reduce() *
**********************************/

ptr .req x0
Expand Down Expand Up @@ -55,22 +55,22 @@ MLK_ASM_NAMESPACE(poly_reduce_asm_clean):
mov count, #8
loop_start:
ldr q_data, [ptr], #64
barrett_reduce data
mlk_barrett_reduce data
scalar_signed_to_unsigned data
str q_data, [ptr, #-64]

ldr q_data, [ptr, #-48]
barrett_reduce data
mlk_barrett_reduce data
scalar_signed_to_unsigned data
str q_data, [ptr, #-48]

ldr q_data, [ptr, #-32]
barrett_reduce data
mlk_barrett_reduce data
scalar_signed_to_unsigned data
str q_data, [ptr, #-32]

ldr q_data, [ptr, #-16]
barrett_reduce data
mlk_barrett_reduce data
scalar_signed_to_unsigned data
str q_data, [ptr, #-16]

Expand Down
2 changes: 1 addition & 1 deletion dev/aarch64_clean/src/poly_tobytes_asm_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* simpasm: header-end */

/********************************************
* poly_tobytes() *
* mlk_poly_tobytes() *
********************************************/

data0 .req v0
Expand Down
2 changes: 1 addition & 1 deletion dev/aarch64_clean/src/poly_tomont_asm_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.endm

/**********************************
* poly_tomont() *
* mlk_poly_tomont() *
**********************************/

src .req x0
Expand Down
2 changes: 1 addition & 1 deletion dev/aarch64_clean/src/rej_uniform_asm_clean.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*************************************************
* Name: rej_uniform_asm_clean
* Name: mlk_rej_uniform_asm_clean
*
* Description: Run rejection sampling on uniform random bytes to generate
* uniform random integers mod q
Expand Down
2 changes: 1 addition & 1 deletion dev/aarch64_clean/src/rej_uniform_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Lookup table used by rejection sampling of the public matrix.
* See autogen for details.
*/
MLK_ALIGN const uint8_t rej_uniform_table[] = {
MLK_ALIGN const uint8_t mlk_rej_uniform_table[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0 */,
0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 1 */,
2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 2 */,
Expand Down
6 changes: 3 additions & 3 deletions dev/aarch64_opt/src/aarch64_zetas.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Table of zeta values used in the AArch64 forward NTT
* See autogen for details.
*/
MLK_ALIGN const int16_t aarch64_ntt_zetas_layer01234[] = {
MLK_ALIGN const int16_t mlk_aarch64_ntt_zetas_layer01234[] = {
-1600, -15749, -749, -7373, -40, -394, -687, -6762, 630, 6201,
-1432, -14095, 848, 8347, 0, 0, 1062, 10453, 296, 2914,
-882, -8682, 0, 0, -1410, -13879, 1339, 13180, 1476, 14529,
Expand All @@ -31,7 +31,7 @@ MLK_ALIGN const int16_t aarch64_ntt_zetas_layer01234[] = {
0, 0, -1583, -15582, -1355, -13338, 821, 8081, 0, 0,
};

MLK_ALIGN const int16_t aarch64_ntt_zetas_layer56[] = {
MLK_ALIGN const int16_t mlk_aarch64_ntt_zetas_layer56[] = {
289, 289, 331, 331, -76, -76, -1573, -1573, 2845,
2845, 3258, 3258, -748, -748, -15483, -15483, 17, 17,
583, 583, 1637, 1637, -1041, -1041, 167, 167, 5739,
Expand Down Expand Up @@ -88,7 +88,7 @@ MLK_ALIGN const int16_t aarch64_invntt_zetas_layer01234[] = {
-848, -8347, 1432, 14095, -630, -6201, 687, 6762, 0, 0,
};

MLK_ALIGN const int16_t aarch64_invntt_zetas_layer56[] = {
MLK_ALIGN const int16_t mlk_aarch64_invntt_zetas_layer56[] = {
-910, -910, -1227, -1227, 219, 219, 855, 855, -8957,
-8957, -12078, -12078, 2156, 2156, 8416, 8416, 1175, 1175,
394, 394, -1029, -1029, -1212, -1212, 11566, 11566, 3878,
Expand Down
Loading

0 comments on commit bc96b5d

Please sign in to comment.