{"record":{"id":"bef12028c8605739","repo":"shadowsocks/shadowsocks-rust","slug":"aes-256","errorCode":null,"errorMessage":"AES-256","messagePattern":"AES-256","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks/src/relay/tcprelay/aead_2022.rs","lineNumber":324,"sourceCode":"                        return Err(ProtocolError::MissingExtendedIdentityHeader).into();\n                    }\n\n                    let (eih, remain_header_chunk) = header_chunk.split_at_mut(16);\n                    header_chunk = remain_header_chunk;\n\n                    let key_material = [key, salt].concat();\n                    let identity_sub_key = blake3::derive_key(AEAD2022_EIH_SUBKEY_CONTEXT, &key_material);\n                    let mut user_hash = Block::from([0u8; 16]);\n                    match self.method {\n                        CipherKind::AEAD2022_BLAKE3_AES_128_GCM => {\n                            let cipher = Aes128::new_from_slice(&identity_sub_key[0..16]).expect(\"AES-128\");\n                            cipher.decrypt_block_b2b(\n                                <&Block as TryFrom<&[u8]>>::try_from(eih).expect(\"EIH key length mismatch\"),\n                                &mut user_hash,\n                            );\n                        }\n                        CipherKind::AEAD2022_BLAKE3_AES_256_GCM => {\n                            let cipher = Aes256::new_from_slice(&identity_sub_key[0..32]).expect(\"AES-256\");\n                            cipher.decrypt_block_b2b(\n                                <&Block as TryFrom<&[u8]>>::try_from(eih).expect(\"EIH key length mismatch\"),\n                                &mut user_hash,\n                            );\n                        }\n                        _ => unreachable!(\"{} doesn't support EIH\", self.method),\n                    }\n\n                    let user_hash = user_hash.as_slice();\n                    trace!(\n                        \"server EIH {:?}, hash: {:?}\",\n                        ByteStr::new(eih),\n                        ByteStr::new(user_hash)\n                    );\n\n                    match user_manager.get_user_by_hash(user_hash) {\n                        None => {\n                            return Err(ProtocolError::InvalidClientUser(Bytes::copy_from_slice(user_hash))).into();","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks/src/relay/tcprelay/aead_2022.rs#L306-L342","documentation":"Counterpart for AES-256 methods: Aes256::new_from_slice(&identity_sub_key[0..32]).expect(\"AES-256\") unwraps the key-length conversion. Like the AES-128 case it is an internal invariant (blake3 derive_key supplies 32 bytes), so it should never fire in normal operation; a panic indicates the key material slicing/derivation was broken by a code or dependency change.","triggerScenarios":"Only reachable if blake3::derive_key returns fewer than 32 bytes or the 0..32 slice is altered — effectively a code bug, not a runtime condition users can trigger.","commonSituations":"Seen only during development after refactoring the EIH sub-key derivation or swapping the KDF/aes crates.","solutions":["Report a bug if encountered at runtime with crate versions","Propagate an error instead of expect when modifying the derivation code","After dependency upgrades, assert derive_key output length in tests"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"debug_assert!(identity_sub_key.len() >= 32, \"EIH sub-key too short\");","typeGuard":"fn key_material_ok(k: &[u8]) -> bool { k.len() >= 32 }","tryCatchPattern":"let cipher = Aes256::new_from_slice(&identity_sub_key[0..32])\n    .map_err(|_| ProtocolError::InvalidState)?;","preventionTips":["Add unit tests asserting derive_key output >= 32 bytes","Pin KDF and aes crate versions","Propagate errors instead of expect in derived code paths"],"tags":["rust","aead-2022","panic","cryptography"],"backgroundTag":"internal-invariant-violation","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"}