Skip to content

Commit 7120fc2

Browse files
committed
tests: Replace counting_illegal_callbacks with CHECK_ILLEGAL_VOID
This commit also explicitly initializes shortpubkey. For some reason, removing surrounding, unrelated lines results in gcc warnings when configured with --enable-ctime-tests=no --with-valgrind=no.
1 parent 3aa9d00 commit 7120fc2

File tree

5 files changed

+151
-451
lines changed

5 files changed

+151
-451
lines changed

src/modules/ecdh/tests_impl.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,19 @@ static int ecdh_hash_function_custom(unsigned char *output, const unsigned char
2626

2727
static void test_ecdh_api(void) {
2828
/* Setup context that just counts errors */
29-
secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
3029
secp256k1_pubkey point;
3130
unsigned char res[32];
3231
unsigned char s_one[32] = { 0 };
33-
int32_t ecount = 0;
3432
s_one[31] = 1;
3533

36-
secp256k1_context_set_error_callback(tctx, counting_illegal_callback_fn, &ecount);
37-
secp256k1_context_set_illegal_callback(tctx, counting_illegal_callback_fn, &ecount);
38-
CHECK(secp256k1_ec_pubkey_create(tctx, &point, s_one) == 1);
34+
CHECK(secp256k1_ec_pubkey_create(CTX, &point, s_one) == 1);
3935

4036
/* Check all NULLs are detected */
41-
CHECK(secp256k1_ecdh(tctx, res, &point, s_one, NULL, NULL) == 1);
42-
CHECK(ecount == 0);
43-
CHECK(secp256k1_ecdh(tctx, NULL, &point, s_one, NULL, NULL) == 0);
44-
CHECK(ecount == 1);
45-
CHECK(secp256k1_ecdh(tctx, res, NULL, s_one, NULL, NULL) == 0);
46-
CHECK(ecount == 2);
47-
CHECK(secp256k1_ecdh(tctx, res, &point, NULL, NULL, NULL) == 0);
48-
CHECK(ecount == 3);
49-
CHECK(secp256k1_ecdh(tctx, res, &point, s_one, NULL, NULL) == 1);
50-
CHECK(ecount == 3);
51-
52-
/* Cleanup */
53-
secp256k1_context_destroy(tctx);
37+
CHECK(secp256k1_ecdh(CTX, res, &point, s_one, NULL, NULL) == 1);
38+
CHECK_ILLEGAL(CTX, secp256k1_ecdh(CTX, NULL, &point, s_one, NULL, NULL));
39+
CHECK_ILLEGAL(CTX, secp256k1_ecdh(CTX, res, NULL, s_one, NULL, NULL));
40+
CHECK_ILLEGAL(CTX, secp256k1_ecdh(CTX, res, &point, NULL, NULL, NULL));
41+
CHECK(secp256k1_ecdh(CTX, res, &point, s_one, NULL, NULL) == 1);
5442
}
5543

5644
static void test_ecdh_generator_basepoint(void) {

0 commit comments

Comments
 (0)