Skip to content

Commit c443375

Browse files
committed
Squashed 'src/secp256k1/' changes from 7a30cb0c9d9..14620d13125
14620d13125 rangeproof: add a "net blinding factor" API for Elements d22774e248c Merge BlockstreamResearch/secp256k1-zkp#203: MuSig doc fixes dd83e72d52d Add ordinary tweak info d26100cab26 Exclude nonce_process from pre-processing steps b7607f93f23 Fix reference to xonly_tweak_add f7e9a8544f3 Merge BlockstreamResearch/secp256k1-zkp#201: rangeproof: add secp256k1_rangeproof_max_size function to estimate rangeproof size 6b6ced9839f rangeproof: add more max_size tests 34876ecb5fa rangeproof: add more static test vectors 310e5170619 rangeproof: add a bunch more testing f1410cb67a2 rangeproof: add secp256k1_rangeproof_max_size function to estimate rangeproof size c137ddbdff7 Merge BlockstreamResearch/secp256k1-zkp#200: build: automatically enable module dependencies 0202d839fb1 Merge BlockstreamResearch/secp256k1-zkp#199: surjectionproof: make sure that n_used_pubkeys > 0 in generate 5ac8fb035e8 surjectionproof: make sure that n_used_pubkeys > 0 in generate 7ff446df8b9 Merge BlockstreamResearch/secp256k1-zkp#198: rangeproof: add a test for all-zero blinding factors 5a40f3d99bb replace memcmp with secp256k1_memcmp_var throughout the codebase 92820d944b5 rangeproof: add a test for all-zero blinding factors 171b294a1c7 build: improve error message if --enable-experimental is missed 58ab152bb4b build: move all output concerning enabled modules at single place 1493113e61e build: automatically enable module dependencies 4fd7e1eabda Merge BlockstreamResearch/secp256k1-zkp#197: fix include paths in all the -zkp modules 347f96d94a6 fix include paths in all the -zkp modules d1d6e47c17c Merge BlockstreamResearch/secp256k1-zkp#196: surjectionproof: fail to generate proofs when an input equals the output d1175d265d5 surjectionproof: use secp256k1_memcmp_var rather than bare memcmp bf18ff5a8c6 surjectionproof: fix generation to fail when any input == the output 4ff6e4274d4 surjectionproof: add test for existing behavior on input=output proofs 71a206fa5bb Merge BlockstreamResearch/secp256k1-zkp#194: extrakeys: rename swap/swap64 to fix OpenBSD 7.1 compilation db648478c3c extrakeys: rename swap/swap64 to fix OpenBSD 7.1 compilation git-subtree-dir: src/secp256k1 git-subtree-split: 14620d131250b141f4d3ab352fedac0aef45eb30
1 parent 35d6112 commit c443375

25 files changed

+1320
-197
lines changed

configure.ac

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
385385
### Handle module options
386386
###
387387

388+
# Besides testing whether modules are enabled, the following code also enables
389+
# module dependencies. The order of the tests matters: the dependency must be
390+
# tested first.
391+
388392
if test x"$enable_module_ecdh" = x"yes"; then
389393
AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
390394
fi
@@ -398,30 +402,30 @@ if test x"$enable_module_recovery" = x"yes"; then
398402
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
399403
fi
400404

401-
if test x"$enable_module_generator" = x"yes"; then
402-
AC_DEFINE(ENABLE_MODULE_GENERATOR, 1, [Define this symbol to enable the NUMS generator module])
405+
if test x"$enable_module_whitelist" = x"yes"; then
406+
enable_module_rangeproof=yes
407+
AC_DEFINE(ENABLE_MODULE_WHITELIST, 1, [Define this symbol to enable the key whitelisting module])
408+
fi
409+
410+
if test x"$enable_module_surjectionproof" = x"yes"; then
411+
enable_module_rangeproof=yes
412+
AC_DEFINE(ENABLE_MODULE_SURJECTIONPROOF, 1, [Define this symbol to enable the surjection proof module])
403413
fi
404414

