| 
									
										
										
										
											2018-11-27 16:48:57 +01: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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-03-29 22:27:01 +01:00
										 |  |  |  * 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 | 
					
						
							| 
									
										
										
										
											2019-07-18 08:35:42 +08:00
										 |  |  |  * API function that expects a context object (see secp256k1.h for details). The | 
					
						
							| 
									
										
										
										
											2019-03-29 22:27:01 +01:00
										 |  |  |  * 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). | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-07-18 08:35:42 +08:00
										 |  |  |  * It is guaranteed that functions in this module will not call malloc or its | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01: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 | 
					
						
							|  |  |  |  *  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.
 | 
					
						
							| 
									
										
										
										
											2019-03-29 22:27:01 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  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. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  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) | 
					
						
							| 
									
										
										
										
											2020-07-30 12:25:59 +03:00
										 |  |  |  *                     bytes, as detailed above. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  *           flags:    which parts of the context to initialize. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-07-06 10:39:14 +02:00
										 |  |  |  *  See secp256k1_context_create (in secp256k1.h) for further details. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-03-29 22:27:01 +01:00
										 |  |  |  *  See also secp256k1_context_randomize (in secp256k1.h) | 
					
						
							|  |  |  |  *  and secp256k1_context_preallocated_destroy. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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. | 
					
						
							| 
									
										
										
										
											2020-07-30 12:25:59 +03:00
										 |  |  |  *  In:      ctx: an existing context to copy. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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.
 | 
					
						
							| 
									
										
										
										
											2019-03-29 22:27:01 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  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. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  Returns: a newly created context object. | 
					
						
							| 
									
										
										
										
											2020-07-30 12:25:59 +03:00
										 |  |  |  *  Args:    ctx:      an existing context to copy. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  *  In:      prealloc: a pointer to a rewritable contiguous block of memory of | 
					
						
							|  |  |  |  *                     size at least secp256k1_context_preallocated_size(flags) | 
					
						
							| 
									
										
										
										
											2020-07-30 12:25:59 +03:00
										 |  |  |  *                     bytes, as detailed above. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-03-29 22:27:01 +01: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 | 
					
						
							|  |  |  |  *  preallocated pointer given to secp256k1_context_preallocated_create or | 
					
						
							|  |  |  |  *  secp256k1_context_preallocated_clone. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  *  Args:   ctx: an existing context to destroy, constructed using | 
					
						
							|  |  |  |  *               secp256k1_context_preallocated_create or | 
					
						
							| 
									
										
										
										
											2020-07-30 12:25:59 +03:00
										 |  |  |  *               secp256k1_context_preallocated_clone. | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | SECP256K1_API void secp256k1_context_preallocated_destroy( | 
					
						
							|  |  |  |     secp256k1_context* ctx | 
					
						
							| 
									
										
										
										
											2020-07-30 12:26:28 +03:00
										 |  |  | ) SECP256K1_ARG_NONNULL(1); | 
					
						
							| 
									
										
										
										
											2018-11-27 16:48:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* SECP256K1_PREALLOCATED_H */
 |