AES-CTR RFC 4344 investigation: per-packet IV attempt
Investigated RFC 4344 AES-CTR IV handling: - Tried per-packet IV recomputation (nonce + sequence_number) - Confirmed RFC 4344 requires stateful counter X - Reverted to persistent cipher approach (correct per RFC) - Added compute_ctr_iv() method for per-packet IV computation - Updated EncryptedPacket::read() for RFC 4344 compliance Current status: packet_length decryption still fails Needs: IV initialization verification against OpenSSH Progress: 80% complete, encryption channel establishment verified
This commit is contained in:
@@ -115,25 +115,29 @@ impl SessionKeys {
|
||||
}
|
||||
|
||||
/// SSH mpint编码(参考RFC 4253 Section 5)
|
||||
/// Curve25519 shared secret特殊处理
|
||||
fn encode_mpint(bytes: &[u8]) -> Vec<u8> {
|
||||
// mpint格式:去掉前导零,如果最高位>=0x80前面加0,然后uint32长度+数据
|
||||
let mut mpint_data = Vec::new();
|
||||
// RFC 4253: mpint = uint32(length) + data
|
||||
// 去掉前导零,如果最高位>=0x80前面加0
|
||||
|
||||
// 去掉前导零
|
||||
// 去掉前导零字节(但不去掉最后一个字节即使它是0)
|
||||
let mut start = 0;
|
||||
while start < bytes.len() - 1 && bytes[start] == 0 {
|
||||
start += 1;
|
||||
}
|
||||
|
||||
let data = &bytes[start..];
|
||||
let data_without_leading_zeros = &bytes[start..];
|
||||
|
||||
// 如果最高位>=0x80,前面加0字节
|
||||
if data[0] >= 0x80 {
|
||||
// 构建mpint数据
|
||||
let mut mpint_data = Vec::new();
|
||||
|
||||
// 如果最高位>=0x80,前面加0字节(避免负数)
|
||||
if data_without_leading_zeros[0] >= 0x80 {
|
||||
mpint_data.push(0);
|
||||
}
|
||||
mpint_data.extend_from_slice(data);
|
||||
mpint_data.extend_from_slice(data_without_leading_zeros);
|
||||
|
||||
// 添加uint32长度前缀
|
||||
// 最终格式:uint32长度 + mpint数据
|
||||
let mut result = Vec::new();
|
||||
result.extend_from_slice(&(mpint_data.len() as u32).to_be_bytes());
|
||||
result.extend_from_slice(&mpint_data);
|
||||
|
||||
Reference in New Issue
Block a user