Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
secp256k1_preallocated.h File Reference
#include "secp256k1.h"
Include dependency graph for secp256k1_preallocated.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SECP256K1_API size_t secp256k1_context_preallocated_size (unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
 
SECP256K1_API secp256k1_contextsecp256k1_context_preallocated_create (void *prealloc, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT
 
SECP256K1_API size_t secp256k1_context_preallocated_clone_size (const secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT
 
SECP256K1_API secp256k1_contextsecp256k1_context_preallocated_clone (const secp256k1_context *ctx, void *prealloc) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT
 
SECP256K1_API void secp256k1_context_preallocated_destroy (secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
 

Function Documentation

◆ secp256k1_context_preallocated_clone()

SECP256K1_API secp256k1_context * secp256k1_context_preallocated_clone ( const secp256k1_context * ctx,
void * prealloc )

Copy a secp256k1 context object into caller-provided memory.

The caller must provide a pointer to a rewritable contiguous block of memory of size at least secp256k1_context_preallocated_size(flags) bytes, suitably aligned to hold an object of any type.

The block of memory is exclusively owned by the created context object during the lifetime of this context object, see the description of secp256k1_context_preallocated_create for details.

Returns: a newly created context object. Args: ctx: an existing context to copy. In: prealloc: a pointer to a rewritable contiguous block of memory of size at least secp256k1_context_preallocated_size(flags) bytes, as detailed above.

Definition at line 118 of file secp256k1.c.

118 {
120 VERIFY_CHECK(ctx != NULL);
121 ARG_CHECK(prealloc != NULL);
122
123 ret = (secp256k1_context*)prealloc;
124 *ret = *ctx;
125 return ret;
126}
#define VERIFY_CHECK(cond)
Definition util.h:95
#define ARG_CHECK(cond)
Definition secp256k1.c:34
CK_RV ret
Here is the caller graph for this function:

◆ secp256k1_context_preallocated_clone_size()

SECP256K1_API size_t secp256k1_context_preallocated_clone_size ( const secp256k1_context * ctx)

Determine the memory size of a secp256k1 context object to be copied into caller-provided memory.

Returns: the required size of the caller-provided memory block. In: ctx: an existing context to copy.

Definition at line 76 of file secp256k1.c.

76 {
77 size_t ret = sizeof(secp256k1_context);
78 VERIFY_CHECK(ctx != NULL);
79 return ret;
80}
struct secp256k1_context_struct secp256k1_context
Definition secp256k1.h:46
Here is the caller graph for this function:

◆ secp256k1_context_preallocated_create()

SECP256K1_API secp256k1_context * secp256k1_context_preallocated_create ( void * prealloc,
unsigned int flags )

Create a secp256k1 context object in caller-provided memory.

The caller must provide a pointer to a rewritable contiguous block of memory of size at least secp256k1_context_preallocated_size(flags) bytes, suitably aligned to hold an object of any type.

The block of memory is exclusively owned by the created context object during the lifetime of this context object, which begins with the call to this function and ends when a call to secp256k1_context_preallocated_destroy (which destroys the context object again) returns. During the lifetime of the context object, the caller is obligated not to access this block of memory, i.e., the caller may not read or write the memory, e.g., by copying the memory contents to a different location or trying to create a second context object in the memory. In simpler words, the prealloc pointer (or any pointer derived from it) should not be used during the lifetime of the context object.

Returns: a newly created context object. In: prealloc: a pointer to a rewritable contiguous block of memory of size at least secp256k1_context_preallocated_size(flags) bytes, as detailed above. flags: which parts of the context to initialize.

See also secp256k1_context_randomize (in secp256k1.h) and secp256k1_context_preallocated_destroy.

Definition at line 82 of file secp256k1.c.

82 {
83 size_t prealloc_size;
85
86 if (!secp256k1_selftest()) {
87 secp256k1_callback_call(&default_error_callback, "self test failed");
88 }
89
91 if (prealloc_size == 0) {
92 return NULL;
93 }
94 VERIFY_CHECK(prealloc != NULL);
95 ret = (secp256k1_context*)prealloc;
96 ret->illegal_callback = default_illegal_callback;
97 ret->error_callback = default_error_callback;
98
99 /* Flags have been checked by secp256k1_context_preallocated_size. */
101 secp256k1_ecmult_gen_context_build(&ret->ecmult_gen_ctx);
103
104 return ret;
105}
size_t secp256k1_context_preallocated_size(unsigned int flags)
Definition secp256k1.c:62
#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY
Definition secp256k1.h:190
#define SECP256K1_FLAGS_TYPE_MASK
Definition secp256k1.h:184
#define SECP256K1_FLAGS_TYPE_CONTEXT
Definition secp256k1.h:185
pInfo flags
Here is the call graph for this function:
Here is the caller graph for this function:

◆ secp256k1_context_preallocated_destroy()

SECP256K1_API void secp256k1_context_preallocated_destroy ( secp256k1_context * ctx)

Destroy a secp256k1 context object that has been created in caller-provided memory.

The context pointer may not be used afterwards.

The context to destroy must have been created using secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone. If the context has instead been created using secp256k1_context_create or secp256k1_context_clone, the behaviour is undefined. In that case, secp256k1_context_destroy must be used instead.

If required, it is the responsibility of the caller to deallocate the block of memory properly after this function returns, e.g., by calling free on the preallocated pointer given to secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone.

Args: ctx: an existing context to destroy, constructed using secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone.

Definition at line 139 of file secp256k1.c.

139 {
141 if (ctx != NULL) {
142 secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);
143 }
144}
const secp256k1_context * secp256k1_context_no_precomp
Definition secp256k1.c:60
#define ARG_CHECK_NO_RETURN(cond)
Definition secp256k1.c:41
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition secp256k1.c:48
Here is the caller graph for this function:

◆ secp256k1_context_preallocated_size()

SECP256K1_API size_t secp256k1_context_preallocated_size ( unsigned int flags)

Determine the memory size of a secp256k1 context object to be created in caller-provided memory.

The purpose of this function is to determine how much memory must be provided to secp256k1_context_preallocated_create.

Returns: the required size of the caller-provided memory block In: flags: which parts of the context to initialize.

Definition at line 62 of file secp256k1.c.

62 {
63 size_t ret = sizeof(secp256k1_context);
64 /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */
65 VERIFY_CHECK(ret != 0);
66
68 secp256k1_callback_call(&default_illegal_callback,
69 "Invalid flags");
70 return 0;
71 }
72
73 return ret;
74}
#define EXPECT(x, c)
Definition util.h:70
Here is the caller graph for this function: