{"record":{"id":"735c009615573a80","repo":"restic/restic","slug":"unable-to-read-enough-random-bytes-for-salt","errorCode":null,"errorMessage":"unable to read enough random bytes for salt: ","messagePattern":"unable to read enough random bytes for salt: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/repository/key.go","lineNumber":251,"sourceCode":"\t\tP:   params.P,\n\t}\n\n\tif newkey.Hostname == \"\" {\n\t\tnewkey.Hostname, _ = os.Hostname()\n\t}\n\n\tif newkey.Username == \"\" {\n\t\tusr, err := user.Current()\n\t\tif err == nil {\n\t\t\tnewkey.Username = usr.Username\n\t\t}\n\t}\n\n\t// generate random salt\n\tvar err error\n\tnewkey.Salt, err = crypto.NewSalt()\n\tif err != nil {\n\t\tpanic(\"unable to read enough random bytes for salt: \" + err.Error())\n\t}\n\n\t// call KDF to derive user key\n\tnewkey.user, err = crypto.KDF(*params, newkey.Salt, password)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif template == nil {\n\t\t// generate new random master keys\n\t\tnewkey.master = crypto.NewRandomKey()\n\t} else {\n\t\t// copy master keys from old key\n\t\tnewkey.master = template\n\t}\n\n\t// encrypt master keys (as json) with user key\n\tbuf, err := json.Marshal(newkey.master)","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/restic/restic/blob/a80be1478a4c537f8396e0db2b05120aa78f11e0/internal/repository/key.go#L233-L269","documentation":"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.","triggerScenarios":"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.","commonSituations":"Minimal containers, chroots without proper /dev; long-running daemons at their fd limit; ancient kernels with entropy starvation.","solutions":["Verify /dev/urandom is available and readable in the environment","Raise the process fd limit before creating keys","Restart the container/host to restore the entropy source, then retry 'restic key add'"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure a working entropy source before key operations","Monitor fd usage in daemons that create keys"],"tags":["key","entropy","random","system","panic","go"],"backgroundTag":null,"analyzedSha":"a80be1478a4c537f8396e0db2b05120aa78f11e0","analyzedAt":"2026-08-15T15:30:29.928Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}