rust-secp256k1-unsafe-fast/secp256k1-sys/depend/secp256k1/include/secp256k1_preallocated.h

135 lines
6.2 KiB
C
Raw Normal View History

#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
* API function that expects a context object (see secp256k1.h for details). The
* only exception is that context objects created by functions in this module
* 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).
*
* It is guaranteed that functions in this module will not call malloc or its
* 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
* to rustsecp256k1_v0_9_2_context_preallocated_create.
*
* Returns: the required size of the caller-provided memory block
* In: flags: which parts of the context to initialize.
*/
SECP256K1_API size_t rustsecp256k1_v0_9_2_context_preallocated_size(
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
* of size at least rustsecp256k1_v0_9_2_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 rustsecp256k1_v0_9_2_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 rustsecp256k1_v0_9_2_context_preallocated_size(flags)
* bytes, as detailed above.
* flags: which parts of the context to initialize.
*
* See rustsecp256k1_v0_9_2_context_create (in secp256k1.h) for further details.
Upgrade the vendored libsecp256k1 code `libsecp256k1` v0.2.0 was just released. Update the vendored code using `./vendor-libsecp.sh depend 0_8_0 21ffe4b` ``` git show 21ffe4b commit 21ffe4b22a9683cf24ae0763359e401d1284cc7a (tag: v0.2.0) Merge: 8c949f5 e025ccd Author: Pieter Wuille <pieter@wuille.net> Date: Mon Dec 12 17:00:52 2022 -0500 Merge bitcoin-core/secp256k1#1055: Prepare initial release e025ccdf7473702a76bb13d763dc096548ffefba release: prepare for initial release 0.2.0 (Jonas Nick) 6d1784a2e2c1c5a8d89ffb08a7f76fa15e84fff5 build: add missing files to EXTRA_DIST (Jonas Nick) 13bf1b6b324f2ed1c1fb4c8d17a4febd3556839e changelog: make order of change types match keepachangelog.com (Jonas Nick) b1f992a552785395d2e60b10862626fd11f66f84 doc: improve release process (Jonas Nick) ad39e2dc417f85c1577a6a6a9c519f5c60453def build: change package version to 0.1.0-dev (Jonas Nick) 90618e9263ebc2a0d73d487d6d94fd3af96b973c doc: move CHANGELOG from doc/ to root directory (Jonas Nick) Pull request description: Based on #964 ACKs for top commit: sipa: ACK e025ccdf7473702a76bb13d763dc096548ffefba Tree-SHA512: b9ab71d7362537d383a32b5e321ef44069f00e3e92340375bcd662267bc5a60c2bad60222998e6602cfac24ad65efb23d772eac37c86065036b90ef090b54c49 ``` Requires a new version of `secp256k1-sys`, use v0.8.0 - Update the `secp256k1-sys` manifest (including links field) - Update symbols to use 0_8_0 - Add a changelog entry - depend on the new version in `secp256k1` Which in turn requires a new version of `secp256k1`, use v0.26.0
2022-12-20 21:11:14 +00:00
*
* See also rustsecp256k1_v0_9_2_context_randomize (in secp256k1.h)
* and rustsecp256k1_v0_9_2_context_preallocated_destroy.
*/
SECP256K1_API rustsecp256k1_v0_9_2_context *rustsecp256k1_v0_9_2_context_preallocated_create(
2023-09-27 18:37:09 +00:00
void *prealloc,
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.
* In: ctx: an existing context to copy.
*/
SECP256K1_API size_t rustsecp256k1_v0_9_2_context_preallocated_clone_size(
const rustsecp256k1_v0_9_2_context *ctx
) 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
* of size at least rustsecp256k1_v0_9_2_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
* rustsecp256k1_v0_9_2_context_preallocated_create for details.
2023-09-27 18:37:09 +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.
*
* Returns: a newly created context object.
* Args: ctx: an existing context to copy (not rustsecp256k1_v0_9_2_context_static).
* In: prealloc: a pointer to a rewritable contiguous block of memory of
* size at least rustsecp256k1_v0_9_2_context_preallocated_size(flags)
* bytes, as detailed above.
*/
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
) 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
* 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.
*
* 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 rustsecp256k1_v0_9_2_context_preallocated_create or
* rustsecp256k1_v0_9_2_context_preallocated_clone.
*
* Args: ctx: an existing context to destroy, constructed using
* rustsecp256k1_v0_9_2_context_preallocated_create or
* rustsecp256k1_v0_9_2_context_preallocated_clone
* (i.e., not rustsecp256k1_v0_9_2_context_static).
*/
SECP256K1_API void rustsecp256k1_v0_9_2_context_preallocated_destroy(
rustsecp256k1_v0_9_2_context *ctx
) SECP256K1_ARG_NONNULL(1);
#ifdef __cplusplus
}
#endif
#endif /* SECP256K1_PREALLOCATED_H */