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.
pull/141/head
Juliusz Sosinowicz 2026-07-16 13:44:55 +00:00
parent 8bb46362b7
commit 2fea30cd32
1 changed files with 4 additions and 0 deletions

View File

@ -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),