Skip to content

Commit 0ee5708

Browse files
committed
Squashed 'src/secp256k1/' changes from 0cdc758a56..4ba1ba2af9
4ba1ba2af9 Merge bitcoin-core/secp256k1#1647: cmake: Adjust diagnostic flags for `clang-cl` abd25054a1 Merge bitcoin-core/secp256k1#1656: musig: Fix clearing of pubnonces 961ec25a83 musig: Fix clearing of pubnonces 3186082387 Merge bitcoin-core/secp256k1#1614: Add _ge_set_all_gej and use it in musig for own public nonces 6c2a39dafb Merge bitcoin-core/secp256k1#1639: Make static context const 432ac57705 Make static context const 1b1fc09341 Merge bitcoin-core/secp256k1#1642: Verify `compressed` argument in `secp256k1_eckey_pubkey_serialize` c0d9480fbb Merge bitcoin-core/secp256k1#1654: use `EXIT_` constants over magic numbers for indicating program execution status 13d389629a CONTRIBUTING: mention that `EXIT_` codes should be used c855581728 test, bench, precompute_ecmult: use `EXIT_...` constants for `main` return values 965393fcea examples: use `EXIT_...` constants for `main` return values 2e3bf13653 Merge bitcoin-core/secp256k1#1646: README: add instructions for verifying GPG signatures b682dbcf84 README: add instructions for verifying GPG signatures 00774d0723 Merge bitcoin-core/secp256k1#1650: schnorrsig: clear out masked secret key in BIP-340 nonce function a82287fb85 schnorrsig: clear out masked secret key in BIP-340 nonce function 4c50d73dd9 ci: Add new "Windows (clang-cl)" job 84c0bd1f72 cmake: Adjust diagnostic flags for clang-cl f79f46c703 Merge bitcoin-core/secp256k1#1641: doc: Improve cmake instructions in README 2ac9f558c4 doc: Improve cmake instructions in README 1823594761 Verify `compressed` argument in `secp256k1_eckey_pubkey_serialize` 8deef00b33 Merge bitcoin-core/secp256k1#1634: Fix some misspellings 39705450eb Fix some misspellings ec329c2501 Merge bitcoin-core/secp256k1#1633: release cleanup: bump version after 0.6.0 c97059f594 release cleanup: bump version after 0.6.0 64228a648f musig: Use _ge_set_all_gej for own public nonces 300aab1c05 tests: Improve _ge_set_all_gej(_var) tests 365f274ce3 group: Simplify secp256k1_ge_set_all_gej d3082ddead group: Add constant-time secp256k1_ge_set_all_gej git-subtree-dir: src/secp256k1 git-subtree-split: 4ba1ba2af953b7d124db9b80b34568e5c4a2d48a
1 parent 2d46a89 commit 0ee5708

29 files changed

+226
-91
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ jobs:
746746
cpp_flags: '/DSECP256K1_MSVC_MULH_TEST_OVERRIDE'
747747
- job_name: 'x86 (MSVC): Windows (VS 2022)'
748748
cmake_options: '-A Win32'
749+
- job_name: 'x64 (MSVC): Windows (clang-cl)'
750+
cmake_options: '-T ClangCL'
749751

750752
steps:
751753
- name: Checkout

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
810
## [0.6.0] - 2024-11-04
911

1012
#### Added
@@ -162,6 +164,7 @@ This version was in fact never released.
162164
The number was given by the build system since the introduction of autotools in Jan 2014 (ea0fe5a5bf0c04f9cc955b2966b614f5f378c6f6).
163165
Therefore, this version number does not uniquely identify a set of source files.
164166