405415
if test x"$enable_module_rangeproof" = x"yes"; then
416+
enable_module_generator=yes
406417
AC_DEFINE(ENABLE_MODULE_RANGEPROOF, 1, [Define this symbol to enable the Pedersen / zero knowledge range proof module])
407418
fi
408419

409-
if test x"$enable_module_whitelist" = x"yes"; then
410-
AC_DEFINE(ENABLE_MODULE_WHITELIST, 1, [Define this symbol to enable the key whitelisting module])
420+
if test x"$enable_module_generator" = x"yes"; then
421+
AC_DEFINE(ENABLE_MODULE_GENERATOR, 1, [Define this symbol to enable the NUMS generator module])
411422
fi
412423

413-
if test x"$enable_module_surjectionproof" = x"yes"; then
414-
AC_DEFINE(ENABLE_MODULE_SURJECTIONPROOF, 1, [Define this symbol to enable the surjection proof module])
415-
fi
416-
# Test if extrakeys is set _after_ the MuSig module to allow the MuSig
417-
# module to set enable_module_schnorrsig=yes
418424
if test x"$enable_module_schnorrsig" = x"yes"; then
419425
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
420426
enable_module_extrakeys=yes
421427
fi
422428

423-
# Test if extrakeys is set after the schnorrsig module to allow the schnorrsig
424-
# module to set enable_module_extrakeys=yes
425429
if test x"$enable_module_extrakeys" = x"yes"; then
426430
AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module])
427431
fi
@@ -450,37 +454,24 @@ if test x"$enable_experimental" = x"yes"; then
450454
AC_MSG_NOTICE([******])
451455
AC_MSG_NOTICE([WARNING: experimental build])
452456
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
453-
AC_MSG_NOTICE([Building NUMS generator module: $enable_module_generator])
454-
AC_MSG_NOTICE([Building range proof module: $enable_module_rangeproof])
455-
AC_MSG_NOTICE([Building key whitelisting module: $enable_module_whitelist])
456-
AC_MSG_NOTICE([Building surjection proof module: $enable_module_surjectionproof])
457-
AC_MSG_NOTICE([Building MuSig module: $enable_module_musig])
458-
AC_MSG_NOTICE([Building ECDSA sign-to-contract module: $enable_module_ecdsa_s2c])
459-
AC_MSG_NOTICE([Building ECDSA adaptor signatures module: $enable_module_ecdsa_adaptor])
460457
AC_MSG_NOTICE([******])
461-
462-
463-
if test x"$enable_module_schnorrsig" != x"yes"; then
464-
if test x"$enable_module_musig" = x"yes"; then
465-
AC_MSG_ERROR([MuSig module requires the schnorrsig module. Use --enable-module-schnorrsig to allow.])
466-
fi
458+
else
459+
# The order of the following tests matters. If the user enables a dependent
460+
# module (which automatically enables the module dependencies) we want to
461+
# print an error for the dependent module, not the module dependency. Hence,
462+
# we first test dependent modules.
463+
if test x"$enable_module_whitelist" = x"yes"; then
464+
AC_MSG_ERROR([Key whitelisting module is experimental. Use --enable-experimental to allow.])
467465
fi
468-
469-
if test x"$enable_module_generator" != x"yes"; then
470-
if test x"$enable_module_rangeproof" = x"yes"; then
471-
AC_MSG_ERROR([Rangeproof module requires the generator module. Use --enable-module-generator to allow.])
472-
fi
466+
if test x"$enable_module_surjectionproof" = x"yes"; then
467+
AC_MSG_ERROR([Surjection proof module is experimental. Use --enable-experimental to allow.])
473468
fi
474-
475-
if test x"$enable_module_rangeproof" != x"yes"; then
476-
if test x"$enable_module_whitelist" = x"yes"; then
477-
AC_MSG_ERROR([Whitelist module requires the rangeproof module. Use --enable-module-rangeproof to allow.])
478-
fi
479-
if test x"$enable_module_surjectionproof" = x"yes"; then
480-
AC_MSG_ERROR([Surjection proof module requires the rangeproof module. Use --enable-module-rangeproof to allow.])
481-
fi
469+
if test x"$enable_module_rangeproof" = x"yes"; then
470+
AC_MSG_ERROR([Range proof module is experimental. Use --enable-experimental to allow.])
471+
fi
472+
if test x"$enable_module_generator" = x"yes"; then
473+
AC_MSG_ERROR([NUMS generator module is experimental. Use --enable-experimental to allow.])
482474
fi
483-
else
484475
if test x"$enable_module_musig" = x"yes"; then
485476
AC_MSG_ERROR([MuSig module is experimental. Use --enable-experimental to allow.])
486477
fi
@@ -493,18 +484,6 @@ else
493484
if test x"$set_asm" = x"arm"; then
494485
AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
495486
fi
496-
if test x"$enable_module_generator" = x"yes"; then
497-
AC_MSG_ERROR([NUMS generator module is experimental. Use --enable-experimental to allow.])
498-
fi
499-
if test x"$enable_module_rangeproof" = x"yes"; then
500-
AC_MSG_ERROR([Range proof module is experimental. Use --enable-experimental to allow.])
501-
fi
502-
if test x"$enable_module_whitelist" = x"yes"; then
503-
AC_MSG_ERROR([Key whitelisting module is experimental. Use --enable-experimental to allow.])
504-
fi
505-
if test x"$enable_module_surjectionproof" = x"yes"; then
506-
AC_MSG_ERROR([Surjection proof module is experimental. Use --enable-experimental to allow.])
507-
fi
508487
fi
509488

