Skip to content

Commit 80459bf

Browse files
committed
test: Add tests for signing and verifying with ML-DSA keys
Create mldsa-44 & mldsa-65 keys if mldsa44 can be created with the installed version of OpenSSL. Add test cases for signing and verifying with these types of keys. Do not test with mldsa-87 keys since the signatures they create may be too large for some filesystems' xattrs. On btrfs, however, it is possible to store their large signatures. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
1 parent e896da7 commit 80459bf

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

tests/gen-keys.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ if [ -x /opt/openssl3/bin/openssl ]; then
148148
done)
149149
fi
150150

151+
# If creating mldsa44 key works, create all ML-DSA sizes
152+
if openssl genpkey -algorithm mldsa44 &>/dev/null; then
153+
for mldsa in mldsa44 mldsa65; do
154+
if [ "$1" = clean ] || [ "$1" = force ]; then
155+
rm -f test-$mldsa.cer test-$mldsa.key test-$mldsa.pub
156+
fi
157+
if [ "$1" = clean ]; then
158+
continue
159+
fi
160+
if [ ! -e test-$mldsa.key ]; then
161+
log openssl req -verbose -new -nodes -utf8 -sha256 -days 10000 -batch -x509 \
162+
-config test-ca.conf \
163+
-newkey "$mldsa" \
164+
-out test-$mldsa.cer -outform DER \
165+
-keyout test-$mldsa.key
166+
if [ -s test-$mldsa.key ]; then
167+
log openssl pkey -in test-$mldsa.key -out test-$mldsa.pub -pubout
168+
fi
169+
fi
170+
done
171+
fi
172+
151173
# This script leaves test-ca.conf, *.cer, *.pub, *.key files for sing/verify tests.
152174
# They are never deleted except by `make distclean'.
153175

tests/sign_verify.test

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ check_sign() {
166166
fi
167167

168168
# Can openssl sign with this digest and key?
169-
cmd="openssl dgst $OPENSSL_ENGINE $OPENSSL_KEYFORM -$ALG -sign $key -hex $FILE"
170-
echo - "$cmd"
171-
if ! $cmd >/dev/null; then
172-
echo "${CYAN}$ALG ($key) test is skipped (openssl is unable to sign)$NORM"
173-
return "$SKIP"
169+
if [ "${KEY:0:10}" != "test-mldsa" ]; then
170+
cmd="openssl dgst $OPENSSL_ENGINE $OPENSSL_KEYFORM -$ALG -sign $key -hex $FILE"
171+
echo - "$cmd"
172+
if ! $cmd >/dev/null; then
173+
echo "${CYAN}$ALG ($key) test is skipped (openssl is unable to sign)$NORM"
174+
return "$SKIP"
175+
fi
174176
fi
175177
fi
176178

@@ -213,8 +215,11 @@ check_sign() {
213215
verifykey=${key}
214216
fi
215217

216-
cmd="openssl dgst $OPENSSL_ENGINE $OPENSSL_KEYFORM -$ALG -verify ${verifykey} \
217-
-signature $FILE.sig2 $FILE"
218+
# ML-DSA uses preHashing, which does not work on command line
219+
if [ "${KEY:0:10}" != "test-mldsa" ]; then
220+
cmd="openssl dgst $OPENSSL_ENGINE $OPENSSL_KEYFORM -$ALG -verify ${verifykey} \
221+
-signature $FILE.sig2 $FILE"
222+
fi
218223
echo - "$cmd"
219224
if ! $cmd; then
220225
color_red_on_failure
@@ -405,6 +410,11 @@ sign_verify prime256v1 sha256 0x030204:K:004[345678]
405410
sign_verify prime256v1 sha384 0x030205:K:004[345678]
406411
sign_verify prime256v1 sha512 0x030206:K:004[345678]
407412

413+
sign_verify mldsa44 sha256 0x030204:K:0974
414+
sign_verify mldsa44 sha512 0x030206:K:0974
415+
sign_verify mldsa65 sha256 0x030204:K:0ced
416+
sign_verify mldsa65 sha512 0x030206:K:0ced
417+
408418
# If openssl 3.0 is installed, test the SM2/3 algorithm combination
409419
ssl_major_version=$(openssl version | sed -n 's/^OpenSSL \([^\.]\).*/\1/p')
410420
if [ "${ssl_major_version}" = 3 ]; then

0 commit comments

Comments
 (0)