167+
[unreleased]: https://github.com/bitcoin-core/secp256k1/compare/v0.6.0...HEAD
165168
[0.6.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.5.1...v0.6.0
166169
[0.5.1]: https://github.com/bitcoin-core/secp256k1/compare/v0.5.0...v0.5.1
167170
[0.5.0]: https://github.com/bitcoin-core/secp256k1/compare/v0.4.1...v0.5.0

CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project(libsecp256k1
77
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
88
# the API. All changes in experimental modules are treated as
99
# backwards-compatible and therefore at most increase the minor version.
10-
VERSION 0.6.0
10+
VERSION 0.6.1
1111
DESCRIPTION "Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1."
1212
HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"
1313
LANGUAGES C
@@ -32,7 +32,7 @@ endif()
3232
# All changes in experimental modules are treated as if they don't affect the
3333
# interface and therefore only increase the revision.
3434
set(${PROJECT_NAME}_LIB_VERSION_CURRENT 5)
35-
set(${PROJECT_NAME}_LIB_VERSION_REVISION 0)
35+
set(${PROJECT_NAME}_LIB_VERSION_REVISION 1)
3636
set(${PROJECT_NAME}_LIB_VERSION_AGE 0)
3737

3838
#=============================
@@ -55,7 +55,7 @@ option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
5555
## Modules
5656

5757
# We declare all options before processing them, to make sure we can express
58-
# dependendencies while processing.
58+
# dependencies while processing.
5959
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
6060
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
6161
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
@@ -242,17 +242,21 @@ endif()
242242

243243
include(TryAppendCFlags)
244244
if(MSVC)
245-
# Keep the following commands ordered lexicographically.
245+
# For both cl and clang-cl compilers.
246246
try_append_c_flags(/W3) # Production quality warning level.
247+
# Eliminate deprecation warnings for the older, less secure functions.
248+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
249+
else()
250+
try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.
251+
endif()
252+
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
253+
# Keep the following commands ordered lexicographically.
247254
try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
248255
try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".
249256
try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
250-
# Eliminate deprecation warnings for the older, less secure functions.
251-
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
252257
else()
253258
# Keep the following commands ordered lexicographically.
254259
try_append_c_flags(-pedantic)
255-
try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.
256260
try_append_c_flags(-Wcast-align) # GCC >= 2.95.
257261
try_append_c_flags(-Wcast-align=strict) # GCC >= 8.0.
258262
try_append_c_flags(-Wconditional-uninitialized) # Clang >= 3.0 only.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ In addition, libsecp256k1 tries to maintain the following coding conventions:
7474
* User-facing comment lines in headers should be limited to 80 chars if possible.
7575
* All identifiers in file scope should start with `secp256k1_`.
7676
* Avoid trailing whitespace.
77+
* Use the constants `EXIT_SUCCESS`/`EXIT_FAILURE` (defined in `stdlib.h`) to indicate program execution status for examples and other binaries.
7778

7879
### Tests
7980

README.md

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,50 @@ Implementation details
6161
* Optional runtime blinding which attempts to frustrate differential power analysis.
6262
* The precomputed tables add and eventually subtract points for which no known scalar (secret key) is known, preventing even an attacker with control over the secret key used to control the data internally.
6363

64+
Obtaining and verifying
65+
-----------------------
66+
67+
The git tag for each release (e.g. `v0.6.0`) is GPG-signed by one of the maintainers.
68+
For a fully verified build of this project, it is recommended to obtain this repository
69+
via git, obtain the GPG keys of the signing maintainer(s), and then verify the release
70+
tag's signature using git.
71+
72+
This can be done with the following steps:
73+
74+
1. Obtain the GPG keys listed in [SECURITY.md](./SECURITY.md).
75+
2. If possible, cross-reference these key IDs with another source controlled by its owner (e.g.
76+
social media, personal website). This is to mitigate the unlikely case that incorrect
77+
content is being presented by this repository.
78+
3. Clone the repository:
79+
```
80+
git clone https://github.com/bitcoin-core/secp256k1
81+
```
82+
4. Check out the latest release tag, e.g.
83+
```
84+
git checkout v0.6.0
85+
```
86+
5. Use git to verify the GPG signature:
87+
```
88+
% git tag -v v0.6.0 | grep -C 3 'Good signature'
89+
90+
gpg: Signature made Mon 04 Nov 2024 12:14:44 PM EST
91+
gpg: using RSA key 4BBB845A6F5A65A69DFAEC234861DBF262123605
92+
gpg: Good signature from "Jonas Nick <[email protected]>" [unknown]
93+
gpg: aka "Jonas Nick <[email protected]>" [unknown]
94+
gpg: WARNING: This key is not certified with a trusted signature!
95+
gpg: There is no indication that the signature belongs to the owner.
96+
Primary key fingerprint: 36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366
97+
Subkey fingerprint: 4BBB 845A 6F5A 65A6 9DFA EC23 4861 DBF2 6212 3605
98+
```
99+
64100
Building with Autotools
65101
-----------------------
66102
67-
$ ./autogen.sh
68-
$ ./configure
69-
$ make
70-
$ make check # run the test suite
71-
$ sudo make install # optional
103+
$ ./autogen.sh # Generate a ./configure script
104+
$ ./configure # Generate a build system
105+
$ make # Run the actual build process
106+
$ make check # Run the test suite
107+
$ sudo make install # Install the library into the system (optional)
72108
73109
To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags.
74110
@@ -79,24 +115,23 @@ To maintain a pristine source tree, CMake encourages to perform an out-of-source
79115
80116
### Building on POSIX systems
81117
82-
$ mkdir build && cd build
83-
$ cmake ..
84-
$ cmake --build .
85-
$ ctest # run the test suite
86-
$ sudo cmake --install . # optional
118+
$ cmake -B build # Generate a build system in subdirectory "build"
119+
$ cmake --build build # Run the actual build process
120+
$ ctest --test-dir build # Run the test suite
121+
$ sudo cmake --install build # Install the library into the system (optional)
87122
88-
To compile optional modules (such as Schnorr signatures), you need to run `cmake` with additional flags (such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON`). Run `cmake .. -LH` to see the full list of available flags.
123+
To compile optional modules (such as Schnorr signatures), you need to run `cmake` with additional flags (such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON`). Run `cmake -B build -LH` or `ccmake -B build` to see the full list of available flags.
89124
90125
### Cross compiling
91126
92127
To alleviate issues with cross compiling, preconfigured toolchain files are available in the `cmake` directory.
93128
For example, to cross compile for Windows:
94129
95-
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-w64-mingw32.toolchain.cmake
130+
$ cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-w64-mingw32.toolchain.cmake
96131
97132
To cross compile for Android with [NDK](https://developer.android.com/ndk/guides/cmake) (using NDK's toolchain file, and assuming the `ANDROID_NDK_ROOT` environment variable has been set):
98133
99-
$ cmake .. -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=28
134+
$ cmake -B build -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=28
100135
101136
### Building on Windows
102137
@@ -106,7 +141,7 @@ The following example assumes using of Visual Studio 2022 and CMake v3.21+.
106141
107142
In "Developer Command Prompt for VS 2022":
108143
109-
>cmake -G "Visual Studio 17 2022" -A x64 -S . -B build
144+
>cmake -G "Visual Studio 17 2022" -A x64 -B build
110145
>cmake --build build --config RelWithDebInfo
111146
112147
Usage examples

configure.ac

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ AC_PREREQ([2.60])
55
# backwards-compatible and therefore at most increase the minor version.
66
define(_PKG_VERSION_MAJOR, 0)
77
define(_PKG_VERSION_MINOR, 6)
8-
define(_PKG_VERSION_PATCH, 0)
9-
define(_PKG_VERSION_IS_RELEASE, true)
8+
define(_PKG_VERSION_PATCH, 1)
9+
define(_PKG_VERSION_IS_RELEASE, false)
1010

1111
# The library version is based on libtool versioning of the ABI. The set of
1212
# rules for updating the version can be found here:
1313
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
1414
# All changes in experimental modules are treated as if they don't affect the
1515
# interface and therefore only increase the revision.
1616
define(_LIB_VERSION_CURRENT, 5)
17-
define(_LIB_VERSION_REVISION, 0)
17+
define(_LIB_VERSION_REVISION, 1)
1818
define(_LIB_VERSION_AGE, 0)
1919

2020
AC_INIT([libsecp256k1],m4_join([.], _PKG_VERSION_MAJOR, _PKG_VERSION_MINOR, _PKG_VERSION_PATCH)m4_if(_PKG_VERSION_IS_RELEASE, [true], [], [-dev]),[https://github.com/bitcoin-core/secp256k1/issues],[libsecp256k1],[https://github.com/bitcoin-core/secp256k1])
@@ -254,8 +254,8 @@ fi
254254
print_msan_notice=no
255255
if test x"$enable_ctime_tests" = x"yes"; then
256256
SECP_MSAN_CHECK
257-
# MSan on Clang >=16 reports unitialized memory in function parameters and return values, even if
258-
# the uninitalized variable is never actually "used". This is called "eager" checking, and it's
257+
# MSan on Clang >=16 reports uninitialized memory in function parameters and return values, even if
258+
# the uninitialized variable is never actually "used". This is called "eager" checking, and it's
259259
# sounds like good idea for normal use of MSan. However, it yields many false positives in the
260260
# ctime_tests because many return values depend on secret (i.e., "uninitialized") values, and
261261
# we're only interested in detecting branches (which count as "uses") on secret data.

examples/ecdh.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*************************************************************************/
99

1010
#include <stdio.h>
11+
#include <stdlib.h>
1112
#include <assert.h>
1213
#include <string.h>
1314

@@ -33,7 +34,7 @@ int main(void) {
3334
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
3435
if (!fill_random(randomize, sizeof(randomize))) {
3536
printf("Failed to generate randomness\n");
36-
return 1;
37+
return EXIT_FAILURE;
3738
}
3839
/* Randomizing the context is recommended to protect against side-channel
3940
* leakage See `secp256k1_context_randomize` in secp256k1.h for more
@@ -44,14 +45,14 @@ int main(void) {
4445
/*** Key Generation ***/
4546
if (!fill_random(seckey1, sizeof(seckey1)) || !fill_random(seckey2, sizeof(seckey2))) {
4647
printf("Failed to generate randomness\n");
47-
return 1;
48+
return EXIT_FAILURE;
4849
}
4950
/* If the secret key is zero or out of range (greater than secp256k1's
5051
* order), we fail. Note that the probability of this occurring is negligible
5152
* with a properly functioning random number generator. */
5253
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
5354
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
54-
return 1;
55+
return EXIT_FAILURE;
5556
}
5657

5758
/* Public key creation using a valid context with a verified secret key should never fail */
@@ -116,5 +117,5 @@ int main(void) {
116117
secure_erase(shared_secret1, sizeof(shared_secret1));
117118
secure_erase(shared_secret2, sizeof(shared_secret2));
118119

119-
return 0;
120+
return EXIT_SUCCESS;
120121
}

examples/ecdsa.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*************************************************************************/
99

1010
#include <stdio.h>
11+
#include <stdlib.h>
1112
#include <assert.h>
1213
#include <string.h>
1314

@@ -40,7 +41,7 @@ int main(void) {
4041
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
4142
if (!fill_random(randomize, sizeof(randomize))) {
4243
printf("Failed to generate randomness\n");
43-
return 1;
44+
return EXIT_FAILURE;
4445
}
4546
/* Randomizing the context is recommended to protect against side-channel
4647
* leakage See `secp256k1_context_randomize` in secp256k1.h for more
@@ -51,14 +52,14 @@ int main(void) {
5152
/*** Key Generation ***/
5253
if (!fill_random(seckey, sizeof(seckey))) {
5354
printf("Failed to generate randomness\n");
54-
return 1;
55+
return EXIT_FAILURE;
5556
}
5657
/* If the secret key is zero or out of range (greater than secp256k1's
5758
* order), we fail. Note that the probability of this occurring is negligible
5859
* with a properly functioning random number generator. */
5960
if (!secp256k1_ec_seckey_verify(ctx, seckey)) {
6061
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
61-
return 1;
62+
return EXIT_FAILURE;
6263
}
6364

6465
/* Public key creation using a valid context with a verified secret key should never fail */
@@ -92,13 +93,13 @@ int main(void) {
9293
/* Deserialize the signature. This will return 0 if the signature can't be parsed correctly. */
9394
if (!secp256k1_ecdsa_signature_parse_compact(ctx, &sig, serialized_signature)) {
9495
printf("Failed parsing the signature\n");
95-
return 1;
96+
return EXIT_FAILURE;
9697
}
9798

9899
/* Deserialize the public key. This will return 0 if the public key can't be parsed correctly. */
99100
if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, compressed_pubkey, sizeof(compressed_pubkey))) {
100101
printf("Failed parsing the public key\n");
101-
return 1;
102+
return EXIT_FAILURE;
102103
}
103104

104105
/* Verify a signature. This will return 1 if it's valid and 0 if it's not. */
@@ -133,5 +134,5 @@ int main(void) {
133134
* will remove any writes that aren't used. */
134135
secure_erase(seckey, sizeof(seckey));
135136

136-
return 0;
137+
return EXIT_SUCCESS;
137138
}

examples/ellswift.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include <stdio.h>
16+
#include <stdlib.h>
1617
#include <assert.h>
1718
#include <string.h>
1819

@@ -38,7 +39,7 @@ int main(void) {
3839
ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
3940
if (!fill_random(randomize, sizeof(randomize))) {
4041
printf("Failed to generate randomness\n");
41-
return 1;
42+
return EXIT_FAILURE;
4243
}
4344
/* Randomizing the context is recommended to protect against side-channel
4445
* leakage. See `secp256k1_context_randomize` in secp256k1.h for more
@@ -49,22 +50,22 @@ int main(void) {
4950
/*** Generate secret keys ***/
5051
if (!fill_random(seckey1, sizeof(seckey1)) || !fill_random(seckey2, sizeof(seckey2))) {
5152
printf("Failed to generate randomness\n");
52-
return 1;
53+
return EXIT_FAILURE;
5354
}
5455
/* If the secret key is zero or out of range (greater than secp256k1's
5556
* order), we fail. Note that the probability of this occurring is negligible
5657
* with a properly functioning random number generator. */
5758
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
5859
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
59-
return 1;
60+
return EXIT_FAILURE;
6061
}
6162

6263
/* Generate ElligatorSwift public keys. This should never fail with valid context and
6364
verified secret keys. Note that providing additional randomness (fourth parameter) is
6465
optional, but recommended. */
6566
if (!fill_random(auxrand1, sizeof(auxrand1)) || !fill_random(auxrand2, sizeof(auxrand2))) {
6667
printf("Failed to generate randomness\n");
67-
return 1;
68+
return EXIT_FAILURE;
6869
}
6970
return_val = secp256k1_ellswift_create(ctx, ellswift_pubkey1, seckey1, auxrand1);
7071
assert(return_val);
@@ -117,5 +118,5 @@ int main(void) {
117118
secure_erase(shared_secret1, sizeof(shared_secret1));
118119
secure_erase(shared_secret2, sizeof(shared_secret2));
119120

120-
return 0;
121+
return EXIT_SUCCESS;
121122
}

0 commit comments

Comments
 (0)