Skip to content

[Bug]: Mismatching docs for ML-DSA size functions #12040

Open

Description

@tobiasbrunner

Contact Details

No response

Version

5.9.4 (same in master)

Description

The documentation of wc_MlDsaKey_Size and wc_MlDsaKey_PrivSize (and the related wc_MlDsaKey_GetPrivLen) is incorrect in doc/dox_comments/header_files/wc_mldsa.h.

It's currently stated that the former is equivalent to the latter and exists for API compatibility only and that both return the size of the private key.

However, the implementation (and documentation) in wolfcrypt/src/wc_mldsa.c shows that while wc_MlDsaKey_Size does, in fact, return the size of the private key, wc_MlDsaKey_PrivSize returns the size of both the private and public key.

So not only are the two functions not equivalent, their naming is quite counter-intuitive (i.e. ...Size would be more suitable for the private+public key size than ...PrivSize and vice-versa). But I guess that can't be changed anymore to remain backwards compatible. But at least the docs should match the actual implementation.

Reproduction steps

No response

Relevant log output

Activity

  1. self-assigned this
    on Nov 6, 2026
  2. dgarske commented on Nov 6, 2026

    @dgarske
    Member

    Hi @tobiasbrunner , thank you for the report and you wc_MlDsaKey_Size() is the private key alone (what wc_MlDsaKey_ExportPrivRaw() writes), and wc_MlDsaKey_PrivSize() / wc_MlDsaKey_GetPrivLen() are the private key with the public key appended, the encoding wc_MlDsaKey_ImportKey() and wc_MlDsaKey_PrivateKeyDecode() take. The names come from the original wc_dilithium_size() / wc_dilithium_priv_size() API, which still map onto them, so as you say they stay. The Doxygen and source comments were wrong; the fix (plus a test pinning PrivSize() == Size() + PubSize()) is in PR #12052.
    Thanks, David Garske, wolfSSL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions