This reminds me of https://github.com/bitcoin-core/secp256k1/pull/636/commits/b33a8e49e89f5a1ea02a9b9b9b208cb4f3d59e44 Okay, the PR is almost 4 years old now… :/ But I should continue the work at some point.
Currently, clear
is mostly used to kill secrets (though that doesn’t work due to dead-store elimination), and this should be separated from setting to 0 in the future for the purposes of the aforementioned PR. Now, the advantage of clear
over set_int(0)
is that the former sets the magnitude to 0 instead of 1. In the mentioned PR, I change set_int
to do the same for input 0 but that’s a bad idea because we want statically implied magnitude in the long term. The proper solution to all of this is a set_zero
function that guarantees to set the value and magnitude to 0 (and won’t just clear out memory).
What does this mean for this PR? To avoid getting side tracked again, I’d say don’t introduce that new function here, but maybe keep that line and the instances below just how it is. That avoids introducing more code locations where clear
is not used for clearing memory. The current behavior of setting magnitude of 1 is apparently good enough with the current code.