introduce `secp256k1_eckey_pubkey_serialize{33,65}` functions
What changed, and why it matters
This commit adds two new internal helper functions for converting elliptic-curve points into the standard 33-byte compressed and 65-byte uncompressed public-key formats. It is a straightforward code-organization change with no visible security relevance.
No security action required; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces secp256k1_eckey_pubkey_serialize33 and secp256k1_eckey_pubkey_serialize65 in src/eckey_impl.h and declares them in src/eckey.h. Both functions wrap existing field-element serialization primitives (secp256k1_fe_normalize_var, secp256k1_fe_get_b32) and include VERIFY_CHECK guards against serializing the point at infinity. They do not change any public API, existing behavior, or memory-safety boundary.
Changed components
src/eckey.hsrc/eckey_impl.hInspect captured patch +23 / −0
diff --git a/src/eckey.h b/src/eckey.h
index d54d44c..3ebe896 100644
--- a/src/eckey.h
+++ b/src/eckey.h
@@ -16,6 +16,10 @@
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size);
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed);
+/** Serialize a group element (that is not allowed to be infinity) to a compressed public key (33 bytes). */
+static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33);
+/** Serialize a group element (that is not allowed to be infinity) to an uncompressed public key (65 bytes). */
+static void secp256k1_eckey_pubkey_serialize65(secp256k1_ge *elem, unsigned char *pub65);
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak);
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak);
diff --git a/src/eckey_impl.h b/src/eckey_impl.h
index a88a596..4f64760 100644
--- a/src/eckey_impl.h
+++ b/src/eckey_impl.h
@@ -55,6 +55,25 @@ static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *p
return 1;
}
+static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33) {
+ VERIFY_CHECK(!secp256k1_ge_is_infinity(elem));
+
+ secp256k1_fe_normalize_var(&elem->x);
+ secp256k1_fe_normalize_var(&elem->y);
+ pub33[0] = secp256k1_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN;
+ secp256k1_fe_get_b32(&pub33[1], &elem->x);
+}
+
+static void secp256k1_eckey_pubkey_serialize65(secp256k1_ge *elem, unsigned char *pub65) {
+ VERIFY_CHECK(!secp256k1_ge_is_infinity(elem));
+
+ secp256k1_fe_normalize_var(&elem->x);
+ secp256k1_fe_normalize_var(&elem->y);
+ pub65[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED;
+ secp256k1_fe_get_b32(&pub65[1], &elem->x);
+ secp256k1_fe_get_b32(&pub65[33], &elem->y);
+}
+
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak) {
secp256k1_scalar_add(key, key, tweak);
return !secp256k1_scalar_is_zero(key);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.