Skip to content

eBPF-based security platform

sign: sign only with ML-DSA-87 keys

Daniel Borkmann9d6faffcae78
diff --git a/testing/t0029-mldsa-sign.sh b/testing/t0029-mldsa-sign.sh
index 3c7a7644..11992d07 100755
--- a/testing/t0029-mldsa-sign.sh
+++ b/testing/t0029-mldsa-sign.sh
@@ -8,7 +8,8 @@
# SignerInfo, keyid signer, no embedded cert, SHA-512 signed attributes
# without signingTime on OpenSSL 3.x) by verifying it with openssl over
# the exact loader_insns || data bytes the kernel folds. Also checks
-# that the builder refuses a classical (RSA) signing key outright.
+# that the builder refuses a classical (RSA) signing key outright, and
+# an ML-DSA key of a smaller parameter set than ML-DSA-87.
# Needs clang and shirudo-build; the ML-DSA cases need OpenSSL >= 3.5.
cd "$(dirname "$0")"
@@ -58,7 +59,7 @@ test_expect_success 'shirudo-build refuses to sign with an RSA key' '
! ( cd .. && "$B" "$WORK/t.bpf.c" -o "$WORK/rsa.upatch" --vmlinux vendor/linux/vmlinux.h \
--name t0029rsa --key "$WORK/rsa.pem" --cert "$WORK/rsa.der" ) \
>"$WORK/rsa.out" 2>&1 &&
- grep -q "ML-DSA only" "$WORK/rsa.out" &&
+ grep -q "ML-DSA-87 only" "$WORK/rsa.out" &&
! test -e "$WORK/rsa.upatch"
'
@@ -67,6 +68,17 @@ if ! openssl list -public-key-algorithms 2>/dev/null | grep -qi 'ML-DSA'; then
test_done
fi
+test_expect_success 'shirudo-build refuses to sign with an ML-DSA-65 key' '
+ openssl req -x509 -newkey ML-DSA-65 -nodes -keyout "$WORK/mldsa65.pem" \
+ -outform DER -out "$WORK/mldsa65.der" -days 1 -subj "/CN=t0029" \
+ >/dev/null 2>&1 &&
+ ! ( cd .. && "$B" "$WORK/t.bpf.c" -o "$WORK/mldsa65.upatch" --vmlinux vendor/linux/vmlinux.h \
+ --name t0029mldsa65 --key "$WORK/mldsa65.pem" --cert "$WORK/mldsa65.der" ) \
+ >"$WORK/mldsa65.out" 2>&1 &&
+ grep -q "ML-DSA-65 key; shirudo signs with ML-DSA-87 only" "$WORK/mldsa65.out" &&
+ ! test -e "$WORK/mldsa65.upatch"
+'
+
"$S" genkey --keys-dir "$WORK/keys" >/dev/null 2>&1 ||
test_skip_all "genkey failed"
( cd .. && "$B" "$WORK/t.bpf.c" -o "$WORK/u.upatch" --vmlinux vendor/linux/vmlinux.h \
diff --git a/util/sign.c b/util/sign.c
index 77037630..37f11069 100644
--- a/util/sign.c
+++ b/util/sign.c
@@ -20,7 +20,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <strings.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -152,11 +151,13 @@ cleanup:
return x509;
}
-static bool pkey_is_mldsa(const EVP_PKEY *pkey)
+/*
+ * Only ML-DSA-87: the target's trust set refuses the smaller parameter
+ * sets, so an artifact signed with one could never load.
+ */
+static bool pkey_is_mldsa87(const EVP_PKEY *pkey)
{
- const char *name = EVP_PKEY_get0_type_name(pkey);
-
- return name && strncasecmp(name, "ML-DSA", 6) == 0;
+ return EVP_PKEY_is_a(pkey, "ML-DSA-87");
}
int cms_sign(struct shirudo_sign_io *io,
@@ -204,8 +205,8 @@ int cms_sign(struct shirudo_sign_io *io,
err = -EINVAL;
goto cleanup;
}
- if (!pkey_is_mldsa(private_key)) {
- pr_err("%s: %s key; shirudo signs with ML-DSA only "
+ if (!pkey_is_mldsa87(private_key)) {
+ pr_err("%s: %s key; shirudo signs with ML-DSA-87 only "
"(re-key with shirudo genkey)", pkey_path,
EVP_PKEY_get0_type_name(private_key) ?: "unknown");
err = -EINVAL;
@@ -225,7 +226,7 @@ int cms_sign(struct shirudo_sign_io *io,
* (crypto/asymmetric_keys/public_key.c). Same workaround as
* bpftool and module signing; OpenSSL 4 signs the content directly.
*/
- if (pkey_is_mldsa(private_key)) {
+ if (pkey_is_mldsa87(private_key)) {
signer_flags &= ~CMS_NOATTR;
cms_digest = EVP_sha512();
}