From 2fea30cd32ee09e4e2090f43d3227d5f3fea45c0 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Thu, 16 Jul 2026 13:44:55 +0000 Subject: [PATCH] Validate ctx length in MlDsa.verify (F-4014) MlDsa.sign/sign_with_seed reject a context longer than 255 bytes with ValueError, but verify did not. With ctxLen now correctly declared as byte in the cdef, an over-long ctx would surface as a low-level CFFI OverflowError instead of the consistent ValueError callers get from the signing paths. Reject len(ctx) > 255 with ValueError in verify, matching sign. --- wolfcrypt/ciphers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wolfcrypt/ciphers.py b/wolfcrypt/ciphers.py index b7b8c05..d66071e 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -2364,6 +2364,10 @@ if _lib.ML_DSA_ENABLED: if ctx is not None: ctx_bytestype = t2b(ctx) + if len(ctx_bytestype) > 255: + raise ValueError( + f"context length {len(ctx_bytestype)} too large: must be 255 or less" + ) ret = _lib.wc_dilithium_verify_ctx_msg( sig_bytestype, len(sig_bytestype),