Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ jobs:
- name: make lib
run: |
make lib
simpasm:
strategy:
fail-fast: false
matrix:
backend:
- arg: '--aarch64-clean'
name: Clean
# TODO: add backend option after we have optimized/clean seperation
# - arg: ''
# name: Optimized
simplify:
- arg: ''
name: Simplified
- arg: '--no-simplify'
name: Unmodified
runs-on: pqcp-arm64
name: AArch64 dev backend (${{ matrix.simplify.name }})
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Reinstate and test backend
uses: ./.github/actions/setup-shell
with:
nix-shell: 'ci'
gh_token: ${{ secrets.GITHUB_TOKEN }}
script: |
./scripts/autogen ${{ matrix.simplify.arg }}
make clean
OPT=1 make quickcheck
scan-build:
strategy:
fail-fast: false
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ jobs:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: ./.github/actions/setup-shell
with:
nix-shell: 'ci'
nix-shell: 'ci-cross' # Need cross-compiler for ASM simplification
nix-cache: 'true'
gh_token: ${{ secrets.GITHUB_TOKEN }}
script: |
python3 ./scripts/autogen --dry-run
python3 ./scripts/autogen --dry-run --force-cross
24 changes: 24 additions & 0 deletions BIBLIOGRAPHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ source code and documentation.
- Matthias J. Kannwischer
* URL: https://eprint.iacr.org/2022/1243
* Referenced from:
- [dev/fips202/aarch64/auto.h](dev/fips202/aarch64/auto.h)
- [dev/fips202/aarch64/src/keccak_f1600_x1_v84a_asm.S](dev/fips202/aarch64/src/keccak_f1600_x1_v84a_asm.S)
- [dev/fips202/aarch64/src/keccak_f1600_x2_v84a_asm.S](dev/fips202/aarch64/src/keccak_f1600_x2_v84a_asm.S)
- [mldsa/fips202/native/aarch64/auto.h](mldsa/fips202/native/aarch64/auto.h)
- [mldsa/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S](mldsa/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S)
- [mldsa/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S](mldsa/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S)
Expand Down Expand Up @@ -145,6 +148,27 @@ source code and documentation.
- Damien Stehlé
* URL: https://github.com/pq-crystals/dilithium/tree/master/avx2
* Referenced from:
- [dev/x86_64/src/align.h](dev/x86_64/src/align.h)
- [dev/x86_64/src/consts.c](dev/x86_64/src/consts.c)
- [dev/x86_64/src/consts.h](dev/x86_64/src/consts.h)
- [dev/x86_64/src/intt.S](dev/x86_64/src/intt.S)
- [dev/x86_64/src/ntt.S](dev/x86_64/src/ntt.S)
- [dev/x86_64/src/nttunpack.S](dev/x86_64/src/nttunpack.S)
- [dev/x86_64/src/pointwise.S](dev/x86_64/src/pointwise.S)
- [dev/x86_64/src/pointwise_acc_l4.S](dev/x86_64/src/pointwise_acc_l4.S)
- [dev/x86_64/src/pointwise_acc_l5.S](dev/x86_64/src/pointwise_acc_l5.S)
- [dev/x86_64/src/pointwise_acc_l7.S](dev/x86_64/src/pointwise_acc_l7.S)
- [dev/x86_64/src/poly_caddq_avx2.c](dev/x86_64/src/poly_caddq_avx2.c)
- [dev/x86_64/src/poly_chknorm_avx2.c](dev/x86_64/src/poly_chknorm_avx2.c)
- [dev/x86_64/src/poly_decompose_32_avx2.c](dev/x86_64/src/poly_decompose_32_avx2.c)
- [dev/x86_64/src/poly_decompose_88_avx2.c](dev/x86_64/src/poly_decompose_88_avx2.c)
- [dev/x86_64/src/poly_use_hint_32_avx2.c](dev/x86_64/src/poly_use_hint_32_avx2.c)
- [dev/x86_64/src/poly_use_hint_88_avx2.c](dev/x86_64/src/poly_use_hint_88_avx2.c)
- [dev/x86_64/src/polyz_unpack_17_avx2.c](dev/x86_64/src/polyz_unpack_17_avx2.c)
- [dev/x86_64/src/polyz_unpack_19_avx2.c](dev/x86_64/src/polyz_unpack_19_avx2.c)
- [dev/x86_64/src/rej_uniform_avx2.c](dev/x86_64/src/rej_uniform_avx2.c)
- [dev/x86_64/src/rej_uniform_eta2_avx2.c](dev/x86_64/src/rej_uniform_eta2_avx2.c)
- [dev/x86_64/src/rej_uniform_eta4_avx2.c](dev/x86_64/src/rej_uniform_eta4_avx2.c)
- [mldsa/native/x86_64/src/align.h](mldsa/native/x86_64/src/align.h)
- [mldsa/native/x86_64/src/consts.c](mldsa/native/x86_64/src/consts.c)
- [mldsa/native/x86_64/src/consts.h](mldsa/native/x86_64/src/consts.h)
Expand Down
188 changes: 188 additions & 0 deletions dev/aarch64_clean/meta.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* Copyright (c) The mlkem-native project authors
* Copyright (c) The mldsa-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#ifndef MLD_NATIVE_AARCH64_META_H
#define MLD_NATIVE_AARCH64_META_H

