Skip to content

Commit e3f8477

Browse files
committed
Merge #1126: API cleanup with respect to contexts
4386a23 examples: Switch to NONE contexts (Tim Ruffing) 7289b51 docs: Use doxygen style if and only if comment is user-facing (Tim Ruffing) e7d0185 docs: Get rid of "initialized for signing" terminology (Tim Ruffing) 0612636 docs: Tidy and improve docs about contexts and randomization (Tim Ruffing) e02d686 selftest: Expose in public API (Tim Ruffing) e383fbf selftest: Rename internal function to make name available for API (Tim Ruffing) d2c6d48 tests: Use new name of static context (Tim Ruffing) 53796d2 contexts: Rename static context (Tim Ruffing) 72fedf8 docs: Improve docs for static context (Tim Ruffing) 316ac76 contexts: Deprecate all context flags except SECP256K1_CONTEXT_NONE (Tim Ruffing) 1a553ee docs: Change signature "validation" to "verification" (Tim Ruffing) ee7341f docs: Never require a verification context (Tim Ruffing) Pull request description: ACKs for top commit: sipa: utACK 4386a23 jonasnick: ACK 4386a23 Tree-SHA512: 7bf07dfae0ecbf7de1418de64ef743a23dc5f244aeba2c1cf3ecbdc117d6ac12bb6c8f17f739605566074a9b901765ee4a32288b6edc6f9a0040a70cb472f6ee
2 parents 477f02c + 4386a23 commit e3f8477

File tree

16 files changed

+174
-99
lines changed

16 files changed

+174
-99
lines changed

