This repository provides code for our implementations of Kyber and Dilithium on the Arm Cortex-M4.
The setup for testing and evaluating of our code is based on the framework provided in the pqm4 project. Detailed instructions on interacting with the hardware and on installing required software can be found in pqm4's readme.
arm-none-eabi-gcc: version 10.2.1libopencm3: commitb1d8a4c546531d6a79f9a7be156205c6a40f215cfrom GitHubst-linkfor flashing the binariespython3with the packagespyserialandnumpy(only required for the evaluation scripts)- Hardware:
STM32F4DISCOVERY
common: contains code that is shared between different schemesconfig.py: Saves platform configurationcrypto_kem: contains the implementations for kyber512, kyber768, kyber1024kyber512(-90s)old: Code from the implementation in pqm4new: Code containing all of our proposalsnewstack: Code containing only optimizations that do not require additional stack usage
kyber768(-90s)old: Code from the implementation in pqm4new: Code containing all of our proposalsnewstack: Code containing only optimizations that do not require additional stack usage
kyber1024(-90s)old: Code from the implementation in pqm4new: Code containing all of our proposalsnewstack: Code containing only optimizations that do not require additional stack usage
f_speed.c: Firmware used for benchmarking parts of the scheme. Can be used by usingf_benchmarks.py.speed.c: From pqm4; Firmware for benchmarking the schemes' cycle counts. Can be used by usingbenchmarks.py.stack.c: From pqm4; Firmware for benchmarking the schemes' stack usage.test.c: From pqm4; Firmware for self-testing the schemes. Can be used by usingtest.py.testvectors.c: From pqm4; Firmware for computing testvectors.
crypto_sign: contains the implementations for dilithium2, dilithium3, dilithium5dilithium2old: Code from the implementation in pqm4 reshuffled to save stacknew: Code containing all of our proposals
dilithium3old: Code from the implementation in pqm4 reshuffled to save stacknew: Code containing all of our proposals
dilithium5old: Code from the implementation in pqm4 reshuffled to save stacknew: Code containing all of our proposals
f_speed.c: Firmware used for benchmarking parts of the scheme. Can be used by usingf_benchmarks.py.speed.c: From pqm4; Firmware for benchmarking the schemes' cycle counts.stack.c: From pqm4; Firmware for benchmarking the schemes' stack usage.test.c: From pqm4; Firmware for self-testing the schemes.testvectors.c: From pqm4; Firmware for computing testvectors.
gen_table: contains code to generate the twiddle factors for our implementations.Makefile: Makefile to build the codebenchmarks.py: This script is used for building, flashing, and evaluating the outputs produced byspeed.c. The desired algorithms as well as the number of iterations can be set in the code.f_benchmarks.py: This script is used for building, flashing, and evaluating the outputs produced byf_speed.c. The desired algorithms as well as the number of iterations can be set in the code. Additionally, it can be switched wether the hashing should be included in the benchmark for the matrix-vector multiplication.read_serial.py: Script to receive serial communication from the target.stack_benchmarks.py: This script is used for building, flashing, and evaluating the outputs produced bystack.c. The desired algorithms as well as the number of iterations can be set in the code.stm32f405x6_full.ld: Linker script using 128kB of memory (SRAM1 and SRAM2)stm32f405x6.ld: Linker script using 112kB of memory (SRAM1 only)stm32f4discovery.cfg: Configuration for openocd in case debugging is desiredtest.py: This script is used for building, flashing, and evaluating the outputs produced bytest.c.
The scripts benchmarks.py, f_benchmarks.py, stack.py and test.py cover most of the frequent use cases.
In case separate, manual testing is required, the binaries for a scheme can be build using
make IMPLEMENTATION_PATH=crypto_{kem,sign}/{scheme}/{variant} bin/crypto_{kem,sign}_{scheme}_{variant}_{firmware}.bin
, where firmware is one of {test, testvectors, speed, f_speed, stack} and variant is one of old, new, newstack (newstack only available for Kyber).
It can then be flashed using:
st-flash --reset write bin/crypto_{kem,sign}_{scheme}_{variant}_{firmware}.bin 0x8000000
For building the test firmware for our speed-optimized version of kyber768 the following command can be used:
make IMPLEMENTATION_PATH=crypto_kem/kyber768/new bin/crypto_kem_kyber768_new_test.bin
It can the be flashed using:
st-flash --reset write bin/crypto_kem_kyber768_new_test.bin 0x8000000