/* Set of primitives that this backend replaces */
#define MLD_USE_NATIVE_NTT
#define MLD_USE_NATIVE_INTT
#define MLD_USE_NATIVE_REJ_UNIFORM
#define MLD_USE_NATIVE_REJ_UNIFORM_ETA2
#define MLD_USE_NATIVE_REJ_UNIFORM_ETA4
#define MLD_USE_NATIVE_POLY_DECOMPOSE_32
#define MLD_USE_NATIVE_POLY_DECOMPOSE_88
#define MLD_USE_NATIVE_POLY_CADDQ
#define MLD_USE_NATIVE_POLY_USE_HINT_32
#define MLD_USE_NATIVE_POLY_USE_HINT_88
#define MLD_USE_NATIVE_POLY_CHKNORM
#define MLD_USE_NATIVE_POLYZ_UNPACK_17
#define MLD_USE_NATIVE_POLYZ_UNPACK_19
#define MLD_USE_NATIVE_POINTWISE_MONTGOMERY
#define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4
#define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5
#define MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7

/* Identifier for this backend so that source and assembly files
* in the build can be appropriately guarded. */
#define MLD_ARITH_BACKEND_AARCH64


#if !defined(__ASSEMBLER__)
#include "src/arith_native_aarch64.h"

static MLD_INLINE void mld_ntt_native(int32_t data[MLDSA_N])
{
mld_ntt_asm(data, mld_aarch64_ntt_zetas_layer123456,
mld_aarch64_ntt_zetas_layer78);
}

static MLD_INLINE void mld_intt_native(int32_t data[MLDSA_N])
{
mld_intt_asm(data, mld_aarch64_intt_zetas_layer78,
mld_aarch64_intt_zetas_layer123456);
}

static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len,
const uint8_t *buf,
unsigned buflen)
{
if (len != MLDSA_N || buflen % 24 != 0)
{
return -1;
}

/* Safety: outlen is at most MLDSA_N, hence, this cast is safe. */
return (int)mld_rej_uniform_asm(r, buf, buflen, mld_rej_uniform_table);
}

static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len,
const uint8_t *buf,
unsigned buflen)
{
unsigned int outlen;
/* AArch64 implementation assumes specific buffer lengths */
if (len != MLDSA_N || buflen != MLD_AARCH64_REJ_UNIFORM_ETA2_BUFLEN)
{
return -1;
}
/* Constant time: Inputs and outputs to this function are secret.
* It is safe to leak which coefficients are accepted/rejected.
* The assembly implementation must not leak any other information about the
* accepted coefficients. Constant-time testing cannot cover this, and we
* hence have to manually verify the assembly.
* We declassify prior the input data and mark the outputs as secret.
*/
MLD_CT_TESTING_DECLASSIFY(buf, buflen);
outlen = mld_rej_uniform_eta2_asm(r, buf, buflen, mld_rej_uniform_eta_table);
MLD_CT_TESTING_SECRET(r, sizeof(int32_t) * outlen);
/* Safety: outlen is at most MLDSA_N and, hence, this cast is safe. */
return (int)outlen;
}

