Verify non-null data arg in ellswift xdh_hash_function_prefix #1806

pull furszy wants to merge 1 commits into bitcoin-core:master from furszy:2026_ellswift_xdh_verify_data_arg changing 1 files +1 −0
  1. furszy commented at 8:14 pm on January 23, 2026: member

    The secp256k1_ellswift_xdh API has a data arg that is optional for one of the hash functions (unused) but required for the other.

    This adds a simple check to provide a clear error instead of crashing due to an out-of-bounds memory access when the user mistakenly provides data=NULL and selects the xdh_hash_function_prefix() function.

    Note: Open to improving the arg description in the API as well. I’m just adding this check because a better error would have saved me a few minutes.

  2. Verify non-null data arg in ellswift xdh_hash_function_prefix
    The secp256k1_ellswift_xdh API has a `data` arg that is optional
    for one of the hash functions (unused) but required for the other.
    
    This adds a simple check to provide a clear error instead of crashing
    due to an out-of-bounds memory access when the user mistakenly provides
    data=NULL and selects the `xdh_hash_function_prefix()` function.
    f4708d24d2
  3. sipa commented at 8:19 pm on January 23, 2026: contributor
    ACK f4708d24d21c252279cd865d0e64799ab2159f90
  4. real-or-random added the label assurance on Jan 23, 2026
  5. real-or-random added the label tweak/refactor on Jan 23, 2026
  6. real-or-random commented at 8:23 pm on January 23, 2026: contributor

    when the user mistakenly provides data=NULL

    Note that VERIFY_CHECKs are only active in the tests.

  7. furszy commented at 8:26 pm on January 23, 2026: member

    when the user mistakenly provides data=NULL

    Note that VERIFY_CHECKs are only active in the tests.

    We can’t use ARG_CHECK because ellswift_xdh_hash_function_prefix() doesn’t receive the context (for now). #1777 will solve that and let us add the proper arg check.

    Update: We probably could leave this open until the other PR gets merged.

  8. real-or-random commented at 10:45 am on March 9, 2026: contributor

    We can’t use ARG_CHECK because ellswift_xdh_hash_function_prefix() doesn’t receive the context (for now). #1777 will solve that and let us add the proper arg check.

    Unfortunately, not exactly. ellswift_xdh_hash_function_prefix() now gets the static context, hardcoded. But we need the real context to call the right illegal_callback.

    I think this is an oversight in the API design.

    Whenever there’s an argument where the user can provide a hash function (nonce derivation functions and hashing the raw secret in ECDH/Ellswift), we expose a pointer to our built-in functions in the API. These functions don’t get a context object, which makes sense: the corresponding function type doesn’t allow for a context object because user-provided functions aren’t meant to deal with context objects.

    But what perhaps doesn’t make sense is that we expose these function pointers at all. The user isn’t really supposed to call these functions directly. If anything, the user is supposed to pass these function pointers back to our API functions. So they should have been rather something like “handles” or enum values representing the built-in functions.

    In fact, we always have NULL as a value representing the default built-in, but at least in the ellswift module, there are two built-in functions, one of them being the default. And one of them even makes use of the data pointer, so we can’t even abuse the data pointer to pass the context object…

    All of this is a bit unsatisfactory because it means that the runtime SHA256 won’t work for nonce derivation and ECDH hashing.

    For this PR, using ARG_CHECK will still be okay, I think. Then we call the default illegal callback, which is still better than dereferencing a NULL pointer.


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-03-09 12:15 UTC

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