doc: fix msg argument description of nonce function typedefs #1985

pull amartya1523 wants to merge 2 commits into bitcoin-core:master from amartya1523:doc-api-fixes changing 2 files +2 −2
  1. amartya1523 commented at 4:07 PM on November 3, 2026: contributor

    The docs for secp256k1_nonce_function and secp256k1_nonce_function_hardened both describe the message argument as the one "being verified". Nonce functions are only ever called from the signing functions, so the first commit changes this to "being signed".

    The hardened nonce function docs also say msg is NULL if and only if msglen is 0. That is stricter than what secp256k1_schnorrsig_sign_custom enforces: it only checks msg != NULL || msglen == 0 and passes msg through to the nonce function unchanged, so a custom nonce function can see a non-NULL msg with msglen == 0. The second commit uses the same "Can only be NULL if msglen is 0" wording that sign_custom already has.

  2. doc: nonce functions are called on the message being signed
    Both nonce function typedefs described the msg argument as the message
    "being verified", but nonce functions are only ever invoked by the
    signing functions (secp256k1_ecdsa_sign, secp256k1_ecdsa_sign_recoverable
    and secp256k1_schnorrsig_sign_*).
    5871168f7d
  3. doc: msg passed to hardened nonce function can be non-NULL when empty
    The hardened nonce function docs claimed msg is NULL if and only if
    msglen is 0. secp256k1_schnorrsig_sign_custom only requires that msg is
    non-NULL when msglen is non-zero and hands msg through to the nonce
    function unchanged, so a caller signing an empty message may pass either
    NULL or a non-NULL pointer. Use the same wording as sign_custom.
    c93c85c3eb
  4. amartya1523 closed this on Nov 3, 2026

  5. real-or-random commented at 7:11 AM on November 5, 2026: contributor

    The docs for secp256k1_nonce_function and secp256k1_nonce_function_hardened both describe the message argument as the one "being verified". Nonce functions are only ever called from the signing functions, so the first commit changes this to "being signed".

    Nice catch, ACK.

    The hardened nonce function docs also say msg is NULL if and only if msglen is 0. That is stricter than what secp256k1_schnorrsig_sign_custom enforces: it only checks msg != NULL || msglen == 0 and passes msg through to the nonce function unchanged, so a custom nonce function can see a non-NULL msg with msglen == 0. The second commit uses the same "Can only be NULL if msglen is 0" wording that sign_custom already has.

    Hm, I think this is a genuine bug. There's a non-zero probability that there's a custom nonce function out there that relies on the promise and just hasn't been called with an empty message so far. So I tend to think that we should err on the safe side here and rather change the semantics to what the API promised, i.e., add an if (msglen == 0) msg = NULL; with an appropriate comment to secp256k1_schnorrsig_sign_internal(). Ideally, this should get a test, too.

  6. real-or-random reopened this on Nov 5, 2026

  7. real-or-random added the label user-documentation on Nov 5, 2026
  8. real-or-random added the label bug on Nov 5, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-12 07:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me