|
| 1 | +# Copyright (c) The mlkem-native project authors |
| 2 | +# Copyright (c) The mldsa-native project authors |
| 3 | +# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | + |
| 5 | +.PHONY: build run clean |
| 6 | +.DEFAULT_GOAL := all |
| 7 | + |
| 8 | +CC ?= gcc |
| 9 | + |
| 10 | +# Adjust CFLAGS if needed |
| 11 | +CFLAGS := \ |
| 12 | + -Wall \ |
| 13 | + -Wextra \ |
| 14 | + -Werror=unused-result \ |
| 15 | + -Wpedantic \ |
| 16 | + -Werror \ |
| 17 | + -Wmissing-prototypes \ |
| 18 | + -Wshadow \ |
| 19 | + -Wpointer-arith \ |
| 20 | + -Wredundant-decls \ |
| 21 | + -Wconversion \ |
| 22 | + -Wsign-conversion \ |
| 23 | + -Wno-long-long \ |
| 24 | + -Wno-unknown-pragmas \ |
| 25 | + -Wno-unused-command-line-argument \ |
| 26 | + -O3 \ |
| 27 | + -fomit-frame-pointer \ |
| 28 | + -std=c99 \ |
| 29 | + -pedantic \ |
| 30 | + -MMD \ |
| 31 | + $(CFLAGS) |
| 32 | + |
| 33 | +# If you want to use the native backends, the compiler needs to know about |
| 34 | +# the target architecture. Here, we import the default host detection from |
| 35 | +# mldsa-native's tests, but you can write your own or specialize accordingly. |
| 36 | +AUTO ?= 1 |
| 37 | +include auto.mk |
| 38 | + |
| 39 | +# The following only concerns the cross-compilation tests. |
| 40 | +# You can likely ignore the following for your application. |
| 41 | +# |
| 42 | +# Append cross-prefix for cross compilation |
| 43 | +# When called from the root Makefile, CROSS_PREFIX has already been added here |
| 44 | +ifeq (,$(findstring $(CROSS_PREFIX),$(CC))) |
| 45 | +CC := $(CROSS_PREFIX)$(CC) |
| 46 | +endif |
| 47 | + |
| 48 | +# Part A: |
| 49 | +# |
| 50 | +# mldsa-native source and header files |
| 51 | +# |
| 52 | +# In this example, we compile the individual mldsa-native source files directly. |
| 53 | +# Alternatively, you can compile the 'monobuild' source file mldsa_native.c. |
| 54 | +# See examples/monolithic_build for that. |
| 55 | +MLD_SOURCE=$(wildcard \ |
| 56 | + mldsa_native/*.c \ |
| 57 | + mldsa_native/**/*.c \ |
| 58 | + mldsa_native/**/**/*.c \ |
| 59 | + mldsa_native/**/**/**/*.c) |
| 60 | + |
| 61 | +INC=-Imldsa_native/ |
| 62 | + |
| 63 | +# Part B: |
| 64 | +# |
| 65 | +# Custom FIPS-202 implementation |
| 66 | +FIPS202_SOURCE=custom_fips202/tiny_sha3/sha3.c |
| 67 | + |
| 68 | +# Part C: |
| 69 | +# |
| 70 | +# Random number generator |
| 71 | +# |
| 72 | +# !!! WARNING !!! |
| 73 | +# |
| 74 | +# The randombytes() implementation used here is for TESTING ONLY. |
| 75 | +# You MUST NOT use this implementation outside of testing. |
| 76 | +# |
| 77 | +# !!! WARNING !!! |
| 78 | +RNG_SOURCE=$(wildcard test_only_rng/*.c) |
| 79 | + |
| 80 | +# Part D: |
| 81 | +# |
| 82 | +# Your application source code |
| 83 | +APP_SOURCE=$(wildcard *.c) |
| 84 | + |
| 85 | +ALL_SOURCE=$(MLD_SOURCE) $(FIPS202_SOURCE) $(RNG_SOURCE) $(APP_SOURCE) |
| 86 | + |
| 87 | +# |
| 88 | +# Configuration adjustments |
| 89 | +# |
| 90 | + |
| 91 | +# Pick prefix |
| 92 | +CFLAGS += -DMLD_CONFIG_NAMESPACE_PREFIX=mldsa |
| 93 | +# Tell mldsa-native to use serial-FIPS202 only |
| 94 | +CFLAGS += -DMLD_CONFIG_SERIAL_FIPS202_ONLY |
| 95 | +# Tell mldsa-native where to find the header for the custom FIPS202 |
| 96 | +CFLAGS += -DMLD_CONFIG_FIPS202_CUSTOM_HEADER="\"../custom_fips202/fips202.h\"" |
| 97 | + |
| 98 | +BUILD_DIR=build |
| 99 | +BIN=test_binary |
| 100 | + |
| 101 | +BINARY_NAME_FULL_44=$(BUILD_DIR)/$(BIN)44 |
| 102 | +BINARY_NAME_FULL_65=$(BUILD_DIR)/$(BIN)65 |
| 103 | +BINARY_NAME_FULL_87=$(BUILD_DIR)/$(BIN)87 |
| 104 | +BINARIES_FULL=$(BINARY_NAME_FULL_44) $(BINARY_NAME_FULL_65) $(BINARY_NAME_FULL_87) |
| 105 | + |
| 106 | +$(BINARY_NAME_FULL_44): CFLAGS += -DMLD_CONFIG_PARAMETER_SET=44 |
| 107 | +$(BINARY_NAME_FULL_65): CFLAGS += -DMLD_CONFIG_PARAMETER_SET=65 |
| 108 | +$(BINARY_NAME_FULL_87): CFLAGS += -DMLD_CONFIG_PARAMETER_SET=87 |
| 109 | + |
| 110 | +$(BINARIES_FULL): $(ALL_SOURCE) |
| 111 | + echo "$@" |
| 112 | + mkdir -p $(BUILD_DIR) |
| 113 | + $(CC) $(CFLAGS) $(INC) $^ -o $@ |
| 114 | + |
| 115 | +all: build |
| 116 | + |
| 117 | +build: $(BINARIES_FULL) |
| 118 | + |
| 119 | +run: $(BINARIES_FULL) |
| 120 | + $(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_44) |
| 121 | + $(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_65) |
| 122 | + $(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_87) |
| 123 | + |
| 124 | +clean: |
| 125 | + rm -rf $(BUILD_DIR) |
0 commit comments