mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-10 09:06:15 +01:00
d8311688bd Merge bitcoin-core/secp256k1#1515: ci: Note affected clangs in comment on ASLR quirk a85e2233e7 ci: Note affected clangs in comment on ASLR quirk 4b77fec67a Merge bitcoin-core/secp256k1#1512: msan: notate more variable assignments from assembly code f7f0184ba1 msan: notate more variable assignments from assembly code a61339149f change inconsistent array param to pointer 05bfab69ae Merge bitcoin-core/secp256k1#1507: ci: Add workaround for ASLR bug in sanitizers a5e8ab2484 ci: Add sanitizer env variables to debug output 84a93de4d2 ci: Add workaround for ASLR bug in sanitizers 427e86b9ed Merge bitcoin-core/secp256k1#1490: tests: improve fe_sqr test (issue #1472) 2028069df2 doc: clarify input requirements for secp256k1_fe_mul 11420a7a28 tests: improve fe_sqr test cdc9a6258e Merge bitcoin-core/secp256k1#1489: tests: add missing fe comparison checks for inverse field test cases d926510cf7 Merge bitcoin-core/secp256k1#1496: msan: notate variable assignments from assembly code 31ba404944 msan: notate variable assignments from assembly code e7ea32e30a msan: Add SECP256K1_CHECKMEM_MSAN_DEFINE which applies to memory sanitizer and not valgrind e7bdddd9c9 refactor: rename `check_fe_equal` -> `fe_equal` 00111c9c56 tests: add missing fe comparison checks for inverse field test cases 0653a25d50 Merge bitcoin-core/secp256k1#1486: ci: Update cache action 94a14d5290 ci: Update cache action 2483627299 Merge bitcoin-core/secp256k1#1483: cmake: Recommend native CMake commands in README 5ad3aa3dcd Merge bitcoin-core/secp256k1#1484: tests: Drop redundant _scalar_check_overflow calls 51df2d9ab3 tests: Drop redundant _scalar_check_overflow calls 3777e3f36a cmake: Recommend native CMake commands in README e4af41c61b Merge bitcoin-core/secp256k1#1249: cmake: Add `SECP256K1_LATE_CFLAGS` configure option 3bf4d68fc0 Merge bitcoin-core/secp256k1#1482: build: Clean up handling of module dependencies e6822678ea build: Error if required module explicitly off 89ec583ccf build: Clean up handling of module dependencies 44378867a0 Merge bitcoin-core/secp256k1#1468: v0.4.1 release aftermath a9db9f2d75 Merge bitcoin-core/secp256k1#1480: Get rid of untested sizeof(secp256k1_ge_storage) == 64 code path 74b7c3b53e Merge bitcoin-core/secp256k1#1476: include: make docs more consistent b37fdb28ce check-abi: Minor UI improvements ad5f589a94 check-abi: Default to HEAD for new version 9fb7e2f156 release process: Style and formatting nits ba5d72d626 assumptions: Use new STATIC_ASSERT macro e53c2d9ffc Require that sizeof(secp256k1_ge_storage) == 64 d0ba2abbff util: Add STATIC_ASSERT macro da7bc1b803 include: in doc, remove article in front of "pointer" aa3dd5280b include: make doc about ctx more consistent e3f690015a include: remove obvious "cannot be NULL" doc d373bf6d08 Merge bitcoin-core/secp256k1#1474: tests: restore scalar_mul test 79e094517c Merge bitcoin-core/secp256k1#1473: Fix typos 3dbfb48946 tests: restore scalar_mul test d77170a88d Fix typos e7053d065b release process: Add email step 429d21dc79 release process: Run sanity checks on release PR 42f8c51402 cmake: Add `SECP256K1_LATE_CFLAGS` configure option git-subtree-dir: src/secp256k1 git-subtree-split: d8311688bd383d3a923a1b11789cded3cc8e5e03
134 lines
5.8 KiB
C
134 lines
5.8 KiB
C
#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 secp256k1_context_preallocated_destroy (in this
|
|
* module) instead of secp256k1_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 secp256k1_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 secp256k1_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 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: pointer to newly created context object.
|
|
* In: prealloc: 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 secp256k1_context_create (in secp256k1.h) for further details.
|
|
*
|
|
* See also secp256k1_context_randomize (in secp256k1.h)
|
|
* and secp256k1_context_preallocated_destroy.
|
|
*/
|
|
SECP256K1_API secp256k1_context *secp256k1_context_preallocated_create(
|
|
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: pointer to a context to copy.
|
|
*/
|
|
SECP256K1_API size_t secp256k1_context_preallocated_clone_size(
|
|
const secp256k1_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 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.
|
|
*
|
|
* Cloning secp256k1_context_static is not possible, and should not be emulated by
|
|
* the caller (e.g., using memcpy). Create a new context instead.
|
|
*
|
|
* Returns: pointer to a newly created context object.
|
|
* Args: ctx: pointer to a context to copy (not secp256k1_context_static).
|
|
* In: prealloc: pointer to a rewritable contiguous block of memory of
|
|
* size at least secp256k1_context_preallocated_size(flags)
|
|
* bytes, as detailed above.
|
|
*/
|
|
SECP256K1_API secp256k1_context *secp256k1_context_preallocated_clone(
|
|
const secp256k1_context *ctx,
|
|
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
|
|
* 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: pointer to a context to destroy, constructed using
|
|
* secp256k1_context_preallocated_create or
|
|
* secp256k1_context_preallocated_clone
|
|
* (i.e., not secp256k1_context_static).
|
|
*/
|
|
SECP256K1_API void secp256k1_context_preallocated_destroy(
|
|
secp256k1_context *ctx
|
|
) SECP256K1_ARG_NONNULL(1);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* SECP256K1_PREALLOCATED_H */
|