Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
166faba
Merge Dev1 to master
quannguyen247 Aug 23, 2025
475645f
Fix minor bugs
quannguyen247 Aug 23, 2025
aad6834
Complete testing (#3)
quannguyen247 Aug 25, 2025
bc9f4d8
Partial complete time gen logic
quannguyen247 Aug 28, 2025
7ba0889
Reformat + gen timing output
quannguyen247 Aug 29, 2025
8031606
Add print testing info
quannguyen247 Aug 29, 2025
68ef354
Fix some minor output, split sign.c to test file and old file
quannguyen247 Aug 29, 2025
6333674
Add ms
quannguyen247 Aug 29, 2025
df71d7a
Add minor things
quannguyen247 Aug 29, 2025
ea35caa
Complete gen testing output
quannguyen247 Aug 29, 2025
2f89516
Fix bug
quannguyen247 Aug 29, 2025
fbfdecf
Merge dev1linux to main (#4)
quannguyen247 Aug 29, 2025
7a07fb7
Add testing function and refactor main for improved test execution
quannguyen247 Aug 30, 2025
0f6feb8
Refactor timing variables in sign.c and update test_dilithium.c for c…
quannguyen247 Aug 30, 2025
0126c4e
Refactor timing structure and enhance test output for better performa…
quannguyen247 Aug 30, 2025
832779c
Fix typo
quannguyen247 Aug 30, 2025
bf34cbf
Set default test count and reformat words
quannguyen247 Aug 30, 2025
7fa2f33
Merge branch 'master' into dev1linux
quannguyen247 Aug 30, 2025
4248cc8
Add CPU usage test script to measure average CPU percent used
quannguyen247 Aug 30, 2025
791eee9
Disable test vector targets for testing
quannguyen247 Aug 30, 2025
6e39ae5
Fix timing and output
quannguyen247 Sep 3, 2025
2fa4c6e
Update minor things
quannguyen247 Nov 28, 2025
9f03174
Sync LICENSE with original repo
quannguyen247 Nov 28, 2025
6bbc3fc
Add CHANGELOG.md and update README.md
quannguyen247 Nov 28, 2025
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
29 changes: 29 additions & 0 deletions .github/workflows/test-ref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests for Dilithium ref implementation

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
level: [2, 3, 5]
steps:
- uses: actions/checkout@v4
- name: Run make
run: |
make -C ref clean
make -C ref nistkat
- name: Copy req file
run: |
cp Dilithium_KAT/Dilithium${{ matrix.level }}/PQCsignKAT_Dilithium${{ matrix.level }}.req ref/
- name: Run PQCgenKAT_sign
run: |
cd ref
chmod +x ./nistkat/PQCgenKAT_sign${{ matrix.level }}
./nistkat/PQCgenKAT_sign${{ matrix.level }}
- name: Verify KAT output
run: |
diff ref/PQCsignKAT_Dilithium${{ matrix.level }}.rsp Dilithium_KAT/Dilithium${{ matrix.level }}/PQCsignKAT_Dilithium${{ matrix.level }}.rsp
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
PQCsignKAT_Dilithium2.req
PQCsignKAT_Dilithium2.rsp
PQCsignKAT_Dilithium3.req
PQCsignKAT_Dilithium3.rsp
PQCsignKAT_Dilithium5.req
PQCsignKAT_Dilithium5.rsp
tvecs2
tvecs3
tvecs5
tvecs5
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.html).

### Summary
This version introduces modifications to the `ref` implementation for performance analysis and benchmarking purposes. The core cryptographic logic of the original Dilithium algorithm remains unchanged. All modifications are confined to the `ref` directory and supplementary testing scripts.

### Added
- **Performance Benchmarking Framework:**
- Introduced a `timing_info_t` struct in `ref/sign.h` to capture execution time for key generation, signing, and verification steps.
- Integrated `clock_gettime` with `CLOCK_MONOTONIC` in `ref/sign.c` to precisely measure the duration of `crypto_sign_keypair`, `crypto_sign_signature`, and `crypto_sign_verify`. This required adding `#include <time.h>` and defining `_POSIX_C_SOURCE`.
- Added `print_timing_info()` function to display aggregated timing results.
- **Automated Testing Support:**
- Added `run_test` function prototype in `ref/sign.h` to facilitate running tests multiple times for stable performance metrics.
- **Sample Input File:**
- Added `ref/test/input.txt` to provide a consistent sample input for testing and debugging.

### Changed
- **Disabled Debug Outputs:**
- The extensive `printf` statements previously used for tracing the algorithm's flow in `ref/sign.c` have been disabled to allow for clean performance measurement. The original version with these outputs is preserved in `sign.c.old` for reference.
- The temporary debug feature in `ref/test/test_dilithium.c` that wrote detailed outputs to `output.txt` has also been disabled. The test now only reads from `input.txt`.
- **Code Formatting:**
- Applied consistent code formatting (e.g., spacing, newlines) across multiple files in the `ref` directory to improve readability.
- **Makefile Adjustments:**
- Modified `ref/Makefile` to disable the compilation of `test_vectors` targets, streamlining the build process for performance testing.

### Removed
- (No features removed from the core implementation)

### Acknowledgements
This project is a fork of the official [pq-crystals/dilithium](https://github.com/pq-crystals/dilithium) repository. The modifications, available at [quannguyen247/dilithium-dev](https://github.com/quannguyen247/dilithium-dev), are focused on performance analysis and benchmarking. The core cryptographic logic of the original public domain implementation of CRYSTALS-Dilithium remains unchanged.
900 changes: 900 additions & 0 deletions Dilithium_KAT/Dilithium2/PQCsignKAT_Dilithium2.req

Large diffs are not rendered by default.

902 changes: 902 additions & 0 deletions Dilithium_KAT/Dilithium2/PQCsignKAT_Dilithium2.rsp

Large diffs are not rendered by default.

900 changes: 900 additions & 0 deletions Dilithium_KAT/Dilithium3/PQCsignKAT_Dilithium3.req

Large diffs are not rendered by default.

902 changes: 902 additions & 0 deletions Dilithium_KAT/Dilithium3/PQCsignKAT_Dilithium3.rsp

Large diffs are not rendered by default.

900 changes: 900 additions & 0 deletions Dilithium_KAT/Dilithium5/PQCsignKAT_Dilithium5.req

Large diffs are not rendered by default.

902 changes: 902 additions & 0 deletions Dilithium_KAT/Dilithium5/PQCsignKAT_Dilithium5.rsp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Public Domain (https://creativecommons.org/share-your-work/public-domain/cc0/);
or Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0.html).
or Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0.html) or GPL 2.0 License (http://www.gnu.org/licenses/gpl-2.0.html).

For Keccak and the random number generator
we are using public-domain code from sources
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Custom Dilithium Implementation for PQC Research & Benchmarking

This repository is a fork of the official [Dilithium](https://github.com/pq-crystals/dilithium) implementation, customized by **quannguyen247** for the purpose of experimenting with, modifying, and benchmarking Post-Quantum Cryptography (PQC) algorithms.

## Purpose
The primary goal of this fork is to provide a flexible framework for research and detailed performance analysis. Key objectives include:
- **Algorithmic Experimentation:** Facilitating modifications to core components such as hash functions and matrix operations to study their impact on security and efficiency.
- **Comparative Analysis:** Enabling side-by-side performance comparisons of different implementation strategies and optimizations.
- **Performance Metrics:** Precise execution time measurement for key generation, signing, and verification.

## Key Modifications
Significant changes have been made to the `ref` implementation to support these goals. For a detailed list of all modifications, please refer to the [CHANGELOG.md](CHANGELOG.md) file.

---

# Dilithium

[![Build Status](https://travis-ci.org/pq-crystals/dilithium.svg?branch=master)](https://travis-ci.org/pq-crystals/dilithium) [![Coverage Status](https://coveralls.io/repos/github/pq-crystals/dilithium/badge.svg?branch=master)](https://coveralls.io/github/pq-crystals/dilithium?branch=master)
Expand Down
10 changes: 10 additions & 0 deletions ref/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
*.so
*.o
test/test_vectors*
test/test_dilithium*
test/test_speed*
test/test_mul
test/output.txt
nistkat/*.req
nistkat/*.rsp
nistkat/PQCgenKAT_sign2
nistkat/PQCgenKAT_sign3
nistkat/PQCgenKAT_sign5
13 changes: 7 additions & 6 deletions ref/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CC ?= /usr/bin/cc
CC = gcc
CFLAGS += -Wall -Wextra -Wpedantic -Wmissing-prototypes -Wredundant-decls \
-Wshadow -Wvla -Wpointer-arith -O3 -fomit-frame-pointer
-Wshadow -Wvla -Wpointer-arith -O3 -fomit-frame-pointer \
-z noexecstack
NISTFLAGS += -Wno-unused-result -O3 -fomit-frame-pointer
SOURCES = sign.c packing.c polyvec.c poly.c ntt.c reduce.c rounding.c
HEADERS = config.h params.h api.h sign.h packing.h polyvec.h poly.h ntt.h \
Expand All @@ -14,9 +15,9 @@ all: \
test/test_dilithium2 \
test/test_dilithium3 \
test/test_dilithium5 \
test/test_vectors2 \
test/test_vectors3 \
test/test_vectors5
#test/test_vectors2 \
#test/test_vectors3 \
#test/test_vectors5

nistkat: \
nistkat/PQCgenKAT_sign2 \
Expand Down Expand Up @@ -136,4 +137,4 @@ clean:
rm -f test/test_mul
rm -f nistkat/PQCgenKAT_sign2
rm -f nistkat/PQCgenKAT_sign3
rm -f nistkat/PQCgenKAT_sign5
rm -f nistkat/PQCgenKAT_sign5
3 changes: 0 additions & 3 deletions ref/nistkat/.gitignore

This file was deleted.

Loading