Skip to content

Commit e8295d0

Browse files
committed
Merge bitcoin-core/secp256k1#1311: Revert "Remove unused scratch space from API"
3ad1027 Revert "Remove unused scratch space from API" (Jonas Nick) Pull request description: This reverts commit 712e7f8. Removing the scratch space from the API may break bindings to the library. ACKs for top commit: sipa: ACK 3ad1027 real-or-random: ACK 3ad1027 Tree-SHA512: ad394c0a2f83fe3a5f400c0e8f2b9bf40037ce4141d4414e6345918f5e6003c61da02a538425a49bdeb5700f5ecb713bd58f5752c0715fb1fcc4950099fdc0e6
2 parents 7d4f86d + 3ad1027 commit e8295d0

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

include/secp256k1.h

+36
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ extern "C" {
4949
*/
5050
typedef struct secp256k1_context_struct secp256k1_context;
5151

52+
/** Opaque data structure that holds rewritable "scratch space"
53+
*
54+
* The purpose of this structure is to replace dynamic memory allocations,
55+
* because we target architectures where this may not be available. It is
56+
* essentially a resizable (within specified parameters) block of bytes,
57+
* which is initially created either by memory allocation or TODO as a pointer
58+
* into some fixed rewritable space.
59+
*
60+
* Unlike the context object, this cannot safely be shared between threads
61+
* without additional synchronization logic.
62+
*/
63+
typedef struct secp256k1_scratch_space_struct secp256k1_scratch_space;
64+
5265
/** Opaque data structure that holds a parsed and valid public key.
5366
*
5467
* The exact representation of data inside is implementation defined and not
@@ -372,6 +385,29 @@ SECP256K1_API void secp256k1_context_set_error_callback(
372385
const void *data
373386
) SECP256K1_ARG_NONNULL(1);
374387

388+
/** Create a secp256k1 scratch space object.
389+
*
390+
* Returns: a newly created scratch space.
391+
* Args: ctx: an existing context object.
392+
* In: size: amount of memory to be available as scratch space. Some extra
393+
* (<100 bytes) will be allocated for extra accounting.
394+
*/
395+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_scratch_space_create(
396+
const secp256k1_context *ctx,
397+
size_t size
398+
) SECP256K1_ARG_NONNULL(1);
399+
400+
/** Destroy a secp256k1 scratch space.
401+
*
402+
* The pointer may not be used afterwards.
403+
* Args: ctx: a secp256k1 context object.
404+
* scratch: space to destroy
405+
*/
406+
SECP256K1_API void secp256k1_scratch_space_destroy(
407+
const secp256k1_context *ctx,
408+
secp256k1_scratch_space *scratch
409+
) SECP256K1_ARG_NONNULL(1);
410+
375411
/** Parse a variable-length public key into the pubkey object.
376412
*
377413
* Returns: 1 if the public key was fully valid.

src/scratch.h

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ typedef struct secp256k1_scratch_space_struct {
2121
size_t max_size;
2222
} secp256k1_scratch;
2323

24-
typedef struct secp256k1_scratch_space_struct secp256k1_scratch_space;
25-
2624
static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t max_size);
2725

2826
static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch);

src/secp256k1.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(co
219219
ctx->error_callback.data = data;
220220
}
221221

222-
static secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
222+
secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
223223
VERIFY_CHECK(ctx != NULL);
224224
return secp256k1_scratch_create(&ctx->error_callback, max_size);
225225
}
226226

227-
static void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
227+
void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
228228
VERIFY_CHECK(ctx != NULL);
229229
secp256k1_scratch_destroy(&ctx->error_callback, scratch);
230230
}

0 commit comments

Comments
 (0)