2019-05-28 12:23:28 +00:00
|
|
|
#ifndef SECP256K1_PREALLOCATED_H
|
|
|
|
#define SECP256K1_PREALLOCATED_H
|
|
|
|
|
|
|
|
#include "secp256k1.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The module provided by this header file is intended for settings in which it
|
|
|
|
* is not possible or desirable to rely on dynamic memory allocation. It provides
|
|
|
|
* functions for creating, cloning, and destroying secp256k1 context objects in a
|
|
|
|
* contiguous fixed-size block of memory provided by the caller.
|
|
|
|
*
|
|
|
|
* Context objects created by functions in this module can be used like contexts
|
|
|
|
* objects created by functions in secp256k1.h, i.e., they can be passed to any
|
2020-08-26 17:35:27 +00:00
|
|
|
* API function that expects a context object (see secp256k1.h for details). The
|
2019-05-28 12:23:28 +00:00
|
|
|
* only exception is that context objects created by functions in this module
|
2024-01-02 16:22:20 +00:00
|
|
|
* must be destroyed using rustsecp256k1_v0_9_2_context_preallocated_destroy (in this
|
|
|
|
* module) instead of rustsecp256k1_v0_9_2_context_destroy (in secp256k1.h).
|
2019-05-28 12:23:28 +00:00
|
|
|
*
|
2020-08-26 17:35:27 +00:00
|
|
|
* It is guaranteed that functions in this module will not call malloc or its
|
2019-05-28 12:23:28 +00:00
|
|
|
* friends realloc, calloc, and free.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** 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
|
2024-01-02 16:22:20 +00:00
|
|
|
* to rustsecp256k1_v0_9_2_context_preallocated_create.
|
2019-05-28 12:23:28 +00:00
|
|
|
*
|
|
|
|
* Returns: the required size of the caller-provided memory block
|
|
|
|
* In: flags: which parts of the context to initialize.
|
|
|
|
*/
|
2024-01-02 16:22:20 +00:00
|
|
|
SECP256K1_API size_t rustsecp256k1_v0_9_2_context_preallocated_size(
|
2019-05-28 12:23:28 +00:00
|
|
|
unsigned int flags
|
|
|
|
) SECP256K1_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/** Create a secp256k1 context object in caller-provided memory.
|
|
|
|
*
|
|
|
|
* The caller must provide a pointer to a rewritable contiguous block of memory
|
2024-01-02 16:22:20 +00:00
|
|
|
* of size at least rustsecp256k1_v0_9_2_context_preallocated_size(flags) bytes, suitably
|
2019-05-28 12:23:28 +00:00
|
|
|
* 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
|
2024-01-02 16:22:20 +00:00
|
|
|
* function and ends when a call to rustsecp256k1_v0_9_2_context_preallocated_destroy
|
2019-05-28 12:23:28 +00:00
|
|
|
* (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
|
2024-01-02 16:22:20 +00:00
|
|
|
* size at least rustsecp256k1_v0_9_2_context_preallocated_size(flags)
|
2022-03-08 19:45:41 +00:00
|
|
|
* bytes, as detailed above.
|
2019-05-28 12:23:28 +00:00
|
|
|
* flags: which parts of the context to initialize.
|
|
|
|
*
|
2024-01-02 16:22:20 +00:00
|
|
|
* See rustsecp256k1_v0_9_2_context_create (in secp256k1.h) for further details.
|
2022-12-20 21:11:14 +00:00
|
|
|
*
|
2024-01-02 16:22:20 +00:00
|
|
|
* See also rustsecp256k1_v0_9_2_context_randomize (in secp256k1.h)
|
|
|
|
* and rustsecp256k1_v0_9_2_context_preallocated_destroy.
|
2019-05-28 12:23:28 +00:00
|
|
|
*/
|
2024-01-02 16:22:20 +00:00
|
|
|
SECP256K1_API rustsecp256k1_v0_9_2_context *rustsecp256k1_v0_9_2_context_preallocated_create(
|
2023-09-27 18:37:09 +00:00
|
|
|
void *prealloc,
|
2019-05-28 12:23:28 +00:00
|
|
|
unsigned int flags
|
|
|
|
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/** 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.
|
2022-03-08 19:45:41 +00:00
|
|
|
* In: ctx: an existing context to copy.
|
2019-05-28 12:23:28 +00:00
|
|
|
*/
|
2024-01-02 16:22:20 +00:00
|
|
|
SECP256K1_API size_t rustsecp256k1_v0_9_2_context_preallocated_clone_size(
|
|
|
|
const rustsecp256k1_v0_9_2_context *ctx
|
2019-05-28 12:23:28 +00:00
|
|
|
) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/** Copy a secp256k1 context object into caller-provided memory.
|
|
|
|
*
|
|
|
|
* The caller must provide a pointer to a rewritable contiguous block of memory
|
2024-01-02 16:22:20 +00:00
|
|
|
* of size at least rustsecp256k1_v0_9_2_context_preallocated_size(flags) bytes, suitably
|
2019-05-28 12:23:28 +00:00
|
|
|
* 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
|
2024-01-02 16:22:20 +00:00
|
|
|
* rustsecp256k1_v0_9_2_context_preallocated_create for details.
|
2023-09-27 18:37:09 +00:00
|
|
|
*
|
2024-01-02 16:22:20 +00:00
|
|
|
* Cloning rustsecp256k1_v0_9_2_context_static is not possible, and should not be emulated by
|
2023-09-27 18:37:09 +00:00
|
|
|
* the caller (e.g., using memcpy). Create a new context instead.
|
2019-05-28 12:23:28 +00:00
|
|
|
*
|
|
|
|
* Returns: a newly created context object.
|
2024-01-02 16:22:20 +00:00
|
|
|
* Args: ctx: an existing context to copy (not rustsecp256k1_v0_9_2_context_static).
|
2019-05-28 12:23:28 +00:00
|
|
|
* In: prealloc: a pointer to a rewritable contiguous block of memory of
|
2024-01-02 16:22:20 +00:00
|
|
|
* size at least rustsecp256k1_v0_9_2_context_preallocated_size(flags)
|
2022-03-08 19:45:41 +00:00
|
|
|
* bytes, as detailed above.
|
2019-05-28 12:23:28 +00:00
|
|
|
*/
|
2024-01-02 16:22:20 +00:00
|
|
|
SECP256K1_API rustsecp256k1_v0_9_2_context *rustsecp256k1_v0_9_2_context_preallocated_clone(
|
|
|
|
const rustsecp256k1_v0_9_2_context *ctx,
|
2023-09-27 18:37:09 +00:00
|
|
|
void *prealloc
|
2019-05-28 12:23:28 +00:00
|
|
|
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/** 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
|
2024-01-02 16:22:20 +00:00
|
|
|
* rustsecp256k1_v0_9_2_context_preallocated_create or rustsecp256k1_v0_9_2_context_preallocated_clone.
|
|
|
|
* If the context has instead been created using rustsecp256k1_v0_9_2_context_create or
|
|
|
|
* rustsecp256k1_v0_9_2_context_clone, the behaviour is undefined. In that case,
|
|
|
|
* rustsecp256k1_v0_9_2_context_destroy must be used instead.
|
2019-05-28 12:23:28 +00:00
|
|
|
*
|
|
|
|
* 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
|
2024-01-02 16:22:20 +00:00
|
|
|
* preallocated pointer given to rustsecp256k1_v0_9_2_context_preallocated_create or
|
|
|
|
* rustsecp256k1_v0_9_2_context_preallocated_clone.
|
2019-05-28 12:23:28 +00:00
|
|
|
*
|
|
|
|
* Args: ctx: an existing context to destroy, constructed using
|
2024-01-02 16:22:20 +00:00
|
|
|
* rustsecp256k1_v0_9_2_context_preallocated_create or
|
|
|
|
* rustsecp256k1_v0_9_2_context_preallocated_clone
|
|
|
|
* (i.e., not rustsecp256k1_v0_9_2_context_static).
|
2019-05-28 12:23:28 +00:00
|
|
|
*/
|
2024-01-02 16:22:20 +00:00
|
|
|
SECP256K1_API void rustsecp256k1_v0_9_2_context_preallocated_destroy(
|
|
|
|
rustsecp256k1_v0_9_2_context *ctx
|
2022-03-08 19:45:41 +00:00
|
|
|
) SECP256K1_ARG_NONNULL(1);
|
2019-05-28 12:23:28 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* SECP256K1_PREALLOCATED_H */
|