golang/go · error

boringcrypto: unknown elliptic curve

Error message

boringcrypto: unknown elliptic curve

What it means

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.

Source

Thrown at src/crypto/internal/boring/ecdsa.go:36

}

type PrivateKeyECDSA struct {
	key *C.GO_EC_KEY
}

func (k *PrivateKeyECDSA) finalize() {
	C._goboringcrypto_EC_KEY_free(k.key)
}

type PublicKeyECDSA struct {
	key *C.GO_EC_KEY
}

func (k *PublicKeyECDSA) finalize() {
	C._goboringcrypto_EC_KEY_free(k.key)
}

var errUnknownCurve = errors.New("boringcrypto: unknown elliptic curve")

func curveNID(curve string) (C.int, error) {
	switch curve {
	case "P-224":
		return C.GO_NID_secp224r1, nil
	case "P-256":
		return C.GO_NID_X9_62_prime256v1, nil
	case "P-384":
		return C.GO_NID_secp384r1, nil
	case "P-521":
		return C.GO_NID_secp521r1, nil
	}
	return 0, errUnknownCurve
}

func NewPublicKeyECDSA(curve string, X, Y BigInt) (*PublicKeyECDSA, error) {
	key, err := newECKey(curve, X, Y)
	if err != nil {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Use only P-224, P-256, P-384, or P-521 with the boring ECDSA/ECDH functions.
  2. For X25519/Ed25519, use the dedicated crypto/ecdh.X25519 / crypto/ed25519 paths, not the boring EC_KEY path.
  3. Verify the curve string spelling/case exactly matches the switch arms.

Example fix

// before
nid, err := curveNID("X25519") // unknown curve

// after
nid, err := curveNID("P-256") // one of the four supported
Defensive patterns

Strategy: validation

Validate before calling

var supportedBoringCurves = map[string]bool{"P-224": true, "P-256": true, "P-384": true, "P-521": true}

func validateCurveName(curve string) error {
    if !supportedBoringCurves[curve] {
        return fmt.Errorf("boringcrypto: unsupported curve %q", curve)
    }
    return nil
}

Type guard

func isSupportedBoringCurve(c string) bool {
    switch c {
    case "P-224", "P-256", "P-384", "P-521":
        return true
    }
    return false
}

Prevention

When it happens

Trigger: 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".

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/689f97810e627840. Report an issue: GitHub.