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
2 changes: 1 addition & 1 deletion .github/actions/multi-functest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ runs:
nix-verbose: ${{ inputs.nix-verbose }}
gh_token: ${{ inputs.gh_token }}
custom_shell: ${{ inputs.custom_shell }}
cflags: "${{ inputs.cflags }} -DMLK_FORCE_PPC64LE"
cflags: "${{ inputs.cflags }} -DMLK_FORCE_PPC64LE -mvsx"
cross_prefix: powerpc64le-unknown-linux-gnu-
exec_wrapper: qemu-ppc64le
opt: ${{ inputs.opt }}
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,33 @@ jobs:
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: build + test
- name: build + test (no-opt)
uses: ./.github/actions/multi-functest
with:
nix-shell: ${{ matrix.target.nix_shell }}
nix-cache: ${{ matrix.target.mode == 'native' && 'false' || 'true' }}
gh_token: ${{ secrets.GITHUB_TOKEN }}
compile_mode: ${{ matrix.target.mode }}
# There is no native code yet on PPC64LE, R-V or AArch64_be, so no point running opt tests
opt: ${{ (matrix.target.arch != 'ppc64le' && matrix.target.arch != 'riscv64' && matrix.target.arch != 'riscv32' && matrix.target.arch != 'aarch64_be') && 'all' || 'no_opt' }}
- name: build + test (+debug+memsan+ubsan)
opt: 'no_opt'
- name: build + test (+debug+memsan+ubsan, native)
uses: ./.github/actions/multi-functest
if: ${{ matrix.target.mode == 'native' }}
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
compile_mode: native
cflags: "-DMLKEM_DEBUG -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
check_namespace: 'false'
- name: build + test (+debug, cross, opt)
uses: ./.github/actions/multi-functest
# There is no native code yet on riscv64, riscv32 or AArch64_be, so no point running opt tests
if: ${{ matrix.target.mode != 'native' && (matrix.target.arch != 'riscv64' && matrix.target.arch != 'riscv32' && matrix.target.arch != 'aarch64_be') }}
with:
nix-shell: ${{ matrix.target.nix_shell }}
nix-cache: ${{ matrix.target.mode == 'native' && 'false' || 'true' }}
gh_token: ${{ secrets.GITHUB_TOKEN }}
compile_mode: ${{ matrix.target.mode }}
cflags: "-DMLKEM_DEBUG"
opt: 'opt'
backend_tests:
name: AArch64 FIPS202 backends (${{ matrix.backend }})
strategy:
Expand Down
1 change: 1 addition & 0 deletions BIBLIOGRAPHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source code and documentation.
- [examples/basic_deterministic/mlkem_native/custom_no_randomized_config.h](examples/basic_deterministic/mlkem_native/custom_no_randomized_config.h)
- [integration/liboqs/config_aarch64.h](integration/liboqs/config_aarch64.h)
- [integration/liboqs/config_c.h](integration/liboqs/config_c.h)
- [integration/liboqs/config_ppc64le.h](integration/liboqs/config_ppc64le.h)
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
- [mlkem/src/config.h](mlkem/src/config.h)
- [mlkem/src/kem.c](mlkem/src/kem.c)
Expand Down
6 changes: 6 additions & 0 deletions dev/ppc64le/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[//]: # (SPDX-License-Identifier: CC-BY-4.0)

# ppc64le backend (little endian)

This directory contains a native backend for little endian POWER 8 (ppc64le) and above systems.

53 changes: 53 additions & 0 deletions dev/ppc64le/meta.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#ifndef MLK_DEV_PPC64LE_META_H
#define MLK_DEV_PPC64LE_META_H

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

#define MLK_ARITH_BACKEND_NAME PPC64LE_DEFAULT

/* Set of primitives that this backend replaces */
#define MLK_USE_NATIVE_NTT
#define MLK_USE_NATIVE_INTT
#define MLK_USE_NATIVE_POLY_REDUCE
#define MLK_USE_NATIVE_POLY_TOMONT

#if !defined(__ASSEMBLER__)
#include <string.h>
#include "../../common.h"
#include "../../params.h"
#include "../api.h"
#include "src/arith_native_ppc64le.h"

static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N])
{
mlk_ntt_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}

static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N])
{
mlk_intt_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}

