Skip to content

Commit f8d7ea6

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 a1d52e3 commit f8d7ea6

File tree

5 files changed

+151
-455
lines changed

5 files changed

+151
-455
lines changed

src/modules/ecdh/tests_impl.h

+6-19
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,19 @@ static int ecdh_hash_function_custom(unsigned char *output, const unsigned char
2525
}
2626

2727
static void test_ecdh_api(void) {
28-
/* Setup context that just counts errors */
29-
secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
3028
secp256k1_pubkey point;
3129
unsigned char res[32];
3230
unsigned char s_one[32] = { 0 };
33-
int32_t ecount = 0;
3431
s_one[31] = 1;
3532

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);
33+
CHECK(secp256k1_ec_pubkey_create(CTX, &point, s_one) == 1);
3934

4035
/* 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);
36+
CHECK(secp256k1_ecdh(CTX, res, &point, s_one, NULL, NULL) == 1);
37+
CHECK_ILLEGAL(CTX, secp256k1_ecdh(CTX, NULL, &point, s_one, NULL, NULL));
38+
CHECK_ILLEGAL(CTX, secp256k1_ecdh(CTX, res, NULL, s_one, NULL, NULL));
39+
CHECK_ILLEGAL(CTX, secp256k1_ecdh(CTX, res, &point, NULL, NULL, NULL));
40+
CHECK(secp256k1_ecdh(CTX, res, &point, s_one, NULL, NULL) == 1);
5441
}
5542

5643
static void test_ecdh_generator_basepoint(void) {

0 commit comments

Comments
 (0)