From 126501f58b41f2374d6a75a183f01d14a2d548dc Mon Sep 17 00:00:00 2001 From: mllwchrry Date: Tue, 3 Mar 2026 15:16:04 +0200 Subject: [PATCH] modules: Port bitcoin-core/secp256k1#1815 to zkp-specific code --- src/modules/bppp/main_impl.h | 8 ++++---- src/modules/bppp/tests_impl.h | 4 ++-- src/modules/rangeproof/tests_impl.h | 4 ++-- src/modules/surjection/main_impl.h | 2 +- src/modules/whitelist/tests_impl.h | 12 ++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/modules/bppp/main_impl.h b/src/modules/bppp/main_impl.h index 49a09447..e8e9e30a 100644 --- a/src/modules/bppp/main_impl.h +++ b/src/modules/bppp/main_impl.h @@ -23,11 +23,11 @@ secp256k1_bppp_generators *secp256k1_bppp_generators_create(const secp256k1_cont VERIFY_CHECK(ctx != NULL); - ret = (secp256k1_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); + ret = checked_malloc(&ctx->error_callback, sizeof(*ret)); if (ret == NULL) { return NULL; } - ret->gens = (secp256k1_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); + ret->gens = checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); if (ret->gens == NULL) { free(ret); return NULL; @@ -60,12 +60,12 @@ secp256k1_bppp_generators* secp256k1_bppp_generators_parse(const secp256k1_conte return NULL; } - ret = (secp256k1_bppp_generators *)checked_malloc(&ctx->error_callback, sizeof(*ret)); + ret = checked_malloc(&ctx->error_callback, sizeof(*ret)); if (ret == NULL) { return NULL; } ret->n = n; - ret->gens = (secp256k1_ge*)checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); + ret->gens = checked_malloc(&ctx->error_callback, n * sizeof(*ret->gens)); if (ret->gens == NULL) { free(ret); return NULL; diff --git a/src/modules/bppp/tests_impl.h b/src/modules/bppp/tests_impl.h index 85d1c1ca..dda9a8c0 100644 --- a/src/modules/bppp/tests_impl.h +++ b/src/modules/bppp/tests_impl.h @@ -514,12 +514,12 @@ secp256k1_bppp_generators* bppp_generators_parse_regular(const unsigned char* da return NULL; } - ret = (secp256k1_bppp_generators *)checked_malloc(&CTX->error_callback, sizeof(*ret)); + ret = checked_malloc(&CTX->error_callback, sizeof(*ret)); if (ret == NULL) { return NULL; } ret->n = n; - ret->gens = (secp256k1_ge*)checked_malloc(&CTX->error_callback, n * sizeof(*ret->gens)); + ret->gens = checked_malloc(&CTX->error_callback, n * sizeof(*ret->gens)); if (ret->gens == NULL) { free(ret); return NULL; diff --git a/src/modules/rangeproof/tests_impl.h b/src/modules/rangeproof/tests_impl.h index 74d9f3fd..7538558e 100644 --- a/src/modules/rangeproof/tests_impl.h +++ b/src/modules/rangeproof/tests_impl.h @@ -544,8 +544,8 @@ static void test_multiple_generators(void) { secp256k1_scalar_get_b32(generator_seed, &s); /* Create all the needed generators */ for (i = 0; i < n_generators; i++) { - generator_blind[i] = (unsigned char*) malloc(32); - pedersen_blind[i] = (unsigned char*) malloc(32); + generator_blind[i] = malloc(32); + pedersen_blind[i] = malloc(32); testutil_random_scalar_order(&s); secp256k1_scalar_get_b32(generator_blind[i], &s); diff --git a/src/modules/surjection/main_impl.h b/src/modules/surjection/main_impl.h index 1d35219a..2bd2c2cd 100644 --- a/src/modules/surjection/main_impl.h +++ b/src/modules/surjection/main_impl.h @@ -182,7 +182,7 @@ int secp256k1_surjectionproof_allocate_initialized(const secp256k1_context* ctx, ARG_CHECK(proof_out_p != NULL); *proof_out_p = 0; - proof = (secp256k1_surjectionproof*)checked_malloc(&ctx->error_callback, sizeof(secp256k1_surjectionproof)); + proof = checked_malloc(&ctx->error_callback, sizeof(secp256k1_surjectionproof)); if (proof != NULL) { ret = secp256k1_surjectionproof_initialize(ctx, proof, input_index, fixed_input_tags, n_input_tags, n_input_tags_to_use, fixed_output_tag, n_max_iterations, random_seed32); if (ret) { diff --git a/src/modules/whitelist/tests_impl.h b/src/modules/whitelist/tests_impl.h index 9cbb8287..dad8a479 100644 --- a/src/modules/whitelist/tests_impl.h +++ b/src/modules/whitelist/tests_impl.h @@ -43,10 +43,10 @@ static void test_whitelist_end_to_end_internal(const unsigned char *summed_secke } static void test_whitelist_end_to_end(const size_t n_keys, int test_all_keys) { - unsigned char **online_seckey = (unsigned char **) malloc(n_keys * sizeof(*online_seckey)); - unsigned char **summed_seckey = (unsigned char **) malloc(n_keys * sizeof(*summed_seckey)); - secp256k1_pubkey *online_pubkeys = (secp256k1_pubkey *) malloc(n_keys * sizeof(*online_pubkeys)); - secp256k1_pubkey *offline_pubkeys = (secp256k1_pubkey *) malloc(n_keys * sizeof(*offline_pubkeys)); + unsigned char **online_seckey = malloc(n_keys * sizeof(*online_seckey)); + unsigned char **summed_seckey = malloc(n_keys * sizeof(*summed_seckey)); + secp256k1_pubkey *online_pubkeys = malloc(n_keys * sizeof(*online_pubkeys)); + secp256k1_pubkey *offline_pubkeys = malloc(n_keys * sizeof(*offline_pubkeys)); secp256k1_scalar ssub; unsigned char csub[32]; @@ -63,8 +63,8 @@ static void test_whitelist_end_to_end(const size_t n_keys, int test_all_keys) { for (i = 0; i < n_keys; i++) { secp256k1_scalar son, soff; - online_seckey[i] = (unsigned char *) malloc(32); - summed_seckey[i] = (unsigned char *) malloc(32); + online_seckey[i] = malloc(32); + summed_seckey[i] = malloc(32); /* Create two keys */ testutil_random_scalar_order_test(&son);