1
- FROM ubuntu:focal
1
+ FROM ubuntu:focal as base
2
2
3
3
# Install MoCOCrW dependencies (except OpenSSL)
4
4
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
@@ -18,5 +18,82 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-rec
18
18
make \
19
19
ninja-build \
20
20
pkg-config \
21
- wget \
22
- && rm -rf /var/lib/apt/lists/*
21
+ wget
22
+
23
+ FROM base as hsm
24
+
25
+ ARG LIBP11_URL=https://github.com/OpenSC/libp11/releases/download/libp11-0.4.12/libp11-0.4.12.tar.gz
26
+ COPY hsm-patches/0001-Introduce-generic-keypair-generation-interface-and-e.patch \
27
+ dilithium-patches/0001-CMakeLists.txt-Add-BUILD_TESTING-compile-flag.patch \
28
+ dilithium-patches/0002-CMakeLists.txt-Enable-parallel-test-execution.patch \
29
+ dilithium-patches/0003-CMakeLists.txt-Enable-PIE-compilation-flag.patch \
30
+ dilithium-patches/0004-CMakeLists.txt-Add-UBSAN-and-ASAN-build-types.patch \
31
+ dilithium-patches/0005-CMakeLists.txt-Add-cmake-install-target.patch \
32
+ dilithium-patches/0006-CMakelists.txt-Add-stack-protector-strong-flag.patch \
33
+ dilithium-patches/0007-CMakeLists.txt-Change-target_compile_definition.patch \
34
+ dilithium-patches/0008-Add-function-for-pub-key-extraction.patch \
35
+ /tmp/patches/
36
+
37
+ # Install:
38
+ # * MoCOCrW dependencies (except OpenSSL)
39
+ # * libp11
40
+ # * libdilithium
41
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
42
+ # for pkcs11-tool which we use to create keys in token
43
+ opensc \
44
+ # p11-kit-modules allows loading of libp11 engine without having to edit openssl.cnf
45
+ p11-kit-modules \
46
+ # softhsm2: includes both softhsm2-util and libsofthsm2
47
+ softhsm2 \
48
+ # libp11 needs this
49
+ libtool && \
50
+ rm -rf /var/lib/apt/lists/*
51
+
52
+ # Build libp11
53
+ RUN mkdir -p /tmp/libp11 && \
54
+ cd /tmp/libp11 && \
55
+ wget "${LIBP11_URL}" && \
56
+ tar xf libp11-0.4.12.tar.gz && \
57
+ cd libp11-0.4.12 && \
58
+ git apply /tmp/patches/0001-Introduce-generic-keypair-generation-interface-and-e.patch && \
59
+ echo "Successfully patched libp11" && \
60
+ autoreconf --verbose --install --force && \
61
+ ./configure --enable-strict && \
62
+ make -j"$(nproc)" && \
63
+ make check && \
64
+ make install && \
65
+ rm -rf /tmp/libp11
66
+
67
+ FROM base as dilithium
68
+ RUN mkdir /tmp/patches
69
+ COPY dilithium-patches/0001-CMakeLists.txt-Add-BUILD_TESTING-compile-flag.patch \
70
+ dilithium-patches/0002-CMakeLists.txt-Enable-parallel-test-execution.patch \
71
+ dilithium-patches/0003-CMakeLists.txt-Enable-PIE-compilation-flag.patch \
72
+ dilithium-patches/0004-CMakeLists.txt-Add-UBSAN-and-ASAN-build-types.patch \
73
+ dilithium-patches/0005-CMakeLists.txt-Add-cmake-install-target.patch \
74
+ dilithium-patches/0006-CMakelists.txt-Add-stack-protector-strong-flag.patch \
75
+ dilithium-patches/0007-CMakeLists.txt-Change-target_compile_definition.patch \
76
+ dilithium-patches/0008-Add-function-for-pub-key-extraction.patch \
77
+ /tmp/patches/
78
+ RUN mkdir /tmp/libdilithium && \
79
+ cd /tmp/libdilithium && \
80
+ git clone https://github.com/pq-crystals/dilithium && \
81
+ cd dilithium && \
82
+ git checkout 3e9b9f1412f6c7435dbeb4e10692ea58f181ee51 && \
83
+ git apply /tmp/patches/0001-CMakeLists.txt-Add-BUILD_TESTING-compile-flag.patch && \
84
+ git apply /tmp/patches/0002-CMakeLists.txt-Enable-parallel-test-execution.patch && \
85
+ git apply /tmp/patches/0003-CMakeLists.txt-Enable-PIE-compilation-flag.patch && \
86
+ git apply /tmp/patches/0004-CMakeLists.txt-Add-UBSAN-and-ASAN-build-types.patch && \
87
+ git apply /tmp/patches/0005-CMakeLists.txt-Add-cmake-install-target.patch && \
88
+ git apply /tmp/patches/0006-CMakelists.txt-Add-stack-protector-strong-flag.patch && \
89
+ git apply /tmp/patches/0007-CMakeLists.txt-Change-target_compile_definition.patch && \
90
+ git apply /tmp/patches/0008-Add-function-for-pub-key-extraction.patch && \
91
+ mkdir build && \
92
+ cd build && \
93
+ cmake -GNinja .. -DBUILD_TESTING=ON&& \
94
+ ninja && \
95
+ ctest -j"$(nproc)" && \
96
+ ninja install && \
97
+ cd / && \
98
+ rm -rf /tmp/libdilithium && \
99
+ rm -rf /tmp/patches
0 commit comments