github.com/aquanetwork/aquachain@v1.7.8/crypto/secp256k1/libsecp256k1/src/scratch.h (about) 1 /********************************************************************** 2 * Copyright (c) 2017 Andrew Poelstra * 3 * Distributed under the MIT software license, see the accompanying * 4 * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 **********************************************************************/ 6 7 #ifndef _SECP256K1_SCRATCH_ 8 #define _SECP256K1_SCRATCH_ 9 10 #define SECP256K1_SCRATCH_MAX_FRAMES 5 11 12 /* The typedef is used internally; the struct name is used in the public API 13 * (where it is exposed as a different typedef) */ 14 typedef struct secp256k1_scratch_space_struct { 15 void *data[SECP256K1_SCRATCH_MAX_FRAMES]; 16 size_t offset[SECP256K1_SCRATCH_MAX_FRAMES]; 17 size_t frame_size[SECP256K1_SCRATCH_MAX_FRAMES]; 18 size_t frame; 19 size_t max_size; 20 const secp256k1_callback* error_callback; 21 } secp256k1_scratch; 22 23 static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t max_size); 24 25 static void secp256k1_scratch_destroy(secp256k1_scratch* scratch); 26 27 /** Attempts to allocate a new stack frame with `n` available bytes. Returns 1 on success, 0 on failure */ 28 static int secp256k1_scratch_allocate_frame(secp256k1_scratch* scratch, size_t n, size_t objects); 29 30 /** Deallocates a stack frame */ 31 static void secp256k1_scratch_deallocate_frame(secp256k1_scratch* scratch); 32 33 /** Returns the maximum allocation the scratch space will allow */ 34 static size_t secp256k1_scratch_max_allocation(const secp256k1_scratch* scratch, size_t n_objects); 35 36 /** Returns a pointer into the most recently allocated frame, or NULL if there is insufficient available space */ 37 static void *secp256k1_scratch_alloc(secp256k1_scratch* scratch, size_t n); 38 39 #endif