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.
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.
Perhaps foolishly I made the flags handling in secp256k1_ec_pubkey_serialize absolutely strict. Is this what we want to do? ... would we really ever want to add any more flags there? (hybrid? 0_o).
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);
Sure. Do you mean leave all this checking out or just the flag part?
Just the flag part.
Okay, flags test gone.
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. */
I don't think 'abs' has much meaning in a finite field...
Do you mean sqrt?
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)) &&
I'm confused about what ypass means, if it can also be true for 33-byte pubkeys?
Got it. It means "when taking the current prefix byte + subsequence of input, we can parse and reserialize the result as uncompressed, and it will be identical to the input". Took me 10 minutes :)
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));
Seems it starts with 0xfe, not with 0x04?
Nevermind, pubkeyc vs 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);
That looks like an error. We know ec_pubkey_parse won't go look beyond the 65th byte, but it's a bit ugly that the correctness of the test code relies on that. Can you add a padding byte to pubkeyc?
ACK with tiny nits.
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.
Nits should all be corrected now.