contrib/lax_der_privatekey_parsing.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ extern "C" {
4343
/** Export a private key in DER format.
4444
*
4545
* Returns: 1 if the private key was valid.
46-
* Args: ctx: pointer to a context object, initialized for signing (cannot
47-
* be NULL)
46+
* Args: ctx: pointer to a context object (not secp256k1_context_static).
4847
* Out: privkey: pointer to an array for storing the private key in BER.
4948
* Should have space for 279 bytes, and cannot be NULL.
5049
* privkeylen: Pointer to an int where the length of the private key in

doc/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Each change falls into one of the following categories: Added, Changed, Deprecat
99
### Changed
1010
- Enable modules schnorrsig, extrakeys and ECDH by default in ./configure
1111

12+
### Deprecated
13+
- Deprecated context flags `SECP256K1_CONTEXT_VERIFY` and `SECP256K1_CONTEXT_SIGN`. Use `SECP256K1_CONTEXT_NONE` instead.
14+
- Renamed `secp256k1_context_no_precomp` to `secp256k1_context_static`.
15+
16+
### Added
17+
- Added `secp256k1_selftest`, to be used in conjunction with `secp256k1_context_static`.
18+
1219
## [MAJOR.MINOR.PATCH] - YYYY-MM-DD
1320

1421
### Added/Changed/Deprecated/Removed/Fixed/Security

examples/ecdh.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ int main(void) {
3030
secp256k1_pubkey pubkey1;
3131
secp256k1_pubkey pubkey2;
3232

33-
/* The specification in secp256k1.h states that `secp256k1_ec_pubkey_create`
34-
* needs a context object initialized for signing, which is why we create
35-
* a context with the SECP256K1_CONTEXT_SIGN flag.
36-
* (The docs for `secp256k1_ecdh` don't require any special context, just
37-
* some initialized context) */
38-
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
33+
/* Before we can call actual API functions, we need to create a "context". */
34+
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
3935
if (!fill_random(randomize, sizeof(randomize))) {
4036
printf("Failed to generate randomness\n");
4137
return 1;

examples/ecdsa.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ int main(void) {
3838
int return_val;
3939
secp256k1_pubkey pubkey;
4040
secp256k1_ecdsa_signature sig;
41-
/* The specification in secp256k1.h states that `secp256k1_ec_pubkey_create` needs
42-
* a context object initialized for signing and `secp256k1_ecdsa_verify` needs
43-
* a context initialized for verification, which is why we create a context
44-
* for both signing and verification with the SECP256K1_CONTEXT_SIGN and
45-
* SECP256K1_CONTEXT_VERIFY flags. */
46-
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
41+
/* Before we can call actual API functions, we need to create a "context". */
42+
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
4743
if (!fill_random(randomize, sizeof(randomize))) {
4844
printf("Failed to generate randomness\n");
4945
return 1;

examples/schnorr.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ int main(void) {
3030
int return_val;
3131
secp256k1_xonly_pubkey pubkey;
3232
secp256k1_keypair keypair;
33-
/* The specification in secp256k1_extrakeys.h states that `secp256k1_keypair_create`
34-
* needs a context object initialized for signing. And in secp256k1_schnorrsig.h
35-
* they state that `secp256k1_schnorrsig_verify` needs a context initialized for
36-
* verification, which is why we create a context for both signing and verification
37-
* with the SECP256K1_CONTEXT_SIGN and SECP256K1_CONTEXT_VERIFY flags. */
38-
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
33+
/* Before we can call actual API functions, we need to create a "context". */
34+
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
3935
if (!fill_random(randomize, sizeof(randomize))) {
4036
printf("Failed to generate randomness\n");
4137
return 1;

include/secp256k1.h

Lines changed: 120 additions & 55 deletions
Large diffs are not rendered by default.

include/secp256k1_extrakeys.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_from_pubke
108108
* invalid (only when the tweak is the negation of the corresponding
109109
* secret key). 1 otherwise.
110110
*
111-
* Args: ctx: pointer to a context object initialized for verification.
111+
* Args: ctx: pointer to a context object.
112112
* Out: output_pubkey: pointer to a public key to store the result. Will be set
113113
* to an invalid value if this function returns 0.
114114
* In: internal_pubkey: pointer to an x-only pubkey to apply the tweak to.
@@ -137,7 +137,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_add(
137137
*
138138
* Returns: 0 if the arguments are invalid or the tweaked pubkey is not the
139139
* result of tweaking the internal_pubkey with tweak32. 1 otherwise.
140-
* Args: ctx: pointer to a context object initialized for verification.
140+
* Args: ctx: pointer to a context object.
141141
* In: tweaked_pubkey32: pointer to a serialized xonly_pubkey.
142142
* tweaked_pk_parity: the parity of the tweaked pubkey (whose serialization
143143
* is passed in as tweaked_pubkey32). This must match the
@@ -159,7 +159,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_add_
159159
*
160160
* Returns: 1: secret was valid, keypair is ready to use
161161
* 0: secret was invalid, try again with a different secret
162-
* Args: ctx: pointer to a context object, initialized for signing.
162+
* Args: ctx: pointer to a context object (not secp256k1_context_static).
163163
* Out: keypair: pointer to the created keypair.
164164
* In: seckey: pointer to a 32-byte secret key.
165165
*/
@@ -228,7 +228,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_keypair_xonly_pub(
228228
* invalid (only when the tweak is the negation of the keypair's
229229
* secret key). 1 otherwise.
230230
*
231-
* Args: ctx: pointer to a context object initialized for verification.
231+
* Args: ctx: pointer to a context object.
232232
* In/Out: keypair: pointer to a keypair to apply the tweak to. Will be set to
233233
* an invalid value if this function returns 0.
234234
* In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according

include/secp256k1_preallocated.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ SECP256K1_API size_t secp256k1_context_preallocated_size(
5858
* bytes, as detailed above.
5959
* flags: which parts of the context to initialize.
6060
*
61+
* See secp256k1_context_create (in secp256k1.h) for further details.
62+
*
6163
* See also secp256k1_context_randomize (in secp256k1.h)
6264
* and secp256k1_context_preallocated_destroy.
6365
*/

include/secp256k1_recovery.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(
7272
*
7373
* Returns: 1: signature created
7474
* 0: the nonce generation function failed, or the secret key was invalid.
75-
* Args: ctx: pointer to a context object, initialized for signing.
75+
* Args: ctx: pointer to a context object (not secp256k1_context_static).
7676
* Out: sig: pointer to an array where the signature will be placed.
7777
* In: msghash32: the 32-byte message hash being signed.
7878
* seckey: pointer to a 32-byte secret key.
@@ -94,7 +94,7 @@ SECP256K1_API int secp256k1_ecdsa_sign_recoverable(
9494
*
9595
* Returns: 1: public key successfully recovered (which guarantees a correct signature).
9696
* 0: otherwise.
97-
* Args: ctx: pointer to a context object, initialized for verification.
97+
* Args: ctx: pointer to a context object.
9898
* Out: pubkey: pointer to the recovered public key.
9999
* In: sig: pointer to initialized signature that supports pubkey recovery.
100100
* msghash32: the 32-byte message hash assumed to be signed.

include/secp256k1_schnorrsig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct {
106106
* signatures from being valid in multiple contexts by accident.
107107
*
108108
* Returns 1 on success, 0 on failure.
109-
* Args: ctx: pointer to a context object, initialized for signing.
109+
* Args: ctx: pointer to a context object (not secp256k1_context_static).
110110
* Out: sig64: pointer to a 64-byte array to store the serialized signature.
111111
* In: msg32: the 32-byte message being signed.
112112
* keypair: pointer to an initialized keypair.
@@ -161,7 +161,7 @@ SECP256K1_API int secp256k1_schnorrsig_sign_custom(
161161
*
162162
* Returns: 1: correct signature
163163
* 0: incorrect signature
164-
* Args: ctx: a secp256k1 context object, initialized for verification.
164+
* Args: ctx: a secp256k1 context object.
165165
* In: sig64: pointer to the 64-byte signature to verify.
166166
* msg: the message being verified. Can only be NULL if msglen is 0.
167167
* msglen: length of the message

0 commit comments

Comments
 (0)