Skip to content

Commit 864da3a

Browse files
fixup! Export functions for preallocated memory
1 parent de5ee80 commit 864da3a

File tree

5 files changed

+92
-75
lines changed

5 files changed

+92
-75
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ else
88
JNI_LIB =
99
endif
1010
include_HEADERS = include/secp256k1.h
11+
include_HEADERS += include/secp256k1_prealloc.h
1112
noinst_HEADERS =
1213
noinst_HEADERS += src/scalar.h
1314
noinst_HEADERS += src/scalar_4x64.h

include/secp256k1.h

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -225,81 +225,6 @@ SECP256K1_API void secp256k1_context_destroy(
225225
secp256k1_context* ctx
226226
);
227227

228-
/** Determine the memory size of a secp256k1 context object to be created in
229-
* caller-provided memory.
230-
*
231-
* The purpose of this function is to determine how much memory must be provided
232-
* to secp256k1_context_prealloc_create.
233-
*
234-
* Returns: the required size of the caller-provided memory block
235-
* In: flags: which parts of the context to initialize.
236-
*/
237-
SECP256K1_API size_t secp256k1_context_prealloc_size(
238-
unsigned int flags
239-
) SECP256K1_WARN_UNUSED_RESULT;
240-
241-
/** Create a secp256k1 context object in caller-provided memory.
242-
*
243-
* Returns: a newly created context object.
244-
* In: prealloc: a pointer to a rewritable contiguous block of memory of
245-
* size at least secp256k1_context_prealloc_size(flags)
246-
* bytes, suitably aligned to hold an object of any type
247-
* (cannot be NULL)
248-
* flags: which parts of the context to initialize.
249-
*
250-
* See also secp256k1_context_randomize.
251-
*/
252-
SECP256K1_API secp256k1_context* secp256k1_context_prealloc_create(
253-
void* prealloc,
254-
unsigned int flags
255-
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
256-
257-
/** Determine the memory size of a secp256k1 context object to be copied into
258-
* caller-provided memory.
259-
*
260-
* The purpose of this function is to determine how much memory must be provided
261-
* to secp256k1_context_prealloc_clone when copying the context ctx.
262-
*
263-
* Returns: the required size of the caller-provided memory block.
264-
* In: ctx: an existing context to copy (cannot be NULL)
265-
*/
266-
SECP256K1_API size_t secp256k1_context_prealloc_clone_size(
267-
const secp256k1_context* ctx
268-
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
269-
270-
/** Copy a secp256k1 context object into caller-provided memory.
271-
*
272-
* Returns: a newly created context object.
273-
* Args: ctx: an existing context to copy (cannot be NULL)
274-
* In: prealloc: a pointer to a rewritable contiguous block of memory of
275-
* size at least secp256k1_context_prealloc_size(flags)
276-
* bytes, suitably aligned to hold an object of any type
277-
* (cannot be NULL)
278-
*/
279-
SECP256K1_API secp256k1_context* secp256k1_context_prealloc_clone(
280-
const secp256k1_context* ctx,
281-
void* prealloc
282-
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT;
283-
284-
/** Destroy a secp256k1 context object that has been created in
285-
* caller-provided memory.
286-
*
287-
* The context pointer may not be used afterwards.
288-
*
289-
* The context to destroy must have been created using
290-
* secp256k1_context_prealloc_create or secp256k1_context_prealloc_clone.
291-
* If the context has instead been created using secp256k1_context_create or
292-
* secp256k1_context_clone, the behaviour is undefined. In that case,
293-
* secp256k1_context_destroy must be used instead.
294-
*
295-
* Args: ctx: an existing context to destroy, constructed using
296-
* secp256k1_context_prealloc_create or
297-
* secp256k1_context_prealloc_clone (cannot be NULL)
298-
*/
299-
SECP256K1_API void secp256k1_context_prealloc_destroy(
300-
secp256k1_context* ctx
301-
);
302-
303228
/** Set a callback function to be called when an illegal argument is passed to
304229
* an API call. It will only trigger for violations that are mentioned
305230
* explicitly in the header.

include/secp256k1_prealloc.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ifndef SECP256K1_PREALLOC_H
2+
#define SECP256K1_PREALLOC_H
3+
4+
#include "secp256k1.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
/** Determine the memory size of a secp256k1 context object to be created in
11+
* caller-provided memory.
12+
*
13+
* The purpose of this function is to determine how much memory must be provided
14+
* to secp256k1_context_prealloc_create.
15+
*
16+
* Returns: the required size of the caller-provided memory block
17+
* In: flags: which parts of the context to initialize.
18+
*/
19+
SECP256K1_API size_t secp256k1_context_prealloc_size(
20+
unsigned int flags
21+
) SECP256K1_WARN_UNUSED_RESULT;
22+
23+
/** Create a secp256k1 context object in caller-provided memory.
24+
*
25+
* Returns: a newly created context object.
26+
* In: prealloc: a pointer to a rewritable contiguous block of memory of
27+
* size at least secp256k1_context_prealloc_size(flags)
28+
* bytes, suitably aligned to hold an object of any type
29+
* (cannot be NULL)
30+
* flags: which parts of the context to initialize.
31+
*
32+
* See also secp256k1_context_randomize.
33+
*/
34+
SECP256K1_API secp256k1_context* secp256k1_context_prealloc_create(
35+
void* prealloc,
36+
unsigned int flags
37+
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
38+
39+
/** Determine the memory size of a secp256k1 context object to be copied into
40+
* caller-provided memory.
41+
*
42+
* The purpose of this function is to determine how much memory must be provided
43+
* to secp256k1_context_prealloc_clone when copying the context ctx.
44+
*
45+
* Returns: the required size of the caller-provided memory block.
46+
* In: ctx: an existing context to copy (cannot be NULL)
47+
*/
48+
SECP256K1_API size_t secp256k1_context_prealloc_clone_size(
49+
const secp256k1_context* ctx
50+
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
51+
52+
/** Copy a secp256k1 context object into caller-provided memory.
53+
*
54+
* Returns: a newly created context object.
55+
* Args: ctx: an existing context to copy (cannot be NULL)
56+
* In: prealloc: a pointer to a rewritable contiguous block of memory of
57+
* size at least secp256k1_context_prealloc_size(flags)
58+
* bytes, suitably aligned to hold an object of any type
59+
* (cannot be NULL)
60+
*/
61+
SECP256K1_API secp256k1_context* secp256k1_context_prealloc_clone(
62+
const secp256k1_context* ctx,
63+
void* prealloc
64+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT;
65+
66+
/** Destroy a secp256k1 context object that has been created in
67+
* caller-provided memory.
68+
*
69+
* The context pointer may not be used afterwards.
70+
*
71+
* The context to destroy must have been created using
72+
* secp256k1_context_prealloc_create or secp256k1_context_prealloc_clone.
73+
* If the context has instead been created using secp256k1_context_create or
74+
* secp256k1_context_clone, the behaviour is undefined. In that case,
75+
* secp256k1_context_destroy must be used instead.
76+
*
77+
* Args: ctx: an existing context to destroy, constructed using
78+
* secp256k1_context_prealloc_create or
79+
* secp256k1_context_prealloc_clone (cannot be NULL)
80+
*/
81+
SECP256K1_API void secp256k1_context_prealloc_destroy(
82+
secp256k1_context* ctx
83+
);
84+
85+
#ifdef __cplusplus
86+
}
87+
#endif
88+
89+
#endif /* SECP256K1_PREALLOC_H */

src/secp256k1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**********************************************************************/
66

77
#include "include/secp256k1.h"
8+
#include "include/secp256k1_prealloc.h"
89

910
#include "util.h"
1011
#include "num_impl.h"

src/tests.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "secp256k1.c"
1818
#include "include/secp256k1.h"
19+
#include "include/secp256k1_prealloc.h"
1920
#include "testrand_impl.h"
2021

2122
#ifdef ENABLE_OPENSSL_TESTS

0 commit comments

Comments
 (0)