Skip to content

Commit f5e815f

Browse files
committed
remove secp256k1_eckey_pubkey_serialize function
1 parent 0d3659c commit f5e815f

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

src/eckey.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "ecmult_gen.h"
1616

1717
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size);
18-
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed);
1918
/** Serialize a group element (that is not allowed to be infinity) to a compressed public key (33 bytes). */
2019
static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33);
2120
/** Serialize a group element (that is not allowed to be infinity) to an uncompressed public key (65 bytes). */

src/eckey_impl.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,6 @@ static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char
3535
}
3636
}
3737

38-
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) {
39-
VERIFY_CHECK(compressed == 0 || compressed == 1);
40-
41-
if (secp256k1_ge_is_infinity(elem)) {
42-
return 0;
43-
}
44-
secp256k1_fe_normalize_var(&elem->x);
45-
secp256k1_fe_normalize_var(&elem->y);
46-
secp256k1_fe_get_b32(&pub[1], &elem->x);
47-
if (compressed) {
48-
*size = 33;
49-
pub[0] = secp256k1_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN;
50-
} else {
51-
*size = 65;
52-
pub[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED;
53-
secp256k1_fe_get_b32(&pub[33], &elem->y);
54-
}
55-
return 1;
56-
}
57-
5838
static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33) {
5939
VERIFY_CHECK(!secp256k1_ge_is_infinity(elem));
6040

src/tests.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,8 +4315,6 @@ static void test_point_times_order(const secp256k1_gej *point) {
43154315
secp256k1_scalar nx;
43164316
secp256k1_gej res1, res2;
43174317
secp256k1_ge res3;
4318-
unsigned char pub[65];
4319-
size_t psize = 65;
43204318
testutil_random_scalar_order_test(&x);
43214319
secp256k1_scalar_negate(&nx, &x);
43224320
secp256k1_ecmult(&res1, point, &x, &x); /* calc res1 = x * point + x * G; */
@@ -4326,9 +4324,6 @@ static void test_point_times_order(const secp256k1_gej *point) {
43264324
secp256k1_ge_set_gej(&res3, &res1);
43274325
CHECK(secp256k1_ge_is_infinity(&res3));
43284326
CHECK(secp256k1_ge_is_valid_var(&res3) == 0);
4329-
CHECK(secp256k1_eckey_pubkey_serialize(&res3, pub, &psize, 0) == 0);
4330-
psize = 65;
4331-
CHECK(secp256k1_eckey_pubkey_serialize(&res3, pub, &psize, 1) == 0);
43324327
/* check zero/one edge cases */
43334328
secp256k1_ecmult(&res1, point, &secp256k1_scalar_zero, &secp256k1_scalar_zero);
43344329
secp256k1_ge_set_gej(&res3, &res1);
@@ -5435,7 +5430,6 @@ static void test_ecmult_accumulate(secp256k1_sha256* acc, const secp256k1_scalar
54355430
secp256k1_gej rj1, rj2, rj3, rj4, rj5, rj6, gj, infj;
54365431
secp256k1_ge r;
54375432
unsigned char bytes[65];
5438-
size_t size = 65;
54395433
secp256k1_gej_set_ge(&gj, &secp256k1_ge_const_g);
54405434
secp256k1_gej_set_infinity(&infj);
54415435
secp256k1_ecmult_gen(&CTX->ecmult_gen_ctx, &rj1, x);
@@ -5456,9 +5450,8 @@ static void test_ecmult_accumulate(secp256k1_sha256* acc, const secp256k1_scalar
54565450
secp256k1_sha256_write(acc, zerobyte, 1);
54575451
} else {
54585452
/* Store other points using their uncompressed serialization. */
5459-
secp256k1_eckey_pubkey_serialize(&r, bytes, &size, 0);
5460-
CHECK(size == 65);
5461-
secp256k1_sha256_write(acc, bytes, size);
5453+
secp256k1_eckey_pubkey_serialize65(&r, bytes);
5454+
secp256k1_sha256_write(acc, bytes, sizeof(bytes));
54625455
}
54635456
}
54645457

@@ -6543,16 +6536,18 @@ static void test_random_pubkeys(void) {
65436536
size_t size = len;
65446537
firstb = in[0];
65456538
/* If the pubkey can be parsed, it should round-trip... */
6546-
CHECK(secp256k1_eckey_pubkey_serialize(&elem, out, &size, len == 33));
6547-
CHECK(size == len);
6539+
if (len == 33) {
6540+
secp256k1_eckey_pubkey_serialize33(&elem, out);
6541+
} else {
6542+
secp256k1_eckey_pubkey_serialize65(&elem, out);
6543+
}
65486544
CHECK(secp256k1_memcmp_var(&in[1], &out[1], len-1) == 0);
65496545
/* ... except for the type of hybrid inputs. */
65506546
if ((in[0] != 6) && (in[0] != 7)) {
65516547
CHECK(in[0] == out[0]);
65526548
}
65536549
size = 65;
6554-
CHECK(secp256k1_eckey_pubkey_serialize(&elem, in, &size, 0));
6555-
CHECK(size == 65);
6550+
secp256k1_eckey_pubkey_serialize65(&elem, in);
65566551
CHECK(secp256k1_eckey_pubkey_parse(&elem2, in, size));
65576552
CHECK(secp256k1_ge_eq_var(&elem2, &elem));
65586553
/* Check that the X9.62 hybrid type is checked. */
@@ -6567,7 +6562,7 @@ static void test_random_pubkeys(void) {
65676562
}
65686563
if (res) {
65696564
CHECK(secp256k1_ge_eq_var(&elem, &elem2));
6570-
CHECK(secp256k1_eckey_pubkey_serialize(&elem, out, &size, 0));
6565+
secp256k1_eckey_pubkey_serialize65(&elem, out);
65716566
CHECK(secp256k1_memcmp_var(&in[1], &out[1], 64) == 0);
65726567
}
65736568
}

0 commit comments

Comments
 (0)