Skip to content

Commit 78e66ec

Browse files
committed
Only have declassify flag in context when checkmem available
1 parent 23b6772 commit 78e66ec

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/secp256k1.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ struct secp256k1_context_struct {
6060
secp256k1_ecmult_gen_context ecmult_gen_ctx;
6161
secp256k1_callback illegal_callback;
6262
secp256k1_callback error_callback;
63+
#if SECP256K1_CHECKMEM_ENABLED
6364
int declassify;
65+
#endif
6466
};
6567

6668
static const secp256k1_context secp256k1_context_static_ = {
6769
{ 0 },
6870
{ secp256k1_default_illegal_callback_fn, 0 },
69-
{ secp256k1_default_error_callback_fn, 0 },
70-
0
71+
{ secp256k1_default_error_callback_fn, 0 }
72+
#if SECP256K1_CHECKMEM_ENABLED
73+
, 0
74+
#endif
7175
};
7276
const secp256k1_context *secp256k1_context_static = &secp256k1_context_static_;
7377
const secp256k1_context *secp256k1_context_no_precomp = &secp256k1_context_static_;
@@ -116,7 +120,9 @@ secp256k1_context* secp256k1_context_preallocated_create(void* prealloc, unsigne
116120
/* Flags have been checked by secp256k1_context_preallocated_size. */
117121
VERIFY_CHECK((flags & SECP256K1_FLAGS_TYPE_MASK) == SECP256K1_FLAGS_TYPE_CONTEXT);
118122
secp256k1_ecmult_gen_context_build(&ret->ecmult_gen_ctx);
123+
#if SECP256K1_CHECKMEM_ENABLED
119124
ret->declassify = !!(flags & SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY);
125+
#endif
120126

121127
return ret;
122128
}
@@ -199,7 +205,13 @@ void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scr
199205
* of the software.
200206
*/
201207
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context* ctx, const void *p, size_t len) {
208+
#if SECP256K1_CHECKMEM_ENABLED
202209
if (EXPECT(ctx->declassify, 0)) SECP256K1_CHECKMEM_DEFINE(p, len);
210+
#else
211+
(void)ctx;
212+
(void)p;
213+
(void)len;
214+
#endif
203215
}
204216

205217
static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {

src/tests.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ int ecmult_gen_context_eq(const secp256k1_ecmult_gen_context *a, const secp256k1
150150
}
151151

152152
int context_eq(const secp256k1_context *a, const secp256k1_context *b) {
153-
return a->declassify == b->declassify
154-
&& ecmult_gen_context_eq(&a->ecmult_gen_ctx, &b->ecmult_gen_ctx)
153+
return ecmult_gen_context_eq(&a->ecmult_gen_ctx, &b->ecmult_gen_ctx)
154+
#if SECP256K1_CHECKMEM_ENABLED
155+
&& a->declassify == b->declassify
156+
#endif
155157
&& a->illegal_callback.fn == b->illegal_callback.fn
156-
&& a->illegal_callback.data == b->illegal_callback.
157-
data
158+
&& a->illegal_callback.data == b->illegal_callback.data
158159
&& a->error_callback.fn == b->error_callback.fn
159160
&& a->error_callback.data == b->error_callback.data;
160161
}

0 commit comments

Comments
 (0)