{"record":{"id":"1f82dfa50109c8fc","repo":"shadowsocks/shadowsocks-rust","slug":"method-don-t-know-how-to-generate-nonce","errorCode":null,"errorMessage":"{method} don't know how to generate nonce","messagePattern":"(.+?) don't know how to generate nonce","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks/src/context.rs","lineNumber":85,"sourceCode":"\n        #[cfg(any(feature = \"stream-cipher\", feature = \"aead-cipher\", feature = \"aead-cipher-2022\"))]\n        loop {\n            use crate::crypto::utils::random_iv_or_salt;\n\n            random_iv_or_salt(nonce);\n\n            // Salt already exists, generate a new one.\n            if unique && self.check_nonce_and_set(method, nonce) {\n                continue;\n            }\n\n            break;\n        }\n\n        #[cfg(not(any(feature = \"stream-cipher\", feature = \"aead-cipher\", feature = \"aead-cipher-2022\")))]\n        if !nonce.is_empty() {\n            let _ = unique;\n            panic!(\"{method} don't know how to generate nonce\");\n        }\n    }\n\n    /// Check nonce replay\n    pub fn check_nonce_replay(&self, method: CipherKind, nonce: &[u8]) -> io::Result<()> {\n        if nonce.is_empty() {\n            return Ok(());\n        }\n\n        #[allow(unused_mut)]\n        let mut replay_policy = self.replay_policy;\n\n        #[cfg(feature = \"aead-cipher-2022\")]\n        if method.is_aead_2022() {\n            // AEAD-2022 can't be ignored.\n            replay_policy = ReplayAttackPolicy::Reject;\n        }\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks/src/context.rs#L67-L103","documentation":"Context::generate_nonce panics when the configured cipher method has no nonce-generation implementation compiled in or supported. Nonce generation is only provided for stream, AEAD, and AEAD-2022 cipher features; with none enabled (e.g. method \"none\"/\"plain\" with empty nonce handling excluded) there is no way to fill the nonce buffer, so it fails fast. It reflects a feature/cipher mismatch rather than runtime data corruption.","triggerScenarios":"Calling `Context::generate_nonce` (directly or via from_stream_with_identity / encrypt_payload_aead / encrypt_client_payload_aead_2022 / encrypt_server_payload_aead_2022 / encrypt_payload_stream) when no cipher features (stream-cipher, aead-cipher, aead-cipher-2022) are enabled and the method yields a non-empty nonce requirement.","commonSituations":"Building shadowsocks-rust with default features disabled and then running with a cipher method; a client/server built without AEAD support negotiating AEAD methods; library users who compile with `default-features = false`.","solutions":["Rebuild with the cipher features enabled: enable `aead-cipher` (and/or `stream-cipher`, `aead-cipher-2022`)","Use a method supported by your build (e.g. plain/none if that is all you need)","Ensure client and server negotiate a method class that exists in both binaries"],"exampleFix":"// before (Cargo.toml)\nshadowsocks = { version = \"...\", default-features = false }\n// after\nshadowsocks = { version = \"...\", features = [\"aead-cipher\"] }","handlingStrategy":"validation","validationCode":"// only call generate_nonce for builds that support the method's cipher family\n#[cfg(any(feature = \"stream-cipher\", feature = \"aead-cipher\", feature = \"aead-cipher-2022\"))]\nctx.generate_nonce(method, &mut nonce, unique);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match Cargo features to the cipher methods you plan to use","Avoid `default-features = false` unless you re-enable needed features","Keep client and server feature sets symmetric","Add a smoke test that encrypts one payload with each supported method"],"tags":["panic","crypto","feature-flags","cipher"],"backgroundTag":"feature-not-enabled","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}