This also makes use of optional valgrind instrumentation if -DVALGRIND is set.
0This also moves secp256k1.c above secp256k1.h in tests.c or otherwise
1 we get non-null macros on the public functions which may defeat some
2 of the VERIFY checks.
This also makes use of optional valgrind instrumentation if -DVALGRIND is set.
0This also moves secp256k1.c above secp256k1.h in tests.c or otherwise
1 we get non-null macros on the public functions which may defeat some
2 of the VERIFY checks.
161@@ -159,6 +162,11 @@ int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *o
162 secp256k1_ge Q;
163
164 (void)ctx;
165+ VERIFY_CHECK(ctx != NULL);
166+ ARG_CHECK(output != NULL);
167+ ARG_CHECK(outputlen != NULL);
168+ ARG_CHECK(pubkey != NULL);
169+ ARG_CHECK((flags | SECP256K1_EC_COMPRESSED) == SECP256K1_EC_COMPRESSED);
1973+ }
1974+ };
1975+#define SECP256K1_EC_PARSE_TEST_NINVALID (7)
1976+ const unsigned char invalid[SECP256K1_EC_PARSE_TEST_NINVALID][64] = {
1977+ {
1978+ /* x is third root of -8, y is abs(x^3+7); also on the curve for y^2 = x^3 + 9. */
1800+ pubkeyc[0] = i;
1801+ /* What sign does this point have? */
1802+ ysign = (input[63] & 1) + 2;
1803+ /* For the current type (i) do we expect parsing to work? Handled all of compressed/uncompressed/hybrid. */
1804+ xpass = xvalid && (pubkeyclen == 33) && ((i & 254) == 2);
1805+ ypass = xvalid && yvalid && ((i & 4) == ((pubkeyclen == 65) << 2)) &&
2075+ CHECK(ecount == 0);
2076+ CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0);
2077+ CHECK(ecount == 1);
2078+ }
2079+ /* 33 bytes claimed on otherwise valid input starting with 0x04, fail, zeroize output, no illegal arg error. */
2080+ memset(&pubkey, 0xfe, sizeof(pubkey));
2108+ CHECK(ecount == 1);
2109+ /* 66 bytes claimed, fail, zeroize output, no illegal arg error. */
2110+ memset(&pubkey, 0xfe, sizeof(pubkey));
2111+ ecount = 0;
2112+ VG_UNDEF(&pubkey, sizeof(pubkey));
2113+ CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 66) == 0);
This also makes secp256k1_ec_pubkey_parse's init of pubkey more unconditional.
This also makes use of optional valgrind instrumentation if -DVALGRIND
is set.
This also moves secp256k1.c above secp256k1.h in tests.c or otherwise
we get non-null macros on the public functions which may defeat some
of the VERIFY checks.