{"record":{"id":"644f51da4bc6d446","repo":"golang/go","slug":"ecdsa-curve-not-supported-by-deterministic-signat","errorCode":null,"errorMessage":"ecdsa: curve not supported by deterministic signatures","messagePattern":"ecdsa: curve not supported by deterministic signatures","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/ecdsa/ecdsa.go","lineNumber":454,"sourceCode":"\treturn encodeSignature(sig.R, sig.S)\n}\n\nfunc signRFC6979(priv *PrivateKey, hash []byte, opts crypto.SignerOpts) ([]byte, error) {\n\tif opts == nil {\n\t\treturn nil, errors.New(\"ecdsa: Sign called with nil random and nil opts\")\n\t}\n\th := opts.HashFunc()\n\tswitch priv.Curve.Params() {\n\tcase elliptic.P224().Params():\n\t\treturn signFIPSDeterministic(ecdsa.P224(), h, priv, hash)\n\tcase elliptic.P256().Params():\n\t\treturn signFIPSDeterministic(ecdsa.P256(), h, priv, hash)\n\tcase elliptic.P384().Params():\n\t\treturn signFIPSDeterministic(ecdsa.P384(), h, priv, hash)\n\tcase elliptic.P521().Params():\n\t\treturn signFIPSDeterministic(ecdsa.P521(), h, priv, hash)\n\tdefault:\n\t\treturn nil, errors.New(\"ecdsa: curve not supported by deterministic signatures\")\n\t}\n}\n\nfunc signFIPSDeterministic[P ecdsa.Point[P]](c *ecdsa.Curve[P], hashFunc crypto.Hash, priv *PrivateKey, hash []byte) ([]byte, error) {\n\tk, err := privateKeyToFIPS(c, priv)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !hashFunc.Available() {\n\t\treturn nil, errors.New(\"ecdsa: requested hash function unavailable: \" + hashFunc.String())\n\t}\n\th := fips140hash.UnwrapNew(hashFunc.New)\n\tif fips140only.Enforced() && !fips140only.ApprovedHash(h()) {\n\t\treturn nil, errors.New(\"crypto/ecdsa: use of hash functions other than SHA-2 or SHA-3 is not allowed in FIPS 140-only mode\")\n\t}\n\tsig, err := ecdsa.SignDeterministic(c, h, k, hash)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/ecdsa/ecdsa.go#L436-L472","documentation":"Thrown by signRFC6979 when priv.Curve.Params() does not match P224, P256, P384, or P521 in the switch statement. RFC 6979 deterministic signing is only implemented for standard NIST curves through the internal FIPS ecdsa.SignDeterministic function. Custom or non-standard curves cannot produce deterministic signatures via this code path.","triggerScenarios":"Calling priv.Sign(nil, digest, opts) (deterministic mode) on a PrivateKey whose Curve is not one of the four NIST curves. The signRFC6979 switch falls through to the default case.","commonSituations":"Using a custom curve and requesting deterministic signing; loading keys with non-standard curves; code that generically calls Sign with nil random across different curve types.","solutions":["Use randomized signing instead: pass a non-nil random reader (e.g., crypto/rand.Reader) which goes through SignASN1 rather than signRFC6979.","Ensure the PrivateKey uses a standard NIST curve (P224/P256/P384/P521) if deterministic signing is required.","For non-NIST deterministic signing, implement RFC 6979 externally using the curve's parameters."],"exampleFix":"// before\nsig, err := priv.Sign(nil, digest, crypto.SHA256) // deterministic on custom curve\n\n// after\nsig, err := priv.Sign(rand.Reader, digest, crypto.SHA256) // randomized signing works on all curves","handlingStrategy":"validation","validationCode":"func supportsDeterministicSign(curve elliptic.Curve) bool {\n    switch curve.Params() {\n    case elliptic.P224().Params(), elliptic.P256().Params(),\n         elliptic.P384().Params(), elliptic.P521().Params():\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"sig, err := priv.Sign(nil, digest, opts) // deterministic\nif err != nil && strings.Contains(err.Error(), \"deterministic\") {\n    // fall back to randomized signing\n    sig, err = priv.Sign(rand.Reader, digest, opts)\n}","preventionTips":["Use randomized signing (non-nil random reader) for non-NIST curves.","Check the curve before requesting deterministic signing."],"tags":["crypto","ecdsa","signing","rfc6979","curve-mismatch","nist-curves"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}