I'm trying to parse an EC Point
04410478ed041c12ddaf693958f91f1174e0c790b2ff580ddca39bc2a4f78ad041dc379aaefe27cede2fa7601f90e3f397938ee53268564e346ac7a58aac8c28ca5415
to a ecdsa.PublickKey struct with the following code:
x, y := readECPoint(elliptic.P256(), point)
if x == nil || y == nil {
panic("unable to parse the public key")
}
pubKey := &ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y}
pubKeyBytes := elliptic.Marshal(curve, pubKey.X, pubKey.Y)
Browsing on github I noticed this piece of code, which made sense to me:
func readECPoint(curve elliptic.Curve, ecpoint []byte) (*big.Int, *big.Int) {
x, y := elliptic.Unmarshal(curve, ecpoint)
if x == nil {
// http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/os/pkcs11-curr-v2.40-os.html#_ftn1
// PKCS#11 v2.20 specified that the CKA_EC_POINT was to be store in a DER-encoded
// OCTET STRING.
var point asn1.RawValue
asn1.Unmarshal(ecpoint, &point)
if len(point.Bytes) > 0 {
x, y = elliptic.Unmarshal(curve, point.Bytes)
}
}
return x, y
}
Other things I tried were:
curve := new(secp256k1.BitCurve)
x, y := curve.Unmarshal(point)
However all those previous code always returns with x=nil and y=nil
I know the KeyPair was generated in an HSM with the bitcoin curve
asn1.ObjectIdentifier 1.3.132.0.10
Am I missing something else to properly parse an EC Point from a bitcoin/ethereum curve?