golang/go · error

crypto/dsa: use of DSA is not allowed in FIPS 140-only mode

Error message

crypto/dsa: use of DSA is not allowed in FIPS 140-only mode

What it means

In FIPS 140-only mode, dsa.GenerateParameters refuses to run because DSA is not an approved algorithm under FIPS-only policy. The check is the first statement, before any parameter sizing or prime generation.

Source

Thrown at src/crypto/dsa/dsa.go:68

// in a set of DSA parameters. See FIPS 186-3, section 4.2.
type ParameterSizes int

const (
	L1024N160 ParameterSizes = iota
	L2048N224
	L2048N256
	L3072N256
)

// numMRTests is the number of Miller-Rabin primality tests that we perform. We
// pick the largest recommended number from table C.1 of FIPS 186-3.
const numMRTests = 64

// GenerateParameters puts a random, valid set of DSA parameters into params.
// This function can take many seconds, even on fast machines.
func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error {
	if fips140only.Enforced() {
		return errors.New("crypto/dsa: use of DSA is not allowed in FIPS 140-only mode")
	}

	// This function doesn't follow FIPS 186-3 exactly in that it doesn't
	// use a verification seed to generate the primes. The verification
	// seed doesn't appear to be exported or used by other code and
	// omitting it makes the code cleaner.

	var L, N int
	switch sizes {
	case L1024N160:
		L = 1024
		N = 160
	case L2048N224:
		L = 2048
		N = 224
	case L2048N256:
		L = 2048
		N = 256

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Migrate to an approved signature scheme: ecdsa.GenerateKey or ed25519.GenerateKey.
  2. If FIPS-only is not required, rebuild without FIPS 140-only enforcement.
  3. Pre-generate DSA parameters in a non-FIPS environment and load them, if DSA is unavoidable (still not FIPS-approved).

Example fix

// before
var params dsa.Parameters
dsa.GenerateParameters(&params, rand.Reader, dsa.L2048N256)
// after
priv, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
Defensive patterns

Strategy: fallback

Validate before calling

func genParams(rand io.Reader) (*dsa.PrivateKey, error) {
    if fipsEnabled() {
        // DSA not approved under FIPS; use ECDSA instead.
        priv, err := ecdsa.GenerateKey(elliptic.P256(), rand)
        return (*dsa.PrivateKey)(unsafe.Pointer(priv)), err // illustrative; prefer returning ecdsa key
    }
    var params dsa.Parameters
    return dsa.GenerateParameters(&params, rand, dsa.L2048N256)
}

Try / catch

err := dsa.GenerateParameters(&params, rand.Reader, sizes)
if err != nil && strings.Contains(err.Error(), "FIPS 140-only mode") {
    // fall back to ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
}

Prevention

When it happens

Trigger: Calling dsa.GenerateParameters(&params, rand, sizes) in a binary built/run with FIPS 140-only enforcement.

Common situations: Generating DSA keys in a FIPS-regulated deployment; CI pipeline switched to a FIPS toolchain; compliance-mandated runtime.

Related errors


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