Skip to content
Open
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
92 changes: 91 additions & 1 deletion .github/actions/config-variations/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inputs:
description: 'List of tests to run (space-separated IDs) or "all" for all tests. Available IDs: pct-enabled,
pct-enabled-broken, custom-alloc-heap, custom-zeroize, native-cap-ON, native-cap-OFF, native-cap-ID_AA64PFR1_EL1,
native-cap-CPUID_AVX2, no-asm, serial-fips202, custom-randombytes, custom-memcpy, custom-memset, custom-stdlib,
nblocks-1, nblocks-2, nblocks-4'
nblocks-1, nblocks-2, nblocks-4, keygen-only, encaps-only, decaps-only, keygen-encaps, keygen-decaps, encaps-decaps'
required: false
default: 'all'
opt:
Expand Down Expand Up @@ -276,3 +276,93 @@ runs:
examples: false # Some examples use a custom config themselves
alloc: false # Requires custom config
rng_fail: true
- name: "Keygen-only API"
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'keygen-only') }}
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ inputs.gh_token }}
compile_mode: native
cflags: "-DMLK_CONFIG_NO_ENCAPS_API -DMLK_CONFIG_NO_DECAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
func: true
kat: true
acvp: true
stack: true
rng_fail: true
opt: ${{ inputs.opt }}
examples: true
- name: "Encaps-only API"
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'encaps-only') }}
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ inputs.gh_token }}
compile_mode: native
cflags: "-DMLK_CONFIG_NO_KEYPAIR_API -DMLK_CONFIG_NO_DECAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
func: true
kat: true
acvp: true
stack: true
rng_fail: true
opt: ${{ inputs.opt }}
examples: true
- name: "Decaps-only API"
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'decaps-only') }}
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ inputs.gh_token }}
compile_mode: native
cflags: "-DMLK_CONFIG_NO_KEYPAIR_API -DMLK_CONFIG_NO_ENCAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
func: true
kat: true
acvp: true
stack: true
rng_fail: true
opt: ${{ inputs.opt }}
examples: true
- name: "Keygen+Encaps API (no decaps)"
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'keygen-encaps') }}
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ inputs.gh_token }}
compile_mode: native
cflags: "-DMLK_CONFIG_NO_DECAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
func: true
kat: true
acvp: true
stack: true
rng_fail: true
opt: ${{ inputs.opt }}
examples: true
- name: "Keygen+Decaps API (no encaps)"
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'keygen-decaps') }}
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ inputs.gh_token }}
compile_mode: native
cflags: "-DMLK_CONFIG_NO_ENCAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
func: true
kat: true
acvp: true
stack: true
rng_fail: true
opt: ${{ inputs.opt }}
examples: true
- name: "Encaps+Decaps API (no keygen)"
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'encaps-decaps') }}
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ inputs.gh_token }}
compile_mode: native
cflags: "-DMLK_CONFIG_NO_KEYPAIR_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
func: true
kat: true
acvp: true
stack: true
rng_fail: true
opt: ${{ inputs.opt }}
examples: true
2 changes: 1 addition & 1 deletion .github/workflows/baremetal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
target:
- runner: ubuntu-latest
name: 'AVR ATmega128RFR2 (modified for 32K RAM)'
name: 'AVR ATmega128RFR2 (modified for 63.5K RAM)'
makefile: test/baremetal/platform/avr/platform.mk
nix-shell: cross-avr
func: true
Expand Down
15 changes: 12 additions & 3 deletions META.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# Checks the KAT output of a gen_KAT binary against META.yml.
#
# Reads the KAT bytes from stdin, hashes them with SHA-256, and compares
# against the kat-sha256 field for the given scheme in META.yml.
# against the kat-sha256 field for the given scheme in META.yml. If stdin is
# "SKIPPED" (emitted by gen_KAT for reduced-API builds), the check is reported
# as skipped.
#
# To run manually, pipe a gen_KAT binary into it, e.g.:
#
Expand Down Expand Up @@ -53,9 +55,16 @@ def main():
err(f"META.yml: no kat-sha256 entry for {scheme_name}")
sys.exit(1)

# Hash the raw bytes piped in from gen_KAT on stdin. Read in binary mode so
# Read the raw bytes piped in from gen_KAT on stdin. Read in binary mode so
# that no newline translation occurs on Windows.
computed = hashlib.sha256(sys.stdin.buffer.read()).hexdigest()
data = sys.stdin.buffer.read()

# Reduced-API builds emit "SKIPPED" instead of KAT bytes; report as skipped.
if data.startswith(b"SKIPPED"):
info(f"META.yml {scheme_name} kat-sha256: SKIPPED")
sys.exit(0)

computed = hashlib.sha256(data).hexdigest()

if computed == ref:
info(f"META.yml {scheme_name} kat-sha256: OK")
Expand Down
6 changes: 6 additions & 0 deletions dev/aarch64_clean/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
return MLK_NATIVE_FUNC_SUCCESS;
}

#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
{
Expand All @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
mlk_aarch64_invntt_zetas_layer67);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */

MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
Expand All @@ -60,6 +62,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
return MLK_NATIVE_FUNC_SUCCESS;
}

#if !defined(MLK_CONFIG_NO_KEYPAIR_API)
MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
{
Expand All @@ -70,6 +73,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
mlk_poly_tomont_aarch64_asm(data);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !MLK_CONFIG_NO_KEYPAIR_API */

MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2],
Expand Down Expand Up @@ -130,6 +134,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native(
}
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */

