{"record":{"id":"ef1f2a85b5297ab6","repo":"ory/hydra","slug":"cannot-create-xchacha20-poly1305-aead","errorCode":null,"errorMessage":"cannot create XChaCha20-Poly1305 AEAD","messagePattern":"cannot create XChaCha20-Poly1305 AEAD","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/aead/aead_oss.go","lineNumber":22,"sourceCode":"//go:build !commercial\n\n// Package aead provides the authenticated cipher (AEAD) that Ory uses to\n// seal opaque payloads such as pagination tokens.\npackage aead\n\nimport (\n\t\"crypto/cipher\"\n\n\t\"github.com/pkg/errors\"\n\t\"golang.org/x/crypto/chacha20poly1305\"\n)\n\n// New returns the XChaCha20-Poly1305 AEAD that seals opaque payloads under\n// the given key. Its 192-bit random nonce imposes no practical limit on the\n// number of payloads sealed per key.\nfunc New(key [32]byte) (cipher.AEAD, error) {\n\ta, err := chacha20poly1305.NewX(key[:])\n\treturn a, errors.Wrap(err, \"cannot create XChaCha20-Poly1305 AEAD\")\n}\n","sourceCodeStart":4,"sourceCodeEnd":24,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/aead/aead_oss.go#L4-L24","documentation":"New constructs an XChaCha20-Poly1305 AEAD cipher used to seal opaque payloads (like JWK encryption). It only fails if chacha20poly1305.NewX rejects the key; since the key is a fixed [32]byte, failure indicates the underlying crypto library could not initialize the cipher — practically never hit by key size, but wrapped for safety.","triggerScenarios":"chacha20poly1305.NewX returning an error — in current golang.org/x/crypto this only happens with keys not 32 bytes long, which is prevented by the [32]byte type, so it may occur from an incompatible/older x/crypto build or FIPS-restricted crypto environment.","commonSituations":"Builds with vendored/outdated golang.org/x/crypto; restricted environments (FIPS-only crypto policies) where ChaCha20-Poly1305 is disallowed; corrupt builds.","solutions":["Update golang.org/x/crypto to a current version (go get -u golang.org/x/crypto)","Check the environment for FIPS/restricted crypto policies that disable ChaCha20-Poly1305 and switch to AES-GCM-backed AEAD if supported","Rebuild the binary to ensure a consistent vendored crypto library","Inspect the wrapped cause (%+v) to see the exact error from chacha20poly1305.NewX"],"exampleFix":"// before\naead.New(key) // assumes XChaCha20 always available\n// after\na, err := aead.New(key)\nif err != nil {\n    // fall back or abort with a clear log\n    return errors.Wrap(err, \"AEAD init failed\")\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"a, err := aead.New(key)\nif err != nil {\n    return fmt.Errorf(\"AEAD unavailable: %w\", err) // inspect cause; check x/crypto version & FIPS policy\n}","preventionTips":["Keep golang.org/x/crypto up to date in go.mod","Confirm the deployment image permits ChaCha20-Poly1305 (non-FIPS-restricted crypto policy)","Fail fast at startup by initializing the AEAD once and reusing it","Log the wrapped cause with %+v to capture the underlying chacha20poly1305 error"],"tags":["crypto","aead","chacha20","initialization"],"backgroundTag":"aead-cipher-init-failed","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}