static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N])
{
mlk_reduce_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}

static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N])
{
mlk_poly_tomont_ppc(data, mlk_ppc_qdata);
return MLK_NATIVE_FUNC_SUCCESS;
}
#endif /* !__ASSEMBLER__ */

#endif /* !MLK_DEV_PPC64LE_META_H */
24 changes: 24 additions & 0 deletions dev/ppc64le/src/arith_native_ppc64le.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/
#ifndef MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H
#define MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H

#include <stdint.h>
#include "../../../common.h"
#include "consts.h"

#define mlk_ntt_ppc MLK_NAMESPACE(ntt_ppc)
void mlk_ntt_ppc(int16_t *, const int16_t *);

#define mlk_intt_ppc MLK_NAMESPACE(intt_ppc)
void mlk_intt_ppc(int16_t *, const int16_t *);

#define mlk_reduce_ppc MLK_NAMESPACE(reduce_ppc)
void mlk_reduce_ppc(int16_t *r, const int16_t *);

#define mlk_poly_tomont_ppc MLK_NAMESPACE(poly_tomont_ppc)
void mlk_poly_tomont_ppc(int16_t *, const int16_t *);

#endif /* !MLK_DEV_PPC64LE_SRC_ARITH_NATIVE_PPC64LE_H */
77 changes: 77 additions & 0 deletions dev/ppc64le/src/consts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#include "../../../common.h"

#if defined(MLK_ARITH_BACKEND_PPC64LE) && \
!defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)

#include "consts.h"

MLK_ALIGN const int16_t mlk_ppc_qdata[] = {
/* -Q */
/* check-magic: -3329 == -1 * MLKEM_Q */
-3329,
-3329,
-3329,
-3329,
-3329,
-3329,
-3329,
-3329,
/* QINV */
/* check-magic: -3327 == pow(MLKEM_Q,-1,2^16) */
-3327,
-3327,
-3327,
-3327,
-3327,
-3327,
-3327,
-3327,
/* Q */
3329,
3329,
3329,
3329,
3329,
3329,
3329,
3329,
/* check-magic: 20159 == round(2^26 / MLKEM_Q) */
20159,
20159,
20159,
20159,
20159,
20159,
20159,
20159,
/* check-magic: 1441 == pow(2,32-7,MLKEM_Q) */
1441,
1441,
1441,
1441,
1441,
1441,
1441,
1441,
/* check-magic: 1353 == pow(2, 32, MLKEM_Q) */
1353,
1353,
1353,
1353,
1353,
1353,
1353,
1353,
/* zetas for NTT */
#include "consts_ntt.inc"
,
/* zetas for invNTT */
#include "consts_intt.inc"
};

#endif /* MLK_ARITH_BACKEND_PPC64LE && !MLK_CONFIG_MULTILEVEL_NO_SHARED */
29 changes: 29 additions & 0 deletions dev/ppc64le/src/consts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

#ifndef MLK_DEV_PPC64LE_SRC_CONSTS_H
#define MLK_DEV_PPC64LE_SRC_CONSTS_H
#include "../../../common.h"

/* Offsets into the constant table */
/* check-magic: off */
#define NQ_OFFSET 0
#define QINV_OFFSET 16
#define Q_OFFSET 32
#define C20159_OFFSET 48
#define C1441_OFFSET 64
#define C1353_OFFSET 80
#define ZETA_NTT_OFFSET 96
#define ZETA_NTT_OFFSET64 1104
#define IZETA_NTT_OFFSET127 1616
#define IZETA_NTT_OFFSET63 2128
/* check-magic: on */

#ifndef __ASSEMBLER__
#define mlk_ppc_qdata MLK_NAMESPACE(ppc_qdata)
extern const int16_t mlk_ppc_qdata[];
#endif

#endif /* !MLK_DEV_PPC64LE_SRC_CONSTS_H */
90 changes: 90 additions & 0 deletions dev/ppc64le/src/consts_intt.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/