static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
const uint8_t *buf,
unsigned buflen)
{
unsigned int outlen;
/* AArch64 implementation assumes specific buffer lengths */
if (len != MLDSA_N || buflen != MLD_AARCH64_REJ_UNIFORM_ETA4_BUFLEN)
{
return -1;
}
/* Constant time: Inputs and outputs to this function are secret.
* It is safe to leak which coefficients are accepted/rejected.
* The assembly implementation must not leak any other information about the
* accepted coefficients. Constant-time testing cannot cover this, and we
* hence have to manually verify the assembly.
* We declassify prior the input data and mark the outputs as secret.
*/
MLD_CT_TESTING_DECLASSIFY(buf, buflen);
outlen = mld_rej_uniform_eta4_asm(r, buf, buflen, mld_rej_uniform_eta_table);
MLD_CT_TESTING_SECRET(r, sizeof(int32_t) * outlen);
/* Safety: outlen is at most MLDSA_N and, hence, this cast is safe. */
return (int)outlen;
}

static MLD_INLINE void mld_poly_decompose_32_native(int32_t *a1, int32_t *a0,
const int32_t *a)
{
mld_poly_decompose_32_asm(a1, a0, a);
}

static MLD_INLINE void mld_poly_decompose_88_native(int32_t *a1, int32_t *a0,
const int32_t *a)
{
mld_poly_decompose_88_asm(a1, a0, a);
}

static MLD_INLINE void mld_poly_caddq_native(int32_t a[MLDSA_N])
{
mld_poly_caddq_asm(a);
}

static MLD_INLINE void mld_poly_use_hint_32_native(int32_t *b, const int32_t *a,
const int32_t *h)
{
mld_poly_use_hint_32_asm(b, a, h);
}

static MLD_INLINE void mld_poly_use_hint_88_native(int32_t *b, const int32_t *a,
const int32_t *h)
{
mld_poly_use_hint_88_asm(b, a, h);
}

static MLD_INLINE uint32_t mld_poly_chknorm_native(const int32_t *a, int32_t B)
{
return mld_poly_chknorm_asm(a, B);
}

static MLD_INLINE void mld_polyz_unpack_17_native(int32_t *r,
const uint8_t *buf)
{
mld_polyz_unpack_17_asm(r, buf, mld_polyz_unpack_17_indices);
}

static MLD_INLINE void mld_polyz_unpack_19_native(int32_t *r,
const uint8_t *buf)
{
mld_polyz_unpack_19_asm(r, buf, mld_polyz_unpack_19_indices);
}

static MLD_INLINE void mld_poly_pointwise_montgomery_native(
int32_t out[MLDSA_N], const int32_t in0[MLDSA_N],
const int32_t in1[MLDSA_N])
{
mld_poly_pointwise_montgomery_asm(out, in0, in1);
}

static MLD_INLINE void mld_polyvecl_pointwise_acc_montgomery_l4_native(
int32_t w[MLDSA_N], const int32_t u[4][MLDSA_N],
const int32_t v[4][MLDSA_N])
{
mld_polyvecl_pointwise_acc_montgomery_l4_asm(w, (const int32_t *)u,
(const int32_t *)v);
}

static MLD_INLINE void mld_polyvecl_pointwise_acc_montgomery_l5_native(
int32_t w[MLDSA_N], const int32_t u[5][MLDSA_N],
const int32_t v[5][MLDSA_N])
{
mld_polyvecl_pointwise_acc_montgomery_l5_asm(w, (const int32_t *)u,
(const int32_t *)v);
}

static MLD_INLINE void mld_polyvecl_pointwise_acc_montgomery_l7_native(
int32_t w[MLDSA_N], const int32_t u[7][MLDSA_N],
const int32_t v[7][MLDSA_N])
{
mld_polyvecl_pointwise_acc_montgomery_l7_asm(w, (const int32_t *)u,
(const int32_t *)v);
}

#endif /* !__ASSEMBLER__ */
#endif /* !MLD_NATIVE_AARCH64_META_H */
Loading