510489
###
@@ -555,6 +534,10 @@ echo " module ecdh = $enable_module_ecdh"
555534
echo " module recovery = $enable_module_recovery"
556535
echo " module extrakeys = $enable_module_extrakeys"
557536
echo " module schnorrsig = $enable_module_schnorrsig"
537+
echo " module generator = $enable_module_generator"
538+
echo " module rangeproof = $enable_module_rangeproof"
539+
echo " module surjectionproof = $enable_module_surjectionproof"
540+
echo " module whitelist = $enable_module_whitelist"
558541
echo " module musig = $enable_module_musig"
559542
echo " module ecdsa-s2c = $enable_module_ecdsa_s2c"
560543
echo " module ecdsa-adaptor = $enable_module_ecdsa_adaptor"

include/secp256k1_rangeproof.h

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ extern "C" {
1010

1111
#include <stdint.h>
1212

13+
/** Length of a message that can be embedded into a maximally-sized rangeproof
14+
*
15+
* It is not be possible to fit a message of this size into a non-maximally-sized
16+
* rangeproof, but it is guaranteed that any embeddable message can fit into an
17+
* array of this size. This constant is intended to be used for memory allocations
18+
* and sanity checks.
19+
*/
20+
#define SECP256K1_RANGEPROOF_MAX_MESSAGE_LEN 3968
21+
1322
/** Opaque data structure that stores a Pedersen commitment
1423
*
1524
* The exact representation of data inside is implementation defined and not
@@ -119,6 +128,49 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_pedersen_verify_tally(
119128
size_t ncnt
120129
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4);
121130

131+
/** Compute the "net blinding factor" for an asset/amount pair of Pedersen commitments
132+
*
133+
* Returns 0 if either input is out of range, otherwise 1
134+
* Args: ctx: a secp256k1 context object.
135+
* Out: output: 32-byte array into which the result will be written
136+
* In: val: the value of the amount commitment
137+
* vbf: the amount commitment's blinding factor
138+
* abf: the asset commitment's blinding factor
139+
*
140+
* This computse val*abf + vbf
141+
*/
142+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_netbf_compute(
143+
const secp256k1_context* ctx,
144+
unsigned char* output,
145+
uint64_t val,
146+
const unsigned char* vbf,
147+
const unsigned char* abf
148+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
149+
150+
/** Accumulate a net blinding factor
151+
*
152+
* Returns 0 if the input is out of range, otherwise 1
153+
* Args: ctx: a secp256k1 context object.
154+
* In/Out: acc: initially set to the current state of the accumulator; updated in place
155+
* In: nbf: the net blinding factor to add to the accumulator
156+
*/
157+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_netbf_acc(
158+
const secp256k1_context* ctx,
159+
unsigned char* acc,
160+
const unsigned char* nbf
161+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
162+
163+
/** Negate a(n accumulated) net blinding factor
164+
*
165+
* Returns 0 if the input is out of range, otherwise 1
166+
* Args: ctx: a secp256k1 context object.
167+
* In/Out: acc: initially set to the bf to negate; changed to the negated version
168+
*/
169+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_netbf_neg(
170+
const secp256k1_context* ctx,
171+
unsigned char* output
172+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
173+
122174
/** Sets the final Pedersen blinding factor correctly when the generators themselves
123175
* have blinding factors.
124176
*
@@ -227,7 +279,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_rangeproof_rewind(
227279
* proof: pointer to array to receive the proof, can be up to 5134 bytes. (cannot be NULL)
228280
* min_value: constructs a proof where the verifer can tell the minimum value is at least the specified amount.
229281
* commit: the commitment being proved.
230-
* blind: 32-byte blinding factor used by commit.
282+
* blind: 32-byte blinding factor used by commit. The blinding factor may be all-zeros as long as min_bits is set to 3 or greater.
283+
* This is a side-effect of the underlying crypto, not a deliberate API choice, but it may be useful when balancing CT transactions.
231284
* nonce: 32-byte secret nonce used to initialize the proof (value can be reverse-engineered out of the proof if this secret is known.)
232285
* exp: Base-10 exponent. Digits below above will be made public, but the proof will be made smaller. Allowed range is -1 to 18.
233286
* (-1 is a special case that makes the value public. 0 is the most private.)
@@ -286,6 +339,33 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_rangeproof_info(
286339
size_t plen
287340
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
288341

342+
/** Returns an upper bound on the size of a rangeproof with the given parameters
343+
*
344+
* An actual rangeproof may be smaller, for example if the actual value
345+
* is less than both the provided `max_value` and 2^`min_bits`, or if
346+
* the `exp` parameter to `secp256k1_rangeproof_sign` is set such that
347+
* the proven range is compressed. In particular this function will always
348+
* overestimate the size of single-value proofs. Also, if `min_value`
349+
* is set to 0 in the proof, the result will usually, but not always,
350+
* be 8 bytes smaller than if a nonzero value had been passed.
351+
*
352+
* The goal of this function is to provide a useful upper bound for
353+
* memory allocation or fee estimation purposes, without requiring
354+
* too many parameters be fixed in advance.
355+
*
356+
* To obtain the size of largest possible proof, set `max_value` to
357+
* `UINT64_MAX` (and `min_bits` to any valid value such as 0).
358+
*
359+
* In: ctx: pointer to a context object
360+
* max_value: the maximum value that might be passed for `value` for the proof.
361+
* min_bits: the value that will be passed as `min_bits` for the proof.
362+
*/
363+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT size_t secp256k1_rangeproof_max_size(
364+
const secp256k1_context* ctx,
365+
uint64_t max_value,
366+
int min_bits
367+
) SECP256K1_ARG_NONNULL(1);
368+
289369
# ifdef __cplusplus
290370
}
291371
# endif

src/modules/ecdsa_adaptor/main_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#ifndef SECP256K1_MODULE_ECDSA_ADAPTOR_MAIN_H
88
#define SECP256K1_MODULE_ECDSA_ADAPTOR_MAIN_H
99

10-
#include "include/secp256k1_ecdsa_adaptor.h"
11-
#include "modules/ecdsa_adaptor/dleq_impl.h"
10+
#include "../../../include/secp256k1_ecdsa_adaptor.h"
11+
#include "dleq_impl.h"
1212

1313
/* (R, R', s', dleq_proof) */
1414
static int secp256k1_ecdsa_adaptor_sig_serialize(unsigned char *adaptor_sig162, secp256k1_ge *r, secp256k1_ge *rp, const secp256k1_scalar *sp, const secp256k1_scalar *dleq_proof_e, const secp256k1_scalar *dleq_proof_s) {

src/modules/ecdsa_adaptor/tests_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SECP256K1_MODULE_ECDSA_ADAPTOR_TESTS_H
22
#define SECP256K1_MODULE_ECDSA_ADAPTOR_TESTS_H
33

4-
#include "include/secp256k1_ecdsa_adaptor.h"
4+
#include "../../../include/secp256k1_ecdsa_adaptor.h"
55

66
void rand_scalar(secp256k1_scalar *scalar) {
77
unsigned char buf32[32];

src/modules/ecdsa_s2c/main_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#ifndef SECP256K1_MODULE_ECDSA_S2C_MAIN_H
88
#define SECP256K1_MODULE_ECDSA_S2C_MAIN_H
99

10-
#include "include/secp256k1.h"
11-
#include "include/secp256k1_ecdsa_s2c.h"
10+
#include "../../../include/secp256k1.h"
11+
#include "../../../include/secp256k1_ecdsa_s2c.h"
1212

1313
static void secp256k1_ecdsa_s2c_opening_save(secp256k1_ecdsa_s2c_opening* opening, secp256k1_ge* ge) {
1414
secp256k1_pubkey_save((secp256k1_pubkey*) opening, ge);

src/modules/ecdsa_s2c/tests_impl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef SECP256K1_MODULE_ECDSA_S2C_TESTS_H
88
#define SECP256K1_MODULE_ECDSA_S2C_TESTS_H
99

10-
#include "include/secp256k1_ecdsa_s2c.h"
10+
#include "../../../include/secp256k1_ecdsa_s2c.h"
1111

1212
static void test_ecdsa_s2c_tagged_hash(void) {
1313
unsigned char tag_data[14] = "s2c/ecdsa/data";
@@ -78,7 +78,7 @@ void run_s2c_opening_test(void) {
7878
* points' x-coordinates are uniformly random */
7979
if (secp256k1_ecdsa_s2c_opening_parse(none, &opening, input) == 1) {
8080
CHECK(secp256k1_ecdsa_s2c_opening_serialize(none, output, &opening) == 1);
81-
CHECK(memcmp(output, input, sizeof(output)) == 0);
81+
CHECK(secp256k1_memcmp_var(output, input, sizeof(output)) == 0);
8282
}
8383
secp256k1_testrand256(&input[1]);
8484
/* Set pubkey oddness tag to first bit of input[1] */
@@ -255,7 +255,7 @@ static void test_ecdsa_s2c_fixed_vectors(void) {
255255
secp256k1_ecdsa_signature signature;
256256
CHECK(secp256k1_ecdsa_s2c_sign(ctx, &signature, &s2c_opening, message, privkey, test->s2c_data) == 1);
257257
CHECK(secp256k1_ecdsa_s2c_opening_serialize(ctx, opening_ser, &s2c_opening) == 1);
258-
CHECK(memcmp(test->expected_s2c_opening, opening_ser, sizeof(opening_ser)) == 0);
258+
CHECK(secp256k1_memcmp_var(test->expected_s2c_opening, opening_ser, sizeof(opening_ser)) == 0);
259259
CHECK(secp256k1_ecdsa_s2c_verify_commit(ctx, &signature, test->s2c_data, &s2c_opening) == 1);
260260
}
261261
}
@@ -331,7 +331,7 @@ static void test_ecdsa_anti_exfil_signer_commit(void) {
331331
const ecdsa_s2c_test *test = &ecdsa_s2c_tests[i];
332332
CHECK(secp256k1_ecdsa_anti_exfil_signer_commit(ctx, &s2c_opening, message, privkey, test->s2c_data) == 1);
333333
CHECK(secp256k1_ecdsa_s2c_opening_serialize(ctx, buf, &s2c_opening) == 1);
334-
CHECK(memcmp(test->expected_s2c_exfil_opening, buf, sizeof(buf)) == 0);
334+
CHECK(secp256k1_memcmp_var(test->expected_s2c_exfil_opening, buf, sizeof(buf)) == 0);
335335
}
336336
}
337337

@@ -397,7 +397,7 @@ static void test_ecdsa_anti_exfil(void) {
397397
CHECK(secp256k1_ecdsa_verify(ctx, &signature, host_msg, &signer_pubkey) == 1);
398398
CHECK(secp256k1_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, host_nonce_contribution, &s2c_opening) == 0);
399399
CHECK(secp256k1_anti_exfil_host_verify(ctx, &signature, host_msg, &signer_pubkey, bad_nonce_contribution, &s2c_opening) == 1);
400-
CHECK(memcmp(&s2c_opening, &orig_opening, sizeof(s2c_opening)) != 0);
400+
CHECK(secp256k1_memcmp_var(&s2c_opening, &orig_opening, sizeof(s2c_opening)) != 0);
401401
}
402402
}
403403

src/modules/extrakeys/hsort_impl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ static SECP256K1_INLINE size_t child2(size_t i) {
2323
return child1(i)+1;
2424
}
2525

26-
static SECP256K1_INLINE void swap64(unsigned char *a, size_t i, size_t j, size_t stride) {
26+
static SECP256K1_INLINE void heap_swap64(unsigned char *a, size_t i, size_t j, size_t stride) {
2727
unsigned char tmp[64];
2828
VERIFY_CHECK(stride <= 64);
2929
memcpy(tmp, a + i*stride, stride);
3030
memmove(a + i*stride, a + j*stride, stride);
3131
memcpy(a + j*stride, tmp, stride);
3232
}
3333

34-
static SECP256K1_INLINE void swap(unsigned char *a, size_t i, size_t j, size_t stride) {
34+
static SECP256K1_INLINE void heap_swap(unsigned char *a, size_t i, size_t j, size_t stride) {
3535
while (64 < stride) {
36-
swap64(a + (stride - 64), i, j, 64);
36+
heap_swap64(a + (stride - 64), i, j, 64);
3737
stride -= 64;
3838
}
39-
swap64(a, i, j, stride);
39+
heap_swap64(a, i, j, stride);
4040
}
4141

4242
static SECP256K1_INLINE void heap_down(unsigned char *a, size_t i, size_t heap_size, size_t stride,
@@ -71,7 +71,7 @@ static SECP256K1_INLINE void heap_down(unsigned char *a, size_t i, size_t heap_s
7171
if (child2(i) < heap_size
7272
&& 0 <= cmp(a + child2(i)*stride, a + child1(i)*stride, cmp_data)) {
7373
if (0 < cmp(a + child2(i)*stride, a + i*stride, cmp_data)) {
74-
swap(a, i, child2(i), stride);
74+
heap_swap(a, i, child2(i), stride);
7575
i = child2(i);
7676
} else {
7777
/* At this point we have [child2(i)] >= [child1(i)] and we have
@@ -80,7 +80,7 @@ static SECP256K1_INLINE void heap_down(unsigned char *a, size_t i, size_t heap_s
8080
return;
8181
}
8282
} else if (0 < cmp(a + child1(i)*stride, a + i*stride, cmp_data)) {
83-
swap(a, i, child1(i), stride);
83+
heap_swap(a, i, child1(i), stride);
8484
i = child1(i);
8585
} else {
8686
return;
@@ -106,7 +106,7 @@ static void secp256k1_hsort(void *ptr, size_t count, size_t size,
106106
}
107107
for(i = count; 1 < i; --i) {
108108
/* Extract the largest value from the heap */
109-
swap(ptr, 0, i-1, size);
109+
heap_swap(ptr, 0, i-1, size);
110110

111111
/* Repair the heap condition */
112112
heap_down(ptr, 0, i-1, size, cmp, cmp_data);

src/modules/generator/main_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
#include <stdio.h>
1111

12-
#include "field.h"
13-
#include "group.h"
14-
#include "hash.h"
15-
#include "scalar.h"
12+
#include "../../field.h"
13+
#include "../../group.h"
14+
#include "../../hash.h"
15+
#include "../../scalar.h"
1616

1717
static void secp256k1_generator_load(secp256k1_ge* ge, const secp256k1_generator* gen) {
1818
int succeed;

0 commit comments

Comments
 (0)