{"record":{"id":"689f97810e627840","repo":"golang/go","slug":"boringcrypto-unknown-elliptic-curve","errorCode":null,"errorMessage":"boringcrypto: unknown elliptic curve","messagePattern":"boringcrypto: unknown elliptic curve","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/internal/boring/ecdsa.go","lineNumber":36,"sourceCode":"}\n\ntype PrivateKeyECDSA struct {\n\tkey *C.GO_EC_KEY\n}\n\nfunc (k *PrivateKeyECDSA) finalize() {\n\tC._goboringcrypto_EC_KEY_free(k.key)\n}\n\ntype PublicKeyECDSA struct {\n\tkey *C.GO_EC_KEY\n}\n\nfunc (k *PublicKeyECDSA) finalize() {\n\tC._goboringcrypto_EC_KEY_free(k.key)\n}\n\nvar errUnknownCurve = errors.New(\"boringcrypto: unknown elliptic curve\")\n\nfunc curveNID(curve string) (C.int, error) {\n\tswitch curve {\n\tcase \"P-224\":\n\t\treturn C.GO_NID_secp224r1, nil\n\tcase \"P-256\":\n\t\treturn C.GO_NID_X9_62_prime256v1, nil\n\tcase \"P-384\":\n\t\treturn C.GO_NID_secp384r1, nil\n\tcase \"P-521\":\n\t\treturn C.GO_NID_secp521r1, nil\n\t}\n\treturn 0, errUnknownCurve\n}\n\nfunc NewPublicKeyECDSA(curve string, X, Y BigInt) (*PublicKeyECDSA, error) {\n\tkey, err := newECKey(curve, X, Y)\n\tif err != nil {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/internal/boring/ecdsa.go#L18-L54","documentation":"errUnknownCurve is returned by curveNID when the curve name is not one of the four supported NIST curves: P-224, P-256, P-384, P-521. BoringCrypto's ECDSA/ECDH path only registers those curve NIDs; any other curve string yields this error.","triggerScenarios":"Calling curveNID (and any ECDSA/ECDH constructor that uses it) with a curve string outside {\"P-224\",\"P-256\",\"P-384\",\"P-521\"}: e.g. \"X25519\", \"Ed25519\", \"secp256k1\", or a typo like \"P256\".","commonSituations":"Passing Curve25519/Ed25519 curve names into the boring EC path (those use a different API); typos or case variations in the curve name; non-NIST curves used in some blockchains.","solutions":["Use only P-224, P-256, P-384, or P-521 with the boring ECDSA/ECDH functions.","For X25519/Ed25519, use the dedicated crypto/ecdh.X25519 / crypto/ed25519 paths, not the boring EC_KEY path.","Verify the curve string spelling/case exactly matches the switch arms."],"exampleFix":"// before\nnid, err := curveNID(\"X25519\") // unknown curve\n\n// after\nnid, err := curveNID(\"P-256\") // one of the four supported","handlingStrategy":"validation","validationCode":"var supportedBoringCurves = map[string]bool{\"P-224\": true, \"P-256\": true, \"P-384\": true, \"P-521\": true}\n\nfunc validateCurveName(curve string) error {\n    if !supportedBoringCurves[curve] {\n        return fmt.Errorf(\"boringcrypto: unsupported curve %q\", curve)\n    }\n    return nil\n}","typeGuard":"func isSupportedBoringCurve(c string) bool {\n    switch c {\n    case \"P-224\", \"P-256\", \"P-384\", \"P-521\":\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Use exact NIST curve names with the dash: \"P-256\", not \"P256\" or \"secp256r1\".","Route X25519/Ed25519 through their dedicated APIs, not the boring EC path.","Validate curve names at configuration load time."],"tags":["crypto","ecdsa","ecdh","boringcrypto","fips","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}