musig: declassify the keypair's pubkey in nonce_gen_counter #1979

pull fametrano wants to merge 1 commits into bitcoin-core:master from fametrano:musig-declassify-nonce-gen-counter changing 2 files +4 −0
  1. fametrano commented at 10:40 PM on October 23, 2026: contributor

    nonce_gen_counter does not declassify the pubkey it copies from the keypair, though nonce_gen_internal loads it with pubkey_load, which ARG_CHECKs it, and serializes it. keypair_load declassifies the same data for the same reason. Declassify the copy here too.

    ctime_tests passed a keypair that was never marked as secret, so it could not see this. It now marks the keypair as undefined before the call. Without the declassify, ctime_tests under valgrind reports 3 errors. With it, it reports none.

  2. fametrano force-pushed on Nov 2, 2026
  3. musig: declassify the keypair's pubkey in nonce_gen_counter
    nonce_gen_counter does not declassify the pubkey it copies from the
    keypair, though nonce_gen_internal loads it with pubkey_load, which
    ARG_CHECKs it, and serializes it. keypair_load declassifies the same
    data for the same reason. Declassify the copy here too.
    
    ctime_tests passed a keypair that was never marked as secret, so it
    could not see this. It now marks the keypair as undefined before the
    call. Without the declassify, ctime_tests under valgrind reports 3
    errors. With it, it reports none.
    9dbda26ae2
  4. fametrano force-pushed on Nov 20, 2026
  5. IsaqueFranklin commented at 2:22 AM on November 24, 2026: none

    utACK 9dbda26ae23b7460164f5e43d1e21895dbd3ba91

    Seems reasonable to cover this on the tests and the code looks okay. Did not run Valgrind.

    I initially thought about declassifying the pubkey inside the _nonce_gen_internal instead, because both _nonce_gen and _nonce_gen_counter use it, but _nonce_gen does not copy the pubkey from a keypair, but receives it already loaded as a pubkey object. So, I guess this approach makes more sense.

  6. theStack approved
  7. theStack commented at 2:37 PM on November 26, 2026: contributor

    ACK 9dbda26ae23b7460164f5e43d1e21895dbd3ba91

  8. theStack merged this on Nov 26, 2026
  9. theStack closed this on Nov 26, 2026

  10. github-actions[bot] referenced this in commit 0f14125a1f on Nov 26, 2026
  11. in src/ctime_tests.c:303 in 9dbda26ae2
     299 | @@ -300,6 +300,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) {
     300 |          ret = secp256k1_musig_nonce_gen(ctx, &secnonce, &pubnonce, session_secrand, key, &pk, msg, &cache, extra_input);
     301 |          SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret));
     302 |          CHECK(ret == 1);
     303 | +        SECP256K1_CHECKMEM_UNDEFINE(&keypair, sizeof(keypair));
    


    real-or-random commented at 7:28 AM on November 27, 2026:

    I think that's the wrong fix. Only the secret part of keypair should be undefined.

    The best way to achieve this is to undefine the secret key key from which the keypair is created, as in the other tests. This is done a few lines above but too late, namely only after keypair is generated.


    theStack commented at 1:53 PM on November 27, 2026:

    I agree that's the better solution. In terms of test coverage it doesn't seem different though, as _keypair_create with an undefined key also taints the keypair's public part, IIUC?


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-12-02 10:15 UTC

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