{"record":{"id":"9ac846a1d626b9ca","repo":"golang/go","slug":"ecdsa-curve-not-supported-by-parseuncompressedpub","errorCode":null,"errorMessage":"ecdsa: curve not supported by ParseUncompressedPublicKey","messagePattern":"ecdsa: curve not supported by ParseUncompressedPublicKey","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/ecdsa/ecdsa.go","lineNumber":121,"sourceCode":"// instead of an [ecdh.PublicKey].\n//\n// Note that public keys are more commonly encoded in DER (or PEM) format, which\n// can be parsed with [crypto/x509.ParsePKIXPublicKey] (and [encoding/pem]).\nfunc ParseUncompressedPublicKey(curve elliptic.Curve, data []byte) (*PublicKey, error) {\n\tif len(data) < 1 || data[0] != 4 {\n\t\treturn nil, errors.New(\"ecdsa: invalid uncompressed public key\")\n\t}\n\tswitch curve {\n\tcase elliptic.P224():\n\t\treturn parseUncompressedPublicKey(ecdsa.P224(), curve, data)\n\tcase elliptic.P256():\n\t\treturn parseUncompressedPublicKey(ecdsa.P256(), curve, data)\n\tcase elliptic.P384():\n\t\treturn parseUncompressedPublicKey(ecdsa.P384(), curve, data)\n\tcase elliptic.P521():\n\t\treturn parseUncompressedPublicKey(ecdsa.P521(), curve, data)\n\tdefault:\n\t\treturn nil, errors.New(\"ecdsa: curve not supported by ParseUncompressedPublicKey\")\n\t}\n}\n\nfunc parseUncompressedPublicKey[P ecdsa.Point[P]](c *ecdsa.Curve[P], curve elliptic.Curve, data []byte) (*PublicKey, error) {\n\tk, err := ecdsa.NewPublicKey(c, data)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn publicKeyFromFIPS(curve, k)\n}\n\n// Bytes encodes the public key as an uncompressed point according to SEC 1,\n// Version 2.0, Section 2.3.3 (also known as the X9.62 uncompressed format).\n// It returns an error if the public key is invalid.\n//\n// PublicKey.Curve must be one of [elliptic.P224], [elliptic.P256],\n// [elliptic.P384], or [elliptic.P521], or Bytes returns an error.\n//","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/ecdsa/ecdsa.go#L103-L139","documentation":"Thrown by ParseUncompressedPublicKey when the provided curve does not match any of the four supported NIST curves: elliptic.P224, P256, P384, or P521. The switch statement has no case for custom or non-NIST curves, so the default branch fires.","triggerScenarios":"Calling ParseUncompressedPublicKey with a custom elliptic.Curve implementation, a curve from a third-party library, or any curve not returned by elliptic.P224()/P256()/P384()/P521(). Note that even elliptic.P521() is supported but using curve.Params() instead of the singleton may fail because the switch compares interface values.","commonSituations":"Using a non-standard curve for specialized applications; passing elliptic.P256().Params() instead of elliptic.P256() (the switch compares the concrete curve object); third-party curve implementations that wrap or extend the standard curves.","solutions":["Use the canonical curve singletons: elliptic.P224(), elliptic.P256(), elliptic.P384(), or elliptic.P521() — not their .Params() counterparts.","If using a non-NIST curve, implement your own point parsing logic rather than relying on ParseUncompressedPublicKey.","Verify the curve identity with a type assertion or comparison to the known singletons before calling this function."],"exampleFix":"// before\npub, err := ecdsa.ParseUncompressedPublicKey(curve.Params(), data)\n\n// after\npub, err := ecdsa.ParseUncompressedPublicKey(elliptic.P256(), data) // pass the singleton, not .Params()","handlingStrategy":"validation","validationCode":"func isSupportedNISTCurve(c elliptic.Curve) bool {\n    switch c {\n    case elliptic.P224(), elliptic.P256(), elliptic.P384(), elliptic.P521():\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"pub, err := ecdsa.ParseUncompressedPublicKey(curve, data)\nif err != nil {\n    return fmt.Errorf(\"curve %s not supported: %w\", curve.Params().Name, err)\n}","preventionTips":["Pass curve singletons (elliptic.P256()) not curve.Params() — the switch compares interface identity.","Validate the curve is a standard NIST singleton before calling curve-specific functions."],"tags":["crypto","ecdsa","curve-mismatch","nist-curves","input-validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}