| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef MLD_NATIVE_AARCH64_META_H |
| 8 |
#define MLD_NATIVE_AARCH64_META_H |
| 9 |
|
| 10 |
|
| 11 |
#define MLD_USE_NATIVE_NTT |
| 12 |
#define MLD_USE_NATIVE_INTT |
| 13 |
#define MLD_USE_NATIVE_REJ_UNIFORM |
| 14 |
#define MLD_USE_NATIVE_REJ_UNIFORM_ETA2 |
| 15 |
#define MLD_USE_NATIVE_REJ_UNIFORM_ETA4 |
| 16 |
#define MLD_USE_NATIVE_POLY_DECOMPOSE_32 |
| 17 |
#define MLD_USE_NATIVE_POLY_DECOMPOSE_88 |
| 18 |
#define MLD_USE_NATIVE_POLY_CADDQ |
| 19 |
#define MLD_USE_NATIVE_POLY_USE_HINT_32 |
| 20 |
#define MLD_USE_NATIVE_POLY_USE_HINT_88 |
| 21 |
#define MLD_USE_NATIVE_POLY_CHKNORM |
| 22 |
#define MLD_USE_NATIVE_POLYZ_UNPACK_17 |
| 23 |
#define MLD_USE_NATIVE_POLYZ_UNPACK_19 |
| 24 |
#define MLD_USE_NATIVE_POINTWISE_MONTGOMERY |
| 25 |
#define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4 |
| 26 |
#define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5 |
| 27 |
#define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7 |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#define MLD_ARITH_BACKEND_AARCH64 |
| 32 |
|
| 33 |
|
| 34 |
#if !defined(__ASSEMBLER__) |
| 35 |
#include "../api.h" |
| 36 |
#include "src/arith_native_aarch64.h" |
| 37 |
|
| 38 |
static MLD_INLINE int mld_ntt_native(int32_t data[MLDSA_N]) |
| 39 |
{ |
| 40 |
mld_ntt_asm(data, mld_aarch64_ntt_zetas_layer123456, |
| 41 |
mld_aarch64_ntt_zetas_layer78); |
| 42 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 43 |
} |
| 44 |
|
| 45 |
static MLD_INLINE int mld_intt_native(int32_t data[MLDSA_N]) |
| 46 |
{ |
| 47 |
mld_intt_asm(data, mld_aarch64_intt_zetas_layer78, |
| 48 |
mld_aarch64_intt_zetas_layer123456); |
| 49 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 50 |
} |
| 51 |
|
| 52 |
static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len, |
| 53 |
const uint8_t *buf, |
| 54 |
unsigned buflen) |
| 55 |
{ |
| 56 |
if (len != MLDSA_N || |
| 57 |
buflen % 24 != 0) |
| 58 |
{ |
| 59 |
return MLD_NATIVE_FUNC_FALLBACK; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
return (int)mld_rej_uniform_asm(r, buf, buflen, mld_rej_uniform_table); |
| 64 |
} |
| 65 |
|
| 66 |
static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len, |
| 67 |
const uint8_t *buf, |
| 68 |
unsigned buflen) |
| 69 |
{ |
| 70 |
uint64_t outlen; |
| 71 |
|
| 72 |
if (len != MLDSA_N || buflen != MLD_AARCH64_REJ_UNIFORM_ETA2_BUFLEN) |
| 73 |
{ |
| 74 |
return MLD_NATIVE_FUNC_FALLBACK; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
MLD_CT_TESTING_DECLASSIFY(buf, buflen); |
| 84 |
outlen = mld_rej_uniform_eta2_asm(r, buf, buflen, mld_rej_uniform_eta_table); |
| 85 |
MLD_CT_TESTING_SECRET(r, sizeof(int32_t) * outlen); |
| 86 |
|
| 87 |
return (int)outlen; |
| 88 |
} |
| 89 |
|
| 90 |
static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len, |
| 91 |
const uint8_t *buf, |
| 92 |
unsigned buflen) |
| 93 |
{ |
| 94 |
uint64_t outlen; |
| 95 |
|
| 96 |
if (len != MLDSA_N || buflen != MLD_AARCH64_REJ_UNIFORM_ETA4_BUFLEN) |
| 97 |
{ |
| 98 |
return MLD_NATIVE_FUNC_FALLBACK; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
MLD_CT_TESTING_DECLASSIFY(buf, buflen); |
| 108 |
outlen = mld_rej_uniform_eta4_asm(r, buf, buflen, mld_rej_uniform_eta_table); |
| 109 |
MLD_CT_TESTING_SECRET(r, sizeof(int32_t) * outlen); |
| 110 |
|
| 111 |
return (int)outlen; |
| 112 |
} |
| 113 |
|
| 114 |
static MLD_INLINE int mld_poly_decompose_32_native(int32_t *a1, int32_t *a0) |
| 115 |
{ |
| 116 |
mld_poly_decompose_32_asm(a1, a0); |
| 117 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 118 |
} |
| 119 |
|
| 120 |
static MLD_INLINE int mld_poly_decompose_88_native(int32_t *a1, int32_t *a0) |
| 121 |
{ |
| 122 |
mld_poly_decompose_88_asm(a1, a0); |
| 123 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 124 |
} |
| 125 |
|
| 126 |
static MLD_INLINE int mld_poly_caddq_native(int32_t a[MLDSA_N]) |
| 127 |
{ |
| 128 |
mld_poly_caddq_asm(a); |
| 129 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 130 |
} |
| 131 |
|
| 132 |
static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *b, const int32_t *a, |
| 133 |
const int32_t *h) |
| 134 |
{ |
| 135 |
mld_poly_use_hint_32_asm(b, a, h); |
| 136 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 137 |
} |
| 138 |
|
| 139 |
static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *b, const int32_t *a, |
| 140 |
const int32_t *h) |
| 141 |
{ |
| 142 |
mld_poly_use_hint_88_asm(b, a, h); |
| 143 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 144 |
} |
| 145 |
|
| 146 |
static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B) |
| 147 |
{ |
| 148 |
return mld_poly_chknorm_asm(a, B); |
| 149 |
} |
| 150 |
|
| 151 |
static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *buf) |
| 152 |
{ |
| 153 |
mld_polyz_unpack_17_asm(r, buf, mld_polyz_unpack_17_indices); |
| 154 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 155 |
} |
| 156 |
|
| 157 |
static MLD_INLINE int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *buf) |
| 158 |
{ |
| 159 |
mld_polyz_unpack_19_asm(r, buf, mld_polyz_unpack_19_indices); |
| 160 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 161 |
} |
| 162 |
|
| 163 |
static MLD_INLINE int mld_poly_pointwise_montgomery_native( |
| 164 |
int32_t out[MLDSA_N], const int32_t in0[MLDSA_N], |
| 165 |
const int32_t in1[MLDSA_N]) |
| 166 |
{ |
| 167 |
mld_poly_pointwise_montgomery_asm(out, in0, in1); |
| 168 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 169 |
} |
| 170 |
|
| 171 |
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l4_native( |
| 172 |
int32_t w[MLDSA_N], const int32_t u[4][MLDSA_N], |
| 173 |
const int32_t v[4][MLDSA_N]) |
| 174 |
{ |
| 175 |
mld_polyvecl_pointwise_acc_montgomery_l4_asm(w, (const int32_t *)u, |
| 176 |
(const int32_t *)v); |
| 177 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 178 |
} |
| 179 |
|
| 180 |
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l5_native( |
| 181 |
int32_t w[MLDSA_N], const int32_t u[5][MLDSA_N], |
| 182 |
const int32_t v[5][MLDSA_N]) |
| 183 |
{ |
| 184 |
mld_polyvecl_pointwise_acc_montgomery_l5_asm(w, (const int32_t *)u, |
| 185 |
(const int32_t *)v); |
| 186 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 187 |
} |
| 188 |
|
| 189 |
static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l7_native( |
| 190 |
int32_t w[MLDSA_N], const int32_t u[7][MLDSA_N], |
| 191 |
const int32_t v[7][MLDSA_N]) |
| 192 |
{ |
| 193 |
mld_polyvecl_pointwise_acc_montgomery_l7_asm(w, (const int32_t *)u, |
| 194 |
(const int32_t *)v); |
| 195 |
return MLD_NATIVE_FUNC_SUCCESS; |
| 196 |
} |
| 197 |
|
| 198 |
#endif |
| 199 |
#endif |