Commit Graph

1327 Commits

Author SHA1 Message Date
Jonas Nick
5e74086dc8 Merge bitcoin-core/secp256k1#1705: musig/test: Remove dead code
8d967a602b musig/test: Remove dead code (Tim Ruffing)
983711cd6d musig/tests: Refactor vectors_signverify (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 8d967a602b

Tree-SHA512: 9cc3d84250a677a22badf8fb18d5c159816f2237f9dd8ac796e65a6e89921066aa718b4eb773e9c473ac61d5f18c392ae380d4e4b4e2c3424feff9475a1ce053
2025-07-21 13:06:25 +00:00
merge-script
7c3380423c Merge bitcoin-core/secp256k1#1696: build: Refactor visibility logic and add override
c82d84bb86 build: add CMake option for disabling symbol visibility attributes (Cory Fields)
ce7923874f build: Add SECP256K1_NO_API_VISIBILITY_ATTRIBUTES (Tim Ruffing)
e5297f6d79 build: Refactor visibility logic (Tim Ruffing)

Pull request description:

  This is less invasive than #1695. The latter might be the right thing in a new library (and then we'd probably not support autotools in the first place), but any semantic change to this code has the potential to create news bug, or at least breakages for downstream users.

  This is different from #1677 in that it does not set `hidden` explicitly. I agree with the comment in #1677 that setting `hidden` violates the principle of least surprise.

  So this similar in spirit to #1674. So I wonder if this should also include
  3eef7362c4. I'd say no, `fvisibility` should then set by the user. But can you, in CMake, set `CMAKE_C_VISIBILITY_PRESET` from a parent project?

ACKs for top commit:
  hebasto:
    ACK c82d84bb86, I have reviewed the code and it looks OK.

Tree-SHA512: dad36c32a108d813e8d4e1849260af43f79a9aa8fbfb9a42b07d737e0467924a511110df0a2c6761539a1587b617a1b11123610a3db9d4cdf2b985dfb3eb21da
2025-07-21 14:55:10 +02:00
Tim Ruffing
8d967a602b musig/test: Remove dead code
This avoids a compiler warning on clang-snapshot about &keypair being uninitialized.
2025-07-21 14:47:57 +02:00
Tim Ruffing
983711cd6d musig/tests: Refactor vectors_signverify
for improved readability
2025-07-21 14:44:57 +02:00
Hennadii Stepanov
bf082221ff cmake: Make secp256k1_objs inherit interface defines from secp256k1
This change effectively adds `-DSECP256K1_STATIC` to usage requirements
of `secp256k1_objs` on Windows, preventing LNK4217 linker warnings.
2025-07-18 17:37:09 +01:00
Cory Fields
c82d84bb86 build: add CMake option for disabling symbol visibility attributes
Co-authored-by: Tim Ruffing <me@real-or-random.org>
2025-07-18 13:59:51 +02:00
merge-script
29e73f4ba5 Merge bitcoin-core/secp256k1#1685: cmake: Emulate Libtool's behavior on FreeBSD
37dd422b5c cmake: Emulate Libtool's behavior on FreeBSD (Hennadii Stepanov)

Pull request description:

  Building the master branch @ f24b838bed on FreeBSD 14.3:
  - with Autotools:
  ```
  $ ./autogen.sh
  $ ./configure --disable-static --prefix /tmp/AUTOTOOLS
  $ gmake
  $ gmake install
  $ tree /tmp/AUTOTOOLS/lib
  /tmp/AUTOTOOLS/lib
  ├── libsecp256k1.la
  ├── libsecp256k1.so -> libsecp256k1.so.5.0.1
  ├── libsecp256k1.so.5 -> libsecp256k1.so.5.0.1
  ├── libsecp256k1.so.5.0.1
  └── pkgconfig
      └── libsecp256k1.pc

  2 directories, 5 files
  ```
  - with CMake:
  ```
  $ cmake -B build -DCMAKE_INSTALL_PREFIX=/tmp/CMAKE
  $ cmake --build build
  $ cmake --install build
  $ tree /tmp/CMAKE/lib
  /tmp/CMAKE/lib
  ├── cmake
  │   └── libsecp256k1
  │       ├── libsecp256k1-config-version.cmake
  │       ├── libsecp256k1-config.cmake
  │       ├── libsecp256k1-targets-relwithdebinfo.cmake
  │       └── libsecp256k1-targets.cmake
  ├── libsecp256k1.so -> libsecp256k1.so.5
  ├── libsecp256k1.so.5
  └── pkgconfig
      └── libsecp256k1.pc

  4 directories, 7 files
  ```

  With this PR:
  ```
  $ cmake -B build -DCMAKE_INSTALL_PREFIX=/tmp/CMAKE+PR
  $ cmake --build build
  $ cmake --install build
  $ tree /tmp/CMAKE+PR/lib
  /tmp/CMAKE+PR/lib
  ├── cmake
  │   └── libsecp256k1
  │       ├── libsecp256k1-config-version.cmake
  │       ├── libsecp256k1-config.cmake
  │       ├── libsecp256k1-targets-relwithdebinfo.cmake
  │       └── libsecp256k1-targets.cmake
  ├── libsecp256k1.so -> libsecp256k1.so.5
  ├── libsecp256k1.so.5 -> libsecp256k1.so.5.0.1
  ├── libsecp256k1.so.5.0.1
  └── pkgconfig
      └── libsecp256k1.pc

  4 directories, 8 files
  ```

  From [FreeBSD Developers' Handbook](https://docs.freebsd.org/en/books/developers-handbook/policies/#policies-shlib):
  > If you are adding shared library support to a port or other piece of software that does not have one, the version numbers should follow these rules. Generally, the resulting numbers will have nothing to do with the release version of the software.
  >
  > For ports:
  >
  >    - Prefer using the number already selected by upstream
  >
  >    - If upstream provides symbol versioning, ensure that we use their script

ACKs for top commit:
  real-or-random:
    utACK 37dd422b5c

Tree-SHA512: b603d7e293ae1fb15c2b3c05957dcc3cbe94294083ad1d8cb00b06b0e295597fa09719d32c18d628670952b6d00467f5bc884be9ab791baf59ec265e26032470
2025-06-24 11:45:28 +02:00
Cory Fields
145ae3e28d cmake: add a helper for linking into static libs
Parent projects (Bitcoin Core in this case) may wish to include secp256k1
in another static library (libbitcoinkernel) so that users are not forced
to bring their own static libsecp256k1.

Unfortunately, CMake lacks the machinery to link (combine) one static lib
into another.

To work around this, secp256k1_objs is exposed as an interface library which
parent projects can "link" into static libs..
2025-06-16 16:59:52 +00:00
Hennadii Stepanov
37dd422b5c cmake: Emulate Libtool's behavior on FreeBSD 2025-06-11 01:01:34 +01:00
Hennadii Stepanov
6f67151ee2 cmake: Use PUBLIC_HEADER target property
This change simplifies the installation logic.
2025-06-04 14:46:10 +01:00
Hennadii Stepanov
c32715b2a0 cmake, move-only: Move module option processing to src/CMakeLists.txt
This change simplifies the following commit.
2025-06-04 13:13:33 +01:00
Hennadii Stepanov
3af71987a8 cmake: Bump minimum required CMake version to 3.22
Ubuntu 20.04 LTS has reached the end of standard support. There no
longer appear to be compelling reasons to maintain compatibility with
CMake 3.16.
The new suggested minimum, CMake 3.22, is shipped with Ubuntu 22.04 LTS,
which is supported until April 2027.

This change also introduces new CMake policies, from CMP0098 to CMP0128.
2025-05-30 11:59:31 +01:00
Peter.Dettman
3a4f448cb4 Assert field magnitude at control-flow join 2025-05-20 17:48:22 +07:00
Jonas Nick
9fab425256 Merge bitcoin-core/secp256k1#1668: bench_ecmult: add benchmark for ecmult_const_xonly
05445377f4 bench_ecmult: add benchmark for ecmult_const_xonly (Sebastian Falbesoner)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 05445377f4

Tree-SHA512: cb676bc561f742782795015a4e32c6c505817ae6a48fbe5accf4c0fb7690077a7f9f2836431b11be83983b3fffd494437e10ddea6e81226dbd2e05177647ea33
2025-05-14 20:00:54 +00:00
Sebastian Falbesoner
05445377f4 bench_ecmult: add benchmark for ecmult_const_xonly 2025-05-14 17:45:19 +02:00
RandomLattice
d73ed99479 tests: update wycheproof files
Wycheproof ownership was recently moved to C2SP
(https://github.com/C2SP/wycheproof). This PR updates all references to the new
URL and bumps to the latest version of the vector files.

This commit does not change the content of processed .h testvector files. To test:
```
make clean-testvectors testvectors
```

See: https://github.com/bitcoin-core/secp256k1/pull/1492#discussion_r1572443456

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
2025-05-13 19:46:47 +09:00
Jonas Nick
4187a46649 Merge bitcoin-core/secp256k1#1492: tests: Add Wycheproof ECDH vectors
e266ba11ae tests: Add Wycheproof ECDH vectors (RandomLattice)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK e266ba11ae

Tree-SHA512: a5cc59886595b134dadcc50e6cd6f03ce036c2857cdd848f138f0c49d4bd742ae5eb5ebca7840ec8666b5d43fa9c4f67cde4d0fb2245b1cf56b079ca3f7c7f8e
2025-05-12 19:50:56 +00:00
RandomLattice
e266ba11ae tests: Add Wycheproof ECDH vectors
Adds a test for the ECDH module using the Wycheproof vectors.
We use a python script to convert the JSON-formatted vectors
into C code, in the same spirit as https://github.com/bitcoin-core/secp256k1/pull/1245

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
2025-05-12 11:27:45 -04:00
Jonas Nick
6b3fe51fb6 bench: add ellswift to bench help output 2025-03-13 14:51:17 +00:00
Jonas Nick
51907fa918 tests: remove unused uncounting_illegal_callback_fn
This callback function has been unused since
a1d52e3e12
2025-03-13 08:01:08 +00:00
merge-script
a7a5117144 Merge bitcoin-core/secp256k1#1359: Fix symbol visibility issues, add test for it
d1478763a5 build: Drop no longer needed  `-fvisibility=hidden` compiler option (Hennadii Stepanov)
8ed1d83d92 ci: Run `tools/symbol-check.py` (Hennadii Stepanov)
41d32ab2de test: Add `tools/symbol-check.py` (Hennadii Stepanov)
88548058b3 Introduce `SECP256K1_LOCAL_VAR` macro (Hennadii Stepanov)

Pull request description:

  Closes https://github.com/bitcoin-core/secp256k1/issues/1181.

  [Catches](https://github.com/bitcoin-core/secp256k1/pull/1359#issuecomment-2417892235) the actual symbol visibility issue.

  Replaces https://github.com/bitcoin-core/secp256k1/pull/1135.

ACKs for top commit:
  real-or-random:
    reACK d1478763a5

Tree-SHA512: 4d39f3c4cd32afa2b4418ca79331c72827c76a49a5422afa7c85e60d00a750b91b1b1ab10d91ba578f5817dd938016751168758461fb89de8da56f7d005ae2da
2025-03-13 08:29:42 +01:00
Jonas Nick
13ed6f65dc Merge bitcoin-core/secp256k1#1593: Remove deprecated _ec_privkey_{negate,tweak_add,tweak_mul} aliases from API
37d2c60bec Remove deprecated _ec_privkey_{negate,tweak_add,tweak_mul} aliases (Sebastian Falbesoner)

Pull request description:

ACKs for top commit:
  real-or-random:
    utACK 37d2c60bec
  sipa:
    utACK 37d2c60bec
  jonasnick:
    ACK 37d2c60bec

Tree-SHA512: 5d3c836c3c4d5cde143fe5b5235f9fc108174439b056f3418834f33d12ea28bdf09d11a81917d679b4b9a93da26304241c8fe389549e72796bbda116e9ff4945
2025-03-12 20:01:59 +00:00
Hennadii Stepanov
88548058b3 Introduce SECP256K1_LOCAL_VAR macro
This change makes the `-fvisibility=hidden` compiler option unnecessary.
2025-03-11 21:58:55 +00:00
Tim Ruffing
961ec25a83 musig: Fix clearing of pubnonces
Fixes a silent merge conflict between #1614 and #1579.
2025-03-10 15:10:29 +01:00
merge-script
3186082387 Merge bitcoin-core/secp256k1#1614: Add _ge_set_all_gej and use it in musig for own public nonces
64228a648f musig: Use _ge_set_all_gej for own public nonces (Tim Ruffing)
300aab1c05 tests: Improve _ge_set_all_gej(_var) tests (Tim Ruffing)
365f274ce3 group: Simplify secp256k1_ge_set_all_gej (Tim Ruffing)
d3082ddead group: Add constant-time secp256k1_ge_set_all_gej (Tim Ruffing)

Pull request description:

  As suggested in https://github.com/bitcoin-core/secp256k1/pull/1479#discussion_r1781469191

ACKs for top commit:
  theStack:
    re-ACK 64228a648f
  sipa:
    ACK 64228a648f

Tree-SHA512: f62a95e44dc09bb55a64da0640ad323e7ef5acc262d3c2aea6787eae0918769ea97da466b7d602e59693e4fb85c5ec9a67fdfba8b890624467855b6d1e1596c0
2025-03-10 14:44:37 +01:00
Sebastian Falbesoner
37d2c60bec Remove deprecated _ec_privkey_{negate,tweak_add,tweak_mul} aliases
These function aliases have been described as DEPRECATED in the public
API docs already many years ago (see #701, commit 41fc7856), and in
addition explicit deprecation warnings are shown by the compiler at
least since the first official release 0.2.0 (see PR #1089, commit
fc94a2da), so it should be fine to just remove them by now.

Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2025-02-25 04:17:45 +01:00
Daniel Pfeifer
432ac57705 Make static context const 2025-02-24 17:25:27 +01:00
merge-script
1b1fc09341 Merge bitcoin-core/secp256k1#1642: Verify compressed argument in secp256k1_eckey_pubkey_serialize
1823594761 Verify `compressed` argument in `secp256k1_eckey_pubkey_serialize` (Sebastian Falbesoner)

Pull request description:

  Due to similarity to the public API function `secp256k1_ec_pubkey_serialize`, public API flags like `SECP256K1_EC_COMPRESSED` are sometimes mistakingly passed to `secp256k1_eckey_pubkey_serialize` in newly proposed code (this is currently the case for several modules in secp256k1-zkp, see https://github.com/BlockstreamResearch/secp256k1-zkp/pull/300), which is currently not detected. To avoid this in the future, a VERIFY_CHECK is added to check that the `compressed` argument is either 0 or 1.

ACKs for top commit:
  real-or-random:
    utACK 1823594761
  stratospher:
    ACK 1823594. Got tests failures when passing public API flags to `secp256k1_eckey_pubkey_serialize`.

Tree-SHA512: ca542afc87f33e436ba33dc55b285dfe3759007c446ef94503bc1044c7a0a7f7b2208ae82e2c9743fc5fa38cf386127f3fbfa02d2c242f28fab3041ee46f153b
2025-02-24 15:24:38 +01:00
Sebastian Falbesoner
c855581728 test, bench, precompute_ecmult: use EXIT_... constants for main return values 2025-02-14 18:03:36 +01:00
Sebastian Falbesoner
a82287fb85 schnorrsig: clear out masked secret key in BIP-340 nonce function 2025-01-29 04:05:02 +01:00
Sebastian Falbesoner
1823594761 Verify compressed argument in secp256k1_eckey_pubkey_serialize
Due to similarity to the public API function `secp256k1_ec_pubkey_serialize`,
public API flags like `SECP256K1_EC_COMPRESSED` are sometimes mistakingly
passed to newly proposed code (this is currently the case for several modules in
secp256k1-zkp, see https://github.com/BlockstreamResearch/secp256k1-zkp/pull/300).
which is currently not detected. To avoid this in the future, a VERIFY_CHECK
is added to check that the `compressed` argument is either 0 or 1.
2024-12-02 18:20:18 +01:00
Nicolas Iooss
39705450eb Fix some misspellings
Some files contained English misspellings or math issues (`lamba`
instead of `lambda`).
2024-11-05 19:29:03 +01:00
Hennadii Stepanov
145868a84d Do not export secp256k1_musig_nonce_gen_internal 2024-11-04 15:59:41 +00:00
merge-script
b161bffb8b Merge bitcoin-core/secp256k1#1579: Clear sensitive memory without getting optimized out (revival of #636)
765ef53335 Clear _gej instances after point multiplication to avoid potential leaks (Sebastian Falbesoner)
349e6ab916 Introduce separate _clear functions for hash module (Tim Ruffing)
99cc9fd6d0 Don't rely on memset to set signed integers to 0 (Tim Ruffing)
97c57f42ba Implement various _clear() functions with secp256k1_memclear() (Tim Ruffing)
9bb368d146 Use secp256k1_memclear() to clear stack memory instead of memset() (Tim Ruffing)
e3497bbf00 Separate between clearing memory and setting to zero in tests (Tim Ruffing)
d79a6ccd43 Separate secp256k1_fe_set_int( . , 0 ) from secp256k1_fe_clear() (Tim Ruffing)
1c08126222 Add secp256k1_memclear() for clearing secret data (Tim Ruffing)
e7d384488e Don't clear secrets in pippenger implementation (Tim Ruffing)

Pull request description:

  This PR picks up #636 (which in turn picked up #448, so this is take number three) and is essentially a rebase on master.

  Some changes to the original PR:
  * the clearing function now has the `secp256k1_` prefix again, since the related helper `_memczero` got it as well (see PR #835 / commit e89278f211)
  * the original commit b17a7df8145a6a86d49c354c7e7b59a432ea5346 ("Make _set_fe_int( . , 0 ) set magnitude to 0") is not needed anymore, since it was already applied in PR #943 (commit d49011f54c)
  * clearing of stack memory with `secp256k1_memclear` is now also done on modules that have been newly introduced since then, i.e. schnorr and ellswift (of course, there is still no guarantee that all places where clearing is necessary are covered)

  So far I haven't looked at any disassembly and possible performance implications yet (there were some concerns expressed in https://github.com/bitcoin-core/secp256k1/pull/636#issuecomment-620118629), happy to go deeper there if this gets Concept ACKed.

  The proposed method of using a memory barrier to prevent optimizating away the memset is still used in BoringSSL (where it was originally picked up from) and in the Linux Kernel, see e.g. 5af122c3df/crypto/mem.c (L335) and d456068672/include/linux/string.h (L348) / d456068672/include/linux/compiler.h (L102)

  Fixes #185.

ACKs for top commit:
  sipa:
    reACK 765ef53335
  real-or-random:
    ACK 765ef53335

Tree-SHA512: 5a034d5ad14178c06928022459f3d4f0877d06f576b24ab07b86b3608b0b3e9273217b8309a1db606f024f3032731f13013114b1e0828964b578814d1efb2959
2024-11-04 16:34:52 +01:00
Tim Ruffing
64228a648f musig: Use _ge_set_all_gej for own public nonces 2024-11-01 23:33:53 +01:00
Tim Ruffing
300aab1c05 tests: Improve _ge_set_all_gej(_var) tests 2024-11-01 23:31:47 +01:00
Tim Ruffing
365f274ce3 group: Simplify secp256k1_ge_set_all_gej
No semantic changes.
2024-11-01 23:31:47 +01:00
Tim Ruffing
d3082ddead group: Add constant-time secp256k1_ge_set_all_gej
This is a dump mechanical translation of secp256k1_ge_set_all_gej_var
that assumes that inputs are not infinity.
2024-11-01 23:31:47 +01:00
merge-script
7d48f5ed02 Merge bitcoin-core/secp256k1#1581: test, ci: Lower default iteration count to 16
0f73caf7c6 test, ci: Lower default iteration count to 16 (Hennadii Stepanov)

Pull request description:

  The number of test iterations in the CI remains the same.

  Resolves https://github.com/bitcoin-core/secp256k1/issues/1561.

  ```
  $ ./build/src/tests
  test count = 16
  random seed = 59ea2b21267ec0ef0b4d13821292489f
  random run = 2936c044f82c7598a866869b9d954d42
  no problems found
  ```

ACKs for top commit:
  sipa:
    utACK 0f73caf7c6
  jonasnick:
    ACK 0f73caf7c6

Tree-SHA512: 84b265dc5d2780b3ea0a38f50ac8871d850ef2c97f33a0a5816baf20ac71c01db8b85696b343b089d7116d9cdb9450a6ca668229d95e54a39920d0e91a3127b3
2024-11-01 16:44:40 +01:00
Hennadii Stepanov
0f73caf7c6 test, ci: Lower default iteration count to 16
The number of test iterations in the CI remains unchanged.

Additionally, the minimum iteration counts to enable the
`test_ecmult_constants_2bit` test is adjusted from 35 to 16, so it is
run by default.
2024-10-30 14:30:55 +00:00
merge-script
9a8db52f4e Merge bitcoin-core/secp256k1#1582: cmake, test: Add secp256k1_ prefix to test names
87384f5c0f cmake, test: Add `secp256k1_` prefix to test names (Hennadii Stepanov)

Pull request description:

  This PR improves regex matching options when using `ctest` in downstream projects, such as Bitcoin Core.

  For instance, a downstream project users can filter their tests like that:
  ```
  ctest --tests-regex "secp256k1"
  ```
  or
  ```
  ctest --exclude-regex "secp256k1"
  ```

  A `ctest` log with this PR:
  ```
  $ ctest --test-dir build -j 16
  Internal ctest changing into directory: /home/hebasto/git/secp256k1/secp256k1/build
  Test project /home/hebasto/git/secp256k1/secp256k1/build
      Start 1: secp256k1_noverify_tests
      Start 2: secp256k1_tests
      Start 3: secp256k1_exhaustive_tests
      Start 4: secp256k1_ecdsa_example
      Start 5: secp256k1_ecdh_example
      Start 6: secp256k1_schnorr_example
      Start 7: secp256k1_ellswift_example
      Start 8: secp256k1_musig_example
  1/8 Test #4: secp256k1_ecdsa_example ..........   Passed    0.00 sec
  2/8 Test #5: secp256k1_ecdh_example ...........   Passed    0.00 sec
  3/8 Test #6: secp256k1_schnorr_example ........   Passed    0.00 sec
  4/8 Test #7: secp256k1_ellswift_example .......   Passed    0.00 sec
  5/8 Test #8: secp256k1_musig_example ..........   Passed    0.00 sec
  6/8 Test #3: secp256k1_exhaustive_tests .......   Passed    6.19 sec
  7/8 Test #1: secp256k1_noverify_tests .........   Passed   38.83 sec
  8/8 Test #2: secp256k1_tests ..................   Passed   91.66 sec

  100% tests passed, 0 tests failed out of 8

  Total Test time (real) =  91.67 sec
  ```

ACKs for top commit:
  theuni:
    utACK 87384f5c0f
  real-or-random:
    utACK 87384f5c0f

Tree-SHA512: d8e46558cf58c9c660544b7bdfed24c991eb3e120b6511aa3968f509190130e498749a3c4dbabc87a7f22f0aa0056c6bcd3fc6c44f5eb131588945d593546840
2024-10-29 18:10:50 +01:00
Sebastian Falbesoner
765ef53335 Clear _gej instances after point multiplication to avoid potential leaks
Quoting sipa (see https://github.com/bitcoin-core/secp256k1/pull/1479#discussion_r1790079414):
"When performing an EC multiplication A = aG for secret a, the resulting
 _affine_ coordinates of A are presumed to not leak information about a (ECDLP),
  but the same is not necessarily true for the Jacobian coordinates that come
  out of our multiplication algorithm."

For the ECDH point multiplication result, the result in Jacobi coordinates should be
cleared not only to avoid leaking the scalar, but even more so as it's a representation
of the resulting shared secret.
2024-10-25 18:44:48 +02:00
Tim Ruffing
349e6ab916 Introduce separate _clear functions for hash module
This gives the caller more control about whether the state should
be cleaned (= should be considered secret). Moreover, it gives the
caller the possibility to clean a hash struct without finalizing it.
2024-10-25 18:44:48 +02:00
Tim Ruffing
99cc9fd6d0 Don't rely on memset to set signed integers to 0 2024-10-25 18:44:48 +02:00
Tim Ruffing
97c57f42ba Implement various _clear() functions with secp256k1_memclear() 2024-10-25 18:44:48 +02:00
Tim Ruffing
9bb368d146 Use secp256k1_memclear() to clear stack memory instead of memset()
All of the invocations of secp256k1_memclear() operate on stack
memory and happen after the function is done with the memory object.
This commit replaces existing memset() invocations and also adds
secp256k1_memclear() to code locations where clearing was missing;
there is no guarantee that this commit covers all code locations
where clearing is necessary.

Co-Authored-By: isle2983 <isle2983@yahoo.com>
2024-10-25 18:44:48 +02:00
Tim Ruffing
e3497bbf00 Separate between clearing memory and setting to zero in tests
Co-Authored-By: isle2983 <isle2983@yahoo.com>
Co-Authored-By: Pieter Wuille <pieter.wuille@gmail.com>
2024-10-25 18:44:48 +02:00
Tim Ruffing
d79a6ccd43 Separate secp256k1_fe_set_int( . , 0 ) from secp256k1_fe_clear()
There are two uses of the secp256k1_fe_clear() function that are now separated
into these two functions in order to reflect the intent:

1) initializing the memory prior to being used -> converted to fe_set_int( . , 0 )
2) zeroing the memory after being used such that no sensitive data remains. ->
    remains as fe_clear()

In the latter case, 'magnitude' and 'normalized' need to be overwritten when
VERIFY is enabled.

Co-Authored-By: isle2983 <isle2983@yahoo.com>
2024-10-25 18:44:48 +02:00
Tim Ruffing
1c08126222 Add secp256k1_memclear() for clearing secret data
We rely on memset() and an __asm__ memory barrier where it's available or
on SecureZeroMemory() on Windows. The fallback implementation uses a
volatile function pointer to memset which the compiler is not clever
enough to optimize.
2024-10-25 18:44:36 +02:00
Tim Ruffing
980c08df80 util: Remove unused (u)int64_t formatting macros
We should anyway prefer to use the predefined macros from <inttypes.h>.

If I haven't missed anything, this removes the last OS-specific #if,
leaving us only with compiler-specific #if(def)s.
2024-10-25 16:00:25 +02:00