restic/restic · critical

unable to read enough random bytes for salt:

Error message

unable to read enough random bytes for salt: 

What it means

During key creation (restic init / key add), restic generates the scrypt salt via crypto.NewSalt() and treats any returned error as fatal, panicking with the error text appended. In the current code NewSalt itself already panics on short reads (kdf.go), so this outer branch is a defensive assert for an error NewSalt never actually returns. The underlying failure class is OS entropy-source failure, identical to error 262.

Source

Thrown at internal/repository/key.go:251

		P:   params.P,
	}

	if newkey.Hostname == "" {
		newkey.Hostname, _ = os.Hostname()
	}

	if newkey.Username == "" {
		usr, err := user.Current()
		if err == nil {
			newkey.Username = usr.Username
		}
	}

	// generate random salt
	var err error
	newkey.Salt, err = crypto.NewSalt()
	if err != nil {
		panic("unable to read enough random bytes for salt: " + err.Error())
	}

	// call KDF to derive user key
	newkey.user, err = crypto.KDF(*params, newkey.Salt, password)
	if err != nil {
		return nil, err
	}

	if template == nil {
		// generate new random master keys
		newkey.master = crypto.NewRandomKey()
	} else {
		// copy master keys from old key
		newkey.master = template
	}

	// encrypt master keys (as json) with user key
	buf, err := json.Marshal(newkey.master)

View on GitHub (pinned to a80be1478a)

Solutions

  1. Verify /dev/urandom is available and readable in the environment
  2. Raise the process fd limit before creating keys
  3. Restart the container/host to restore the entropy source, then retry 'restic key add'
Defensive patterns

Strategy: retry

Prevention

When it happens

Trigger: Creating or adding a repository key when crypto/rand cannot supply 64 bytes; broken /dev/urandom in a container; fd exhaustion preventing the random device open.

Common situations: Minimal containers, chroots without proper /dev; long-running daemons at their fd limit; ancient kernels with entropy starvation.

Related errors


AI-assisted analysis of restic/restic@a80be1478a (2026-08-15). Data as JSON: /api/errors/735c009615573a80. Report an issue: GitHub.