/* For intt Len=2, offset IZETA_NTT_OFFSET64 */
-1103, -1103, -1103, -1103, 430, 430, 430, 430, 555, 555, 555, 555, 843,
843, 843, 843, -1251, -1251, -1251, -1251, 871, 871, 871, 871, 1550, 1550,
1550, 1550, 105, 105, 105, 105, 422, 422, 422, 422, 587, 587, 587, 587, 177,
177, 177, 177, -235, -235, -235, -235, -291, -291, -291, -291, -460, -460,
-460, -460, 1574, 1574, 1574, 1574, 1653, 1653, 1653, 1653, -246, -246,
-246, -246, 778, 778, 778, 778, 1159, 1159, 1159, 1159, -147, -147, -147,
-147, -777, -777, -777, -777, 1483, 1483, 1483, 1483, -602, -602, -602,
-602, 1119, 1119, 1119, 1119, -1590, -1590, -1590, -1590, 644, 644, 644,
644, -872, -872, -872, -872, 349, 349, 349, 349, 418, 418, 418, 418, 329,
329, 329, 329, -156, -156, -156, -156, -75, -75, -75, -75, 817, 817, 817,
817, 1097, 1097, 1097, 1097, 603, 603, 603, 603, 610, 610, 610, 610, 1322,
1322, 1322, 1322, -1285, -1285, -1285, -1285, -1465, -1465, -1465, -1465,
384, 384, 384, 384, -1215, -1215, -1215, -1215, -136, -136, -136, -136,
1218, 1218, 1218, 1218, -1335, -1335, -1335, -1335, -874, -874, -874, -874,
220, 220, 220, 220, -1187, -1187, -1187, -1187, -1659, -1659, -1659, -1659,
-1185, -1185, -1185, -1185, -1530, -1530, -1530, -1530, -1278, -1278, -1278,
-1278, 794, 794, 794, 794, -1510, -1510, -1510, -1510, -854, -854, -854,
-854, -870, -870, -870, -870, 478, 478, 478, 478, -108, -108, -108, -108,
-308, -308, -308, -308, 996, 996, 996, 996, 991, 991, 991, 991, 958, 958,
958, 958, -1460, -1460, -1460, -1460, 1522, 1522, 1522, 1522, 1628, 1628,
1628, 1628,
/* For intt Len=2, offset IZETA_NTT_OFFSET127 */
1628, 1628, 1628, 1628, 1522, 1522, 1522, 1522, -1460, -1460, -1460, -1460,
958, 958, 958, 958, 991, 991, 991, 991, 996, 996, 996, 996, -308, -308,
-308, -308, -108, -108, -108, -108, 478, 478, 478, 478, -870, -870, -870,
-870, -854, -854, -854, -854, -1510, -1510, -1510, -1510, 794, 794, 794,
794, -1278, -1278, -1278, -1278, -1530, -1530, -1530, -1530, -1185, -1185,
-1185, -1185, -1659, -1659, -1659, -1659, -1187, -1187, -1187, -1187, 220,
220, 220, 220, -874, -874, -874, -874, -1335, -1335, -1335, -1335, 1218,
1218, 1218, 1218, -136, -136, -136, -136, -1215, -1215, -1215, -1215, 384,
384, 384, 384, -1465, -1465, -1465, -1465, -1285, -1285, -1285, -1285, 1322,
1322, 1322, 1322, 610, 610, 610, 610, 603, 603, 603, 603, 1097, 1097, 1097,
1097, 817, 817, 817, 817, -75, -75, -75, -75, -156, -156, -156, -156, 329,
329, 329, 329, 418, 418, 418, 418, 349, 349, 349, 349, -872, -872, -872,
-872, 644, 644, 644, 644, -1590, -1590, -1590, -1590, 1119, 1119, 1119,
1119, -602, -602, -602, -602, 1483, 1483, 1483, 1483, -777, -777, -777,
-777, -147, -147, -147, -147, 1159, 1159, 1159, 1159, 778, 778, 778, 778,
-246, -246, -246, -246, 1653, 1653, 1653, 1653, 1574, 1574, 1574, 1574,
-460, -460, -460, -460, -291, -291, -291, -291, -235, -235, -235, -235, 177,
177, 177, 177, 587, 587, 587, 587, 422, 422, 422, 422, 105, 105, 105, 105,
1550, 1550, 1550, 1550, 871, 871, 871, 871, -1251, -1251, -1251, -1251, 843,
843, 843, 843, 555, 555, 555, 555, 430, 430, 430, 430, -1103, -1103, -1103,
-1103,
/* For intt Len=4 and others, offset IZETA_NTT_OFFSET63 */
-1275, -1275, -1275, -1275, -1275, -1275, -1275, -1275, 677, 677, 677, 677,
677, 677, 677, 677, -1065, -1065, -1065, -1065, -1065, -1065, -1065, -1065,
448, 448, 448, 448, 448, 448, 448, 448, -725, -725, -725, -725, -725, -725,
-725, -725, -1508, -1508, -1508, -1508, -1508, -1508, -1508, -1508, 961,
961, 961, 961, 961, 961, 961, 961, -398, -398, -398, -398, -398, -398, -398,
-398, -951, -951, -951, -951, -951, -951, -951, -951, -247, -247, -247,
-247, -247, -247, -247, -247, -1421, -1421, -1421, -1421, -1421, -1421,
-1421, -1421, 107, 107, 107, 107, 107, 107, 107, 107, 830, 830, 830, 830,
830, 830, 830, 830, -271, -271, -271, -271, -271, -271, -271, -271, -90,
-90, -90, -90, -90, -90, -90, -90, -853, -853, -853, -853, -853, -853, -853,
-853, 1469, 1469, 1469, 1469, 1469, 1469, 1469, 1469, 126, 126, 126, 126,
126, 126, 126, 126, -1162, -1162, -1162, -1162, -1162, -1162, -1162, -1162,
-1618, -1618, -1618, -1618, -1618, -1618, -1618, -1618, -666, -666, -666,
-666, -666, -666, -666, -666, -320, -320, -320, -320, -320, -320, -320,
-320, -8, -8, -8, -8, -8, -8, -8, -8, 516, 516, 516, 516, 516, 516, 516,
516, -1544, -1544, -1544, -1544, -1544, -1544, -1544, -1544, -282, -282,
-282, -282, -282, -282, -282, -282, 1491, 1491, 1491, 1491, 1491, 1491,
1491, 1491, -1293, -1293, -1293, -1293, -1293, -1293, -1293, -1293, 1015,
1015, 1015, 1015, 1015, 1015, 1015, 1015, -552, -552, -552, -552, -552,
-552, -552, -552, 652, 652, 652, 652, 652, 652, 652, 652, 1223, 1223, 1223,
1223, 1223, 1223, 1223, 1223, -1571, -1571, -1571, -1571, -1571, -1571,
-1571, -1571, -205, -205, -205, -205, -205, -205, -205, -205, 411, 411, 411,
411, 411, 411, 411, 411, -1542, -1542, -1542, -1542, -1542, -1542, -1542,
-1542, 608, 608, 608, 608, 608, 608, 608, 608, 732, 732, 732, 732, 732, 732,
732, 732, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, -681, -681, -681,
-681, -681, -681, -681, -681, -130, -130, -130, -130, -130, -130, -130,
-130, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -1602, 1458, 1458,
1458, 1458, 1458, 1458, 1458, 1458, -829, -829, -829, -829, -829, -829,
-829, -829, 383, 383, 383, 383, 383, 383, 383, 383, 264, 264, 264, 264, 264,
264, 264, 264, -1325, -1325, -1325, -1325, -1325, -1325, -1325, -1325, 573,
573, 573, 573, 573, 573, 573, 573, 1468, 1468, 1468, 1468, 1468, 1468, 1468,
1468, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1202, -1202,
-1202, -1202, -1202, -1202, -1202, -1202, 962, 962, 962, 962, 962, 962, 962,
962, 182, 182, 182, 182, 182, 182, 182, 182, 1577, 1577, 1577, 1577, 1577,
1577, 1577, 1577, 622, 622, 622, 622, 622, 622, 622, 622, -171, -171, -171,
-171, -171, -171, -171, -171, 202, 202, 202, 202, 202, 202, 202, 202, 287,
287, 287, 287, 287, 287, 287, 287, 1422, 1422, 1422, 1422, 1422, 1422, 1422,
1422, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, -1517, -1517, -1517,
-1517, -1517, -1517, -1517, -1517, -359, -359, -359, -359, -359, -359, -359,
-359, -758, -758, -758, -758, -758, -758, -758, -758
45 changes: 45 additions & 0 deletions dev/ppc64le/src/consts_ntt.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
*/
/* For ntt Len=128, offset 96 */
-758, -758, -758, -758, -758, -758, -758, -758, -359, -359, -359, -359,
-359, -359, -359, -359, -1517, -1517, -1517, -1517, -1517, -1517, -1517,
-1517, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1493, 1422, 1422, 1422,
1422, 1422, 1422, 1422, 1422, 287, 287, 287, 287, 287, 287, 287, 287, 202,
202, 202, 202, 202, 202, 202, 202, -171, -171, -171, -171, -171, -171, -171,
-171, 622, 622, 622, 622, 622, 622, 622, 622, 1577, 1577, 1577, 1577, 1577,
1577, 1577, 1577, 182, 182, 182, 182, 182, 182, 182, 182, 962, 962, 962,
962, 962, 962, 962, 962, -1202, -1202, -1202, -1202, -1202, -1202, -1202,
-1202, -1474, -1474, -1474, -1474, -1474, -1474, -1474, -1474, 1468, 1468,
1468, 1468, 1468, 1468, 1468, 1468, 573, 573, 573, 573, 573, 573, 573, 573,
-1325, -1325, -1325, -1325, -1325, -1325, -1325, -1325, 264, 264, 264, 264,
264, 264, 264, 264, 383, 383, 383, 383, 383, 383, 383, 383, -829, -829,
-829, -829, -829, -829, -829, -829, 1458, 1458, 1458, 1458, 1458, 1458,
1458, 1458, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -1602, -130,
-130, -130, -130, -130, -130, -130, -130, -681, -681, -681, -681, -681,
-681, -681, -681, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 1017, 732, 732,
732, 732, 732, 732, 732, 732, 608, 608, 608, 608, 608, 608, 608, 608, -1542,
-1542, -1542, -1542, -1542, -1542, -1542, -1542, 411, 411, 411, 411, 411,
411, 411, 411, -205, -205, -205, -205, -205, -205, -205, -205, -1571, -1571,
-1571, -1571, -1571, -1571, -1571, -1571, 1223, 1223, 1223, 1223, 1223,
1223, 1223, 1223, 652, 652, 652, 652, 652, 652, 652, 652, -552, -552, -552,
-552, -552, -552, -552, -552, 1015, 1015, 1015, 1015, 1015, 1015, 1015,
1015, -1293, -1293, -1293, -1293, -1293, -1293, -1293, -1293, 1491, 1491,
1491, 1491, 1491, 1491, 1491, 1491, -282, -282, -282, -282, -282, -282,
-282, -282, -1544, -1544, -1544, -1544, -1544, -1544, -1544, -1544, 516,
516, 516, 516, 516, 516, 516, 516, -8, -8, -8, -8, -8, -8, -8, -8, -320,
-320, -320, -320, -320, -320, -320, -320, -666, -666, -666, -666, -666,
-666, -666, -666, -1618, -1618, -1618, -1618, -1618, -1618, -1618, -1618,
-1162, -1162, -1162, -1162, -1162, -1162, -1162, -1162, 126, 126, 126, 126,
126, 126, 126, 126, 1469, 1469, 1469, 1469, 1469, 1469, 1469, 1469, -853,
-853, -853, -853, -853, -853, -853, -853, -90, -90, -90, -90, -90, -90, -90,
-90, -271, -271, -271, -271, -271, -271, -271, -271, 830, 830, 830, 830,
830, 830, 830, 830, 107, 107, 107, 107, 107, 107, 107, 107, -1421, -1421,
-1421, -1421, -1421, -1421, -1421, -1421, -247, -247, -247, -247, -247,
-247, -247, -247, -951, -951, -951, -951, -951, -951, -951, -951, -398,
-398, -398, -398, -398, -398, -398, -398, 961, 961, 961, 961, 961, 961, 961,
961, -1508, -1508, -1508, -1508, -1508, -1508, -1508, -1508, -725, -725,
-725, -725, -725, -725, -725, -725, 448, 448, 448, 448, 448, 448, 448, 448,
-1065, -1065, -1065, -1065, -1065, -1065, -1065, -1065, 677, 677, 677, 677,
677, 677, 677, 677, -1275, -1275, -1275, -1275, -1275, -1275, -1275, -1275
Loading
Loading