2019-10-21 15:06:23 +00:00
|
|
|
13,37d12
|
|
|
|
< static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
|
2020-09-15 01:39:26 +00:00
|
|
|
< const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
|
2019-10-21 15:06:23 +00:00
|
|
|
< void *alloc = checked_malloc(error_callback, base_alloc + size);
|
|
|
|
< secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
|
|
|
|
< if (ret != NULL) {
|
|
|
|
< memset(ret, 0, sizeof(*ret));
|
|
|
|
< memcpy(ret->magic, "scratch", 8);
|
|
|
|
< ret->data = (void *) ((char *) alloc + base_alloc);
|
|
|
|
< ret->max_size = size;
|
|
|
|
< }
|
|
|
|
< return ret;
|
|
|
|
< }
|
|
|
|
<
|
|
|
|
< static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
|
|
|
|
< if (scratch != NULL) {
|
|
|
|
< VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
|
2020-12-21 22:05:26 +00:00
|
|
|
< if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
|
2019-10-21 15:06:23 +00:00
|
|
|
< secp256k1_callback_call(error_callback, "invalid scratch space");
|
|
|
|
< return;
|
|
|
|
< }
|
|
|
|
< memset(scratch->magic, 0, sizeof(scratch->magic));
|
|
|
|
< free(scratch);
|
|
|
|
< }
|
|
|
|
< }
|
|
|
|
<
|