Skip to content

PROTOTYPE Split headers to make it possible to use only prealloc API #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions contrib/lax_der_privatekey_parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ extern "C" {
/** Export a private key in DER format.
*
* Returns: 1 if the private key was valid.
* Args: ctx: pointer to a context object, initialized for signing (cannot
* be NULL)
* Args: ctx: pointer to a context object (not secp256k1_context_static).
* Out: privkey: pointer to an array for storing the private key in BER.
* Should have space for 279 bytes, and cannot be NULL.
* privkeylen: Pointer to an int where the length of the private key in
Expand Down
7 changes: 7 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Each change falls into one of the following categories: Added, Changed, Deprecat
### Changed
- Enable modules schnorrsig, extrakeys and ECDH by default in ./configure

### Deprecated
- Deprecated context flags `SECP256K1_CONTEXT_VERIFY` and `SECP256K1_CONTEXT_NONE`. Use `SECP256K1_CONTEXT_DEFAULT` instead.
- Renamed `secp256k1_context_no_precomp` to `secp256k1_context_static`.

### Added
- Added `secp256k1_selftest`, to be used in conjunction with `secp256k1_context_static`.

## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

### Added/Changed/Deprecated/Removed/Fixed/Security
Expand Down
7 changes: 4 additions & 3 deletions examples/ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <assert.h>
#include <string.h>

#include <secp256k1.h>
#include <secp256k1_preallocated.h>
#include <secp256k1_ecdh.h>

#include "random.h"
Expand All @@ -35,7 +35,8 @@ int main(void) {
* a context with the SECP256K1_CONTEXT_SIGN flag.
* (The docs for `secp256k1_ecdh` don't require any special context, just
* some initialized context) */
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
unsigned char mem[1000];
secp256k1_context* ctx = secp256k1_context_preallocated_create(mem, SECP256K1_CONTEXT_SIGN);
if (!fill_random(randomize, sizeof(randomize))) {
printf("Failed to generate randomness\n");
return 1;
Expand Down Expand Up @@ -109,7 +110,7 @@ int main(void) {
print_hex(shared_secret1, sizeof(shared_secret1));

/* This will clear everything from the context and free the memory */
secp256k1_context_destroy(ctx);
secp256k1_context_preallocated_destroy(ctx);

/* It's best practice to try to clear secrets from memory after using them.
* This is done because some bugs can allow an attacker to leak memory, for
Expand Down
8 changes: 2 additions & 6 deletions examples/ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ int main(void) {
int return_val;
secp256k1_pubkey pubkey;
secp256k1_ecdsa_signature sig;
/* The specification in secp256k1.h states that `secp256k1_ec_pubkey_create` needs
* a context object initialized for signing and `secp256k1_ecdsa_verify` needs
* a context initialized for verification, which is why we create a context
* for both signing and verification with the SECP256K1_CONTEXT_SIGN and
* SECP256K1_CONTEXT_VERIFY flags. */
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
/* Before we can call actual API functions, we need to create a "context". */
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_DEFAULT);
if (!fill_random(randomize, sizeof(randomize))) {
printf("Failed to generate randomness\n");
return 1;
Expand Down
8 changes: 2 additions & 6 deletions examples/schnorr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ int main(void) {
int return_val;
secp256k1_xonly_pubkey pubkey;
secp256k1_keypair keypair;
/* The specification in secp256k1_extrakeys.h states that `secp256k1_keypair_create`
* needs a context object initialized for signing. And in secp256k1_schnorrsig.h
* they state that `secp256k1_schnorrsig_verify` needs a context initialized for
* verification, which is why we create a context for both signing and verification
* with the SECP256K1_CONTEXT_SIGN and SECP256K1_CONTEXT_VERIFY flags. */
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
/* Before we can call actual API functions, we need to create a "context". */
secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_DEFAULT);
if (!fill_random(randomize, sizeof(randomize))) {
printf("Failed to generate randomness\n");
return 1;
Expand Down
Loading