[PATCH 16/17] cipher:dilithium: Support "no-prefix" flag for Dilithium testing.
NIIBE Yutaka via Gcrypt-devel <[email protected]> Sat, 28 Jun 2025 12:44:53 +0900
| Newsgroups | gmane.comp.encryption.gpg.libgcrypt.devel |
|---|---|
| Message-ID | <24be322f28571145c0497685572a0783de3f9260.1751080340.git.gniibe@fsij.org> |
* src/cipher.h (PUBKEY_FLAG_NO_PREFIX): New. * cipher/pubkey-dilithium.c (mldsa_sign, mldsa_verify): Support PUBKEY_FLAG_NO_PREFIX. * cipher/pubkey-util.c (_gcry_pk_util_parse_flaglist): Support PUBKEY_FLAG_NO_PREFIX. -- GnuPG-bug-id: 7640 Signed-off-by: NIIBE Yutaka <[email protected]> --- cipher/pubkey-dilithium.c | 16 ++++++++++++---- cipher/pubkey-util.c | 2 ++ src/cipher.h | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) _______________________________________________ Gcrypt-devel mailing list [email protected] https://lists.gnupg.org/mailman/listinfo/gcrypt-devel
0016-cipher-dilithium-Support-no-prefix-flag-for-Dilithiu.patch
(text/x-patch, 2.3 KB)
diff --git a/cipher/pubkey-dilithium.c b/cipher/pubkey-dilithium.c
index 31910808..7f87a99f 100644
--- a/cipher/pubkey-dilithium.c
+++ b/cipher/pubkey-dilithium.c
@@ -256,8 +256,12 @@ mldsa_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms)
}
else
randombytes (rnd, RNDBYTES);
- r = dilithium_sign (info->algo, sig, info->sig_len, data, data_len,
- ctx.label, ctx.labellen, sk, rnd);
+ if (ctx.flags & PUBKEY_FLAG_NO_PREFIX)
+ r = dilithium_sign (info->algo, sig, info->sig_len, data, data_len,
+ NULL, -1, sk, rnd);
+ else
+ r = dilithium_sign (info->algo, sig, info->sig_len, data, data_len,
+ ctx.label, ctx.labellen, sk, rnd);
if (r < 0)
{
rc = GPG_ERR_INTERNAL;
@@ -343,8 +347,12 @@ mldsa_verify (gcry_sexp_t s_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms)
goto leave;
}
- r = dilithium_verify (info->algo, sig, info->sig_len, data, data_len,
- ctx.label, ctx.labellen, pk);
+ if (ctx.flags & PUBKEY_FLAG_NO_PREFIX)
+ r = dilithium_verify (info->algo, sig, info->sig_len, data, data_len,
+ NULL, -1, pk);
+ else
+ r = dilithium_verify (info->algo, sig, info->sig_len, data, data_len,
+ ctx.label, ctx.labellen, pk);
if (r < 0)
{
rc = GPG_ERR_BAD_SIGNATURE;
diff --git a/cipher/pubkey-util.c b/cipher/pubkey-util.c
index abb44a90..4e8350a8 100644
--- a/cipher/pubkey-util.c
+++ b/cipher/pubkey-util.c
@@ -162,6 +162,8 @@ _gcry_pk_util_parse_flaglist (gcry_sexp_t list,
encoding = PUBKEY_ENC_RAW;
flags |= PUBKEY_FLAG_DJB_TWEAK;
}
+ else if (!memcmp (s, "no-prefix", 9))
+ flags |= PUBKEY_FLAG_NO_PREFIX;
else if (!igninvflag)
rc = GPG_ERR_INV_FLAG;
break;
diff --git a/src/cipher.h b/src/cipher.h
index 5e2e04e3..14cb6fc6 100644
--- a/src/cipher.h
+++ b/src/cipher.h
@@ -45,6 +45,7 @@
#define PUBKEY_FLAG_SM2 (1 << 16)
#define PUBKEY_FLAG_PREHASH (1 << 17)
#define PUBKEY_FLAG_BYTE_STRING (1 << 18)
+#define PUBKEY_FLAG_NO_PREFIX (1 << 19)
/*
* The internal flag to select least leak implementation for ECC.
* It needs to be a distinct value not covered by PUBKEY_* above.