Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce global config and reorganize backends #535

Merged
merged 3 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
name: Arm Cortex-A55 (Snapdragon 888) benchmarks
bench_pmu: PERF
archflags: "-mcpu=cortex-a55 -march=armv8.2-a"
cflags: "-flto -static -DFORCE_AARCH64 -DFIPS202_NATIVE_PROFILE=\"aarch64/profiles/cortex_a55.h\""
cflags: "-flto -static -DFORCE_AARCH64 -DMLKEM_NATIVE_FIPS202_BACKEND=\\\\\\\"aarch64/cortex_a55.h\\\\\\\""
mkannwischer marked this conversation as resolved.
Show resolved Hide resolved
bench_extra_args: -w exec-on-a55
- system: bpi
name: Bananapi bpi-f3 benchmarks
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ jobs:
- name: bring_your_own_fips202
run: |
make run -C examples/bring_your_own_fips202
- name: custom_backend
run: |
make run -C examples/custom_backend
build_kat:
needs: [quickcheck, quickcheck-windows]
strategy:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ in this repository is for experimental and development purposes only. If you pre
### Can I bring my own backend?

Absolutely: You can add further backends for ML-KEM native arithmetic and/or for FIPS-202. Follow the existing backends
as templates.
as templates, or see [examples/custom_backend](examples/custom_backend) for a minimal example how to register a custom backend.

### Can I bring my own FIPS-202?

Expand Down
5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ See [mlkem_native_as_code_package](mlkem_native_as_code_package).

See [bring_your_own_fips202](bring_your_own_fips202) for an example of how to use mlkem-native with your own FIPS-202
implementation.

## Using mlkem-native as a code package, custom config + custom FIPS-202 backend

See [custom_backend](custom_backend) for an example of how to use mlkem-native with a custom configuration file and a
custom FIPS-202 backend.
1 change: 0 additions & 1 deletion examples/bring_your_own_fips202/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ INC=
INC+=-Imlkem_native/mlkem
INC+=-Imlkem_native/mlkem
INC+=-Imlkem_native/mlkem/native
INC+=-Imlkem_native/mlkem/sys

# Part B:
#
Expand Down
2 changes: 1 addition & 1 deletion examples/bring_your_own_fips202/custom_fips202/fips202.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef FIPS202_H
#define FIPS202_H

#include "namespace.h"
#include "common.h"
#include "tiny_sha3/sha3.h"

#define SHAKE128_RATE 168
Expand Down
30 changes: 0 additions & 30 deletions examples/bring_your_own_fips202/custom_fips202/namespace.h

This file was deleted.

This file was deleted.

196 changes: 0 additions & 196 deletions examples/bring_your_own_fips202/custom_fips202/tiny_sha3/main.c

This file was deleted.

64 changes: 64 additions & 0 deletions examples/custom_backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean

# Part A:
#
# mlkem-native source and header files
#
# If you are not concerned about minimizing for a specific backend,
# you can just include _all_ source files into your build.
MLKEM_NATIVE_SOURCE=$(wildcard \
mlkem_native/**/*.c \
mlkem_native/**/*.c \
mlkem_native/**/**/*.c \
mlkem_native/**/**/**/*.c \
mlkem_native/**/**/**/**/*.c)

INC=
INC+=-Imlkem_native/
INC+=-Imlkem_native/mlkem
INC+=-Imlkem_native/mlkem/native
INC+=-Imlkem_native/fips202
INC+=-Imlkem_native/fips202/native

# Part B:
#
# Random number generator
#
# !!! WARNING !!!
#
# The randombytes() implementation used here is for TESTING ONLY.
# You MUST NOT use this implementation outside of testing.
#
# !!! WARNING !!!
RNG_SOURCE=$(wildcard test_only_rng/*.c)

# Part C:
#
# Your application source code
APP_SOURCE=$(wildcard *.c)

ALL_SOURCE=$(MLKEM_NATIVE_SOURCE) $(RNG_SOURCE) $(APP_SOURCE)

BUILD_DIR=build
BIN=test_binary

CFLAGS=-DMLKEM_NATIVE_CONFIG_FILE="\"custom_config.h\""

BINARY_NAME_FULL=$(BUILD_DIR)/$(BIN)

$(BINARY_NAME_FULL): $(ALL_SOURCE)
echo "$@"
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) $(INC) $^ -o $@

all: run

build: $(BINARY_NAME_FULL)

run: $(BINARY_NAME_FULL)
./$(BINARY_NAME_FULL)

clean:
rm -rf $(BUILD_DIR)
Loading
Loading