#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API)
MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
const int16_t a[MLKEM_N])
Expand All @@ -141,6 +146,7 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
mlk_poly_tobytes_aarch64_asm(r, a);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */

MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len,
Expand Down
2 changes: 2 additions & 0 deletions dev/aarch64_clean/src/aarch64_zetas.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
10129, 10129, -3878, -3878, -11566, -11566,
};

#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
mlk_aarch64_invntt_zetas_layer12345[80] = {
1583, 15582, -821, -8081, 1355, 13338, 0, 0, -569,
Expand Down Expand Up @@ -138,6 +139,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
1041, -1637, -1637, -583, -583, -17, -17, 10247, 10247,
-16113, -16113, -5739, -5739, -167, -167,
};
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */

MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
mlk_aarch64_zetas_mulcache_native[128] = {
Expand Down
7 changes: 5 additions & 2 deletions dev/aarch64_clean/src/intt_aarch64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@

#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
(!defined(MLK_CONFIG_NO_ENCAPS_API) || \
!defined(MLK_CONFIG_NO_DECAPS_API))
/* simpasm: header-end */

// Bounds:
Expand Down Expand Up @@ -400,4 +402,5 @@ mlk_intt_layer123_start:
.unreq ninv_tw

/* simpasm: footer-start */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
(!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */
7 changes: 5 additions & 2 deletions dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
(!defined(MLK_CONFIG_NO_KEYPAIR_API) || \
!defined(MLK_CONFIG_NO_ENCAPS_API))
/* simpasm: header-end */

.macro ld2_wrap a, ptr
Expand Down Expand Up @@ -94,4 +96,5 @@ mlk_poly_tobytes_loop_start:
.unreq count

/* simpasm: footer-start */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
(!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */
6 changes: 4 additions & 2 deletions dev/aarch64_clean/src/poly_tomont_aarch64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
!defined(MLK_CONFIG_NO_KEYPAIR_API)
/* simpasm: header-end */

/* Montgomery multiplication, with precomputed Montgomery twist
Expand Down Expand Up @@ -103,4 +104,5 @@ mlk_poly_tomont_loop:
.unreq tmp0

/* simpasm: footer-start */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
!MLK_CONFIG_NO_KEYPAIR_API */
6 changes: 6 additions & 0 deletions dev/aarch64_opt/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
return MLK_NATIVE_FUNC_SUCCESS;
}

#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
{
Expand All @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
mlk_aarch64_invntt_zetas_layer67);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */

MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
Expand All @@ -60,6 +62,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
return MLK_NATIVE_FUNC_SUCCESS;
}

#if !defined(MLK_CONFIG_NO_KEYPAIR_API)
MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
{
Expand All @@ -70,6 +73,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
mlk_poly_tomont_aarch64_asm(data);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !MLK_CONFIG_NO_KEYPAIR_API */

MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2],
Expand Down Expand Up @@ -130,6 +134,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native(
}
#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */

#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API)
MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
const int16_t a[MLKEM_N])
Expand All @@ -141,6 +146,7 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
mlk_poly_tobytes_aarch64_asm(r, a);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */

MLK_MUST_CHECK_RETURN_VALUE
static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len,
Expand Down
2 changes: 2 additions & 0 deletions dev/aarch64_opt/src/aarch64_zetas.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
10129, 10129, -3878, -3878, -11566, -11566,
};

#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)
MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
mlk_aarch64_invntt_zetas_layer12345[80] = {
1583, 15582, -821, -8081, 1355, 13338, 0, 0, -569,
Expand Down Expand Up @@ -138,6 +139,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
1041, -1637, -1637, -583, -583, -17, -17, 10247, 10247,
-16113, -16113, -5739, -5739, -167, -167,
};
#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */

MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t
mlk_aarch64_zetas_mulcache_native[128] = {
Expand Down
8 changes: 6 additions & 2 deletions dev/aarch64_opt/src/intt_aarch64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
*/

#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
#if defined(MLK_ARITH_BACKEND_AARCH64) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
(!defined(MLK_CONFIG_NO_ENCAPS_API) || \
!defined(MLK_CONFIG_NO_DECAPS_API))
/* simpasm: header-end */

// Bounds:
Expand Down Expand Up @@ -1420,4 +1423,5 @@ mlk_intt_layer123_start:
.unreq ninv_tw

/* simpasm: footer-start */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
(!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */
8 changes: 6 additions & 2 deletions dev/aarch64_opt/src/poly_tobytes_aarch64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
*/

#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
#if defined(MLK_ARITH_BACKEND_AARCH64) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
(!defined(MLK_CONFIG_NO_KEYPAIR_API) || \
!defined(MLK_CONFIG_NO_ENCAPS_API))
/* simpasm: header-end */

.macro ld2_wrap a, ptr
Expand Down Expand Up @@ -253,4 +256,5 @@ mlk_poly_tobytes_loop_start:
.unreq count

/* simpasm: footer-start */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
(!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */
7 changes: 5 additions & 2 deletions dev/aarch64_opt/src/poly_tomont_aarch64_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
*/

#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
#if defined(MLK_ARITH_BACKEND_AARCH64) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \
!defined(MLK_CONFIG_NO_KEYPAIR_API)
/* simpasm: header-end */

/* Montgomery multiplication, with precomputed Montgomery twist
Expand Down Expand Up @@ -220,4 +222,5 @@ mlk_poly_tomont_loop:
.unreq tmp0

/* simpasm: footer-start */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \
!MLK_CONFIG_NO_KEYPAIR_API */
Loading
Loading